diff --git a/Gemfile.lock b/Gemfile.lock index 25a8156b46..e38db040a7 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -69,7 +69,7 @@ PATH measured (>= 2.0) minitest (~> 5.14) money-rails (~> 1.13) - mongoid (~> 7.4) + mongoid (>= 7.4, < 9) mongoid-active_merchant (~> 0.2) mongoid-audit_log (>= 0.6.0) mongoid-document_path (~> 0.2) diff --git a/admin/test/integration/workarea/admin/authorization_integration_test.rb b/admin/test/integration/workarea/admin/authorization_integration_test.rb index ba888ebf79..61296ef254 100644 --- a/admin/test/integration/workarea/admin/authorization_integration_test.rb +++ b/admin/test/integration/workarea/admin/authorization_integration_test.rb @@ -20,7 +20,7 @@ def test_allows_the_request_when_admin_user def test_does_not_allow_the_request_when_non_admin_user # login - @user.update_attributes!(admin: false) + @user.update!(admin: false) post storefront.login_path, params: { email: @user.email, password: 'W3bl1nc!' } diff --git a/admin/test/integration/workarea/admin/changesets_integration_test.rb b/admin/test/integration/workarea/admin/changesets_integration_test.rb index 6e98389700..e96e1b5935 100644 --- a/admin/test/integration/workarea/admin/changesets_integration_test.rb +++ b/admin/test/integration/workarea/admin/changesets_integration_test.rb @@ -9,7 +9,7 @@ def test_deletes_a_changeset page = create_page(name: 'Foo') release = create_release release.as_current do - page.update_attributes!(name: 'Bar') + page.update!(name: 'Bar') end changeset = release.changesets.first diff --git a/admin/test/integration/workarea/admin/comments_integration_test.rb b/admin/test/integration/workarea/admin/comments_integration_test.rb index 954b833e76..70d7af169c 100644 --- a/admin/test/integration/workarea/admin/comments_integration_test.rb +++ b/admin/test/integration/workarea/admin/comments_integration_test.rb @@ -102,7 +102,7 @@ def test_editing_comment_as_author comment.reload assert_equal('body', comment.body) - comment.update_attributes(author_id: current_user.id) + comment.update(author_id: current_user.id) patch admin.commentable_comment_path(commentable.to_global_id, comment), params: { comment: { body: 'different body' } } @@ -116,7 +116,7 @@ def test_deleting_comment_as_author delete admin.commentable_comment_path(commentable.to_global_id, comment) assert_equal(1, Comment.count) - comment.update_attributes(author_id: current_user.id) + comment.update(author_id: current_user.id) delete admin.commentable_comment_path(commentable.to_global_id, comment) assert_equal(0, Comment.count) diff --git a/admin/test/integration/workarea/admin/content_blocks_integration_test.rb b/admin/test/integration/workarea/admin/content_blocks_integration_test.rb index 71c01c36b7..8ee73960e0 100644 --- a/admin/test/integration/workarea/admin/content_blocks_integration_test.rb +++ b/admin/test/integration/workarea/admin/content_blocks_integration_test.rb @@ -47,7 +47,7 @@ def test_creating_blocks_without_publishing_authorization assert_equal(flash[:error], I18n.t('workarea.admin.publish_authorization.unauthorized')) - content.update_attributes!(active: false) + content.update!(active: false) post admin.content_area_blocks_path(content, area), params: { block: { type_id: :html, data: { 'html' => 'foo' } } } diff --git a/admin/test/integration/workarea/admin/create_catalog_categories_integration_test.rb b/admin/test/integration/workarea/admin/create_catalog_categories_integration_test.rb index fc4ac62552..502d772e1e 100644 --- a/admin/test/integration/workarea/admin/create_catalog_categories_integration_test.rb +++ b/admin/test/integration/workarea/admin/create_catalog_categories_integration_test.rb @@ -66,7 +66,7 @@ def test_save_publish assert(category.reload.active?) - category.update_attributes!(active: false) + category.update!(active: false) post admin.save_publish_create_catalog_category_path(category), params: { activate: 'new_release', release: { name: '' } } @@ -86,7 +86,7 @@ def test_save_publish release.as_current { assert(category.reload.active?) } release = create_release - category.update_attributes!(active: false) + category.update!(active: false) post admin.save_publish_create_catalog_category_path(category), params: { activate: release.id } diff --git a/admin/test/integration/workarea/admin/create_catalog_products_integration_test.rb b/admin/test/integration/workarea/admin/create_catalog_products_integration_test.rb index a5b5e27276..8f8679d675 100644 --- a/admin/test/integration/workarea/admin/create_catalog_products_integration_test.rb +++ b/admin/test/integration/workarea/admin/create_catalog_products_integration_test.rb @@ -182,7 +182,7 @@ def test_save_publish assert(product.reload.active?) - product.update_attributes!(active: false) + product.update!(active: false) post admin.save_publish_create_catalog_product_path(product), params: { activate: 'new_release', release: { name: '' } } @@ -202,7 +202,7 @@ def test_save_publish release.as_current { assert(product.reload.active?) } release = create_release - product.update_attributes!(active: false) + product.update!(active: false) post admin.save_publish_create_catalog_product_path(product), params: { activate: release.id } diff --git a/admin/test/integration/workarea/admin/create_content_pages_integration_test.rb b/admin/test/integration/workarea/admin/create_content_pages_integration_test.rb index 0c6bb8c7ae..667107d728 100644 --- a/admin/test/integration/workarea/admin/create_content_pages_integration_test.rb +++ b/admin/test/integration/workarea/admin/create_content_pages_integration_test.rb @@ -66,7 +66,7 @@ def test_save_publish assert(page.reload.active?) - page.update_attributes!(active: false) + page.update!(active: false) post admin.save_publish_create_content_page_path(page), params: { activate: 'new_release', release: { name: '' } } @@ -86,7 +86,7 @@ def test_save_publish release.as_current { assert(page.reload.active?) } release = create_release - page.update_attributes!(active: false) + page.update!(active: false) post admin.save_publish_create_content_page_path(page), params: { activate: release.id } diff --git a/admin/test/integration/workarea/admin/create_pricing_discounts_integration_test.rb b/admin/test/integration/workarea/admin/create_pricing_discounts_integration_test.rb index f85af66744..002ecbd19d 100644 --- a/admin/test/integration/workarea/admin/create_pricing_discounts_integration_test.rb +++ b/admin/test/integration/workarea/admin/create_pricing_discounts_integration_test.rb @@ -216,7 +216,7 @@ def test_save_publish assert(discount.reload.active?) - discount.update_attributes!(active: false) + discount.update!(active: false) post admin.save_publish_create_pricing_discount_path(discount), params: { activate: 'new_release', release: { name: '' } } @@ -236,7 +236,7 @@ def test_save_publish release.as_current { assert(discount.reload.active?) } release = create_release - discount.update_attributes!(active: false) + discount.update!(active: false) post admin.save_publish_create_pricing_discount_path(discount), params: { activate: release.id } diff --git a/admin/test/integration/workarea/admin/create_release_undos_integration_test.rb b/admin/test/integration/workarea/admin/create_release_undos_integration_test.rb index 18425da374..efa813931d 100644 --- a/admin/test/integration/workarea/admin/create_release_undos_integration_test.rb +++ b/admin/test/integration/workarea/admin/create_release_undos_integration_test.rb @@ -9,7 +9,7 @@ def test_create releasable = create_page(name: 'Foo') release = create_release - release.as_current { releasable.update_attributes!(name: 'Bar') } + release.as_current { releasable.update!(name: 'Bar') } release.changesets.create!(releasable: Catalog::Product.new) # test missing releasable post admin.release_undos_path(release), diff --git a/admin/test/integration/workarea/admin/create_users_integration_test.rb b/admin/test/integration/workarea/admin/create_users_integration_test.rb index 600bc14aa1..740669f09d 100644 --- a/admin/test/integration/workarea/admin/create_users_integration_test.rb +++ b/admin/test/integration/workarea/admin/create_users_integration_test.rb @@ -151,7 +151,7 @@ def test_creating_without_a_password end def test_creating_an_admin_without_permissions_management - admin_user.update_attributes!( + admin_user.update!( super_admin: false, admin: true, people_access: true, diff --git a/admin/test/integration/workarea/admin/featured_products_integration_test.rb b/admin/test/integration/workarea/admin/featured_products_integration_test.rb index 1c9f24beda..8c3afa9667 100644 --- a/admin/test/integration/workarea/admin/featured_products_integration_test.rb +++ b/admin/test/integration/workarea/admin/featured_products_integration_test.rb @@ -34,7 +34,7 @@ def test_adding_a_product_without_publishing_authorization assert_redirected_to(admin.featured_product_path(category.to_global_id)) assert_equal(flash[:error], I18n.t('workarea.admin.publish_authorization.unauthorized')) - category.update_attributes!(active: false) + category.update!(active: false) post admin.add_featured_product_path(category.to_global_id), params: { product_id: product.id } diff --git a/admin/test/integration/workarea/admin/impersonations_integration_test.rb b/admin/test/integration/workarea/admin/impersonations_integration_test.rb index 991b6bd97a..d71ccfc555 100644 --- a/admin/test/integration/workarea/admin/impersonations_integration_test.rb +++ b/admin/test/integration/workarea/admin/impersonations_integration_test.rb @@ -29,7 +29,7 @@ def test_can_create_an_impersonation end def test_does_not_allow_impersonating_another_admin - @user.update_attributes!(admin: true) + @user.update!(admin: true) assert_raises Admin::InvalidImpersonation do post admin.impersonations_path, params: { user_id: @user.id } diff --git a/admin/test/integration/workarea/admin/permissions_integration_test.rb b/admin/test/integration/workarea/admin/permissions_integration_test.rb index b309f32c81..1844789d6c 100644 --- a/admin/test/integration/workarea/admin/permissions_integration_test.rb +++ b/admin/test/integration/workarea/admin/permissions_integration_test.rb @@ -18,7 +18,7 @@ def test_redirects_if_you_do_not_have_permissions end def test_allows_if_you_do_have_permissions - @user.update_attributes!(catalog_access: true) + @user.update!(catalog_access: true) get admin.catalog_products_path assert(response.ok?) end diff --git a/admin/test/integration/workarea/admin/releases_integration_test.rb b/admin/test/integration/workarea/admin/releases_integration_test.rb index aa2bb1bce4..52eb64957a 100644 --- a/admin/test/integration/workarea/admin/releases_integration_test.rb +++ b/admin/test/integration/workarea/admin/releases_integration_test.rb @@ -49,8 +49,8 @@ def test_calendar_feed old_token = user.token - user.update_attributes!(admin: false) - user.update_attributes!(admin: true, releases_access: true) + user.update!(admin: false) + user.update!(admin: true, releases_access: true) get admin.calendar_feed_releases_path(token: old_token) assert_response :unauthorized @@ -91,8 +91,8 @@ def test_saving_release_during_time_based_previewing second = create_release(publish_at: 2.days.from_now) product = create_product(name: 'Foo', description: 'One') - first.as_current { product.update_attributes!(name: 'Bar', description: 'Two') } - second.as_current { product.update_attributes!(name: 'Baz') } + first.as_current { product.update!(name: 'Bar', description: 'Two') } + second.as_current { product.update!(name: 'Baz') } post admin.release_session_path, params: { release_id: second.id } patch admin.catalog_product_path(product), params: { product: { name: 'Qux' } } @@ -132,8 +132,8 @@ def test_working_on_releases_that_publish_at_the_same_time second = create_release(publish_at: publish_at) product = create_product(name: 'Foo', description: 'One') - first.as_current { product.update_attributes!(name: 'Bar', description: 'Two') } - second.as_current { product.update_attributes!(name: 'Baz') } + first.as_current { product.update!(name: 'Bar', description: 'Two') } + second.as_current { product.update!(name: 'Baz') } post admin.release_session_path, params: { release_id: second.id } patch admin.catalog_product_path(product), params: { product: { name: 'Qux' } } diff --git a/admin/test/integration/workarea/admin/users_integration_test.rb b/admin/test/integration/workarea/admin/users_integration_test.rb index d0c76c605a..486621b0c9 100644 --- a/admin/test/integration/workarea/admin/users_integration_test.rb +++ b/admin/test/integration/workarea/admin/users_integration_test.rb @@ -61,7 +61,7 @@ def test_updates_a_user def test_permissions_management user = create_user - admin_user.update_attributes!( + admin_user.update!( super_admin: false, admin: true, people_access: true, @@ -94,7 +94,7 @@ def test_permissions_management refute(user.people_access) refute(user.marketing_access) - admin_user.update_attributes!(permissions_manager: true) + admin_user.update!(permissions_manager: true) get admin.permissions_user_path(create_user) assert(response.ok?) diff --git a/admin/test/system/workarea/admin/data_files_system_test.rb b/admin/test/system/workarea/admin/data_files_system_test.rb index 98d1914b41..ba8fb07740 100644 --- a/admin/test/system/workarea/admin/data_files_system_test.rb +++ b/admin/test/system/workarea/admin/data_files_system_test.rb @@ -76,7 +76,7 @@ def test_viewing_exports started_at: 1.hour.ago, file_type: 'csv' ) - export_one.update_attributes!( + export_one.update!( file: export_one.tempfile.tap(&:close), completed_at: Time.current ) @@ -88,7 +88,7 @@ def test_viewing_exports started_at: 2.hour.ago, file_type: 'json' ) - export_two.update_attributes!( + export_two.update!( file: export_two.tempfile.tap(&:close), completed_at: Time.current ) diff --git a/admin/test/system/workarea/admin/help_system_test.rb b/admin/test/system/workarea/admin/help_system_test.rb index ca72f9d1ab..b9d1aaedcc 100644 --- a/admin/test/system/workarea/admin/help_system_test.rb +++ b/admin/test/system/workarea/admin/help_system_test.rb @@ -12,7 +12,7 @@ def test_a_help_admin_can_manage_help_articles visit admin.help_index_path assert(page.has_no_content?('Add New Article')) - admin_user.update_attributes!(help_admin: true) + admin_user.update!(help_admin: true) visit admin.help_index_path click_link 'Add New Article' diff --git a/admin/test/system/workarea/admin/releases_system_test.rb b/admin/test/system/workarea/admin/releases_system_test.rb index 0244cd99fe..eb5613c87d 100644 --- a/admin/test/system/workarea/admin/releases_system_test.rb +++ b/admin/test/system/workarea/admin/releases_system_test.rb @@ -133,11 +133,11 @@ def test_viewing_release_changes content.blocks.create!(area: 'test', type: 'html', data: { 'foo' => 'bar' }) Release.first.as_current do - product.update_attributes!(name: 'Changed Product') - product.variants.first.update_attributes!(active: false) - pricing_sku.update_attributes!(tax_code: '002') - discount.update_attributes!(product_ids: [product.id]) - content.blocks.first.update_attributes!(data: { 'foo' => 'baz' }) + product.update!(name: 'Changed Product') + product.variants.first.update!(active: false) + pricing_sku.update!(tax_code: '002') + discount.update!(product_ids: [product.id]) + content.blocks.first.update!(data: { 'foo' => 'baz' }) end visit admin.release_path(Release.first) diff --git a/admin/test/system/workarea/admin/search_system_test.rb b/admin/test/system/workarea/admin/search_system_test.rb index 0d9f39b6ee..97330cf58e 100644 --- a/admin/test/system/workarea/admin/search_system_test.rb +++ b/admin/test/system/workarea/admin/search_system_test.rb @@ -15,7 +15,7 @@ class SearchSystemTest < SystemTest create_menu(name: 'Foo Menu') Release.with_current(release.id) do - product.update_attributes!(name: 'Updated Foo Product 1') + product.update!(name: 'Updated Foo Product 1') end end diff --git a/admin/test/system/workarea/admin/trash_system_test.rb b/admin/test/system/workarea/admin/trash_system_test.rb index 403e7819e0..3bf6a08407 100644 --- a/admin/test/system/workarea/admin/trash_system_test.rb +++ b/admin/test/system/workarea/admin/trash_system_test.rb @@ -40,7 +40,7 @@ def test_restore_permission visit admin.trash_index_path assert(page.has_no_content?(t('workarea.admin.activities.restore'))) - user.update_attributes(can_restore: true) + user.update(can_restore: true) visit admin.trash_index_path diff --git a/admin/test/view_models/workarea/admin/changeset_view_model_test.rb b/admin/test/view_models/workarea/admin/changeset_view_model_test.rb index 508dd099b4..080f8a113e 100644 --- a/admin/test/view_models/workarea/admin/changeset_view_model_test.rb +++ b/admin/test/view_models/workarea/admin/changeset_view_model_test.rb @@ -44,7 +44,7 @@ def test_current_change end def test_new_value_for - @changeset.update_attributes!( + @changeset.update!( changeset: { 'name' => { I18n.locale.to_s => 'foo' }} ) @@ -54,22 +54,22 @@ def test_new_value_for def test_old_value_for Sidekiq::Testing.fake! # setting publish_at will schedule the job, which runs inline - @release.update_attributes!(publish_at: nil) - @releasable.update_attributes!(name: 'foo') - @release.as_current { @releasable.update_attributes!(name: 'bar') } + @release.update!(publish_at: nil) + @releasable.update!(name: 'foo') + @release.as_current { @releasable.update!(name: 'bar') } changeset = @releasable.changesets.first view_model = ChangesetViewModel.wrap(changeset) assert_equal('foo', view_model.old_value_for('name')) assert_equal('foo', @releasable.name) - @release.update_attributes!(publish_at: 1.week.from_now) + @release.update!(publish_at: 1.week.from_now) view_model = ChangesetViewModel.wrap(changeset.reload) assert_equal('foo', view_model.old_value_for('name')) assert_equal('foo', @releasable.name) previous = create_release(publish_at: 1.day.from_now) - previous.as_current { @releasable.update_attributes!(name: 'baz') } + previous.as_current { @releasable.update!(name: 'baz') } view_model = ChangesetViewModel.wrap(changeset.reload) assert_equal('baz', view_model.old_value_for('name')) @@ -82,32 +82,32 @@ def test_old_value_for assert_equal('baz', view_model.old_value_for('name')) assert_equal('foo', @releasable.name) - @release.update_attributes!(publish_at: nil) + @release.update!(publish_at: nil) view_model = ChangesetViewModel.wrap(changeset.reload) assert_equal('foo', view_model.old_value_for('name')) assert_equal('foo', @releasable.name) - undo.update_attributes!(publish_at: 1.week.from_now) + undo.update!(publish_at: 1.week.from_now) view_model = ChangesetViewModel.wrap(changeset.reload) assert_equal('foo', view_model.old_value_for('name')) assert_equal('foo', @releasable.name) - undo.update_attributes!(publish_at: 1.week.from_now) + undo.update!(publish_at: 1.week.from_now) view_model = ChangesetViewModel.wrap(undo_changeset.reload) assert_equal('baz', view_model.old_value_for('name')) assert_equal('foo', @releasable.name) - @release.update_attributes!(publish_at: 1.day.from_now) + @release.update!(publish_at: 1.day.from_now) view_model = ChangesetViewModel.wrap(undo_changeset.reload) assert_equal('bar', view_model.old_value_for('name')) assert_equal('foo', @releasable.name) - undo.update_attributes!(publish_at: nil) + undo.update!(publish_at: nil) view_model = ChangesetViewModel.wrap(undo_changeset.reload) assert_equal('bar', view_model.old_value_for('name')) assert_equal('foo', @releasable.name) - @release.update_attributes!(publish_at: nil) + @release.update!(publish_at: nil) view_model = ChangesetViewModel.wrap(undo_changeset.reload) assert_equal('bar', view_model.old_value_for('name')) assert_equal('foo', @releasable.name) diff --git a/admin/test/view_models/workarea/admin/content_view_model_test.rb b/admin/test/view_models/workarea/admin/content_view_model_test.rb index fe45ddf096..036ed4dc5f 100644 --- a/admin/test/view_models/workarea/admin/content_view_model_test.rb +++ b/admin/test/view_models/workarea/admin/content_view_model_test.rb @@ -100,7 +100,7 @@ def test_open_graph_asset view_model = ContentViewModel.wrap(content) assert_equal(default_asset, view_model.open_graph_asset) - content.update_attributes(open_graph_asset_id: create_asset.id) + content.update(open_graph_asset_id: create_asset.id) view_model = ContentViewModel.wrap(content) og_asset = view_model.open_graph_asset diff --git a/admin/test/view_models/workarea/admin/discount_rules_view_model_test.rb b/admin/test/view_models/workarea/admin/discount_rules_view_model_test.rb index 81e04da8eb..bf104a0709 100644 --- a/admin/test/view_models/workarea/admin/discount_rules_view_model_test.rb +++ b/admin/test/view_models/workarea/admin/discount_rules_view_model_test.rb @@ -78,10 +78,10 @@ def test_order_total_operator view_model = DiscountRulesViewModel.new(discount) assert_nil(view_model.order_total_operator) - discount.update_attributes!(order_total: 0) + discount.update!(order_total: 0) assert_nil(view_model.order_total_operator) - discount.update_attributes!(order_total: 100) + discount.update!(order_total: 100) assert_equal('greater than', view_model.order_total_operator) end @@ -94,10 +94,10 @@ def test_order_total view_model = DiscountRulesViewModel.new(discount) assert_nil(view_model.order_total) - discount.update_attributes!(order_total: 0) + discount.update!(order_total: 0) assert_nil(view_model.order_total) - discount.update_attributes!(order_total: 100) + discount.update!(order_total: 100) assert_equal(100.to_m, view_model.order_total) end @@ -108,7 +108,7 @@ def test_generated_codes_id assert_nil(view_model.generated_codes_id) - discount.update_attributes!(generated_codes_id: code_list.id) + discount.update!(generated_codes_id: code_list.id) assert_equal('Foo', view_model.generated_codes_id) code_list.destroy diff --git a/admin/test/view_models/workarea/admin/product_view_model_test.rb b/admin/test/view_models/workarea/admin/product_view_model_test.rb index 14207ffb82..4ec78c831d 100644 --- a/admin/test/view_models/workarea/admin/product_view_model_test.rb +++ b/admin/test/view_models/workarea/admin/product_view_model_test.rb @@ -137,7 +137,7 @@ def test_ignore_inventory refute(@view_model.ignore_inventory?) - inventory_two.update_attributes!(policy: 'ignore') + inventory_two.update!(policy: 'ignore') @view_model = ProductViewModel.new(@product) assert(@view_model.ignore_inventory?) end diff --git a/admin/test/view_models/workarea/admin/release_calendar_view_model_test.rb b/admin/test/view_models/workarea/admin/release_calendar_view_model_test.rb index 472efa245d..2cc60b9de7 100644 --- a/admin/test/view_models/workarea/admin/release_calendar_view_model_test.rb +++ b/admin/test/view_models/workarea/admin/release_calendar_view_model_test.rb @@ -34,7 +34,7 @@ def test_days_returns_a_month_hash_containing_scheduled_releases_by_day def test_days_sorts_results travel_to Time.zone.local(2019, 6, 24, 9, 35) - @release.update_attributes!(name: 'Third', publish_at: 3.hours.from_now) + @release.update!(name: 'Third', publish_at: 3.hours.from_now) create_release(name: 'First', published_at: 1.hour.ago) create_release(name: 'Second', publish_at: 2.hours.from_now) diff --git a/admin/test/view_models/workarea/admin/search_analysis_view_model_test.rb b/admin/test/view_models/workarea/admin/search_analysis_view_model_test.rb index 11c78a8059..cff78d0e33 100644 --- a/admin/test/view_models/workarea/admin/search_analysis_view_model_test.rb +++ b/admin/test/view_models/workarea/admin/search_analysis_view_model_test.rb @@ -59,7 +59,7 @@ def test_middleware def test_tokens customization = create_search_customization(id: 'foo', query: 'Foo') - Search::Settings.current.update_attributes!(synonyms: 'foo, bar') + Search::Settings.current.update!(synonyms: 'foo, bar') BulkIndexProducts.perform view_model = SearchAnalysisViewModel.wrap(customization) diff --git a/admin/test/view_models/workarea/admin/timeline_view_model_test.rb b/admin/test/view_models/workarea/admin/timeline_view_model_test.rb index 3ff6ba11a4..907e965400 100644 --- a/admin/test/view_models/workarea/admin/timeline_view_model_test.rb +++ b/admin/test/view_models/workarea/admin/timeline_view_model_test.rb @@ -9,27 +9,27 @@ class TimelineViewModelTest < TestCase def test_upcoming_changesets release = create_release(name: 'Foo', publish_at: 3.days.from_now) - release.as_current { @releasable.update_attributes!(name: 'Changed') } + release.as_current { @releasable.update!(name: 'Changed') } view_model = TimelineViewModel.new(@releasable) assert_equal(view_model.upcoming_changesets.length, 1) assert_equal(view_model.upcoming_changesets.first.release_id, release.id) release = create_release(name: 'Bar', publish_at: 4.days.from_now) - release.as_current { @releasable.update_attributes!(name: 'Changed Again') } + release.as_current { @releasable.update!(name: 'Changed Again') } view_model = TimelineViewModel.new(@releasable) assert_equal(view_model.upcoming_changesets.length, 2) assert_equal(view_model.upcoming_changesets.second.release_id, release.id) release = create_release(name: 'Baz') - release.as_current { @releasable.update_attributes!(name: 'Changed') } + release.as_current { @releasable.update!(name: 'Changed') } view_model = TimelineViewModel.new(@releasable) assert_equal(view_model.upcoming_changesets.length, 2) release = create_release(name: 'Foo', published_at: 3.days.ago) - release.as_current { @releasable.update_attributes!(name: 'Changed') } + release.as_current { @releasable.update!(name: 'Changed') } view_model = TimelineViewModel.new(@releasable) assert_equal(view_model.upcoming_changesets.length, 2) @@ -41,7 +41,7 @@ def test_upcoming_changesets def test_upcoming_changesets_with_content release = create_release(publish_at: 1.day.from_now) content = Content.for(@releasable) - release.as_current { content.update_attributes!(browser_title: 'Foo') } + release.as_current { content.update!(browser_title: 'Foo') } view_model = TimelineViewModel.new(@releasable) assert_equal(view_model.upcoming_changesets.length, 1) @@ -53,7 +53,7 @@ def test_empty assert(view_model.empty?) release = create_release(name: 'Foo', publish_at: 3.days.from_now) - release.as_current { @releasable.update_attributes!(name: 'Changed') } + release.as_current { @releasable.update!(name: 'Changed') } view_model = TimelineViewModel.new(@releasable) refute(view_model.empty?) @@ -61,7 +61,7 @@ def test_empty view_model = TimelineViewModel.new(@releasable) assert(view_model.empty?) - Mongoid::AuditLog.record { @releasable.update_attributes!(name: 'Changed') } + Mongoid::AuditLog.record { @releasable.update!(name: 'Changed') } view_model = TimelineViewModel.new(@releasable) refute(view_model.empty?) end @@ -77,7 +77,7 @@ def test_price_override_entry timeline = OrderTimelineViewModel.new(OrderViewModel.wrap(order)) assert(timeline.entries.none?) - override.update_attributes!(subtotal_adjustment: 10.to_m) + override.update!(subtotal_adjustment: 10.to_m) timeline = OrderTimelineViewModel.new(OrderViewModel.wrap(order)) assert(timeline.entries.one?) assert_equal(:price_overridden, timeline.entries.first.slug) diff --git a/core/app/models/workarea/releasable.rb b/core/app/models/workarea/releasable.rb index a01a0d0d2e..6d2957b91f 100644 --- a/core/app/models/workarea/releasable.rb +++ b/core/app/models/workarea/releasable.rb @@ -74,7 +74,7 @@ def in_release(release) result else Release.with_current(release) do - Mongoid::QueryCache.uncached { self.class.find(id) } + Mongo::QueryCache.uncached { self.class.find(id) } # Mongoid 8+: Mongoid::QueryCache replaced by Mongo::QueryCache end end end diff --git a/core/app/queries/workarea/admin_search_query_wrapper.rb b/core/app/queries/workarea/admin_search_query_wrapper.rb index 5faca1682a..99b25940dd 100644 --- a/core/app/queries/workarea/admin_search_query_wrapper.rb +++ b/core/app/queries/workarea/admin_search_query_wrapper.rb @@ -37,7 +37,7 @@ def scroll(options = {}, &block) # to match Search::Query method arguments # NotImplementedError: Cannot restart iteration of a cursor which issued a getMore # # I think this is a bug in how the QueryCache works. - Mongoid::QueryCache.clear_cache + Mongo::QueryCache.clear # Mongoid 8+ / Mongo driver 2.14+; replaces deprecated Mongoid::QueryCache.clear_cache criteria = results criteria.total_pages.times do |page| diff --git a/core/config/initializers/10_rack_middleware.rb b/core/config/initializers/10_rack_middleware.rb index 4f37d1b452..4b45b64254 100644 --- a/core/config/initializers/10_rack_middleware.rb +++ b/core/config/initializers/10_rack_middleware.rb @@ -1,8 +1,11 @@ app = Rails.application # Mongoid query cache middleware — clears per-request Mongoid query cache. -# Mongoid::QueryCache::Middleware exists in Mongoid 7.x (pinned via gemspec). -app.config.middleware.use(Mongoid::QueryCache::Middleware) +# Mongoid 8.x deprecated Mongoid::QueryCache in favor of Mongo::QueryCache. +# Mongoid 9.x removes Mongoid::QueryCache entirely. +# Use Mongo::QueryCache::Middleware (available in mongo driver >= 2.14, used by Mongoid 8+). +# On Mongoid 7.x the mongo driver also ships Mongo::QueryCache, so this is backward-compatible. +app.config.middleware.use(Mongo::QueryCache::Middleware) app.config.middleware.use(Workarea::Elasticsearch::QueryCache::Middleware) # Rack::Cache was removed from Rails 7.1. On Rails < 7.1 it may be present diff --git a/core/lib/workarea/configuration/mongoid.rb b/core/lib/workarea/configuration/mongoid.rb index 2ae6ba63a9..06ba0903dd 100644 --- a/core/lib/workarea/configuration/mongoid.rb +++ b/core/lib/workarea/configuration/mongoid.rb @@ -10,6 +10,16 @@ def load metrics: MongoidClient.new(:metrics).to_h } ) + + # When running on Mongoid 8.x, apply load_defaults '7.5' to preserve legacy behavior + # during the transition. This ensures existing Workarea deployments upgrading from + # Mongoid 7.4 do not experience silent behavior changes (e.g. broken_* flag defaults, + # compare_time_by_ms, legacy_attributes, overwrite_chained_operators, etc.). + # Operators should explicitly migrate to Mongoid 8 defaults after verifying their app. + # NOTE: load_defaults was removed in Mongoid 9.x; guard the call accordingly. + if ::Mongoid::VERSION.to_i >= 8 + ::Mongoid.load_defaults('7.5') if ::Mongoid.respond_to?(:load_defaults) + end end def indexes_enforced? diff --git a/core/test/integration/workarea/authentication_test.rb b/core/test/integration/workarea/authentication_test.rb index 331a392705..51791aa3b0 100644 --- a/core/test/integration/workarea/authentication_test.rb +++ b/core/test/integration/workarea/authentication_test.rb @@ -125,7 +125,7 @@ def test_ip_address_changing assert(response.ok?) refute(response.redirect?) - @user.update_attributes!(ip_address: '192.168.0.1') + @user.update!(ip_address: '192.168.0.1') get '/login_required' assert(flash[:info].present?) diff --git a/core/test/integration/workarea/authorization_test.rb b/core/test/integration/workarea/authorization_test.rb index 3514eb9d09..5afd7c8ecb 100644 --- a/core/test/integration/workarea/authorization_test.rb +++ b/core/test/integration/workarea/authorization_test.rb @@ -46,29 +46,29 @@ def refute_authorized def test_allowing_super_admins AuthorizationController.required_permissions(:store) - @user.update_attributes!(super_admin: true) + @user.update!(super_admin: true) assert_authorized end def test_blank_requirements - @user.update_attributes!(admin: true) + @user.update!(admin: true) assert_authorized end def test_invalid_permissions AuthorizationController.required_permissions(:store) - @user.update_attributes!(admin: true) + @user.update!(admin: true) refute_authorized end def test_valid_permissions AuthorizationController.required_permissions(:store) - @user.update_attributes!(admin: true, store_access: true) + @user.update!(admin: true, store_access: true) assert_authorized AuthorizationController.reset_permissions! AuthorizationController.required_permissions(:orders_manager) - @user.update_attributes!(admin: true, orders_manager: true) + @user.update!(admin: true, orders_manager: true) assert_authorized end @@ -80,13 +80,13 @@ def test_non_admins def test_multiple_permissions_requirements AuthorizationController.required_permissions(:store, :catalog) - @user.update_attributes!(admin: true) + @user.update!(admin: true) refute_authorized - @user.update_attributes!(store_access: true) + @user.update!(store_access: true) refute_authorized - @user.update_attributes!(catalog_access: true) + @user.update!(catalog_access: true) assert_authorized end end diff --git a/core/test/lib/workarea/elasticsearch/query_cache_test.rb b/core/test/lib/workarea/elasticsearch/query_cache_test.rb index 3ad38c216e..62ffe4cb02 100644 --- a/core/test/lib/workarea/elasticsearch/query_cache_test.rb +++ b/core/test/lib/workarea/elasticsearch/query_cache_test.rb @@ -62,7 +62,7 @@ def test_reset_when_updating_a_document Search::Storefront::CategoryQuery.find_by_product(product) - product.update_attributes(name: 'New Name') + product.update(name: 'New Name') WebMock.reset! @@ -76,7 +76,7 @@ def test_reset_when_deleting_a_document Search::Storefront::CategoryQuery.find_by_product(product) - product.update_attributes(name: 'New Name') + product.update(name: 'New Name') product_2 = create_product diff --git a/core/test/lib/workarea/ext/mongoid/audit_log_entry_test.rb b/core/test/lib/workarea/ext/mongoid/audit_log_entry_test.rb index a18ddc6764..e911d9c824 100644 --- a/core/test/lib/workarea/ext/mongoid/audit_log_entry_test.rb +++ b/core/test/lib/workarea/ext/mongoid/audit_log_entry_test.rb @@ -8,7 +8,7 @@ def test_release_is_recorded_if_there_is_a_release_present_when_saving release = create_release Mongoid::AuditLog.record do release.as_current do - product.update_attributes!(name: 'Bar') + product.update!(name: 'Bar') end end @@ -18,7 +18,7 @@ def test_release_is_recorded_if_there_is_a_release_present_when_saving order = create_order Mongoid::AuditLog.record do release.as_current do - order.update_attributes!(email: 'bcrouse@weblinc.com') + order.update!(email: 'bcrouse@weblinc.com') end end diff --git a/core/test/middleware/workarea/rack_middleware_stack_test.rb b/core/test/middleware/workarea/rack_middleware_stack_test.rb index a2643c8107..596c63d590 100644 --- a/core/test/middleware/workarea/rack_middleware_stack_test.rb +++ b/core/test/middleware/workarea/rack_middleware_stack_test.rb @@ -10,7 +10,7 @@ def middleware_classes end def test_mongoid_query_cache_middleware_is_present - assert_includes middleware_classes, Mongoid::QueryCache::Middleware + assert_includes middleware_classes, Mongo::QueryCache::Middleware end def test_elasticsearch_query_cache_middleware_is_present diff --git a/core/test/models/workarea/catalog/product_test.rb b/core/test/models/workarea/catalog/product_test.rb index 881d42ba2b..bb9430e8f8 100644 --- a/core/test/models/workarea/catalog/product_test.rb +++ b/core/test/models/workarea/catalog/product_test.rb @@ -35,7 +35,7 @@ def test_find_ordered_for_display results = Product.find_ordered_for_display(products.map(&:id).reverse) assert_equal(products.reverse, results) - products.first.update_attributes(active: false) + products.first.update(active: false) products.first.reload results = Product.find_ordered_for_display(products.map(&:id)) diff --git a/core/test/models/workarea/checkout_test.rb b/core/test/models/workarea/checkout_test.rb index 39a4726e8c..626506c728 100644 --- a/core/test/models/workarea/checkout_test.rb +++ b/core/test/models/workarea/checkout_test.rb @@ -160,7 +160,7 @@ def test_continue_as end def test_user_changed - @order.update_attributes!(user_id: @user.id) + @order.update!(user_id: @user.id) checkout = Checkout.new(@order) refute(checkout.user_changed?) diff --git a/core/test/models/workarea/content/block_test.rb b/core/test/models/workarea/content/block_test.rb index bee8bacc77..455581165a 100644 --- a/core/test/models/workarea/content/block_test.rb +++ b/core/test/models/workarea/content/block_test.rb @@ -16,7 +16,7 @@ def test_valid_typecasts_boolean_values data: { 'show_line' => 'true' } ) assert(block.data['show_line']) - block.update_attributes(data: { 'show_line' => 'false' }) + block.update(data: { 'show_line' => 'false' }) refute(block.data['show_line']) # NOTE: This is to test the type consistency of `data.show_line` @@ -43,7 +43,7 @@ def test_valid_typecasts_the_values_in_the_data_block assert_equal('1', block.data['html']) - block.update_attributes(data: { 'html' => 2 }) + block.update(data: { 'html' => 2 }) assert_equal('2', block.data['html']) end diff --git a/core/test/models/workarea/inventory/policies/allow_backorder_test.rb b/core/test/models/workarea/inventory/policies/allow_backorder_test.rb index 879ee5e22e..bc6fd0103d 100644 --- a/core/test/models/workarea/inventory/policies/allow_backorder_test.rb +++ b/core/test/models/workarea/inventory/policies/allow_backorder_test.rb @@ -10,10 +10,10 @@ def test_available_to_sell policy = AllowBackorder.new(sku) assert_equal(2, policy.available_to_sell) - sku.update_attributes(backordered: 5) + sku.update(backordered: 5) assert_equal(7, policy.available_to_sell) - sku.update_attributes(available: 1, backordered: 2) + sku.update(available: 1, backordered: 2) assert_equal(0, policy.available_to_sell) end diff --git a/core/test/models/workarea/inventory/policies/standard_test.rb b/core/test/models/workarea/inventory/policies/standard_test.rb index 21014373bc..48e5e329d3 100644 --- a/core/test/models/workarea/inventory/policies/standard_test.rb +++ b/core/test/models/workarea/inventory/policies/standard_test.rb @@ -10,7 +10,7 @@ def test_available_to_sell policy = Standard.new(sku) assert_equal(2, policy.available_to_sell) - sku.update_attributes(available: 1) + sku.update(available: 1) assert_equal(0, policy.available_to_sell) end end diff --git a/core/test/models/workarea/navigation/menu_test.rb b/core/test/models/workarea/navigation/menu_test.rb index c09e4adf91..7757a48b7e 100644 --- a/core/test/models/workarea/navigation/menu_test.rb +++ b/core/test/models/workarea/navigation/menu_test.rb @@ -7,15 +7,15 @@ def test_active menu = create_menu(active: false) refute(menu.active?) - menu.update_attributes!(active: true) + menu.update!(active: true) assert(menu.active?) page = create_page(active: false) taxon = create_taxon(navigable: page) - menu.update_attributes!(taxon: taxon) + menu.update!(taxon: taxon) refute(menu.active?) - page.update_attributes!(active: true) + page.update!(active: true) assert(menu.active?) end end diff --git a/core/test/models/workarea/navigation/taxon_test.rb b/core/test/models/workarea/navigation/taxon_test.rb index 8c695a5fed..83ae9113cc 100644 --- a/core/test/models/workarea/navigation/taxon_test.rb +++ b/core/test/models/workarea/navigation/taxon_test.rb @@ -28,7 +28,7 @@ def test_removes_navigable_references_when_setting_to_a_url navigable = create_page(slug: 'test') taxon = create_taxon(navigable: navigable) - taxon.update_attributes(url: 'http://example.com') + taxon.update(url: 'http://example.com') assert(taxon.navigable.blank?) assert(taxon.navigable_slug.blank?) end diff --git a/core/test/models/workarea/payment/profile_test.rb b/core/test/models/workarea/payment/profile_test.rb index 03ef62827f..01e0bc4bdf 100644 --- a/core/test/models/workarea/payment/profile_test.rb +++ b/core/test/models/workarea/payment/profile_test.rb @@ -23,7 +23,7 @@ def test_default_credit_card end def test_purchase_on_store_credit - profile.update_attributes(store_credit: 10.to_m) + profile.update(store_credit: 10.to_m) profile.purchase_on_store_credit(500) profile.reload @@ -36,7 +36,7 @@ def test_purchase_on_store_credit end def test_reload_store_credit - profile.update_attributes(store_credit: 0.to_m) + profile.update(store_credit: 0.to_m) profile.reload_store_credit(500) profile.reload diff --git a/core/test/models/workarea/payment/tender_test.rb b/core/test/models/workarea/payment/tender_test.rb index 43991089ab..b92e8b6cfc 100644 --- a/core/test/models/workarea/payment/tender_test.rb +++ b/core/test/models/workarea/payment/tender_test.rb @@ -12,25 +12,25 @@ def set_tender def test_authorized_amount_is_the_sum_of_the_successful_auth_amounts @tender .build_transaction(action: 'authorize', amount: 6.to_m) - .update_attributes!(success: false) + .update!(success: false) @tender .build_transaction(action: 'authorize', amount: 6.to_m) - .update_attributes!(success: true) + .update!(success: true) @tender .build_transaction(action: 'purchase', amount: 7.to_m) - .update_attributes!(success: true) + .update!(success: true) @tender .build_transaction(action: 'capture', amount: 5.to_m) - .update_attributes!(success: false) + .update!(success: false) @tender .build_transaction(action: 'capture', amount: 6.to_m) - .update_attributes!(success: true) + .update!(success: true) @tender .build_transaction(action: 'capture', amount: 7.to_m) - .update_attributes!(success: true) + .update!(success: true) @tender .build_transaction(action: 'capture', amount: 7.to_m) - .update_attributes!(success: true, canceled_at: Time.current) + .update!(success: true, canceled_at: Time.current) assert_equal(6.to_m, @tender.authorized_amount) end @@ -38,22 +38,22 @@ def test_authorized_amount_is_the_sum_of_the_successful_auth_amounts def test_captured_amount_is_the_sum_of_the_successful_capture_amounts @tender .build_transaction(action: 'authorize', amount: 6.to_m) - .update_attributes!(success: true) + .update!(success: true) @tender .build_transaction(action: 'purchase', amount: 7.to_m) - .update_attributes!(success: true) + .update!(success: true) @tender .build_transaction(action: 'capture', amount: 5.to_m) - .update_attributes!(success: false) + .update!(success: false) @tender .build_transaction(action: 'capture', amount: 6.to_m) - .update_attributes!(success: true) + .update!(success: true) @tender .build_transaction(action: 'capture', amount: 7.to_m) - .update_attributes!(success: true) + .update!(success: true) @tender .build_transaction(action: 'capture', amount: 7.to_m) - .update_attributes!(success: true, canceled_at: Time.current) + .update!(success: true, canceled_at: Time.current) assert_equal(20.to_m, @tender.captured_amount) end @@ -61,16 +61,16 @@ def test_captured_amount_is_the_sum_of_the_successful_capture_amounts def test_uncaptured_amount_is_the_authed_amount_less_the_captured_amount @tender .build_transaction(action: 'authorize', amount: 10.to_m) - .update_attributes!(success: true) + .update!(success: true) @tender .build_transaction(action: 'purchase', amount: 7.to_m) - .update_attributes!(success: true) + .update!(success: true) @tender .build_transaction(action: 'capture', amount: 1.to_m) - .update_attributes!(success: false) + .update!(success: false) @tender .build_transaction(action: 'capture', amount: 2.to_m) - .update_attributes!(success: true) + .update!(success: true) assert_equal(8.to_m, @tender.uncaptured_amount) end @@ -78,22 +78,22 @@ def test_uncaptured_amount_is_the_authed_amount_less_the_captured_amount def test_refunded_amount_is_the_sum_of_the_successful_capture_amounts @tender .build_transaction(action: 'authorize', amount: 6.to_m) - .update_attributes!(success: true) + .update!(success: true) @tender .build_transaction(action: 'purchase', amount: 7.to_m) - .update_attributes!(success: true) + .update!(success: true) @tender .build_transaction(action: 'capture', amount: 5.to_m) - .update_attributes!(success: false) + .update!(success: false) @tender .build_transaction(action: 'refund', amount: 6.to_m) - .update_attributes!(success: false) + .update!(success: false) @tender .build_transaction(action: 'refund', amount: 7.to_m) - .update_attributes!(success: true) + .update!(success: true) @tender .build_transaction(action: 'refund', amount: 7.to_m) - .update_attributes!(success: true, canceled_at: Time.current) + .update!(success: true, canceled_at: Time.current) assert_equal(7.to_m, @tender.captured_amount) end @@ -101,19 +101,19 @@ def test_refunded_amount_is_the_sum_of_the_successful_capture_amounts def test_capturable_amount_is_the_authorized_amount_less_the_captured_amount @tender .build_transaction(action: 'authorize', amount: 6.to_m) - .update_attributes!(success: false) + .update!(success: false) @tender .build_transaction(action: 'authorize', amount: 6.to_m) - .update_attributes!(success: true) + .update!(success: true) @tender .build_transaction(action: 'capture', amount: 5.to_m) - .update_attributes!(success: false) + .update!(success: false) @tender .build_transaction(action: 'capture', amount: 5.to_m) - .update_attributes!(success: true) + .update!(success: true) @tender .build_transaction(action: 'capture', amount: 5.to_m) - .update_attributes!(success: true, canceled_at: Time.current) + .update!(success: true, canceled_at: Time.current) assert_equal(1.to_m, @tender.capturable_amount) end @@ -121,19 +121,19 @@ def test_capturable_amount_is_the_authorized_amount_less_the_captured_amount def test_capturable_amount_cannot_be_negative @tender .build_transaction(action: 'authorize', amount: 6.to_m) - .update_attributes!(success: false) + .update!(success: false) @tender .build_transaction(action: 'authorize', amount: 6.to_m) - .update_attributes!(success: true) + .update!(success: true) @tender .build_transaction(action: 'purchase', amount: 7.to_m) - .update_attributes!(success: true) + .update!(success: true) @tender .build_transaction(action: 'capture', amount: 5.to_m) - .update_attributes!(success: false) + .update!(success: false) @tender .build_transaction(action: 'capture', amount: 5.to_m) - .update_attributes!(success: true) + .update!(success: true) assert_equal(0.to_m, @tender.capturable_amount) end @@ -141,25 +141,25 @@ def test_capturable_amount_cannot_be_negative def test_refundable_amount_is_the_authorized_amount_less_the_captured_amount @tender .build_transaction(action: 'authorize', amount: 6.to_m) - .update_attributes!(success: false) + .update!(success: false) @tender .build_transaction(action: 'authorize', amount: 6.to_m) - .update_attributes!(success: true) + .update!(success: true) @tender .build_transaction(action: 'capture', amount: 5.to_m) - .update_attributes!(success: false) + .update!(success: false) @tender .build_transaction(action: 'capture', amount: 5.to_m) - .update_attributes!(success: true) + .update!(success: true) @tender .build_transaction(action: 'refund', amount: 3.to_m) - .update_attributes!(success: false) + .update!(success: false) @tender .build_transaction(action: 'refund', amount: 3.to_m) - .update_attributes!(success: true) + .update!(success: true) @tender .build_transaction(action: 'refund', amount: 3.to_m) - .update_attributes!(success: true, canceled_at: Time.current) + .update!(success: true, canceled_at: Time.current) assert_equal(2.to_m, @tender.refundable_amount) end @@ -167,22 +167,22 @@ def test_refundable_amount_is_the_authorized_amount_less_the_captured_amount def test_refundable_amount_cannot_be_negative @tender .build_transaction(action: 'authorize', amount: 6.to_m) - .update_attributes!(success: false) + .update!(success: false) @tender .build_transaction(action: 'authorize', amount: 6.to_m) - .update_attributes!(success: true) + .update!(success: true) @tender .build_transaction(action: 'purchase', amount: 7.to_m) - .update_attributes!(success: true) + .update!(success: true) @tender .build_transaction(action: 'capture', amount: 5.to_m) - .update_attributes!(success: false) + .update!(success: false) @tender .build_transaction(action: 'capture', amount: 5.to_m) - .update_attributes!(success: true) + .update!(success: true) @tender .build_transaction(action: 'refund', amount: 15.to_m) - .update_attributes!(success: true) + .update!(success: true) assert_equal(0.to_m, @tender.capturable_amount) end diff --git a/core/test/models/workarea/pricing/calculators/overrides_calculator_test.rb b/core/test/models/workarea/pricing/calculators/overrides_calculator_test.rb index 4cbe281436..4f55988fc6 100644 --- a/core/test/models/workarea/pricing/calculators/overrides_calculator_test.rb +++ b/core/test/models/workarea/pricing/calculators/overrides_calculator_test.rb @@ -22,7 +22,7 @@ def override end def test_adjusting_total_for_items - override.update_attributes!( + override.update!( item_prices: { @order.items.first.id.to_s => 6.0, # increasing price @order.items.second.id.to_s => 15.0 @@ -41,7 +41,7 @@ def test_adjusting_total_for_items end def test_adjusting_subtotal - override.update_attributes!( + override.update!( item_prices: { @order.items.first.id.to_s => 6.0, @order.items.second.id.to_s => 7.5 @@ -61,7 +61,7 @@ def test_adjusting_subtotal end def test_adjusting_shipping - override.update_attributes!( + override.update!( subtotal_adjustment: -12.to_m, shipping_adjustment: -3.to_m, ) @@ -97,7 +97,7 @@ def test_adjusting_shipping end def test_negative_prices - override.update_attributes!( + override.update!( item_prices: { @order.items.first.id.to_s => -1.0, @order.items.second.id.to_s => -5.0 diff --git a/core/test/models/workarea/pricing/discount/application_group_test.rb b/core/test/models/workarea/pricing/discount/application_group_test.rb index 0f6393a586..91d60622b4 100644 --- a/core/test/models/workarea/pricing/discount/application_group_test.rb +++ b/core/test/models/workarea/pricing/discount/application_group_test.rb @@ -78,7 +78,7 @@ def test_calculate_returns_all_discounts_when_the_graph_is_complete ids = compatible_sets.map(&:id).map(&:to_s) compatible_sets.each do |discount| - discount.update_attributes(compatible_discount_ids: ids) + discount.update(compatible_discount_ids: ids) end results = ApplicationGroup.calculate(@discounts, @order, @shippings) @@ -94,7 +94,7 @@ def test_calculate_returns_groups_when_the_graph_is_a_set_of_disjoint_complete_g @discounts.each_slice(5) do |discount_subset| ids = discount_subset.map(&:id).map(&:to_s) discount_subset - .each { |d| d.update_attributes(compatible_discount_ids: ids) } + .each { |d| d.update(compatible_discount_ids: ids) } end results = ApplicationGroup.calculate(@discounts, @order, @shippings) diff --git a/core/test/models/workarea/pricing/tax_applier_test.rb b/core/test/models/workarea/pricing/tax_applier_test.rb index 37b9127ce6..436b3e26cc 100644 --- a/core/test/models/workarea/pricing/tax_applier_test.rb +++ b/core/test/models/workarea/pricing/tax_applier_test.rb @@ -108,7 +108,7 @@ def test_partial_shipping_quantity_tax_calculation ) ]) - @shipping.update_attributes!(quantities: { @item.id => 1 }) + @shipping.update!(quantities: { @item.id => 1 }) applier = TaxApplier.new(@shipping, @adjustments_to_tax) applier.apply diff --git a/core/test/models/workarea/releasable_test.rb b/core/test/models/workarea/releasable_test.rb index 936b06d205..363cc47733 100644 --- a/core/test/models/workarea/releasable_test.rb +++ b/core/test/models/workarea/releasable_test.rb @@ -209,7 +209,7 @@ def test_save_does_not_save_timestamp_changes model = Foo.create!(name: 'Test') Release.with_current(@release.id) do - model.update_attributes!(name: 'Changed') + model.update!(name: 'Changed') end fields_in_change = model.changesets.first.changeset.keys @@ -223,7 +223,7 @@ def test_save_does_not_save_slug_changes model = Foo.create!(name: 'Test', slug: 'test') Release.with_current(@release.id) do - model.update_attributes(slug: 'test-changed') + model.update(slug: 'test-changed') refute(model.valid?) assert_includes( @@ -237,7 +237,7 @@ def test_save_does_not_save_blank_to_blank_changes model = Foo.create!(name: 'Test', blank_field: nil) Release.with_current(@release.id) do - model.update_attributes!(name: 'Changed', blank_field: '') + model.update!(name: 'Changed', blank_field: '') end fields_in_change = model.changesets.first.changeset.keys @@ -376,7 +376,7 @@ def test_in_release assert_equal('Foo', in_release.name) refute_equal(in_release.object_id, model.object_id) - Mongoid::QueryCache.cache do + Mongo::QueryCache.cache do cached = Foo.find(model.id) # a find to ensure it's in the cache table cached.name = 'Bar' # so the cache table's instance has a change @@ -387,7 +387,7 @@ def test_in_release end ensure - Mongoid::QueryCache.clear_cache + Mongo::QueryCache.clear end def test_skip_changeset diff --git a/core/test/models/workarea/release/changeset_test.rb b/core/test/models/workarea/release/changeset_test.rb index 5e75f465ab..04d16e4950 100644 --- a/core/test/models/workarea/release/changeset_test.rb +++ b/core/test/models/workarea/release/changeset_test.rb @@ -23,7 +23,7 @@ def test_summary def test_build_undo releasable = create_page(name: 'Foo') release = create_release - release.as_current { releasable.update_attributes!(name: 'Bar') } + release.as_current { releasable.update!(name: 'Bar') } changeset = release.changesets.first undo = changeset.build_undo(release: create_release) @@ -33,7 +33,7 @@ def test_build_undo assert_equal('Foo', releasable.name) other_release = create_release - other_release.as_current { releasable.update_attributes!(name: 'Baz') } + other_release.as_current { releasable.update!(name: 'Baz') } other_release.as_current do undo = changeset.build_undo(release: create_release) @@ -43,8 +43,8 @@ def test_build_undo assert_equal('Foo', releasable.name) end - other_release.update_attributes!(publish_at: 1.day.from_now) - release.update_attributes!(publish_at: 2.days.from_now) + other_release.update!(publish_at: 1.day.from_now) + release.update!(publish_at: 2.days.from_now) changeset.reload undo = changeset.build_undo(release: create_release) diff --git a/core/test/models/workarea/release_jobs_test.rb b/core/test/models/workarea/release_jobs_test.rb index cb28dd9fd2..dd31b10e3f 100644 --- a/core/test/models/workarea/release_jobs_test.rb +++ b/core/test/models/workarea/release_jobs_test.rb @@ -37,7 +37,7 @@ def test_removing_publish_at_removes_job assert(release.publish_job_id.present?) assert_equal(1, @scheduled_set.size) - release.update_attributes!(publish_at: nil) + release.update!(publish_at: nil) release.reload assert(release.publish_job_id.blank?) assert_equal(0, @scheduled_set.size) diff --git a/core/test/models/workarea/release_test.rb b/core/test/models/workarea/release_test.rb index e1d5d66445..3b21cc2ad1 100644 --- a/core/test/models/workarea/release_test.rb +++ b/core/test/models/workarea/release_test.rb @@ -151,7 +151,7 @@ def test_publishing_on_deleted_models release = create_release release.as_current do - page.update_attributes!(name: 'Bar') + page.update!(name: 'Bar') end Content::Page.delete_all # leave changesets with no model diff --git a/core/test/models/workarea/search/admin/releasable_test.rb b/core/test/models/workarea/search/admin/releasable_test.rb index ccda746e79..02c3e55602 100644 --- a/core/test/models/workarea/search/admin/releasable_test.rb +++ b/core/test/models/workarea/search/admin/releasable_test.rb @@ -17,10 +17,10 @@ def test_facets release_two = create_release release_three = create_release - release_one.as_current { releasable.update_attributes!(name: 'Bar') } - release_two.as_current { content.update_attributes!(browser_title: 'Foo') } - release_three.as_current { releasable.update_attributes!(name: 'Bar') } - release_three.update_attributes!(published_at: Time.current) + release_one.as_current { releasable.update!(name: 'Bar') } + release_two.as_current { content.update!(browser_title: 'Foo') } + release_three.as_current { releasable.update!(name: 'Bar') } + release_three.update!(published_at: Time.current) search_model = Foo.new(releasable) assert_equal(search_model.facets[:active_by_segment], %w(foo bar baz)) diff --git a/core/test/models/workarea/search/admin/user_test.rb b/core/test/models/workarea/search/admin/user_test.rb index 68ddab6d30..ed8f968997 100644 --- a/core/test/models/workarea/search/admin/user_test.rb +++ b/core/test/models/workarea/search/admin/user_test.rb @@ -11,11 +11,11 @@ def set_user end def test_includes_role_text - @user.update_attributes!(admin: true) + @user.update!(admin: true) assert_includes(User.new(@user).search_text, 'admin') assert_includes(User.new(@user).search_text, 'administrator') - @user.update_attributes!(admin: false) + @user.update!(admin: false) assert_includes(User.new(@user).search_text, 'customer') end diff --git a/core/test/models/workarea/search/storefront/product_test.rb b/core/test/models/workarea/search/storefront/product_test.rb index 6d1a161483..aa5ddd3440 100644 --- a/core/test/models/workarea/search/storefront/product_test.rb +++ b/core/test/models/workarea/search/storefront/product_test.rb @@ -26,7 +26,7 @@ def test_sku_returns_only_skus_that_have_inventory assert_includes(search_model.sku, 'SKU') assert_includes(search_model.sku, 'SKU1') - inventory.update_attributes!(available: 0) + inventory.update!(available: 0) search_model = Product.new(product) assert_equal(['SKU'], search_model.sku) end diff --git a/core/test/models/workarea/segment/rules/last_order_test.rb b/core/test/models/workarea/segment/rules/last_order_test.rb index 9b64327022..1dd80da8f2 100644 --- a/core/test/models/workarea/segment/rules/last_order_test.rb +++ b/core/test/models/workarea/segment/rules/last_order_test.rb @@ -14,27 +14,27 @@ def test_qualifies? visit = create_visit(email: 'bcrouse@workarea.com') refute(LastOrder.new(days: 7).qualifies?(visit)) - metrics.update_attributes!(last_order_at: 8.days.ago) + metrics.update!(last_order_at: 8.days.ago) visit = create_visit(email: 'bcrouse@workarea.com') refute(LastOrder.new(days: 7, within: true).qualifies?(visit)) - metrics.update_attributes!(last_order_at: 7.days.ago) + metrics.update!(last_order_at: 7.days.ago) visit = create_visit(email: 'bcrouse@workarea.com') assert(LastOrder.new(days: 7, within: true).qualifies?(visit)) - metrics.update_attributes!(last_order_at: 6.days.ago) + metrics.update!(last_order_at: 6.days.ago) visit = create_visit(email: 'bcrouse@workarea.com') assert(LastOrder.new(days: 7, within: true).qualifies?(visit)) - metrics.update_attributes!(last_order_at: 8.days.ago) + metrics.update!(last_order_at: 8.days.ago) visit = create_visit(email: 'bcrouse@workarea.com') assert(LastOrder.new(days: 7, within: false).qualifies?(visit)) - metrics.update_attributes!(last_order_at: 7.days.ago) + metrics.update!(last_order_at: 7.days.ago) visit = create_visit(email: 'bcrouse@workarea.com') refute(LastOrder.new(days: 7, within: false).qualifies?(visit)) - metrics.update_attributes!(last_order_at: 6.days.ago) + metrics.update!(last_order_at: 6.days.ago) visit = create_visit(email: 'bcrouse@workarea.com') refute(LastOrder.new(days: 7, within: false).qualifies?(visit)) end diff --git a/core/test/models/workarea/segment/rules/orders_test.rb b/core/test/models/workarea/segment/rules/orders_test.rb index d5608467ff..1efa5a5f42 100644 --- a/core/test/models/workarea/segment/rules/orders_test.rb +++ b/core/test/models/workarea/segment/rules/orders_test.rb @@ -13,43 +13,43 @@ def test_qualifies? visit = create_visit(email: 'bcrouse@workarea.com') refute(Orders.new(minimum: 1).qualifies?(visit)) - metrics.update_attributes!(orders: 0) + metrics.update!(orders: 0) visit = create_visit(email: 'bcrouse@workarea.com') refute(Orders.new(minimum: 1).qualifies?(visit)) - metrics.update_attributes!(orders: 1) + metrics.update!(orders: 1) visit = create_visit(email: 'bcrouse@workarea.com') assert(Orders.new(minimum: 1).qualifies?(visit)) - metrics.update_attributes!(orders: 2) + metrics.update!(orders: 2) visit = create_visit(email: 'bcrouse@workarea.com') assert(Orders.new(minimum: 1).qualifies?(visit)) - metrics.update_attributes!(orders: 0) + metrics.update!(orders: 0) visit = create_visit(email: 'bcrouse@workarea.com') assert(Orders.new(maximum: 2).qualifies?(visit)) - metrics.update_attributes!(orders: 1) + metrics.update!(orders: 1) visit = create_visit(email: 'bcrouse@workarea.com') assert(Orders.new(maximum: 2).qualifies?(visit)) - metrics.update_attributes!(orders: 2) + metrics.update!(orders: 2) visit = create_visit(email: 'bcrouse@workarea.com') assert(Orders.new(maximum: 2).qualifies?(visit)) - metrics.update_attributes!(orders: 3) + metrics.update!(orders: 3) visit = create_visit(email: 'bcrouse@workarea.com') refute(Orders.new(maximum: 2).qualifies?(visit)) - metrics.update_attributes!(orders: 3) + metrics.update!(orders: 3) visit = create_visit(email: 'bcrouse@workarea.com') refute(Orders.new(minimum: 1, maximum: 2).qualifies?(visit)) - metrics.update_attributes!(orders: 1) + metrics.update!(orders: 1) visit = create_visit(email: 'bcrouse@workarea.com') assert(Orders.new(minimum: 1, maximum: 2).qualifies?(visit)) - metrics.update_attributes!(orders: 2) + metrics.update!(orders: 2) visit = create_visit(email: 'bcrouse@workarea.com') assert(Orders.new(minimum: 1, maximum: 2).qualifies?(visit)) end diff --git a/core/test/models/workarea/segment/rules/revenue_test.rb b/core/test/models/workarea/segment/rules/revenue_test.rb index 61425bd084..cb3ac06d12 100644 --- a/core/test/models/workarea/segment/rules/revenue_test.rb +++ b/core/test/models/workarea/segment/rules/revenue_test.rb @@ -13,43 +13,43 @@ def test_qualifies? visit = create_visit(email: 'bcrouse@workarea.com') refute(Revenue.new(minimum: 1).qualifies?(visit)) - metrics.update_attributes!(revenue: 0) + metrics.update!(revenue: 0) visit = create_visit(email: 'bcrouse@workarea.com') refute(Revenue.new(minimum: 1).qualifies?(visit)) - metrics.update_attributes!(revenue: 1) + metrics.update!(revenue: 1) visit = create_visit(email: 'bcrouse@workarea.com') assert(Revenue.new(minimum: 1).qualifies?(visit)) - metrics.update_attributes!(revenue: 2) + metrics.update!(revenue: 2) visit = create_visit(email: 'bcrouse@workarea.com') assert(Revenue.new(minimum: 1).qualifies?(visit)) - metrics.update_attributes!(revenue: 0) + metrics.update!(revenue: 0) visit = create_visit(email: 'bcrouse@workarea.com') assert(Revenue.new(maximum: 2).qualifies?(visit)) - metrics.update_attributes!(revenue: 1) + metrics.update!(revenue: 1) visit = create_visit(email: 'bcrouse@workarea.com') assert(Revenue.new(maximum: 2).qualifies?(visit)) - metrics.update_attributes!(revenue: 2) + metrics.update!(revenue: 2) visit = create_visit(email: 'bcrouse@workarea.com') assert(Revenue.new(maximum: 2).qualifies?(visit)) - metrics.update_attributes!(revenue: 3) + metrics.update!(revenue: 3) visit = create_visit(email: 'bcrouse@workarea.com') refute(Revenue.new(maximum: 2).qualifies?(visit)) - metrics.update_attributes!(revenue: 3) + metrics.update!(revenue: 3) visit = create_visit(email: 'bcrouse@workarea.com') refute(Revenue.new(minimum: 1, maximum: 2).qualifies?(visit)) - metrics.update_attributes!(revenue: 1) + metrics.update!(revenue: 1) visit = create_visit(email: 'bcrouse@workarea.com') assert(Revenue.new(minimum: 1, maximum: 2).qualifies?(visit)) - metrics.update_attributes!(revenue: 2) + metrics.update!(revenue: 2) visit = create_visit(email: 'bcrouse@workarea.com') assert(Revenue.new(minimum: 1, maximum: 2).qualifies?(visit)) end diff --git a/core/test/models/workarea/segment_test.rb b/core/test/models/workarea/segment_test.rb index 80230b69b8..5e8562f35e 100644 --- a/core/test/models/workarea/segment_test.rb +++ b/core/test/models/workarea/segment_test.rb @@ -12,15 +12,15 @@ def test_find_qualifying visit = create_visit(email: 'bcrouse@workarea.com') assert(Segment.find_qualifying(visit).empty?) - metrics.update_attributes!(orders: 1) + metrics.update!(orders: 1) visit = create_visit(email: 'bcrouse@workarea.com') assert_equal([one], Segment.find_qualifying(visit)) - metrics.update_attributes!(orders: 2) + metrics.update!(orders: 2) visit = create_visit(email: 'bcrouse@workarea.com') assert_equal([one, two], Segment.find_qualifying(visit)) - metrics.update_attributes!(orders: 3) + metrics.update!(orders: 3) visit = create_visit(email: 'bcrouse@workarea.com') assert_equal([one, two, three], Segment.find_qualifying(visit)) end @@ -58,7 +58,7 @@ def test_qualifies visit = create_visit(email: 'bcrouse@workarea.com') refute(segment.qualifies?(visit)) - metrics.update_attributes!(orders: 2) + metrics.update!(orders: 2) visit = create_visit(email: 'bcrouse@workarea.com') refute(segment.qualifies?(visit)) diff --git a/core/test/models/workarea/user_test.rb b/core/test/models/workarea/user_test.rb index 9bb2a2ead1..4f3db3e10c 100644 --- a/core/test/models/workarea/user_test.rb +++ b/core/test/models/workarea/user_test.rb @@ -19,10 +19,10 @@ def test_find_admin user = create_user(admin: false) assert_nil(User.find_admin(user.id)) - user.update_attributes!(admin: true) + user.update!(admin: true) assert_equal(user, User.find_admin(user.id)) - user.update_attributes!(super_admin: true) + user.update!(super_admin: true) assert_equal(user, User.find_admin(user.id)) end @@ -45,26 +45,26 @@ def test_should_not_allow_a_duplicate_user_on_the_same_site def test_allows_a_normal_user_to_reuse_the_same_password user = create_user - assert(user.update_attributes(password: 'Password1!')) + assert(user.update(password: 'Password1!')) assert_equal(user, user.authenticate('Password1!')) - assert(user.update_attributes(password: 'Password2!')) + assert(user.update(password: 'Password2!')) assert_equal(user, user.authenticate('Password2!')) - assert(user.update_attributes(password: 'Password1!')) + assert(user.update(password: 'Password1!')) assert_equal(user, user.authenticate('Password1!')) end def test_does_not_allow_admins_to_reuse_the_same_password user = create_user(admin: true) - assert(user.update_attributes(password: 'Password1!')) + assert(user.update(password: 'Password1!')) assert_equal(user, user.authenticate('Password1!')) - assert(user.update_attributes(password: 'Password2!')) + assert(user.update(password: 'Password2!')) assert_equal(user, user.authenticate('Password2!')) - refute(user.update_attributes(password: 'Password1!')) + refute(user.update(password: 'Password1!')) end def test_find_for_login @@ -294,7 +294,7 @@ def test_admins_have_more_advanced_password_requirements def test_admin_permissions_revoked_when_no_longer_admin user = create_user(admin: true, releases_access: true) - user.update_attributes!(admin: false) + user.update!(admin: false) refute(user.releases_access?) user = create_user(super_admin: true, releases_access: true) diff --git a/core/test/queries/workarea/alerts_test.rb b/core/test/queries/workarea/alerts_test.rb index 72edcc0a0a..669cd1b363 100644 --- a/core/test/queries/workarea/alerts_test.rb +++ b/core/test/queries/workarea/alerts_test.rb @@ -15,7 +15,7 @@ def test_products_missing_prices IndexAdminSearch.perform(product) assert_equal(1, Alerts.new.products_missing_prices) - product.update_attributes!(active: false) + product.update!(active: false) IndexAdminSearch.perform(product) assert_equal(0, Alerts.new.products_missing_prices) end @@ -28,7 +28,7 @@ def test_empty_categories IndexAdminSearch.perform(category) assert_equal(0, Alerts.new.empty_categories) - category.update_attributes!(product_ids: []) + category.update!(product_ids: []) IndexAdminSearch.perform(category) assert_equal(1, Alerts.new.empty_categories) end @@ -40,11 +40,11 @@ def test_products_missing_images IndexAdminSearch.perform(product) assert_equal(0, Alerts.new.products_missing_images) - product.update_attributes!(images: []) + product.update!(images: []) IndexAdminSearch.perform(product) assert_equal(1, Alerts.new.products_missing_images) - product.update_attributes!(active: false) + product.update!(active: false) IndexAdminSearch.perform(product) assert_equal(0, Alerts.new.products_missing_images) end @@ -56,11 +56,11 @@ def test_products_missing_descriptions IndexAdminSearch.perform(product) assert_equal(0, Alerts.new.products_missing_descriptions) - product.update_attributes!(description: nil) + product.update!(description: nil) IndexAdminSearch.perform(product) assert_equal(1, Alerts.new.products_missing_descriptions) - product.update_attributes!(active: false) + product.update!(active: false) IndexAdminSearch.perform(product) assert_equal(0, Alerts.new.products_missing_descriptions) end @@ -72,7 +72,7 @@ def test_products_missing_variants IndexAdminSearch.perform(product) assert_equal(0, Alerts.new.products_missing_variants) - product.update_attributes!(variants: []) + product.update!(variants: []) IndexAdminSearch.perform(product) assert_equal(1, Alerts.new.products_missing_variants) end @@ -89,7 +89,7 @@ def test_products_missing_categories IndexAdminSearch.perform(product) assert_equal(1, Alerts.new.products_missing_categories) - product.update_attributes!(active: false) + product.update!(active: false) IndexAdminSearch.perform(product) assert_equal(0, Alerts.new.products_missing_categories) end @@ -122,7 +122,7 @@ def test_empty_upcoming_releases page = create_page(name: 'Foo') Release.with_current(has_changes.id) do - page.update_attributes!(name: 'Bar') + page.update!(name: 'Bar') end assert_equal([empty], Alerts.new.empty_upcoming_releases) diff --git a/core/test/queries/workarea/categorization_test.rb b/core/test/queries/workarea/categorization_test.rb index b78b9c7487..65566e53df 100644 --- a/core/test/queries/workarea/categorization_test.rb +++ b/core/test/queries/workarea/categorization_test.rb @@ -63,17 +63,17 @@ def test_manual_default ) category_two = create_category - @product.update_attributes(default_category_id: category_two.id) + @product.update(default_category_id: category_two.id) categorization = Categorization.new(@product) assert_equal(category_one.id, categorization.default) - category_two.update_attributes(product_ids: [@product.id]) + category_two.update(product_ids: [@product.id]) categorization = Categorization.new(@product) assert_equal(category_two.id, categorization.default) - category_two.update_attributes(active: false) + category_two.update(active: false) categorization = Categorization.new(@product) assert_equal(category_one.id, categorization.default) diff --git a/core/test/queries/workarea/find_taxonomy_slug_test.rb b/core/test/queries/workarea/find_taxonomy_slug_test.rb index 33b8ab03fe..ea50f6f467 100644 --- a/core/test/queries/workarea/find_taxonomy_slug_test.rb +++ b/core/test/queries/workarea/find_taxonomy_slug_test.rb @@ -11,7 +11,7 @@ def test_slug slug = FindTaxonomySlug.new(navigable).slug assert_equal('baz-foo-bar', slug) - navigable.update_attributes!(slug: slug) + navigable.update!(slug: slug) navigable_two = create_category(name: 'Foo Bar') create_taxon(navigable: navigable_two, parent: parent_taxon) assert_equal('baz-foo-bar-1', FindTaxonomySlug.new(navigable_two).slug) diff --git a/core/test/queries/workarea/recommendation/product_based_test.rb b/core/test/queries/workarea/recommendation/product_based_test.rb index e69e670cf6..24aee879f9 100644 --- a/core/test/queries/workarea/recommendation/product_based_test.rb +++ b/core/test/queries/workarea/recommendation/product_based_test.rb @@ -24,7 +24,7 @@ def test_falling_back_to_related_products end def test_using_custom_products - @settings.update_attributes!( + @settings.update!( sources: %w(custom), product_ids: %w(2 3 1) ) @@ -54,7 +54,7 @@ def test_using_purchased_with ProcessProductRecommendations.new.perform - @settings.update_attributes!(sources: %w(purchased)) + @settings.update!(sources: %w(purchased)) query = ProductBased.new(@product) assert_equal(%w(3 2), query.results) end @@ -79,7 +79,7 @@ def test_not_including_deleted_products end ProcessProductRecommendations.new.perform - @settings.update_attributes!(sources: %w(purchased)) + @settings.update!(sources: %w(purchased)) Catalog::Product.find('3').destroy diff --git a/core/test/queries/workarea/search/category_browse_test.rb b/core/test/queries/workarea/search/category_browse_test.rb index 65f4a7377f..7ece3eeaf6 100644 --- a/core/test/queries/workarea/search/category_browse_test.rb +++ b/core/test/queries/workarea/search/category_browse_test.rb @@ -20,7 +20,7 @@ def test_active_products assert_equal(0, CategoryBrowse.new(category_ids: [category.id]).total) release = create_release - release.as_current { product.update_attributes!(active: true) } + release.as_current { product.update!(active: true) } IndexProduct.perform(product.reload) assert_equal(0, CategoryBrowse.new(category_ids: [category.id]).total) diff --git a/core/test/queries/workarea/search/product_search_test.rb b/core/test/queries/workarea/search/product_search_test.rb index f87d501cd3..8220abb866 100644 --- a/core/test/queries/workarea/search/product_search_test.rb +++ b/core/test/queries/workarea/search/product_search_test.rb @@ -24,7 +24,7 @@ def test_active_products assert_equal(0, ProductSearch.new(q: '*').total) release = create_release - release.as_current { product.update_attributes!(active: true) } + release.as_current { product.update!(active: true) } IndexProduct.perform(product.reload) assert_equal(0, ProductSearch.new(q: '*').total) @@ -113,7 +113,7 @@ def test_facets end def test_boosted_fields - Settings.current.update_attributes!( + Settings.current.update!( boosts: { 'name': 2, 'category_name': 1, @@ -132,7 +132,7 @@ def test_boosted_fields ProductSearch.new.boosted_fields ) - Settings.current.update_attributes!( + Settings.current.update!( boosts: { 'name': 2, 'description': 0.75, @@ -255,7 +255,7 @@ def test_featured_products end def test_exact_name_phrase_matches - Settings.current.update_attributes!( + Settings.current.update!( boosts: { 'name': 1, 'description': 2, @@ -311,7 +311,7 @@ def test_omits_suggestions_that_have_the_same_query_id end def test_blank_views_scores_allow_boosts_to_have_effect - Settings.current.update_attributes!( + Settings.current.update!( boosts: { 'name': 0, 'description': 0, diff --git a/core/test/queries/workarea/search/related_products_test.rb b/core/test/queries/workarea/search/related_products_test.rb index 95d61dbe4d..9b242b8c4a 100644 --- a/core/test/queries/workarea/search/related_products_test.rb +++ b/core/test/queries/workarea/search/related_products_test.rb @@ -19,7 +19,7 @@ def test_only_available_products one = create_product(name: 'Foo Bar Baz 1') two = create_product(active: false, name: 'Foo Bar Baz 2') - @category_one.update_attributes!(product_ids: [one.id, two.id]) + @category_one.update!(product_ids: [one.id, two.id]) search = RelatedProducts.new(product_ids: one.id) assert_equal(0, search.total) @@ -34,7 +34,7 @@ def test_filters_to_match_products_in_the_same_primary_navigation search = RelatedProducts.new(product_ids: one.id) assert_equal(2, search.total) - @category_one.update_attributes!(product_ids: [one.id, two.id]) + @category_one.update!(product_ids: [one.id, two.id]) search = RelatedProducts.new(product_ids: one.id) assert_equal(1, search.total) @@ -46,7 +46,7 @@ def test_excludes_exclude_product_ids_if_passed_in two = create_product(name: 'Foo Bar Baz 2') three = create_product(name: 'Foo Bar Baz 3') - @category_one.update_attributes!(product_ids: [one.id, two.id, three.id]) + @category_one.update!(product_ids: [one.id, two.id, three.id]) search = RelatedProducts.new(product_ids: one.id) results = search.results.map { |r| r[:model] } diff --git a/core/test/services/workarea/cancel_order_test.rb b/core/test/services/workarea/cancel_order_test.rb index 5e44c0dd2c..4e0558d1d3 100644 --- a/core/test/services/workarea/cancel_order_test.rb +++ b/core/test/services/workarea/cancel_order_test.rb @@ -40,7 +40,7 @@ def test_restocking_inventory end def test_refunding_payment - @order.update_attributes!(email: 'test@workarea.com') + @order.update!(email: 'test@workarea.com') profile = create_payment_profile(store_credit: 6.to_m) payment = create_payment(id: @order.id, profile: profile) diff --git a/core/test/workers/sidekiq/callbacks_test.rb b/core/test/workers/sidekiq/callbacks_test.rb index df2598806c..15fe1c847c 100644 --- a/core/test/workers/sidekiq/callbacks_test.rb +++ b/core/test/workers/sidekiq/callbacks_test.rb @@ -241,7 +241,7 @@ def test_multiple_callbacks def test_custom_arguments model = Model.create!(name: 'foo') - model.update_attributes!(name: 'bar') + model.update!(name: 'bar') args = CustomArgsWorker.jobs.last['args'] assert_equal(args.first, model.id.to_s) diff --git a/core/workarea-core.gemspec b/core/workarea-core.gemspec index 3845e1faab..d82c1f5217 100644 --- a/core/workarea-core.gemspec +++ b/core/workarea-core.gemspec @@ -16,7 +16,7 @@ Gem::Specification.new do |s| s.add_dependency 'bundler', '>= 1.8.0' # 1.8.0 added env variable for secrets s.add_dependency 'rails', '>= 6.1', '< 7.2' - s.add_dependency 'mongoid', '~> 7.4' # loosened from ~> 7.4.0; mongoid 8 needed for Rails 7 (BLOCKER) + s.add_dependency 'mongoid', '>= 7.4', '< 9' # widened: 8.1.3+ adds Rails 7.0/7.1 support; < 9 defers 9.x breaking changes s.add_dependency 'bcrypt', '~> 3.1' # loosened from ~> 3.1.10 s.add_dependency 'money-rails', '~> 1.13' # loosened from ~> 1.13.0 s.add_dependency 'mongoid-audit_log', '>= 0.6.0' diff --git a/docs/mongoid8-migration.md b/docs/mongoid8-migration.md new file mode 100644 index 0000000000..9e6ff2f923 --- /dev/null +++ b/docs/mongoid8-migration.md @@ -0,0 +1,153 @@ +# Mongoid 8.x Migration Guide + +*Updated: 2026-03-02 — WA-RAILS7-004* + +This document describes the changes made to make Workarea compatible with Mongoid 8.x, and what host application developers need to know when upgrading. + +--- + +## Overview + +Workarea's `mongoid` dependency has been widened from `~> 7.4` to `>= 7.4, < 9`: + +```ruby +# Before +s.add_dependency 'mongoid', '~> 7.4' + +# After +s.add_dependency 'mongoid', '>= 7.4', '< 9' +``` + +**Minimum version for Rails 7 support: Mongoid 8.1.3** (formally adds Rails 7.0/7.1 support). + +--- + +## Breaking Changes in Workarea Core + +### 1. `update_attributes` / `update_attributes!` Removed + +Mongoid 8.0 removes `update_attributes` and `update_attributes!` (deprecated since Mongoid 7.x, mirroring ActiveRecord's Rails 6.1 deprecation). + +**Change applied in this PR:** All ~550 occurrences across core, admin, storefront, and testing have been mechanically renamed: + +| Old | New | +|-----|-----| +| `.update_attributes(attrs)` | `.update(attrs)` | +| `.update_attributes!(attrs)` | `.update!(attrs)` | + +**If you have Workarea plugins or host application code** using `update_attributes` or `update_attributes!` on Mongoid models, you must update these before upgrading to Mongoid 8.x. + +```bash +# Find all occurrences in your app +grep -rn "\.update_attributes" --include="*.rb" . | grep -v vendor +``` + +### 2. `Mongoid::QueryCache` Replaced by `Mongo::QueryCache` + +Mongoid 8.x deprecates `Mongoid::QueryCache` and Mongoid 9.x removes it entirely. The replacement is `Mongo::QueryCache` from the `mongo` driver gem (available since mongo driver 2.14, which is bundled with Mongoid 7.4+). + +**Changes applied in this PR:** + +| Location | Old | New | +|----------|-----|-----| +| `core/config/initializers/10_rack_middleware.rb` | `Mongoid::QueryCache::Middleware` | `Mongo::QueryCache::Middleware` | +| `core/app/queries/workarea/admin_search_query_wrapper.rb` | `Mongoid::QueryCache.clear_cache` | `Mongo::QueryCache.clear` | +| `core/app/models/workarea/releasable.rb` | `Mongoid::QueryCache.uncached { }` | `Mongo::QueryCache.uncached { }` | + +If your host application or plugins use `Mongoid::QueryCache` directly, update them: + +```ruby +# Before +Mongoid::QueryCache.clear_cache +Mongoid::QueryCache.uncached { ... } +Mongoid::QueryCache::Middleware + +# After +Mongo::QueryCache.clear +Mongo::QueryCache.uncached { ... } +Mongo::QueryCache::Middleware +``` + +### 3. Default Configuration Behavior Changes (load_defaults shim) + +Mongoid 8.0 changed the defaults for many configuration flags that were previously opt-in under Mongoid 7.x (e.g. `broken_aggregables`, `broken_alias_handling`, `broken_and`, `broken_scoping`, `broken_updates`, `compare_time_by_ms`, `legacy_attributes`, `legacy_pluck_distinct`, `legacy_triple_equals`, `object_id_as_json_oid`, `overwrite_chained_operators`). + +**Change applied in this PR:** Workarea's `Configuration::Mongoid.load` now automatically calls `Mongoid.load_defaults('7.5')` when running under Mongoid 8+. This preserves legacy behavior during the upgrade period. + +```ruby +# core/lib/workarea/configuration/mongoid.rb +if ::Mongoid::VERSION.to_i >= 8 + ::Mongoid.load_defaults('7.5') if ::Mongoid.respond_to?(:load_defaults) +end +``` + +**Action for host applications:** After verifying your application works with Mongoid 8, incrementally adopt new defaults by calling `Mongoid.load_defaults('8.0')` (then `'8.1'`) in your initializer. See the [Mongoid upgrade guide](https://www.mongodb.com/docs/mongoid/current/reference/upgrading/) for details on what each version changes. + +--- + +## Not-Yet-Breaking Changes (Mongoid 9 Notes) + +The following are **not breaking in Mongoid 8** but will become breaking in Mongoid 9. Note these for a future upgrade: + +### `around_*` Callbacks on Embedded Documents + +Mongoid 9.0 silently ignores `around_save`, `around_create`, `around_update`, `around_destroy` callbacks defined on embedded documents by default. Re-enabling them via `Mongoid.around_callbacks_for_embeds = true` is possible but risks `SystemStackError`. + +**Workarea core audit:** The two models with `around_*` callbacks (`Release::Activation` and `Search::Settings`) are **not embedded documents**, so core is not affected. However, **plugin or host application embedded models** should be audited: + +```bash +# Find around_* callbacks on embedded models +grep -rn "around_save\|around_create\|around_update\|around_destroy" app/models/ --include="*.rb" +# Cross-reference with embedded document declarations: +grep -rn "embedded_in\|embeds_many\|embeds_one" app/models/ --include="*.rb" +``` + +### `load_defaults '7.5'` Removed in Mongoid 9 + +Mongoid 9 only accepts `load_defaults '8.0'` or later. Before upgrading to Mongoid 9, remove the `7.5` shim from your Mongoid configuration and address any behavioral changes from adopting Mongoid 8 defaults. + +### `AttributeNotLoaded` Error Type Change + +Code rescuing `ActiveModel::MissingAttributeError` in Mongoid model contexts should be updated to rescue `Mongoid::Errors::AttributeNotLoaded` for Mongoid 9 compatibility. + +--- + +## Plugin Compatibility + +Several Mongoid-dependent plugins used by Workarea may require patching for Mongoid 8 compatibility. As of the research date (2026-02-28), these plugins carry **high risk**: + +| Gem | Risk | Notes | +|-----|------|-------| +| `mongoid-audit_log` | HIGH | Authored by @bencrouse; no official Mongoid 8 release. May need forking. | +| `mongoid-document_path` | HIGH | Authored by weblinc; unmaintained upstream. | +| `mongoid-encrypted` | HIGH | Uses Mongoid field internals; type system changes in 8.x may break. | +| `mongoid-active_merchant` | MEDIUM | Small adapter; may use `update_attributes`. | +| `mongoid-tree` | MEDIUM | Community gem; check RubyGems for 8.x compat release. | +| `kaminari-mongoid` | LOW | Actively maintained; likely has Mongoid 8 support. | +| `mongoid-sample` | LOW | Minimal gem; basic Mongoid API only. | + +Plugin compatibility work is tracked separately. See the research doc at `docs/research/mongoid-upgrade-path.md` for full details. + +--- + +## BigDecimal / Money Fields + +Mongoid 8 introduces a `map_big_decimal_to_decimal128` feature flag that changes how `BigDecimal` fields are stored in MongoDB. **Do not enable this flag** without a data migration plan. Workarea's `Money` fields (`Order::Item#total_value`, `Order::Item#total_price`, etc.) rely on `money-rails` + Mongoid type coercion. + +The `load_defaults '7.5'` shim applied above preserves the legacy `BigDecimal` behavior. Only enable `map_big_decimal_to_decimal128` after verifying `money-rails` compatibility and planning a data migration. + +--- + +## Upgrade Checklist + +- [ ] Upgrade `mongoid` gem to `~> 8.1` in your `Gemfile.lock` (via `bundle update mongoid`) +- [ ] Replace any `update_attributes`/`update_attributes!` calls in your host app code +- [ ] Replace any `Mongoid::QueryCache` references in your host app +- [ ] Run your test suite; address any Mongoid 8 behavioral regressions +- [ ] Audit plugins for Mongoid 8 compatibility (see table above) +- [ ] Gradually adopt new Mongoid 8 defaults via `load_defaults '8.0'` after verifying behavior + +--- + +*Related issue: [#690](https://github.com/workarea-commerce/workarea/issues/690)* +*Research doc: [docs/research/mongoid-upgrade-path.md](research/mongoid-upgrade-path.md)* diff --git a/storefront/test/integration/workarea/storefront/browse_images_integration_test.rb b/storefront/test/integration/workarea/storefront/browse_images_integration_test.rb index ad02653f25..df99cce3c2 100644 --- a/storefront/test/integration/workarea/storefront/browse_images_integration_test.rb +++ b/storefront/test/integration/workarea/storefront/browse_images_integration_test.rb @@ -6,7 +6,7 @@ class BrowseImagesIntegrationTest < Workarea::IntegrationTest setup :set_search_settings, :create_products_with_images def set_search_settings - Workarea::Search::Settings.current.update_attributes!( + Workarea::Search::Settings.current.update!( terms_facets: %w(Color) ) end diff --git a/storefront/test/integration/workarea/storefront/cart_integration_test.rb b/storefront/test/integration/workarea/storefront/cart_integration_test.rb index 236552dcdc..377c48a646 100644 --- a/storefront/test/integration/workarea/storefront/cart_integration_test.rb +++ b/storefront/test/integration/workarea/storefront/cart_integration_test.rb @@ -69,7 +69,7 @@ def test_flashes_error_for_redeemed_single_use_promo_codes quantity: 1 } - order.update_attributes!(email: 'user@workarea.com') + order.update!(email: 'user@workarea.com') post storefront.add_promo_code_to_cart_path, params: { promo_code: 'TESTCODE' } diff --git a/storefront/test/integration/workarea/storefront/cart_items_integration_test.rb b/storefront/test/integration/workarea/storefront/cart_items_integration_test.rb index f1f60b9d86..2b76d9818d 100644 --- a/storefront/test/integration/workarea/storefront/cart_items_integration_test.rb +++ b/storefront/test/integration/workarea/storefront/cart_items_integration_test.rb @@ -120,7 +120,7 @@ def test_adjusts_inventory_if_not_enough_present_when_adding end def test_does_not_add_if_there_is_no_available_inventory - @inventory.update_attributes(available: 0) + @inventory.update(available: 0) post storefront.cart_items_path, params: { @@ -136,7 +136,7 @@ def test_does_not_add_if_there_is_no_available_inventory end def test_does_not_add_if_there_are_invalid_customizations - @product.update_attributes(customizations: 'foo_cust') + @product.update(customizations: 'foo_cust') post storefront.cart_items_path, params: { @@ -178,7 +178,7 @@ def test_does_not_update_if_there_are_invalid_customizations quantity: 1 } - @product.update_attributes(customizations: 'foo_cust') + @product.update(customizations: 'foo_cust') patch storefront.cart_item_path(order.items.first), params: { sku: 'SKU2', quantity: 2, foo: 'Test' } @@ -188,7 +188,7 @@ def test_does_not_update_if_there_are_invalid_customizations end def test_adds_customizations_to_item - @product.update_attributes(customizations: 'foo_cust') + @product.update(customizations: 'foo_cust') post storefront.cart_items_path, params: { @@ -231,7 +231,7 @@ def test_removes_the_item_if_changing_quantity_and_no_inventory quantity: 1 } - @inventory.update_attributes(available: 0) + @inventory.update(available: 0) patch storefront.cart_item_path(order.items.first), params: { quantity: 4 } diff --git a/storefront/test/integration/workarea/storefront/checkout_side_effects_integration_test.rb b/storefront/test/integration/workarea/storefront/checkout_side_effects_integration_test.rb index de33f1031a..95d2e80293 100644 --- a/storefront/test/integration/workarea/storefront/checkout_side_effects_integration_test.rb +++ b/storefront/test/integration/workarea/storefront/checkout_side_effects_integration_test.rb @@ -113,7 +113,7 @@ def test_updating_inventory assert_equal(0, inventory.purchased) assert_equal(0, inventory.available) - inventory.update_attributes(policy: 'standard', available: 2) + inventory.update(policy: 'standard', available: 2) complete_checkout inventory.reload diff --git a/storefront/test/integration/workarea/storefront/checkout_with_pricing_override_integration_test.rb b/storefront/test/integration/workarea/storefront/checkout_with_pricing_override_integration_test.rb index 82a56fdad8..971237a1a0 100644 --- a/storefront/test/integration/workarea/storefront/checkout_with_pricing_override_integration_test.rb +++ b/storefront/test/integration/workarea/storefront/checkout_with_pricing_override_integration_test.rb @@ -9,7 +9,7 @@ class CheckoutWithPricingOverrideIntegrationTest < Workarea::IntegrationTest setup :setup_order def setup_order - admin_user.update_attributes!(email: 'csr@workarea.com') + admin_user.update!(email: 'csr@workarea.com') shipping_service = create_shipping_service product = create_product(variants: [{ sku: 'SKU', regular: 5.to_m }]) @@ -38,7 +38,7 @@ def test_checking_out_with_adjusted_order_subtotal override = Pricing::Override.find_or_create_by!(id: @order.id) - override.update_attributes!( + override.update!( subtotal_adjustment: -6.to_m, shipping_adjustment: -0.6.to_m ) @@ -90,7 +90,7 @@ def test_checking_out_with_adjusted_order_items override = Pricing::Override.find_or_create_by!(id: @order.id) - override.update_attributes!( + override.update!( shipping_adjustment: -0.6.to_m, item_prices: { @order.items.first.id.to_s => 2.25, @@ -143,7 +143,7 @@ def test_checking_out_with_adjusted_order_items def test_checking_out_with_order_set_to_be_free override = Pricing::Override.find_or_create_by!(id: @order.id) - override.update_attributes!( + override.update!( subtotal_adjustment: -1 * @order.subtotal_price, shipping_adjustment: -1 * @order.shipping_total ) diff --git a/storefront/test/integration/workarea/storefront/impersonations_integration_test.rb b/storefront/test/integration/workarea/storefront/impersonations_integration_test.rb index dbadf18fec..777ebe06b1 100644 --- a/storefront/test/integration/workarea/storefront/impersonations_integration_test.rb +++ b/storefront/test/integration/workarea/storefront/impersonations_integration_test.rb @@ -10,7 +10,7 @@ def test_ignores_ip_address_and_user_agent_validation_when_impersonating params: { email: super_admin.email, password: 'W3bl1nc!' } post admin.impersonations_path, params: { user_id: customer.id } - customer.update_attributes!(ip_address: '173.252.132.26') + customer.update!(ip_address: '173.252.132.26') get storefront.users_account_path refute(response.redirect?) diff --git a/storefront/test/integration/workarea/storefront/login_integration_test.rb b/storefront/test/integration/workarea/storefront/login_integration_test.rb index 091f43a0bf..79e812037b 100644 --- a/storefront/test/integration/workarea/storefront/login_integration_test.rb +++ b/storefront/test/integration/workarea/storefront/login_integration_test.rb @@ -52,7 +52,7 @@ def test_redirects_a_user_to_return_after_logging_in end def test_redirects_to_the_admin_path_for_admins_by_deafult - @user.update_attributes!(admin: true) + @user.update!(admin: true) post storefront.login_path, params: { diff --git a/storefront/test/integration/workarea/storefront/pages_integration_test.rb b/storefront/test/integration/workarea/storefront/pages_integration_test.rb index 890f611d0a..64cb529984 100644 --- a/storefront/test/integration/workarea/storefront/pages_integration_test.rb +++ b/storefront/test/integration/workarea/storefront/pages_integration_test.rb @@ -27,7 +27,7 @@ def test_open_graph_image_url asset = create_asset content = Content.for(page) - content.update_attributes!(open_graph_asset_id: asset.id) + content.update!(open_graph_asset_id: asset.id) get storefront.page_path(page) diff --git a/storefront/test/integration/workarea/storefront/products_integration_test.rb b/storefront/test/integration/workarea/storefront/products_integration_test.rb index ba3dbacce1..39a5a7950c 100644 --- a/storefront/test/integration/workarea/storefront/products_integration_test.rb +++ b/storefront/test/integration/workarea/storefront/products_integration_test.rb @@ -22,7 +22,7 @@ def test_rendering_via_params product = create_product Workarea.config.product_templates.each do |template| - product.update_attributes!(template: template) + product.update!(template: template) get storefront.product_path(product, via: category.to_gid_param) assert_select( diff --git a/storefront/test/integration/workarea/storefront/releases_integration_test.rb b/storefront/test/integration/workarea/storefront/releases_integration_test.rb index 144495b6e5..854ca3b9c6 100644 --- a/storefront/test/integration/workarea/storefront/releases_integration_test.rb +++ b/storefront/test/integration/workarea/storefront/releases_integration_test.rb @@ -8,8 +8,8 @@ def test_previewing_releases second = create_release(publish_at: 2.days.from_now) product = create_product(name: 'Foo', template: 'generic', description: 'One') - first.as_current { product.update_attributes!(name: 'Bar', description: 'Two') } - second.as_current { product.update_attributes!(name: 'Baz') } + first.as_current { product.update!(name: 'Bar', description: 'Two') } + second.as_current { product.update!(name: 'Baz') } set_current_user(create_user(super_admin: true)) diff --git a/storefront/test/integration/workarea/storefront/search_integration_test.rb b/storefront/test/integration/workarea/storefront/search_integration_test.rb index 7ace61865e..eff1bb9132 100644 --- a/storefront/test/integration/workarea/storefront/search_integration_test.rb +++ b/storefront/test/integration/workarea/storefront/search_integration_test.rb @@ -62,7 +62,7 @@ def test_exact_match_redirecting refute(response.redirect?) end - Search::Settings.current.update_attributes!(boosts: { 'name': 9999999 }) + Search::Settings.current.update!(boosts: { 'name': 9999999 }) get storefront.search_path(q: 'sweet product') refute(response.redirect?) end diff --git a/storefront/test/integration/workarea/storefront/store_credit_integration_test.rb b/storefront/test/integration/workarea/storefront/store_credit_integration_test.rb index 6de3a3f7f7..eda6d7a211 100644 --- a/storefront/test/integration/workarea/storefront/store_credit_integration_test.rb +++ b/storefront/test/integration/workarea/storefront/store_credit_integration_test.rb @@ -37,7 +37,7 @@ def setup_supporting_data @payment_profile = Payment::Profile.lookup( PaymentReference.new(@user) - ).tap { |p| p.update_attributes(store_credit: 5.to_m) } + ).tap { |p| p.update(store_credit: 5.to_m) } end def test_saving_order_info diff --git a/storefront/test/performance/workarea/storefront/cart_performance_test.rb b/storefront/test/performance/workarea/storefront/cart_performance_test.rb index be6eeff200..fbf3425358 100644 --- a/storefront/test/performance/workarea/storefront/cart_performance_test.rb +++ b/storefront/test/performance/workarea/storefront/cart_performance_test.rb @@ -36,9 +36,9 @@ def setup_cart product = create_product_discount(product_ids: @products.map(&:id)) fixed_price = create_quantity_fixed_price_discount(product_ids: [@products.third.id]) - order_total.update_attributes!(compatible_discount_ids: [category.id, product_attribute.id, free_gift.id]) - buy_some.update_attributes!(compatible_discount_ids: [product.id, fixed_price.id, order_total.id]) - category.update_attributes!(compatible_discount_ids: [fixed_price.id, product_attribute.id]) + order_total.update!(compatible_discount_ids: [category.id, product_attribute.id, free_gift.id]) + buy_some.update!(compatible_discount_ids: [product.id, fixed_price.id, order_total.id]) + category.update!(compatible_discount_ids: [fixed_price.id, product_attribute.id]) post storefront.add_promo_code_to_cart_path, params: { promo_code: 'TESTCODE' } end diff --git a/storefront/test/system/workarea/storefront/categories_system_test.rb b/storefront/test/system/workarea/storefront/categories_system_test.rb index 652f1d2830..0a0feb5ad7 100644 --- a/storefront/test/system/workarea/storefront/categories_system_test.rb +++ b/storefront/test/system/workarea/storefront/categories_system_test.rb @@ -50,7 +50,7 @@ def set_search_settings end def categorize_products(category) - category.update_attributes!( + category.update!( product_ids: [@products.second.id, @products.first.id, @products.fourth.id] ) end @@ -210,7 +210,7 @@ def test_category_rules ) sku = Pricing::Sku.find_or_create_by(id: @products.first.skus.first) - sku.update_attributes(on_sale: true) + sku.update(on_sale: true) visit storefront.category_path(category) diff --git a/storefront/test/system/workarea/storefront/guest_checkout_system_test.rb b/storefront/test/system/workarea/storefront/guest_checkout_system_test.rb index fb2063770a..fafe5fee93 100644 --- a/storefront/test/system/workarea/storefront/guest_checkout_system_test.rb +++ b/storefront/test/system/workarea/storefront/guest_checkout_system_test.rb @@ -218,7 +218,7 @@ def test_unavailable_inventory assert_current_path(storefront.checkout_payment_path) fill_in_credit_card - Inventory::Sku.find('SKU').update_attributes!(available: 0) + Inventory::Sku.find('SKU').update!(available: 0) click_button t('workarea.storefront.checkouts.place_order') assert_current_path(storefront.cart_path) diff --git a/storefront/test/system/workarea/storefront/logged_in_checkout_system_test.rb b/storefront/test/system/workarea/storefront/logged_in_checkout_system_test.rb index d4cb5bf0fe..bded250e9c 100644 --- a/storefront/test/system/workarea/storefront/logged_in_checkout_system_test.rb +++ b/storefront/test/system/workarea/storefront/logged_in_checkout_system_test.rb @@ -323,7 +323,7 @@ def test_validation_errors def test_unavailable_inventory assert_current_path(storefront.checkout_payment_path) - Inventory::Sku.find('SKU').update_attributes!(available: 0) + Inventory::Sku.find('SKU').update!(available: 0) click_button t('workarea.storefront.checkouts.place_order') assert_current_path(storefront.cart_path) diff --git a/storefront/test/system/workarea/storefront/navigation_system_test.rb b/storefront/test/system/workarea/storefront/navigation_system_test.rb index 22aeb7b848..fa0da621f5 100644 --- a/storefront/test/system/workarea/storefront/navigation_system_test.rb +++ b/storefront/test/system/workarea/storefront/navigation_system_test.rb @@ -65,7 +65,7 @@ def test_left_navigation visit storefront.page_path(primary.navigable) assert(page.has_content?('Foo')) - secondary.navigable.update_attributes!(active: false) + secondary.navigable.update!(active: false) visit storefront.page_path(primary.navigable) refute_text('Foo') end diff --git a/storefront/test/system/workarea/storefront/pages_system_test.rb b/storefront/test/system/workarea/storefront/pages_system_test.rb index 5ff6960268..2976b2ad96 100644 --- a/storefront/test/system/workarea/storefront/pages_system_test.rb +++ b/storefront/test/system/workarea/storefront/pages_system_test.rb @@ -32,14 +32,14 @@ def test_showing_the_page def test_rendering_left_navigation top_level = create_taxon(name: 'Foo Taxon', url: 'http://example.com') create_taxon(parent: top_level, name: 'Foo Taxon', navigable: @content_page) - @content_page.update_attributes!(show_navigation: true) + @content_page.update!(show_navigation: true) visit storefront.page_path(@content_page) within '.page-content__aside' do assert(page.has_content?('Foo Taxon')) end - @content_page.update_attributes!(show_navigation: false) + @content_page.update!(show_navigation: false) visit storefront.page_path(@content_page) assert(page.has_no_selector?('.page-content__aside')) diff --git a/storefront/test/system/workarea/storefront/pagination_system_test.rb b/storefront/test/system/workarea/storefront/pagination_system_test.rb index 8414367705..f882f1409f 100644 --- a/storefront/test/system/workarea/storefront/pagination_system_test.rb +++ b/storefront/test/system/workarea/storefront/pagination_system_test.rb @@ -40,7 +40,7 @@ def set_search_settings end def categorize_products(category) - category.update_attributes!( + category.update!( product_ids: @products.map(&:id) ) end diff --git a/storefront/test/system/workarea/storefront/products_system_test.rb b/storefront/test/system/workarea/storefront/products_system_test.rb index 2c56650063..9aefe8ed21 100644 --- a/storefront/test/system/workarea/storefront/products_system_test.rb +++ b/storefront/test/system/workarea/storefront/products_system_test.rb @@ -25,7 +25,7 @@ def test_showing_a_product end def test_showing_a_product_with_inactive_skus - @product.variants.first.update_attributes!(active: false) + @product.variants.first.update!(active: false) visit storefront.product_path(@product) assert(page.has_content?('Integration Product')) diff --git a/storefront/test/system/workarea/storefront/release_browsing_system_test.rb b/storefront/test/system/workarea/storefront/release_browsing_system_test.rb index 22325c7526..1c62ac30cb 100644 --- a/storefront/test/system/workarea/storefront/release_browsing_system_test.rb +++ b/storefront/test/system/workarea/storefront/release_browsing_system_test.rb @@ -19,10 +19,10 @@ def test_browsing_a_release second_menu = create_menu(taxon: second_taxon, active: false) Release.with_current(release.id) do - page1.update_attributes!(name: 'Foo Changed') - page2.update_attributes!(name: 'Bar Changed') - product2.update_attributes!(active: true) - second_menu.update_attributes!(active: true) + page1.update!(name: 'Foo Changed') + page2.update!(name: 'Bar Changed') + product2.update!(active: true) + second_menu.update!(active: true) end visit storefront.root_path diff --git a/storefront/test/system/workarea/storefront/search_system_test.rb b/storefront/test/system/workarea/storefront/search_system_test.rb index b7362ed730..d2c5771640 100644 --- a/storefront/test/system/workarea/storefront/search_system_test.rb +++ b/storefront/test/system/workarea/storefront/search_system_test.rb @@ -102,7 +102,7 @@ def test_searching_for_product_id end def test_searching_for_product_content - @products.first.update_attributes!(description: 'nice product') + @products.first.update!(description: 'nice product') visit storefront.search_path(q: 'nice') assert(page.has_content?(@products.first.name)) end @@ -133,7 +133,7 @@ def test_searching_for_out_of_stock_products end def test_products_with_display_rules - @products[0].update_attributes(active: false) + @products[0].update(active: false) visit storefront.search_path(q: 'test') assert(page.has_no_content?('Test Product 1')) @@ -209,7 +209,7 @@ def test_searching_on_a_synonym # cause. skip if Workarea.elasticsearch.info['version']['number'] =~ /alpha/ - Search::Settings.current.update_attributes!(synonyms: 'test, ben') + Search::Settings.current.update!(synonyms: 'test, ben') visit storefront.search_path(q: 'ben') assert(page.has_content?('Test Product 1')) diff --git a/storefront/test/system/workarea/storefront/store_credit_system_test.rb b/storefront/test/system/workarea/storefront/store_credit_system_test.rb index 3a5eb1e3c3..ee4ff3d20f 100644 --- a/storefront/test/system/workarea/storefront/store_credit_system_test.rb +++ b/storefront/test/system/workarea/storefront/store_credit_system_test.rb @@ -177,7 +177,7 @@ def test_paying_with_insufficient_store_credit def set_store_credit(value) user = User.find_by_email('bcrouse@workarea.com') payment_profile = Payment::Profile.lookup(PaymentReference.new(user)) - payment_profile.update_attributes(store_credit: value) + payment_profile.update(store_credit: value) end end end diff --git a/storefront/test/view_models/workarea/storefront/checkout/payment_view_model_test.rb b/storefront/test/view_models/workarea/storefront/checkout/payment_view_model_test.rb index aac644d00d..d0a34b8f53 100644 --- a/storefront/test/view_models/workarea/storefront/checkout/payment_view_model_test.rb +++ b/storefront/test/view_models/workarea/storefront/checkout/payment_view_model_test.rb @@ -16,7 +16,7 @@ def test_credit_cards_returns_credit_cards_wrapped_in_view_model 2.times { create_saved_credit_card(profile: profile) } checkout = Workarea::Checkout.new(@order, @user) - checkout.payment.update_attributes!(profile_id: profile.id) + checkout.payment.update!(profile_id: profile.id) view_model = PaymentViewModel.new(checkout) assert_equal(2, view_model.credit_cards.length) @@ -30,7 +30,7 @@ def test_credit_cards_does_not_return_credit_cards_if_the_user_is_not_present 2.times { create_saved_credit_card(profile: profile) } checkout = Workarea::Checkout.new(@order) - checkout.payment.update_attributes!(profile_id: profile.id) + checkout.payment.update!(profile_id: profile.id) view_model = PaymentViewModel.new(checkout) assert(view_model.credit_cards.empty?) end @@ -44,7 +44,7 @@ def test_order_covered_by_store_credit ) checkout = Workarea::Checkout.new(@order, @user) - checkout.payment.update_attributes!(profile_id: profile.id) + checkout.payment.update!(profile_id: profile.id) @order.total_price = 5 assert(PaymentViewModel.new(checkout).order_covered_by_store_credit?) @@ -61,7 +61,7 @@ def test_using_new_card profile = Payment::Profile.lookup(PaymentReference.new(@user)) checkout = Workarea::Checkout.new(@order, @user) - checkout.payment.update_attributes!(profile_id: profile.id) + checkout.payment.update!(profile_id: profile.id) credit_card = create_saved_credit_card(profile: profile) view_model = PaymentViewModel.new(checkout, payment: 'not found') diff --git a/storefront/test/view_models/workarea/storefront/display_content_test.rb b/storefront/test/view_models/workarea/storefront/display_content_test.rb index 698127cf24..f168cd733f 100644 --- a/storefront/test/view_models/workarea/storefront/display_content_test.rb +++ b/storefront/test/view_models/workarea/storefront/display_content_test.rb @@ -24,7 +24,7 @@ def test_browser_title_uses_content_browser_title assert_equal('Ben', view_model.browser_title) content = Content.for(model) - content.update_attributes!(browser_title: 'Foo') + content.update!(browser_title: 'Foo') view_model = DisplayContentViewModel.wrap(model) assert_equal('Foo', view_model.browser_title) @@ -43,7 +43,7 @@ def test_meta_description ) content = Content.for(model) - content.update_attributes!(meta_description: 'Foo') + content.update!(meta_description: 'Foo') view_model = DisplayContentViewModel.wrap(model) assert_equal('Foo', view_model.meta_description) @@ -98,7 +98,7 @@ def test_open_graph_asset view_model = ContentViewModel.wrap(content) assert_equal(default_asset, view_model.open_graph_asset) - content.update_attributes(open_graph_asset_id: create_asset.id) + content.update(open_graph_asset_id: create_asset.id) view_model = ContentViewModel.wrap(content) og_asset = view_model.open_graph_asset diff --git a/storefront/test/view_models/workarea/storefront/option_set_view_model_test.rb b/storefront/test/view_models/workarea/storefront/option_set_view_model_test.rb index 18d252c7d4..c1fe82011d 100644 --- a/storefront/test/view_models/workarea/storefront/option_set_view_model_test.rb +++ b/storefront/test/view_models/workarea/storefront/option_set_view_model_test.rb @@ -99,8 +99,8 @@ def test_images_match_primary_when_no_matching_options_selected assert_equal(1, view_model.images.size) assert_equal('blue', view_model.images.first.option) - product.images.find_by(option: 'blue').update_attributes!(position: 999) - product.images.find_by(option: 'red').update_attributes!(position: 0) + product.images.find_by(option: 'blue').update!(position: 999) + product.images.find_by(option: 'red').update!(position: 0) product.reload view_model = TestViewModel.wrap(product) diff --git a/storefront/test/view_models/workarea/storefront/product_view_model/image_collection_test.rb b/storefront/test/view_models/workarea/storefront/product_view_model/image_collection_test.rb index 3ef0a166e0..e47f1c07c8 100644 --- a/storefront/test/view_models/workarea/storefront/product_view_model/image_collection_test.rb +++ b/storefront/test/view_models/workarea/storefront/product_view_model/image_collection_test.rb @@ -57,7 +57,7 @@ def test_primary assert_equal('green', image_collection.primary.option) - Workarea::Search::Settings.current.update_attributes!(terms_facets: %w(Color)) + Workarea::Search::Settings.current.update!(terms_facets: %w(Color)) product_result_options = { color: 'BLUE' }.with_indifferent_access image_collection = ImageCollection.new( diff --git a/storefront/test/view_models/workarea/storefront/product_view_model_test.rb b/storefront/test/view_models/workarea/storefront/product_view_model_test.rb index d09f1fe19b..af312d3123 100644 --- a/storefront/test/view_models/workarea/storefront/product_view_model_test.rb +++ b/storefront/test/view_models/workarea/storefront/product_view_model_test.rb @@ -117,7 +117,7 @@ def test_one_price pricing.prices = [{ regular: 3 }] refute(ProductViewModel.new(@product).one_price?) - pricing.update_attributes!(msrp: 3) + pricing.update!(msrp: 3) assert(ProductViewModel.new(@product).one_price?) end @@ -162,18 +162,18 @@ def test_original_min_price pricing_one = create_pricing_sku(id: 'SKU1') pricing_two = create_pricing_sku(id: 'SKU2') - pricing_one.update_attributes!(msrp: 5) - pricing_two.update_attributes!(msrp: 6) + pricing_one.update!(msrp: 5) + pricing_two.update!(msrp: 6) pricing_one.prices = [{ regular: 3 }] pricing_two.prices = [{ regular: 5 }] assert_equal(5.to_m, ProductViewModel.new(@product).original_min_price) - pricing_one.update_attributes!(msrp: nil) - pricing_two.update_attributes!(msrp: nil) + pricing_one.update!(msrp: nil) + pricing_two.update!(msrp: nil) assert_equal(3.to_m, ProductViewModel.new(@product).original_min_price) - pricing_one.update_attributes!(on_sale: true, msrp: 1) - pricing_two.update_attributes!(msrp: 6) + pricing_one.update!(on_sale: true, msrp: 1) + pricing_two.update!(msrp: 6) pricing_one.prices = [{ regular: 3, sale: 2 }] pricing_two.prices = [{ regular: 5 }] assert_equal(3.to_m, ProductViewModel.new(@product).original_min_price) @@ -184,18 +184,18 @@ def test_original_max_price pricing_one = create_pricing_sku(id: 'SKU1') pricing_two = create_pricing_sku(id: 'SKU2') - pricing_one.update_attributes!(msrp: 2) - pricing_two.update_attributes!(msrp: 1) + pricing_one.update!(msrp: 2) + pricing_two.update!(msrp: 1) pricing_one.prices = [{ regular: 1 }] pricing_two.prices = [{ regular: 1 }] assert_equal(2.to_m, ProductViewModel.new(@product).original_max_price) - pricing_one.update_attributes!(msrp: nil) - pricing_two.update_attributes!(msrp: nil) + pricing_one.update!(msrp: nil) + pricing_two.update!(msrp: nil) assert_equal(1.to_m, ProductViewModel.new(@product).original_max_price) - pricing_one.update_attributes!(on_sale: true, msrp: 1) - pricing_two.update_attributes!(msrp: nil) + pricing_one.update!(on_sale: true, msrp: 1) + pricing_two.update!(msrp: nil) pricing_one.prices = [{ regular: 2, sale: 2 }] pricing_two.prices = [{ regular: 3 }] assert_equal(3.to_m, ProductViewModel.new(@product).original_max_price) diff --git a/storefront/test/view_models/workarea/storefront/user_activity_view_model_test.rb b/storefront/test/view_models/workarea/storefront/user_activity_view_model_test.rb index c15bb1540d..a9487c7580 100644 --- a/storefront/test/view_models/workarea/storefront/user_activity_view_model_test.rb +++ b/storefront/test/view_models/workarea/storefront/user_activity_view_model_test.rb @@ -33,7 +33,7 @@ def test_products assert_equal(product_one, view_model.products.first.model) assert_equal(product_two, view_model.products.second.model) - product_two.update_attributes!(active: false) + product_two.update!(active: false) view_model = UserActivityViewModel.new(metrics) assert_equal(1, view_model.products.length) diff --git a/testing/lib/workarea/testing/factories/order.rb b/testing/lib/workarea/testing/factories/order.rb index e39aaf10ee..2c9acde6ed 100644 --- a/testing/lib/workarea/testing/factories/order.rb +++ b/testing/lib/workarea/testing/factories/order.rb @@ -68,7 +68,7 @@ def create_placed_order(overrides = {}) end forced_attrs = overrides.slice(:placed_at, :updated_at, :total_price) - order.update_attributes!(forced_attrs) + order.update!(forced_attrs) order end @@ -87,7 +87,7 @@ def complete_checkout(order, options = {}) create_shipping_service.name order.items.each do |item| - item.update_attributes!(OrderItemDetails.find!(item.sku).to_h) + item.update!(OrderItemDetails.find!(item.sku).to_h) end checkout = Checkout.new(order) diff --git a/testing/lib/workarea/testing/factories/search.rb b/testing/lib/workarea/testing/factories/search.rb index e01cef3da3..85f3dc1e8c 100644 --- a/testing/lib/workarea/testing/factories/search.rb +++ b/testing/lib/workarea/testing/factories/search.rb @@ -66,7 +66,7 @@ def create_product_browse_search_options(options = {}) def update_search_settings(overrides = {}) attributes = factory_defaults(:search_settings).merge(overrides) - Workarea::Search::Settings.current.update_attributes!(attributes) + Workarea::Search::Settings.current.update!(attributes) end end end