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

replace create_journal methods in specs

ulferts479e4d259b6e
diff --git a/spec/factories/journal_factory.rb b/spec/factories/journal_factory.rb
index ccfd9d4eb91..c75222c4c20 100644
--- a/spec/factories/journal_factory.rb
+++ b/spec/factories/journal_factory.rb
@@ -30,6 +30,7 @@ FactoryBot.define do
factory :journal do
user factory: :user
created_at { Time.zone.now }
+ updated_at { created_at }
validity_period { created_at..Float::INFINITY }
sequence(:version, 1)
diff --git a/spec/factories/work_package_factory.rb b/spec/factories/work_package_factory.rb
index 397942c1592..29d06e8c61e 100644
--- a/spec/factories/work_package_factory.rb
+++ b/spec/factories/work_package_factory.rb
@@ -96,18 +96,28 @@ FactoryBot.define do
if evaluator.journals.present?
work_package.journals.destroy_all
- evaluator.journals.each do |timestamp, attributes|
+ evaluator.journals.each_with_index do |(timestamp, attributes), version|
work_package_attributes = work_package.attributes.except("id")
- journal_attributes = work_package_attributes \
- .extract!(*Journal::WorkPackageJournal.attribute_names) \
- .symbolize_keys.merge(attributes)
+
+ journal_attributes = attributes
+ .extract!(*Journal.attribute_names.map(&:to_sym) + %i[user])
+ .reverse_merge(journable: work_package,
+ created_at: timestamp,
+ updated_at: timestamp,
+ version: version + 1)
+
+ data_attributes = work_package_attributes
+ .extract!(*Journal::WorkPackageJournal.attribute_names)
+ .symbolize_keys
+ .merge(attributes)
+
create(:work_package_journal,
- journable: work_package,
- created_at: timestamp,
- updated_at: timestamp,
- data: build(:journal_work_package_journal, journal_attributes))
+ **journal_attributes,
+ data: build(:journal_work_package_journal, data_attributes))
end
+ work_package.journals.reload
+
work_package.update_columns(created_at: work_package.journals.minimum(:created_at),
updated_at: work_package.journals.maximum(:updated_at))
end
diff --git a/spec/features/work_packages/edit_work_package_spec.rb b/spec/features/work_packages/edit_work_package_spec.rb
index 382304281f0..df3816c95b8 100644
--- a/spec/features/work_packages/edit_work_package_spec.rb
+++ b/spec/features/work_packages/edit_work_package_spec.rb
@@ -50,17 +50,12 @@ RSpec.describe 'edit work package',
let(:type2) { create(:type, custom_fields: [cf_all, cf_tp2]) }
let(:project) { create(:project, types: [type, type2]) }
let(:work_package) do
- work_package = create(:work_package,
- author: dev,
- project:,
- type:,
- created_at: 5.days.ago.to_date.to_fs(:db))
-
- note_journal = work_package.journals.reload.last
- 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
+ create(:work_package,
+ :created_in_past,
+ author: dev,
+ project:,
+ created_at: 5.days.ago,
+ type:)
end
let(:status) { work_package.status }
diff --git a/spec/features/work_packages/tabs/activity_notifications_spec.rb b/spec/features/work_packages/tabs/activity_notifications_spec.rb
index a906a8dc7d1..ed2aca1af31 100644
--- a/spec/features/work_packages/tabs/activity_notifications_spec.rb
+++ b/spec/features/work_packages/tabs/activity_notifications_spec.rb
@@ -6,18 +6,14 @@ require 'support/edit_fields/edit_field'
RSpec.describe 'Activity tab notifications', js: true, selenium: true do
shared_let(:project) { create(:project_with_types, public: true) }
shared_let(:work_package) do
- work_package = create(:work_package,
- project:,
- created_at: 5.days.ago.to_date.to_fs(:db))
-
- work_package.update({ journal_notes: 'First comment on this wp.',
- updated_at: 5.days.ago.to_date.to_s })
- work_package.update({ journal_notes: 'Second comment on this wp.',
- updated_at: 4.days.ago.to_date.to_s })
- work_package.update({ journal_notes: 'Third comment on this wp.',
- updated_at: 3.days.ago.to_date.to_s })
-
- work_package
+ create(:work_package,
+ project:,
+ journals: {
+ 6.days.ago => {},
+ 5.days.ago => { notes: 'First comment on this wp.' },
+ 4.days.ago => { notes: 'Second comment on this wp.' },
+ 3.days.ago => { notes: 'Third comment on this wp.' }
+ })
end
shared_let(:admin) { create(:admin) }
@@ -35,7 +31,7 @@ RSpec.describe 'Activity tab notifications', js: true, selenium: true do
it 'shows a notification icon next to activities that have an unread notification' do
expect(page).to have_selector('[data-qa-selector="user-activity-bubble"]', count: 1)
- expect(page).to have_selector('[data-qa-activity-number="3"] [data-qa-selector="user-activity-bubble"]')
+ expect(page).to have_selector('[data-qa-activity-number="4"] [data-qa-selector="user-activity-bubble"]')
end
it 'shows a button to mark the notifications as read' do
diff --git a/spec/features/work_packages/tabs/activity_revisions_spec.rb b/spec/features/work_packages/tabs/activity_revisions_spec.rb
index 568ea2dffc0..9fbbf0e842d 100644
--- a/spec/features/work_packages/tabs/activity_revisions_spec.rb
+++ b/spec/features/work_packages/tabs/activity_revisions_spec.rb
@@ -3,28 +3,24 @@ require 'spec_helper'
require 'features/work_packages/work_packages_page'
require 'support/edit_fields/edit_field'
-RSpec.describe 'Activity tab', js: true, selenium: true do
- def alter_work_package_at(work_package, attributes:, at:, user:)
- work_package.update(attributes.merge(updated_at: at))
+RSpec.describe 'Activity tab', js: true, with_cuprite: true do
+ let(:project) { create(:project_with_types, public: true) }
- note_journal = work_package.journals.reorder(:id).last
- note_journal.update(created_at: at, updated_at: at, user:)
- end
+ let(:creation_time) { 5.days.ago }
+ let(:subject_change_time) { 3.days.ago }
+ let(:revision_time) { 2.days.ago }
+ let(:comment_time) { 1.day.ago }
- let(:project) { create(:project_with_types, public: true) }
let!(:work_package) do
- at = 5.days.ago.to_date.to_fs(:db)
- work_package = create(:work_package,
- project:,
- created_at: at,
- subject: initial_subject,
- journal_notes: initial_comment)
-
- note_journal = work_package.journals.reorder(:id).last
- note_journal.update(created_at: 5.days.ago.to_date.to_fs(:db),
- updated_at: 5.days.ago.to_date.to_fs(:db))
-
- work_package
+ create(:work_package,
+ project:,
+ created_at: creation_time,
+ subject: initial_subject,
+ journals: {
+ creation_time => { notes: initial_comment },
+ subject_change_time => { subject: 'New subject', description: 'Some not so long description.' },
+ comment_time => { notes: 'A comment by a different user', user: create(:admin) }
+ })
end
let(:initial_subject) { 'My Subject' }
@@ -32,31 +28,11 @@ RSpec.describe 'Activity tab', js: true, selenium: true do
let(:comments_in_reverse) { false }
let(:activity_tab) { Components::WorkPackages::Activities.new(work_package) }
- let(:initial_note) do
+ let(:creation_journal) do
work_package.journals.reload.first
end
-
- let!(:note1) do
- attributes = { subject: 'New subject', description: 'Some not so long description.' }
-
- alter_work_package_at(work_package,
- attributes:,
- at: 3.days.ago.to_date.to_fs(:db),
- user:)
-
- work_package.journals.reorder(:id).last
- end
-
- let!(:note2) do
- attributes = { journal_notes: 'Another comment by a different user' }
-
- alter_work_package_at(work_package,
- attributes:,
- at: 1.day.ago.to_date.to_fs(:db),
- user: create(:admin))
-
- work_package.journals.reorder(:id).last
- end
+ let(:subject_change_journal) { work_package.journals[1] }
+ let(:comment_journal) { work_package.journals[2] }
let!(:revision) do
repo = build(:repository_subversion,
@@ -68,7 +44,7 @@ RSpec.describe 'Activity tab', js: true, selenium: true do
changeset = build(:changeset,
comments: 'A comment on a changeset',
- committed_on: 2.days.ago.to_date.to_fs(:db),
+ committed_on: revision_time,
repository: repo,
committer: '[email protected]')
@@ -77,8 +53,9 @@ RSpec.describe 'Activity tab', js: true, selenium: true do
changeset
end
+ current_user { user }
+
before do
- login_as(user)
allow(user.pref).to receive(:warn_on_leaving_unsaved?).and_return(false)
allow(user.pref).to receive(:comments_sorting).and_return(comments_in_reverse ? 'desc' : 'asc')
allow(user.pref).to receive(:comments_in_reverse_order?).and_return(comments_in_reverse)
@@ -108,13 +85,13 @@ RSpec.describe 'Activity tab', js: true, selenium: true do
activity = page.find("#activity-#{idx + 1}")
- if activity.is_a?(Journal) && activity.id != note1.id
+ if activity.is_a?(Journal) && activity.id != subject_change_journal.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 == note1
+ elsif activity == subject_change_journal
expect(activity).to have_selector('.work-package-details-activities-messages .message',
count: 2)
expect(activity).to have_selector('.message',
@@ -143,7 +120,7 @@ RSpec.describe 'Activity tab', js: true, selenium: true do
member_through_role: role)
end
let(:activities) do
- [initial_note, note1, revision, note2]
+ [creation_journal, subject_change_journal, revision, comment_journal]
end
context 'with ascending comments' do
@@ -160,7 +137,7 @@ RSpec.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: note2.notes)
+ expect(page).to have_selector('.user-comment > .message', text: comment_journal.notes)
# Show only comments
find('.activity-comments--toggler').click
@@ -168,7 +145,7 @@ RSpec.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: note2.notes)
+ expect(page).to have_selector('.user-comment > .message', text: comment_journal.notes)
# Show all again
find('.activity-comments--toggler').click
@@ -222,7 +199,7 @@ RSpec.describe 'Activity tab', js: true, selenium: true do
member_through_role: role)
end
let(:activities) do
- [initial_note, note1, note2]
+ [creation_journal, subject_change_journal, comment_journal]
end
context 'with ascending comments' do
diff --git a/spec/features/work_packages/tabs/activity_tab_spec.rb b/spec/features/work_packages/tabs/activity_tab_spec.rb
index 8f635421175..c9011f90360 100644
--- a/spec/features/work_packages/tabs/activity_tab_spec.rb
+++ b/spec/features/work_packages/tabs/activity_tab_spec.rb
@@ -33,26 +33,24 @@ require 'support/edit_fields/edit_field'
RSpec.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, updated_at: at, user:)
- end
-
+ with_cuprite: true do
let(:project) { create(:project_with_types, public: true) }
- let!(:work_package) do
- work_package = create(:work_package,
- project:,
- created_at: 5.days.ago.to_date.to_fs(:db),
- subject: initial_subject,
- journal_notes: initial_comment)
- note_journal = work_package.journals.reload.last
- note_journal.update(created_at: 5.days.ago.to_date.to_s, updated_at: 5.days.ago.to_date.to_s)
+ let(:creation_time) { 5.days.ago }
+ let(:subject_change_time) { 3.days.ago }
+ let(:revision_time) { 2.days.ago }
+ let(:comment_time) { 1.day.ago }
- work_package
+ let!(:work_package) do
+ create(:work_package,
+ project:,
+ created_at: creation_time,
+ subject: initial_subject,
+ journals: {
+ creation_time => { notes: initial_comment },
+ subject_change_time => { subject: 'New subject', description: 'Some not so long description.' },
+ comment_time => { notes: 'A comment by a different user', user: create(:admin) }
+ })
end
let(:initial_subject) { 'My Subject' }
@@ -60,34 +58,15 @@ RSpec.describe 'Activity tab',
let(:comments_in_reverse) { false }
let(:activity_tab) { Components::WorkPackages::Activities.new(work_package) }
- let(:initial_note) do
- work_package.journals.reload[0]
- end
-
- let!(:note1) do
- attributes = { subject: 'New subject', description: 'Some not so long description.' }
-
- alter_work_package_at(work_package,
- attributes:,
- at: 3.days.ago.to_date.to_fs(:db),
- user:)
-
- work_package.journals.reload.last
+ let(:creation_journal) do
+ work_package.journals.reload.first
end
+ let(:subject_change_journal) { work_package.journals[1] }
+ let(:comment_journal) { work_package.journals[2] }
- let!(:note2) do
- attributes = { journal_notes: 'Another comment by a different user' }
-
- alter_work_package_at(work_package,
- attributes:,
- at: 1.day.ago.to_date.to_fs(:db),
- user: create(:admin))
-
- work_package.journals.reload.last
- end
+ current_user { user }
before do
- login_as(user)
allow(user.pref).to receive(:warn_on_leaving_unsaved?).and_return(false)
allow(user.pref).to receive(:comments_sorting).and_return(comments_in_reverse ? 'desc' : 'asc')
allow(user.pref).to receive(:comments_in_reverse_order?).and_return(comments_in_reverse)
@@ -95,7 +74,7 @@ RSpec.describe 'Activity tab',
shared_examples 'shows activities in order' do
let(:journals) do
- journals = [initial_note, note1, note2]
+ journals = [creation_journal, subject_change_journal, comment_journal]
journals
end
@@ -117,12 +96,12 @@ RSpec.describe 'Activity tab',
activity = page.find("#activity-#{idx + 1}")
- if journal.id != note1.id
+ if journal.id != subject_change_journal.id
expect(activity).to have_selector('.op-user-activity--user-line', text: journal.user.name)
expect(activity).to have_selector('.user-comment > .message', text: journal.notes, visible: :all)
end
- if activity == note1
+ if activity == subject_change_journal
expect(activity).to have_selector('.work-package-details-activities-messages .message',
count: 2)
expect(activity).to have_selector('.message',
@@ -164,18 +143,18 @@ RSpec.describe 'Activity tab',
end
it 'can deep link to an activity' do
- visit "/work_packages/#{work_package.id}/activity#activity-#{note2.id}"
+ visit "/work_packages/#{work_package.id}/activity#activity-#{comment_journal.id}"
work_package_page.ensure_page_loaded
expect(page).to have_selector('.user-comment > .message',
text: initial_comment)
- expect(page.current_url).to match /\/work_packages\/#{work_package.id}\/activity#activity-#{note2.id}/
+ expect(page.current_url).to match /\/work_packages\/#{work_package.id}\/activity#activity-#{comment_journal.id}/
end
it 'can toggle between activities and comments-only' do
expect(page).to have_selector('.work-package-details-activities-activity-contents', count: 3)
- expect(page).to have_selector('.user-comment > .message', text: note2.notes)
+ expect(page).to have_selector('.user-comment > .message', text: comment_journal.notes)
# Show only comments
find('.activity-comments--toggler').click
@@ -183,7 +162,7 @@ RSpec.describe 'Activity tab',
# 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: note2.notes)
+ expect(page).to have_selector('.user-comment > .message', text: comment_journal.notes)
# Show all again
find('.activity-comments--toggler').click
diff --git a/spec/lib/api/v3/work_packages/work_package_collection_representer_spec.rb b/spec/lib/api/v3/work_packages/work_package_collection_representer_spec.rb
index 83ed4831ebf..9fe082dc1b2 100644
--- a/spec/lib/api/v3/work_packages/work_package_collection_representer_spec.rb
+++ b/spec/lib/api/v3/work_packages/work_package_collection_representer_spec.rb
@@ -33,7 +33,11 @@ RSpec.describe API::V3::WorkPackages::WorkPackageCollectionRepresenter do
create_shared_association_defaults_for_work_package_factory
let(:self_base_link) { '/api/v3/example' }
- let(:work_packages) { WorkPackage.all }
+ let(:work_packages) do
+ created_work_packages
+ WorkPackage.all
+ end
+ let(:created_work_packages) { create_list(:work_package, total) }
let(:first_wp) { work_packages.first }
let(:user) { build_stubbed(:user) }
@@ -77,8 +81,6 @@ RSpec.describe API::V3::WorkPackages::WorkPackageCollectionRepresenter do
.to receive(:allowed_to?) do |permission|
permissions.nil? || permissions.include?(permission)
end
-
- create_list(:work_package, total)
end
subject(:collection) { representer.to_json }
@@ -557,15 +559,16 @@ RSpec.describe API::V3::WorkPackages::WorkPackageCollectionRepresenter do
project: first_wp.project,
roles: create_list(:role, 1, permissions: [:view_work_packages]))
end
-
- before do
- # Update the timestamp of the first work package to a different type forcing the inclusion of
+ let(:created_work_packages) do
+ # Let the work package behave as if it used to have a different type forcing the inclusion of
# another schema and set the creation date to be before the baseline time.
- first_wp = WorkPackage.first
- first_wp.update(subject: 'Some new subject', author: current_user)
- first_wp.update_columns(created_at: "2022-01-01T00:00:00Z")
- first_wp.journals.first.update_columns(created_at: "2022-01-01T00:00:00Z", updated_at: "2022-01-01T00:00:00Z")
- first_wp.journals.first.data.update_columns(type_id: other_type.id)
+ create_list(:work_package,
+ 1,
+ subject: 'Some new subject',
+ journals: {
+ DateTime.parse("2022-01-01T00:00:00Z") => { type_id: other_type.id },
+ 1.day.ago => {}
+ })
end
it 'embeds a schema collection', :aggregate_failures do
@@ -574,13 +577,13 @@ RSpec.describe API::V3::WorkPackages::WorkPackageCollectionRepresenter do
.at_path('_embedded/schemas/_embedded/elements')
expected_former_path = api_v3_paths.work_package_schema(first_wp.project.id,
- first_wp.type.id)
+ other_type.id)
expect(collection)
.to be_json_eql(expected_former_path.to_json)
.at_path('_embedded/schemas/_embedded/elements/0/_links/self/href')
expected_current_path = api_v3_paths.work_package_schema(first_wp.project.id,
- other_type.id)
+ first_wp.type.id)
expect(collection)
.to be_json_eql(expected_current_path.to_json)
.at_path('_embedded/schemas/_embedded/elements/1/_links/self/href')
@@ -590,20 +593,18 @@ RSpec.describe API::V3::WorkPackages::WorkPackageCollectionRepresenter do
context 'when passing timestamps' do
let(:work_package) do
- new_work_package = create(:work_package, subject: "The current work package", project:)
- new_work_package.update_columns created_at: baseline_time - 1.day
- new_work_package
- end
- let(:original_journal) do
- create_journal(journable: work_package, timestamp: baseline_time - 1.day,
- version: 1,
- attributes: { subject: "The original work package" })
- end
- let(:current_journal) do
- create_journal(journable: work_package, timestamp: 1.day.ago,
- version: 2,
- attributes: { subject: "The current work package" })
- end
+ create(:work_package,
+ subject: "The current work package",
+ assigned_to: current_user,
+ project:,
+ journals: {
+ baseline_time - 1.day => { subject: "The original work package" },
+ 1.day.ago => {}
+ })
+ end
+ let(:created_work_packages) { [work_package] }
+ let(:original_journal) { work_package.journals.first }
+ let(:current_journal) { work_package.journals.last }
let(:baseline_time) { "2022-01-01".to_time }
let(:project) { create(:project) }
let(:current_user) do
@@ -614,24 +615,6 @@ RSpec.describe API::V3::WorkPackages::WorkPackageCollectionRepresenter do
member_with_permissions: %i[view_work_packages])
end
- def create_journal(journable:, version:, timestamp:, attributes: {})
- work_package_attributes = work_package.attributes.except("id")
- journal_attributes = work_package_attributes \
- .extract!(*Journal::WorkPackageJournal.attribute_names) \
- .symbolize_keys.merge(attributes)
- create(:work_package_journal, version:,
- journable:, created_at: timestamp, updated_at: timestamp,
- data: build(:journal_work_package_journal, journal_attributes))
- end
-
- before do
- WorkPackage.destroy_all
- work_package
- Journal.destroy_all
- original_journal
- current_journal
- end
-
shared_examples_for 'includes the properties of the current work package' do
it 'includes the properties of the current work package' do
expect(collection)
diff --git a/spec/lib/api/v3/work_packages/work_package_representer_spec.rb b/spec/lib/api/v3/work_packages/work_package_representer_spec.rb
index 58dbe85884f..2e34ec372dc 100644
--- a/spec/lib/api/v3/work_packages/work_package_representer_spec.rb
+++ b/spec/lib/api/v3/work_packages/work_package_representer_spec.rb
@@ -1304,28 +1304,14 @@ RSpec.describe API::V3::WorkPackages::WorkPackageRepresenter do
let(:baseline_time) { Time.zone.parse("2022-01-01") }
let(:work_pacakges) { WorkPackage.where(id: work_package.id) }
let(:work_package) do
- new_work_package = create(:work_package,
- subject: "The current work package",
- assigned_to: current_user,
- project:)
- new_work_package.update_columns created_at: baseline_time - 1.day
- new_work_package
- end
- let(:original_journal) do
- create_journal(journable: work_package, timestamp: baseline_time - 1.day,
- version: 1,
- attributes: {
- subject: "The original work package",
- assigned_to: current_user
- })
- end
- let(:current_journal) do
- create_journal(journable: work_package, timestamp: 1.day.ago,
- version: 2,
- attributes: {
- subject: "The current work package",
- assigned_to: current_user
- })
+ create(:work_package,
+ subject: "The current work package",
+ assigned_to: current_user,
+ project:,
+ journals: {
+ baseline_time - 1.day => { subject: "The original work package" },
+ 1.day.ago => {}
+ })
end
let(:project) { create(:project) }
@@ -1337,16 +1323,6 @@ RSpec.describe API::V3::WorkPackages::WorkPackageRepresenter do
member_with_permissions: %i[view_work_packages view_file_links])
end
- def create_journal(journable:, version:, timestamp:, attributes: {})
- work_package_attributes = work_package.attributes.except("id")
- journal_attributes = work_package_attributes \
- .extract!(*Journal::WorkPackageJournal.attribute_names) \
- .symbolize_keys.merge(attributes)
- create(:work_package_journal, version:,
- journable:, created_at: timestamp, updated_at: timestamp,
- data: build(:journal_work_package_journal, journal_attributes))
- end
-
before do
# Usually the eager loading wrapper is mocked
# in spec/support/api/v3/work_packages/work_package_representer_eager_loading.rb.
@@ -1355,12 +1331,6 @@ RSpec.describe API::V3::WorkPackages::WorkPackageRepresenter do
allow(API::V3::WorkPackages::WorkPackageEagerLoadingWrapper)
.to receive(:wrap_one)
.and_call_original
-
- WorkPackage.destroy_all
- work_package
- Journal.destroy_all
- original_journal
- current_journal
end
describe 'attributesByTimestamp' do
diff --git a/spec/models/journable/historic_active_record_relation_spec.rb b/spec/models/journable/historic_active_record_relation_spec.rb
index 24f82085b85..340838d6d40 100644
--- a/spec/models/journable/historic_active_record_relation_spec.rb
+++ b/spec/models/journable/historic_active_record_relation_spec.rb
@@ -37,52 +37,33 @@ RSpec.describe Journable::HistoricActiveRecordRelation do
let(:wednesday) { "2022-08-03".to_datetime }
let(:thursday) { "2022-08-04".to_datetime }
let(:friday) { "2022-08-05".to_datetime }
- let(:default_work_package_attributes) do
- { description: "The work package as it is since Friday", estimated_hours: 10, project: }
- end
let(:work_package_attributes) { {} }
let(:project) { create(:project) }
let!(:work_package) do
- new_work_package = create(:work_package, default_work_package_attributes.merge(work_package_attributes))
- new_work_package.update_columns created_at: monday
- new_work_package
+ create(:work_package,
+ description: "The work package as it is since Friday",
+ estimated_hours: 10,
+ project:,
+ journals: {
+ monday => { description: "The work package as it has been on Monday", estimated_hours: 5 },
+ wednesday => { description: "The work package as it has been on Wednesday", estimated_hours: 10 },
+ friday => { description: "The work package as it is since Friday", estimated_hours: 10 }
+ })
end
let(:journable) { work_package }
-
let(:monday_journal) do
- create_journal(journable: work_package, timestamp: monday,
- attributes: { description: "The work package as it has been on Monday", estimated_hours: 5 })
+ work_package.journals.find_by(created_at: monday)
end
let(:wednesday_journal) do
- create_journal(journable: work_package, timestamp: wednesday,
- attributes: { description: "The work package as it has been on Wednesday", estimated_hours: 10 })
+ work_package.journals.find_by(created_at: wednesday)
end
let(:friday_journal) do
- create_journal(journable: work_package, timestamp: friday,
- attributes: { description: "The work package as it is since Friday", estimated_hours: 10 })
+ work_package.journals.find_by(created_at: friday)
end
let(:relation) { WorkPackage.all }
let(:historic_relation) { relation.at_timestamp(wednesday) }
- def create_journal(journable:, timestamp:, attributes: {})
- work_package_attributes = work_package.attributes.except("id")
- journal_attributes = work_package_attributes \
- .extract!(*Journal::WorkPackageJournal.attribute_names) \
- .symbolize_keys.merge(attributes)
- create(:work_package_journal,
- journable:, created_at: timestamp, updated_at: timestamp,
- data: build(:journal_work_package_journal, journal_attributes))
- end
-
- before do
- work_package.journals.destroy_all
- monday_journal
- wednesday_journal
- friday_journal
- work_package.reload
- end
-
subject { historic_relation }
describe "#pluck" do
diff --git a/spec/models/journable/with_historic_attributes_spec.rb b/spec/models/journable/with_historic_attributes_spec.rb
index d0f2a31acd0..097db49d3f6 100644
--- a/spec/models/journable/with_historic_attributes_spec.rb
+++ b/spec/models/journable/with_historic_attributes_spec.rb
@@ -37,51 +37,28 @@ RSpec.describe Journable::WithHistoricAttributes,
shared_let(:project) { create(:project) }
shared_let(:work_package1) do
- new_work_package = create(:work_package,
- subject: "The current work package 1",
- project:)
- new_work_package.update_columns(created_at:)
- new_work_package
+ create(:work_package,
+ subject: "The current work package 1",
+ project:,
+ journals: {
+ created_at => { subject: "The original work package 1" },
+ 1.day.ago => {}
+ })
end
- shared_let(:original_journal_wp1) do
- work_package1.journals.destroy_all
- create_journal(journable: work_package1,
- timestamp: created_at,
- version: 1,
- attributes: { subject: "The original work package 1", project: })
- end
- shared_let(:current_journal_wp1) do
- create_journal(journable: work_package1,
- timestamp: 1.day.ago,
- version: 2,
- attributes: { subject: "The current work package 1", project: })
- end
-
shared_let(:work_package2) do
- new_work_package = create(:work_package,
- project:,
- subject: "The current work package 2",
- start_date: created_at - 3.days)
- new_work_package.update_columns(created_at:)
- new_work_package
- end
- shared_let(:original_journal_wp2) do
- work_package2.journals.destroy_all
- create_journal(journable: work_package2,
- timestamp: created_at,
- version: 1,
- attributes: { start_date: created_at - 5.days,
- subject: "The original work package 2",
- project: })
- end
- shared_let(:current_journal_wp2) do
- create_journal(journable: work_package2,
- timestamp: 1.day.ago,
- version: 2,
- attributes: { start_date: created_at - 3.days,
- subject: "The current work package 2",
- project: })
+ create(:work_package,
+ subject: "The current work package 2",
+ project:,
+ start_date: created_at - 3.days,
+ journals: {
+ created_at => { subject: "The original work package 2", start_date: created_at - 5.days },
+ 1.day.ago => {}
+ })
end
+ shared_let(:original_journal_wp1) { work_package1.journals.first }
+ shared_let(:current_journal_wp1) { work_package1.last_journal }
+ shared_let(:original_journal_wp2) { work_package2.journals.first }
+ shared_let(:current_journal_wp2) { work_package2.last_journal }
let(:user1) do
create(:user,
@@ -103,22 +80,6 @@ RSpec.describe Journable::WithHistoricAttributes,
current_user { user1 }
- def create_journal(journable:, version:, timestamp:, attributes: {})
- work_package_attributes = journable.attributes.except("id")
-
- journal_attributes = work_package_attributes
- .extract!(*Journal::WorkPackageJournal.attribute_names)
- .symbolize_keys
- .merge(attributes)
-
- create(:work_package_journal,
- version:,
- journable:,
- created_at: timestamp,
- updated_at: timestamp,
- data: build(:journal_work_package_journal, journal_attributes))
- end
-
subject { described_class.wrap(work_packages, timestamps:, query:, include_only_changed_attributes:) }
describe ".wrap" do
diff --git a/spec/models/query/results_filter_on_historic_data_spec.rb b/spec/models/query/results_filter_on_historic_data_spec.rb
index 0ef4a8cc128..8b5f41826c8 100644
--- a/spec/models/query/results_filter_on_historic_data_spec.rb
+++ b/spec/models/query/results_filter_on_historic_data_spec.rb
@@ -37,29 +37,23 @@ RSpec.describe Query::Results,
let(:pre_historic_time) { historic_time - 1.day }
let(:recent_time) { 1.hour.ago }
let!(:work_package) do
- new_work_package = create(:work_package,
- description: "This is the original description of the work package",
- project: project_with_member)
- new_work_package.update_columns created_at: historic_time
- new_work_package.journals.first.update_columns created_at: historic_time, updated_at: historic_time
- new_work_package.reload
- new_work_package.update description: "This is the current description of the work package", updated_at: recent_time
- new_work_package.journals.last.update_columns created_at: recent_time, updated_at: recent_time
- new_work_package.reload
- new_work_package
+ create(:work_package,
+ description: "This is the current description of the work package",
+ project: project_with_member,
+ journals: {
+ historic_time => { description: "This is the original description of the work package" },
+ recent_time => { description: "This is the current description of the work package" }
+ })
end
let!(:work_package2) do
- new_work_package = create(:work_package,
- description: "Lorem ipsum dolor sit amet, consectetur adipiscing elit",
- project: project_with_member)
- new_work_package.update_columns created_at: historic_time
- new_work_package.journals.first.update_columns created_at: historic_time, updated_at: historic_time
- new_work_package.reload
- new_work_package.update description: "Lorem ipsum", updated_at: recent_time
- new_work_package.journals.last.update_columns created_at: recent_time, updated_at: recent_time
- new_work_package.reload
- new_work_package
+ create(:work_package,
+ description: "Lorem ipsum",
+ project: project_with_member,
+ journals: {
+ historic_time => { description: "Lorem ipsum dolor sit amet, consectetur adipiscing elit" },
+ recent_time => { description: "Lorem ipsum" }
+ })
end
let(:project_with_member) { create(:project) }
diff --git a/spec/requests/api/v3/work_packages/index_resource_spec.rb b/spec/requests/api/v3/work_packages/index_resource_spec.rb
index 1120f928544..b8aef340426 100644
--- a/spec/requests/api/v3/work_packages/index_resource_spec.rb
+++ b/spec/requests/api/v3/work_packages/index_resource_spec.rb
@@ -250,44 +250,19 @@ RSpec.describe 'API v3 Work package resource',
let(:baseline_time) { timestamps.first.to_time }
let(:created_at) { baseline_time - 1.day }
- let(:work_package) do
+ let!(:work_package) do
create(:work_package,
- :created_in_past,
created_at:,
subject: "The current work package",
assigned_to: current_user,
- project:)
- end
- let(:original_journal) do
- create_journal(journable: work_package, timestamp: created_at,
- version: 1,
- attributes: { subject: "The original work package",
- assigned_to: current_user,
- project: })
- end
- let(:current_journal) do
- create_journal(journable: work_package, timestamp: 1.day.ago,
- version: 2,
- attributes: { subject: "The current work package",
- assigned_to: current_user,
- project: })
- end
-
- def create_journal(journable:, version:, timestamp:, attributes: {})
- work_package_attributes = work_package.attributes.except("id")
- journal_attributes = work_package_attributes \
- .extract!(*Journal::WorkPackageJournal.attribute_names) \
- .symbolize_keys.merge(attributes)
- create(:work_package_journal, version:,
- journable:, created_at: timestamp, updated_at: timestamp,
- data: build(:journal_work_package_journal, journal_attributes))
- end
-
- before do
- work_package.journals.destroy_all
- original_journal
- current_journal
+ project:,
+ journals: {
+ created_at => { subject: "The original work package" },
+ 1.day.ago => {}
+ })
end
+ let(:original_journal) { work_package.journals.first }
+ let(:current_journal) { work_package.journals.last }
it 'succeeds' do
expect(subject.status).to be 200
@@ -937,23 +912,17 @@ RSpec.describe 'API v3 Work package resource',
let(:original_date) { Date.current }
let(:current_date) { Date.current + 1.day }
- let(:work_package) do
- new_work_package = create(:work_package, due_date: current_date, start_date: current_date, project:, type:)
- new_work_package.update_columns(created_at:)
- new_work_package
- end
-
- let(:original_journal) do
- create_journal(journable: work_package,
- timestamp: created_at,
- version: 1,
- attributes: { due_date: original_date, start_date: original_date, duration: 1 })
- end
- let(:current_journal) do
- create_journal(journable: work_package,
- timestamp: 1.day.ago,
- version: 2,
- attributes: { due_date: current_date, start_date: current_date, duration: 1 })
+ let!(:work_package) do
+ create(:work_package,
+ due_date: current_date,
+ start_date: current_date,
+ duration: 1,
+ project:,
+ type:,
+ journals: {
+ created_at => { due_date: original_date, start_date: original_date },
+ 1.day.ago => {}
+ })
end
it 'displays the original date in the attributesByTimestamp' do
diff --git a/spec/requests/api/v3/work_packages/show_resource_spec.rb b/spec/requests/api/v3/work_packages/show_resource_spec.rb
index f5fc2ceda80..a84fde3878e 100644
--- a/spec/requests/api/v3/work_packages/show_resource_spec.rb
+++ b/spec/requests/api/v3/work_packages/show_resource_spec.rb
@@ -224,39 +224,16 @@ RSpec.describe 'API v3 Work package resource',
let(:created_at) { baseline_time - 1.day }
let(:work_package) do
- new_work_package = create(:work_package, subject: "The current work package", project:)
- new_work_package.update_columns(created_at:)
- new_work_package
- end
- let(:original_journal) do
- create_journal(journable: work_package,
- timestamp: created_at,
- version: 1,
- attributes: { subject: "The original work package" })
- end
- let(:current_journal) do
- create_journal(journable: work_package,
- timestamp: 1.day.ago,
- version: 2,
- attributes: { subject: "The current work package" })
- end
-
- def create_journal(journable:, version:, timestamp:, attributes: {})
- work_package_attributes = work_package.attributes.except("id")
- journal_attributes = work_package_attributes \
- .extract!(*Journal::WorkPackageJournal.attribute_names) \
- .symbolize_keys.merge(attributes)
- create(:work_package_journal, version:,
- journable:, created_at: timestamp, updated_at: timestamp,
- data: build(:journal_work_package_journal, journal_attributes))
- end
-
- before do
- work_package
- Journal.destroy_all
- original_journal
- current_journal
+ create(:work_package,
+ subject: "The current work package",
+ project:,
+ journals: {
+ created_at => { subject: "The original work package" },
+ 1.day.ago => {}
+ })
end
+ let(:original_journal) { work_package.journals.first }
+ let(:current_journal) { work_package.journals.last }
it 'responds with 200' do
expect(subject && last_response.status).to eq(200)
diff --git a/spec/support/components/work_packages/activities.rb b/spec/support/components/work_packages/activities.rb
index 057df871e5a..13ee76eeb20 100644
--- a/spec/support/components/work_packages/activities.rb
+++ b/spec/support/components/work_packages/activities.rb
@@ -57,8 +57,9 @@ module Components
def hover_action(journal_id, action)
retry_block do
# Focus type edit to expose buttons
- activity = page.find("#activity-#{journal_id} .work-package-details-activities-activity-contents")
- page.driver.browser.action.move_to(activity.native).perform
+ page
+ .find("#activity-#{journal_id} .work-package-details-activities-activity-contents")
+ .hover
# Click the corresponding action button
case action