Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

manipulate updated_at in specs

ulfertse515ef9f8c4d
diff --git a/modules/backlogs/spec/models/burndown_spec.rb b/modules/backlogs/spec/models/burndown_spec.rb
index 01dcbf6417b..603a2424aac 100644
--- a/modules/backlogs/spec/models/burndown_spec.rb
+++ b/modules/backlogs/spec/models/burndown_spec.rb
@@ -28,14 +28,12 @@
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
-describe Burndown,
- type: :model,
- with_settings: { journal_aggregation_time_minutes: 0 } do
+describe Burndown, type: :model do
def set_attribute_journalized(story, attribute, value, day)
story.reload
story.send(attribute, value)
story.save!
- story.last_journal.update(created_at: day)
+ story.last_journal.update(created_at: day, updated_at: day)
end
let(:user) { @user ||= create(:user) }
@@ -110,97 +108,96 @@ describe Burndown,
end
describe 'WITH 1 story assigned to the sprint' do
- before do
- @story = build(:story, subject: 'Story 1',
- project:,
- version:,
- type: type_feature,
- status: issue_open,
- priority: issue_priority,
- created_at: Date.today - 20.days,
- updated_at: Date.today - 20.days)
+ let(:story) do
+ build(:story, subject: 'Story 1',
+ project:,
+ version:,
+ type: type_feature,
+ status: issue_open,
+ priority: issue_priority,
+ created_at: Date.today - 20.days,
+ updated_at: Date.today - 20.days)
end
describe 'WITH the story having story_point defined on creation' do
before do
- @story.story_points = 9
- @story.save!
- @story.last_journal.update_attribute(:created_at, @story.created_at)
+ story.story_points = 9
+ story.save!
+ story.last_journal.update_columns(created_at: story.created_at, updated_at: story.created_at)
end
+ subject(:burndown) { Burndown.new(sprint, project) }
+
describe 'WITH the story being closed and opened again within the sprint duration' do
- before do
- set_attribute_journalized @story, :status_id=, issue_closed.id, Time.now - 6.days
- set_attribute_journalized @story, :status_id=, issue_open.id, Time.now - 3.days
- @burndown = Burndown.new(sprint, project)
+ before do
+ set_attribute_journalized story, :status_id=, issue_closed.id, Time.now - 6.days
+ set_attribute_journalized story, :status_id=, issue_open.id, Time.now - 3.days
end
- it { expect(@burndown.story_points).to eql [9.0, 0.0, 0.0, 0.0, 9.0, 9.0] }
- it { expect(@burndown.story_points.unit).to be :points }
- it { expect(@burndown.days).to eql(sprint.days) }
- it { expect(@burndown.max[:hours]).to be 0.0 }
- it { expect(@burndown.max[:points]).to be 9.0 }
- it { expect(@burndown.story_points_ideal).to eql [9.0, 8.0, 7.0, 6.0, 5.0, 4.0, 3.0, 2.0, 1.0, 0.0] }
+ it { expect(burndown.story_points).to eql [9.0, 0.0, 0.0, 0.0, 9.0, 9.0] }
+ it { expect(burndown.story_points.unit).to be :points }
+ it { expect(burndown.days).to eql(sprint.days) }
+ it { expect(burndown.max[:hours]).to be 0.0 }
+ it { expect(burndown.max[:points]).to be 9.0 }
+ it { expect(burndown.story_points_ideal).to eql [9.0, 8.0, 7.0, 6.0, 5.0, 4.0, 3.0, 2.0, 1.0, 0.0] }
end
describe "WITH the story marked as resolved and consequently 'done'" do
before do
- set_attribute_journalized @story, :status_id=, issue_resolved.id, Time.now - 6.days
- set_attribute_journalized @story, :status_id=, issue_open.id, Time.now - 3.days
+ set_attribute_journalized story, :status_id=, issue_resolved.id, Time.now - 6.days
+ set_attribute_journalized story, :status_id=, issue_open.id, Time.now - 3.days
project.done_statuses << issue_resolved
- @burndown = Burndown.new(sprint, project)
end
- it { expect(@story.done?).to be false }
- it { expect(@burndown.story_points).to eql [9.0, 0.0, 0.0, 0.0, 9.0, 9.0] }
+ it { expect(story.done?).to be false }
+ it { expect(burndown.story_points).to eql [9.0, 0.0, 0.0, 0.0, 9.0, 9.0] }
end
end
end
describe 'WITH 10 stories assigned to the sprint' do
- before do
- @stories = []
+ let!(:stories) do
+ stories = []
(0..9).each do |i|
- @stories[i] = create(:story, subject: "Story #{i}",
- project:,
- version:,
- type: type_feature,
- status: issue_open,
- priority: issue_priority,
- created_at: Date.today - (20 - i).days,
- updated_at: Date.today - (20 - i).days)
- @stories[i].last_journal.update_attribute(:created_at, @stories[i].created_at)
+ stories[i] = create(:story, subject: "Story #{i}",
+ project:,
+ version:,
+ type: type_feature,
+ status: issue_open,
+ priority: issue_priority,
+ created_at: Date.today - (20 - i).days,
+ updated_at: Date.today - (20 - i).days)
+ stories[i].last_journal.update_columns(created_at: stories[i].created_at, updated_at: stories[i].created_at)
end
+
+ stories
end
describe 'WITH each story having story points defined at start' do
before do
- @stories.each_with_index do |s, _i|
+ stories.each_with_index do |s, _i|
set_attribute_journalized s, :story_points=, 10, version.start_date - 3.days
end
end
describe 'WITH 5 stories having been reduced to 0 story points, one story per day' do
before do
- @finished_hours
(0..4).each do |i|
- set_attribute_journalized @stories[i], :story_points=, nil, version.start_date + i.days + 1.hour
+ set_attribute_journalized stories[i], :story_points=, nil, version.start_date + i.days + 1.hour
end
end
describe 'THEN' do
- before do
- @burndown = Burndown.new(sprint, project)
- end
-
- it { expect(@burndown.story_points).to eql [90.0, 80.0, 70.0, 60.0, 50.0, 50.0] }
- it { expect(@burndown.story_points.unit).to be :points }
- it { expect(@burndown.days).to eql(sprint.days) }
- it { expect(@burndown.max[:hours]).to be 0.0 }
- it { expect(@burndown.max[:points]).to be 90.0 }
- it { expect(@burndown.story_points_ideal).to eql [90.0, 80.0, 70.0, 60.0, 50.0, 40.0, 30.0, 20.0, 10.0, 0.0] }
+ subject(:burndown) { Burndown.new(sprint, project) }
+
+ it { expect(burndown.story_points).to eql [90.0, 80.0, 70.0, 60.0, 50.0, 50.0] }
+ it { expect(burndown.story_points.unit).to be :points }
+ it { expect(burndown.days).to eql(sprint.days) }
+ it { expect(burndown.max[:hours]).to be 0.0 }
+ it { expect(burndown.max[:points]).to be 90.0 }
+ it { expect(burndown.story_points_ideal).to eql [90.0, 80.0, 70.0, 60.0, 50.0, 40.0, 30.0, 20.0, 10.0, 0.0] }
end
end
end
diff --git a/spec/features/work_packages/edit_work_package_spec.rb b/spec/features/work_packages/edit_work_package_spec.rb
index fc60340c9f4..1d07ea46fd9 100644
--- a/spec/features/work_packages/edit_work_package_spec.rb
+++ b/spec/features/work_packages/edit_work_package_spec.rb
@@ -1,7 +1,8 @@
require 'spec_helper'
require 'features/page_objects/notification'
-describe 'edit work package', js: true do
+describe 'edit work package',
+ js: true do
let(:dev_role) do
create :role,
permissions: %i[view_work_packages
@@ -56,7 +57,8 @@ describe 'edit work package', js: true do
created_at: 5.days.ago.to_date.to_fs(:db))
note_journal = work_package.journals.last
- note_journal.update_column(:created_at, 5.days.ago.to_date.to_fs(:db))
+ note_journal.update_columns(created_at: 5.days.ago.to_date.to_fs(:db),
+ updated_at: 5.days.ago.to_date.to_fs(:db))
work_package
end
diff --git a/spec/features/work_packages/tabs/activity_revisions_spec.rb b/spec/features/work_packages/tabs/activity_revisions_spec.rb
index 6116b9e5af4..0c73710e7cc 100644
--- a/spec/features/work_packages/tabs/activity_revisions_spec.rb
+++ b/spec/features/work_packages/tabs/activity_revisions_spec.rb
@@ -8,7 +8,7 @@ describe 'Activity tab', js: true, selenium: true do
work_package.update(attributes.merge(updated_at: at))
note_journal = work_package.journals.last
- note_journal.update(created_at: at, user:)
+ note_journal.update(created_at: at, updated_at: at, user:)
end
let(:project) { create :project_with_types, public: true }
@@ -20,7 +20,8 @@ describe 'Activity tab', js: true, selenium: true do
journal_notes: initial_comment)
note_journal = work_package.journals.last
- note_journal.update(created_at: 5.days.ago.to_date.to_s)
+ note_journal.update(created_at: 5.days.ago.to_date.to_s,
+ updated_at: 5.days.ago.to_date.to_s)
work_package
end
@@ -34,7 +35,7 @@ describe 'Activity tab', js: true, selenium: true do
work_package.journals[0]
end
- let!(:note_1) do
+ let!(:note1) do
attributes = { subject: 'New subject', description: 'Some not so long description.' }
alter_work_package_at(work_package,
@@ -45,7 +46,7 @@ describe 'Activity tab', js: true, selenium: true do
work_package.journals.last
end
- let!(:note_2) do
+ let!(:note2) do
attributes = { journal_notes: 'Another comment by a different user' }
alter_work_package_at(work_package,
@@ -92,8 +93,7 @@ describe 'Activity tab', js: true, selenium: true do
idx + 1
end
- date_selector = ".work-package-details-activities-activity:nth-of-type(#{actual_index}) " +
- '.activity-date'
+ date_selector = ".work-package-details-activities-activity:nth-of-type(#{actual_index}) .activity-date"
# Do not use :long format to match the printed date without double spaces
# on the first 9 days of the month
expected_date = if activity.is_a?(Journal)
@@ -107,13 +107,13 @@ describe 'Activity tab', js: true, selenium: true do
activity = page.find("#activity-#{idx + 1}")
- if activity.is_a?(Journal) && activity.id != note_1.id
+ if activity.is_a?(Journal) && activity.id != note1.id
expect(activity).to have_selector('.user', text: activity.user.name)
expect(activity).to have_selector('.user-comment > .message', text: activity.notes, visible: :all)
elsif activity.is_a?(Changeset)
expect(activity).to have_selector('.user', text: User.find(activity.user_id).name)
expect(activity).to have_selector('.user-comment > .message', text: activity.notes, visible: :all)
- elsif activity == note_1
+ elsif activity == note1
expect(activity).to have_selector('.work-package-details-activities-messages .message',
count: 2)
expect(activity).to have_selector('.message',
@@ -128,8 +128,6 @@ describe 'Activity tab', js: true, selenium: true do
before do
work_package_page.visit_tab! 'activity'
work_package_page.ensure_page_loaded
- expect(page).to have_selector('.user-comment > .message',
- text: initial_comment)
end
context 'with permission' do
@@ -144,7 +142,7 @@ describe 'Activity tab', js: true, selenium: true do
member_through_role: role)
end
let(:activities) do
- [initial_note, note_1, revision, note_2]
+ [initial_note, note1, revision, note2]
end
context 'with ascending comments' do
@@ -161,7 +159,7 @@ describe 'Activity tab', js: true, selenium: true do
it 'can toggle between activities and comments-only' do
expect(page).to have_selector('.work-package-details-activities-activity-contents', count: 4)
- expect(page).to have_selector('.user-comment > .message', text: note_2.notes)
+ expect(page).to have_selector('.user-comment > .message', text: note2.notes)
# Show only comments
find('.activity-comments--toggler').click
@@ -169,7 +167,7 @@ describe 'Activity tab', js: true, selenium: true do
# It should remove the middle
expect(page).to have_selector('.work-package-details-activities-activity-contents', count: 2)
expect(page).to have_selector('.user-comment > .message', text: initial_comment)
- expect(page).to have_selector('.user-comment > .message', text: note_2.notes)
+ expect(page).to have_selector('.user-comment > .message', text: note2.notes)
# Show all again
find('.activity-comments--toggler').click
@@ -223,7 +221,7 @@ describe 'Activity tab', js: true, selenium: true do
member_through_role: role)
end
let(:activities) do
- [initial_note, note_1, note_2]
+ [initial_note, note1, note2]
end
context 'with ascending comments' do
@@ -233,18 +231,18 @@ describe 'Activity tab', js: true, selenium: true do
end
it 'shows the activities, but does not allow commenting' do
- expect(page).not_to have_selector('.work-packages--activity--add-comment', visible: true)
+ expect(page).not_to have_selector('.work-packages--activity--add-comment', visible: :visible)
end
end
end
- context 'split screen' do
+ context 'when on the split screen' do
let(:work_package_page) { Pages::SplitWorkPackage.new(work_package, project) }
it_behaves_like 'activity tab'
end
- context 'full screen' do
+ context 'when on the full screen' do
let(:work_package_page) { Pages::FullWorkPackage.new(work_package) }
it_behaves_like 'activity tab'
diff --git a/spec/features/work_packages/tabs/activity_tab_spec.rb b/spec/features/work_packages/tabs/activity_tab_spec.rb
index 376fa39536e..b828611632d 100644
--- a/spec/features/work_packages/tabs/activity_tab_spec.rb
+++ b/spec/features/work_packages/tabs/activity_tab_spec.rb
@@ -31,12 +31,14 @@ require 'spec_helper'
require 'features/work_packages/work_packages_page'
require 'support/edit_fields/edit_field'
-describe 'Activity tab', js: true, selenium: true do
+describe 'Activity tab',
+ js: true,
+ selenium: true do
def alter_work_package_at(work_package, attributes:, at:, user: User.current)
work_package.update(attributes.merge(updated_at: at))
note_journal = work_package.journals.last
- note_journal.update(created_at: at, user:)
+ note_journal.update(created_at: at, updated_at: at, user:)
end
let(:project) { create :project_with_types, public: true }
@@ -48,7 +50,7 @@ describe 'Activity tab', js: true, selenium: true do
journal_notes: initial_comment)
note_journal = work_package.journals.last
- note_journal.update(created_at: 5.days.ago.to_date.to_s)
+ note_journal.update(created_at: 5.days.ago.to_date.to_s, updated_at: 5.days.ago.to_date.to_s)
work_package
end
diff --git a/spec/features/work_packages/work_package_workflow_form_spec.rb b/spec/features/work_packages/work_package_workflow_form_spec.rb
index 81e781d153c..068dee52b87 100644
--- a/spec/features/work_packages/work_package_workflow_form_spec.rb
+++ b/spec/features/work_packages/work_package_workflow_form_spec.rb
@@ -53,7 +53,8 @@ describe 'Work package transitive status workflows', js: true do
created_at: 5.days.ago.to_date.to_fs(:db)
note_journal = work_package.journals.last
- note_journal.update(created_at: 5.days.ago.to_date.to_s)
+ note_journal.update(created_at: 5.days.ago.to_date.to_s,
+ updated_at: 5.days.ago.to_date.to_s)
work_package
end