Commit c1bf7fa7 authored by Mayra Cabrera's avatar Mayra Cabrera

Merge branch 'ce-to-ee-2018-05-10' into 'master'

CE upstream - 2018-05-10 12:23 UTC

Closes charts/gitlab#396

See merge request gitlab-org/gitlab-ee!5655
parents 7ffa2b89 0a2fda86
...@@ -30,6 +30,8 @@ module TimeTrackable ...@@ -30,6 +30,8 @@ module TimeTrackable
return if @time_spent == 0 return if @time_spent == 0
touch if touchable?
if @time_spent == :reset if @time_spent == :reset
reset_spent_time reset_spent_time
else else
...@@ -53,6 +55,10 @@ module TimeTrackable ...@@ -53,6 +55,10 @@ module TimeTrackable
private private
def touchable?
valid? && persisted?
end
def reset_spent_time def reset_spent_time
timelogs.new(time_spent: total_time_spent * -1, user: @time_spent_user) # rubocop:disable Gitlab/ModuleWithInstanceVariables timelogs.new(time_spent: total_time_spent * -1, user: @time_spent_user) # rubocop:disable Gitlab/ModuleWithInstanceVariables
end end
......
---
title: Updates updated_at on issuable when setting time spent
merge_request: 18757
author: Jacopo Beschi @jacopo-beschi
type: added
...@@ -579,6 +579,11 @@ module Gitlab ...@@ -579,6 +579,11 @@ module Gitlab
count_commits(from: from, to: to, **options) count_commits(from: from, to: to, **options)
end end
# Counts the amount of commits between `from` and `to`.
def count_commits_between(from, to, options = {})
count_commits(from: from, to: to, **options)
end
# old_rev and new_rev are commit ID's # old_rev and new_rev are commit ID's
# the result of this method is an array of Gitlab::Git::RawDiffChange # the result of this method is an array of Gitlab::Git::RawDiffChange
def raw_changes_between(old_rev, new_rev) def raw_changes_between(old_rev, new_rev)
......
module QA::Page module QA::Page
module Project::Job module Project::Job
class Show < QA::Page::Base class Show < QA::Page::Base
COMPLETED_STATUSES = %w[passed failed canceled blocked skipped manual].freeze # excludes created, pending, running
PASSED_STATUS = 'passed'.freeze
view 'app/views/projects/jobs/show.html.haml' do view 'app/views/projects/jobs/show.html.haml' do
element :build_output, '.js-build-output' element :build_output, '.js-build-output'
end end
def output view 'app/assets/javascripts/vue_shared/components/ci_badge_link.vue' do
css = '.js-build-output' element :status_badge, 'ci-status'
end
wait(reload: false) do def completed?
has_css?(css) COMPLETED_STATUSES.include? find('.ci-status').text
end end
find(css).text def passed?
find('.ci-status').text == PASSED_STATUS
end
# Reminder: You may wish to wait for a particular job status before checking output
def output
find('.js-build-output').text
end end
end end
end end
......
...@@ -87,16 +87,12 @@ module QA ...@@ -87,16 +87,12 @@ module QA
Page::Project::Show.act { wait_for_push } Page::Project::Show.act { wait_for_push }
Page::Menu::Side.act { click_ci_cd_pipelines } Page::Menu::Side.act { click_ci_cd_pipelines }
Page::Project::Pipeline::Index.act { go_to_latest_pipeline } Page::Project::Pipeline::Index.act { go_to_latest_pipeline }
Page::Project::Pipeline::Show.act { go_to_first_job }
Page::Project::Pipeline::Show.act do
go_to_first_job
wait do
!has_content?('running')
end
end
Page::Project::Job::Show.perform do |job| Page::Project::Job::Show.perform do |job|
job.wait(reload: false) { job.completed? }
expect(job.passed?).to be_truthy, "Job status did not become \"passed\"."
expect(job.output).to include(sha1sum) expect(job.output).to include(sha1sum)
end end
end end
......
...@@ -512,6 +512,14 @@ describe Issuable do ...@@ -512,6 +512,14 @@ describe Issuable do
expect(issue.total_time_spent).to eq(1800) expect(issue.total_time_spent).to eq(1800)
end end
it 'updates issues updated_at' do
issue
Timecop.travel(1.minute.from_now) do
expect { spend_time(1800) }.to change { issue.updated_at }
end
end
end end
context 'substracting time' do context 'substracting time' do
...@@ -527,9 +535,13 @@ describe Issuable do ...@@ -527,9 +535,13 @@ describe Issuable do
context 'when time to substract exceeds the total time spent' do context 'when time to substract exceeds the total time spent' do
it 'raise a validation error' do it 'raise a validation error' do
expect do Timecop.travel(1.minute.from_now) do
spend_time(-3600) expect do
end.to raise_error(ActiveRecord::RecordInvalid) expect do
spend_time(-3600)
end.to raise_error(ActiveRecord::RecordInvalid)
end.not_to change { issue.updated_at }
end
end end
end end
end end
......
...@@ -70,8 +70,12 @@ shared_examples 'time tracking endpoints' do |issuable_name| ...@@ -70,8 +70,12 @@ shared_examples 'time tracking endpoints' do |issuable_name|
end end
it "add spent time for #{issuable_name}" do it "add spent time for #{issuable_name}" do
post api("/projects/#{project.id}/#{issuable_collection_name}/#{issuable.iid}/add_spent_time", user), Timecop.travel(1.minute.from_now) do
duration: '2h' expect do
post api("/projects/#{project.id}/#{issuable_collection_name}/#{issuable.iid}/add_spent_time", user),
duration: '2h'
end.to change { issuable.reload.updated_at }
end
expect(response).to have_gitlab_http_status(201) expect(response).to have_gitlab_http_status(201)
expect(json_response['human_total_time_spent']).to eq('2h') expect(json_response['human_total_time_spent']).to eq('2h')
...@@ -79,7 +83,11 @@ shared_examples 'time tracking endpoints' do |issuable_name| ...@@ -79,7 +83,11 @@ shared_examples 'time tracking endpoints' do |issuable_name|
context 'when subtracting time' do context 'when subtracting time' do
it 'subtracts time of the total spent time' do it 'subtracts time of the total spent time' do
issuable.update_attributes!(spend_time: { duration: 7200, user_id: user.id }) Timecop.travel(1.minute.from_now) do
expect do
issuable.update_attributes!(spend_time: { duration: 7200, user_id: user.id })
end.to change { issuable.reload.updated_at }
end
post api("/projects/#{project.id}/#{issuable_collection_name}/#{issuable.iid}/add_spent_time", user), post api("/projects/#{project.id}/#{issuable_collection_name}/#{issuable.iid}/add_spent_time", user),
duration: '-1h' duration: '-1h'
...@@ -93,8 +101,12 @@ shared_examples 'time tracking endpoints' do |issuable_name| ...@@ -93,8 +101,12 @@ shared_examples 'time tracking endpoints' do |issuable_name|
it 'does not modify the total time spent' do it 'does not modify the total time spent' do
issuable.update_attributes!(spend_time: { duration: 7200, user_id: user.id }) issuable.update_attributes!(spend_time: { duration: 7200, user_id: user.id })
post api("/projects/#{project.id}/#{issuable_collection_name}/#{issuable.iid}/add_spent_time", user), Timecop.travel(1.minute.from_now) do
duration: '-1w' expect do
post api("/projects/#{project.id}/#{issuable_collection_name}/#{issuable.iid}/add_spent_time", user),
duration: '-1w'
end.not_to change { issuable.reload.updated_at }
end
expect(response).to have_gitlab_http_status(400) expect(response).to have_gitlab_http_status(400)
expect(json_response['message']['time_spent'].first).to match(/exceeds the total time spent/) expect(json_response['message']['time_spent'].first).to match(/exceeds the total time spent/)
...@@ -110,7 +122,11 @@ shared_examples 'time tracking endpoints' do |issuable_name| ...@@ -110,7 +122,11 @@ shared_examples 'time tracking endpoints' do |issuable_name|
end end
it "resets spent time for #{issuable_name}" do it "resets spent time for #{issuable_name}" do
post api("/projects/#{project.id}/#{issuable_collection_name}/#{issuable.iid}/reset_spent_time", user) Timecop.travel(1.minute.from_now) do
expect do
post api("/projects/#{project.id}/#{issuable_collection_name}/#{issuable.iid}/reset_spent_time", user)
end.to change { issuable.reload.updated_at }
end
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(200)
expect(json_response['total_time_spent']).to eq(0) expect(json_response['total_time_spent']).to eq(0)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment