From 301add4992640486b4a477ca1d129ffc6a174e6d Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Mon, 15 Jan 2024 11:36:21 +1100 Subject: [PATCH 1/7] Remove faulty migration generation The long timestamps don't play well with Rails default timestamps for migrations. They are always seen as the newest. Not using long timestamps leads to duplicate timestamps though. The better solution is to use `rails generate migration` and copy the `change` method. --- spec/models/database_spec.rb | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/spec/models/database_spec.rb b/spec/models/database_spec.rb index 2731e145b8..b8f89dc1f2 100644 --- a/spec/models/database_spec.rb +++ b/spec/models/database_spec.rb @@ -60,11 +60,6 @@ RSpec.describe "Database" do puts migrations.join("\n") puts "\nTo disable this warning, add the class name(s) of the model(s) to models_todo " \ "in #{__FILE__}" - - return if ENV.fetch("OFN_WRITE_FOREIGN_KEY_MIGRATIONS", false) - - puts "Migrations have not been written to disk. To write migrations to disk, please " \ - "add OFN_WRITE_FOREIGN_KEY_MIGRATIONS=true to the file .env.test.local" end def process_association(model_class, association) @@ -104,9 +99,6 @@ RSpec.describe "Database" do migration_name = "add_foreign_key_to_#{model_class.table_name}_" \ "#{foreign_key_table_name}_#{foreign_key_column}" migration_class_name = migration_name.camelize - millisecond_timestamp = generate_timestamp - migration_file_name = "db/migrate/#{millisecond_timestamp}_" \ - "#{migration_name}.rb" orphaned_records_query = generate_orphaned_records_query(model_class, foreign_key_table_name, foreign_key_column) @@ -122,11 +114,6 @@ RSpec.describe "Database" do end MIGRATION - if ENV.fetch("OFN_WRITE_FOREIGN_KEY_MIGRATIONS", false) - File.open(migration_file_name, 'w') do |file| - file.puts migration - end - end migration end From dc411eb42b2ef900c9d82fe20865a9bbfda094cc Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Mon, 15 Jan 2024 14:30:01 +1100 Subject: [PATCH 2/7] Remove migrations with bad ids We could rename them later but we don't want them to be executed under their new name. So we need to deploy the version rename in the database first. --- ...spree_stock_items_spree_stock_locations.rb | 0 ...key_to_spree_stock_items_spree_variants.rb | 0 ...ethod_categories_spree_shipping_methods.rb | 0 ...od_categories_spree_shipping_categories.rb | 0 ...to_report_rendering_options_spree_users.rb | 0 ...dd_foreign_key_to_tag_rules_enterprises.rb | 0 ...spree_stock_movements_spree_stock_items.rb | 0 ...y_to_spree_stock_locations_spree_states.rb | 0 ...o_spree_stock_locations_spree_countries.rb | 0 ...o_spree_shipments_spree_stock_locations.rb | 0 ...eign_key_to_inventory_items_enterprises.rb | 0 ...n_key_to_inventory_items_spree_variants.rb | 0 ..._spree_orders_spree_users_created_by_id.rb | 0 ...40115022359_rename_offending_migrations.rb | 39 +++++++++++++++++++ db/schema.rb | 2 +- 15 files changed, 40 insertions(+), 1 deletion(-) rename db/{migrate => bad_migrations}/20231002000136871_add_foreign_key_to_spree_stock_items_spree_stock_locations.rb (100%) rename db/{migrate => bad_migrations}/20231002000136872_add_foreign_key_to_spree_stock_items_spree_variants.rb (100%) rename db/{migrate => bad_migrations}/20231002000136876_add_foreign_key_to_spree_shipping_method_categories_spree_shipping_methods.rb (100%) rename db/{migrate => bad_migrations}/20231002000136877_add_foreign_key_to_spree_shipping_method_categories_spree_shipping_categories.rb (100%) rename db/{migrate => bad_migrations}/20231002000136879_add_foreign_key_to_report_rendering_options_spree_users.rb (100%) rename db/{migrate => bad_migrations}/20231002000136926_add_foreign_key_to_tag_rules_enterprises.rb (100%) rename db/{migrate => bad_migrations}/20231002000136952_add_foreign_key_to_spree_stock_movements_spree_stock_items.rb (100%) rename db/{migrate => bad_migrations}/20231002000136955_add_foreign_key_to_spree_stock_locations_spree_states.rb (100%) rename db/{migrate => bad_migrations}/20231002000136959_add_foreign_key_to_spree_stock_locations_spree_countries.rb (100%) rename db/{migrate => bad_migrations}/20231002000136976_add_foreign_key_to_spree_shipments_spree_stock_locations.rb (100%) rename db/{migrate => bad_migrations}/20231002000137115_add_foreign_key_to_inventory_items_enterprises.rb (100%) rename db/{migrate => bad_migrations}/20231002000137116_add_foreign_key_to_inventory_items_spree_variants.rb (100%) rename db/{migrate => bad_migrations}/20231003000823494_add_foreign_key_to_spree_orders_spree_users_created_by_id.rb (100%) create mode 100644 db/migrate/20240115022359_rename_offending_migrations.rb diff --git a/db/migrate/20231002000136871_add_foreign_key_to_spree_stock_items_spree_stock_locations.rb b/db/bad_migrations/20231002000136871_add_foreign_key_to_spree_stock_items_spree_stock_locations.rb similarity index 100% rename from db/migrate/20231002000136871_add_foreign_key_to_spree_stock_items_spree_stock_locations.rb rename to db/bad_migrations/20231002000136871_add_foreign_key_to_spree_stock_items_spree_stock_locations.rb diff --git a/db/migrate/20231002000136872_add_foreign_key_to_spree_stock_items_spree_variants.rb b/db/bad_migrations/20231002000136872_add_foreign_key_to_spree_stock_items_spree_variants.rb similarity index 100% rename from db/migrate/20231002000136872_add_foreign_key_to_spree_stock_items_spree_variants.rb rename to db/bad_migrations/20231002000136872_add_foreign_key_to_spree_stock_items_spree_variants.rb diff --git a/db/migrate/20231002000136876_add_foreign_key_to_spree_shipping_method_categories_spree_shipping_methods.rb b/db/bad_migrations/20231002000136876_add_foreign_key_to_spree_shipping_method_categories_spree_shipping_methods.rb similarity index 100% rename from db/migrate/20231002000136876_add_foreign_key_to_spree_shipping_method_categories_spree_shipping_methods.rb rename to db/bad_migrations/20231002000136876_add_foreign_key_to_spree_shipping_method_categories_spree_shipping_methods.rb diff --git a/db/migrate/20231002000136877_add_foreign_key_to_spree_shipping_method_categories_spree_shipping_categories.rb b/db/bad_migrations/20231002000136877_add_foreign_key_to_spree_shipping_method_categories_spree_shipping_categories.rb similarity index 100% rename from db/migrate/20231002000136877_add_foreign_key_to_spree_shipping_method_categories_spree_shipping_categories.rb rename to db/bad_migrations/20231002000136877_add_foreign_key_to_spree_shipping_method_categories_spree_shipping_categories.rb diff --git a/db/migrate/20231002000136879_add_foreign_key_to_report_rendering_options_spree_users.rb b/db/bad_migrations/20231002000136879_add_foreign_key_to_report_rendering_options_spree_users.rb similarity index 100% rename from db/migrate/20231002000136879_add_foreign_key_to_report_rendering_options_spree_users.rb rename to db/bad_migrations/20231002000136879_add_foreign_key_to_report_rendering_options_spree_users.rb diff --git a/db/migrate/20231002000136926_add_foreign_key_to_tag_rules_enterprises.rb b/db/bad_migrations/20231002000136926_add_foreign_key_to_tag_rules_enterprises.rb similarity index 100% rename from db/migrate/20231002000136926_add_foreign_key_to_tag_rules_enterprises.rb rename to db/bad_migrations/20231002000136926_add_foreign_key_to_tag_rules_enterprises.rb diff --git a/db/migrate/20231002000136952_add_foreign_key_to_spree_stock_movements_spree_stock_items.rb b/db/bad_migrations/20231002000136952_add_foreign_key_to_spree_stock_movements_spree_stock_items.rb similarity index 100% rename from db/migrate/20231002000136952_add_foreign_key_to_spree_stock_movements_spree_stock_items.rb rename to db/bad_migrations/20231002000136952_add_foreign_key_to_spree_stock_movements_spree_stock_items.rb diff --git a/db/migrate/20231002000136955_add_foreign_key_to_spree_stock_locations_spree_states.rb b/db/bad_migrations/20231002000136955_add_foreign_key_to_spree_stock_locations_spree_states.rb similarity index 100% rename from db/migrate/20231002000136955_add_foreign_key_to_spree_stock_locations_spree_states.rb rename to db/bad_migrations/20231002000136955_add_foreign_key_to_spree_stock_locations_spree_states.rb diff --git a/db/migrate/20231002000136959_add_foreign_key_to_spree_stock_locations_spree_countries.rb b/db/bad_migrations/20231002000136959_add_foreign_key_to_spree_stock_locations_spree_countries.rb similarity index 100% rename from db/migrate/20231002000136959_add_foreign_key_to_spree_stock_locations_spree_countries.rb rename to db/bad_migrations/20231002000136959_add_foreign_key_to_spree_stock_locations_spree_countries.rb diff --git a/db/migrate/20231002000136976_add_foreign_key_to_spree_shipments_spree_stock_locations.rb b/db/bad_migrations/20231002000136976_add_foreign_key_to_spree_shipments_spree_stock_locations.rb similarity index 100% rename from db/migrate/20231002000136976_add_foreign_key_to_spree_shipments_spree_stock_locations.rb rename to db/bad_migrations/20231002000136976_add_foreign_key_to_spree_shipments_spree_stock_locations.rb diff --git a/db/migrate/20231002000137115_add_foreign_key_to_inventory_items_enterprises.rb b/db/bad_migrations/20231002000137115_add_foreign_key_to_inventory_items_enterprises.rb similarity index 100% rename from db/migrate/20231002000137115_add_foreign_key_to_inventory_items_enterprises.rb rename to db/bad_migrations/20231002000137115_add_foreign_key_to_inventory_items_enterprises.rb diff --git a/db/migrate/20231002000137116_add_foreign_key_to_inventory_items_spree_variants.rb b/db/bad_migrations/20231002000137116_add_foreign_key_to_inventory_items_spree_variants.rb similarity index 100% rename from db/migrate/20231002000137116_add_foreign_key_to_inventory_items_spree_variants.rb rename to db/bad_migrations/20231002000137116_add_foreign_key_to_inventory_items_spree_variants.rb diff --git a/db/migrate/20231003000823494_add_foreign_key_to_spree_orders_spree_users_created_by_id.rb b/db/bad_migrations/20231003000823494_add_foreign_key_to_spree_orders_spree_users_created_by_id.rb similarity index 100% rename from db/migrate/20231003000823494_add_foreign_key_to_spree_orders_spree_users_created_by_id.rb rename to db/bad_migrations/20231003000823494_add_foreign_key_to_spree_orders_spree_users_created_by_id.rb diff --git a/db/migrate/20240115022359_rename_offending_migrations.rb b/db/migrate/20240115022359_rename_offending_migrations.rb new file mode 100644 index 0000000000..21d9c73327 --- /dev/null +++ b/db/migrate/20240115022359_rename_offending_migrations.rb @@ -0,0 +1,39 @@ +# frozen_string_literal: true + +class RenameOffendingMigrations < ActiveRecord::Migration[7.0] + MIGRATION_IDS = { + '20231002000136871': "20231002000136", + '20231002000136872': "20231002000137", + '20231002000136876': "20231002000138", + '20231002000136877': "20231002000139", + '20231002000136879': "20231002000140", + '20231002000136926': "20231002000141", + '20231002000136952': "20231002000142", + '20231002000136955': "20231002000143", + '20231002000136959': "20231002000144", + '20231002000136976': "20231002000145", + '20231002000137115': "20231002000146", + '20231002000137116': "20231002000147", + '20231003000823494': "20231003000823", + }.freeze + + def up + MIGRATION_IDS.each do |bad_id, good_id| + execute <<~SQL.squish + UPDATE schema_migrations + SET version='#{good_id}' + WHERE version='#{bad_id}' + SQL + end + end + + def down + MIGRATION_IDS.each do |bad_id, good_id| + execute <<~SQL.squish + UPDATE schema_migrations + SET version='#{bad_id}' + WHERE version='#{good_id}' + SQL + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 91083ef7e9..301f7e74f8 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 20231003000823494) do +ActiveRecord::Schema[7.0].define(version: 2024_01_15_022359) do # These are extensions that must be enabled in order to support this database enable_extension "pg_stat_statements" enable_extension "plpgsql" From cd9c505c6b51aaba9fb52019b7928f2824861201 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 22 Nov 2023 05:48:57 +0000 Subject: [PATCH 3/7] chore(deps): bump tom-select from 2.2.3 to 2.3.1 Bumps [tom-select](https://github.com/orchidjs/tom-select) from 2.2.3 to 2.3.1. - [Release notes](https://github.com/orchidjs/tom-select/releases) - [Commits](https://github.com/orchidjs/tom-select/compare/v2.2.3...v2.3.1) --- updated-dependencies: - dependency-name: tom-select dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- package.json | 2 +- yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index c9bec5f193..a9b2f6a515 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,7 @@ "stimulus": "^3.2.2", "stimulus-flatpickr": "^1.4.0", "stimulus_reflex": "3.5.0-rc3", - "tom-select": "^2.2.3", + "tom-select": "^2.3.1", "trix": "^2.0.8", "webpack": "~4" }, diff --git a/yarn.lock b/yarn.lock index e104a0e578..c4c2abbc97 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8768,10 +8768,10 @@ toidentifier@1.0.1: resolved "https://registry.yarnpkg.com/toidentifier/-/toidentifier-1.0.1.tgz#3be34321a88a820ed1bd80dfaa33e479fbb8dd35" integrity sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA== -tom-select@^2.2.3: - version "2.2.3" - resolved "https://registry.yarnpkg.com/tom-select/-/tom-select-2.2.3.tgz#858acca2dcec1dbe1a94a3f4c944384e166a4f40" - integrity sha512-VMhRdFlugLGdnNZsP5r8sHKtyvWekIbtr53uoKONMzM+JSBWgy5pV9F+iZ2LTEbzIQI0efIwZ7I6h+wzZoM/zQ== +tom-select@^2.3.1: + version "2.3.1" + resolved "https://registry.yarnpkg.com/tom-select/-/tom-select-2.3.1.tgz#df338d9082874cd0bceb3bee87ed0184447c47f1" + integrity sha512-QS4vnOcB6StNGqX4sGboGXL2fkhBF2gIBB+8Hwv30FZXYPn0CyYO8kkdATRvwfCTThxiR4WcXwKJZ3cOmtI9eg== dependencies: "@orchidjs/sifter" "^1.0.3" "@orchidjs/unicode-variants" "^1.0.4" From 270a310e0fe778142b1fdd475eb36b68acc059f0 Mon Sep 17 00:00:00 2001 From: Gaetan Craig-Riou Date: Mon, 8 Jan 2024 14:44:36 +1100 Subject: [PATCH 4/7] Use send_keys to populate tom select input Setting the value directly doesn't trigger the search, presumably because it doesn't trigger any javascript event. --- spec/support/request/web_helper.rb | 4 ++-- spec/system/admin/order_spec.rb | 11 +++++------ 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/spec/support/request/web_helper.rb b/spec/support/request/web_helper.rb index 4e8aad2be0..e452939972 100644 --- a/spec/support/request/web_helper.rb +++ b/spec/support/request/web_helper.rb @@ -100,8 +100,8 @@ module WebHelper def tomselect_search_and_select(value, options) tomselect_wrapper = page.find("[name='#{options[:from]}']").sibling(".ts-wrapper") tomselect_wrapper.find(".ts-control").click - tomselect_wrapper.find(:css, '.ts-dropdown input.dropdown-input').set(value) - tomselect_wrapper.find(".ts-control").click + # Use send_keys as setting the value directly doesn't trigger the search + tomselect_wrapper.find(:css, '.ts-dropdown input.dropdown-input').send_keys(value) tomselect_wrapper.find(:css, '.ts-dropdown .ts-dropdown-content .option', text: value).click end diff --git a/spec/system/admin/order_spec.rb b/spec/system/admin/order_spec.rb index 379bd88e8f..4c5b677983 100644 --- a/spec/system/admin/order_spec.rb +++ b/spec/system/admin/order_spec.rb @@ -1074,19 +1074,18 @@ describe ' end describe "searching customers" do - def serching_for_customers + def searching_for_customers # opens the customer dropdown find(".items-placeholder").click - # sets the query name - find(".dropdown-input").set("John") + find(".dropdown-input").send_keys("John") within(".customer-details") do expect(page).to have_content("John Doe") expect(page).to have_content(customer.email.to_s) end # sets the query email - find(".dropdown-input").set("maura@smith.biz") + find(".dropdown-input").send_keys("maura@smith.biz") within(".customer-details") do expect(page).to have_content("John Doe") expect(page).to have_content(customer.email.to_s) @@ -1103,7 +1102,7 @@ describe ' end it "finds a customer by name" do - serching_for_customers + searching_for_customers end end @@ -1117,7 +1116,7 @@ describe ' end it "finds a customer by name" do - serching_for_customers + searching_for_customers end end end From d12c0a7d9dcc1ee0597a22a9f9e99a6dd1185d18 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Wed, 24 Jan 2024 12:09:02 +1100 Subject: [PATCH 5/7] Fixup: Remove unused method from spec --- spec/models/database_spec.rb | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/spec/models/database_spec.rb b/spec/models/database_spec.rb index b8f89dc1f2..609f275646 100644 --- a/spec/models/database_spec.rb +++ b/spec/models/database_spec.rb @@ -127,20 +127,4 @@ RSpec.describe "Database" do # AND #{model_class.table_name}.#{foreign_key_column} IS NOT NULL SQL end - - # Generates a unique timestamp. - # - # We may create multiple migrations within the same second, maybe even millisecond. - # So we add precision to milliseconds and increment on conflict. - def generate_timestamp - @last_creation_time ||= Time.new.utc(0) - - creation_time = Time.now.utc - if creation_time <= @last_creation_time - creation_time += 0.001.seconds - end - @last_creation_time = creation_time - - creation_time.utc.strftime('%Y%m%d%H%M%S%L') - end end From 98545741e6069a2ec288552bac7de6e4e690a450 Mon Sep 17 00:00:00 2001 From: Gaetan Craig-Riou Date: Wed, 24 Jan 2024 14:47:21 +1100 Subject: [PATCH 6/7] Add tomselect_select helper When using `tomselect_search_and_select` and searching isn't really required it leaves the dropdown option open. It can then cause problem when trying to interact with other element in the page. This happens because clicking on the chosen option happena before the searching finishes. We can now use `tomselect_select` when searching is not actually required. It should not be a problem when search is required, as capybara will wait for the option to appear on the page before clicking. --- spec/support/request/web_helper.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/spec/support/request/web_helper.rb b/spec/support/request/web_helper.rb index e452939972..01a4796f4e 100644 --- a/spec/support/request/web_helper.rb +++ b/spec/support/request/web_helper.rb @@ -105,6 +105,13 @@ module WebHelper tomselect_wrapper.find(:css, '.ts-dropdown .ts-dropdown-content .option', text: value).click end + def tomselect_select(value, options) + tomselect_wrapper = page.find("[name='#{options[:from]}']").sibling(".ts-wrapper") + tomselect_wrapper.find(".ts-control").click + + tomselect_wrapper.find(:css, '.ts-dropdown .ts-dropdown-content .option', text: value).click + end + def request_monitor_finished(controller = nil) page.evaluate_script("#{angular_scope(controller)}.scope().RequestMonitor.loading == false") end From 67dc79b074f47811850ff39d8263f50b96cd72ac Mon Sep 17 00:00:00 2001 From: Gaetan Craig-Riou Date: Wed, 24 Jan 2024 14:53:44 +1100 Subject: [PATCH 7/7] Replace tomselect_search_and_select by tomselect_select In these scenarios, searching for the option is not actually required, we can directly click on the needed option. It prevent issue with the dropdown option staying open and breaking specs. --- spec/system/admin/orders_spec.rb | 4 ++-- spec/system/admin/subscriptions/crud_spec.rb | 2 +- spec/system/admin/subscriptions/smoke_tests_spec.rb | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/spec/system/admin/orders_spec.rb b/spec/system/admin/orders_spec.rb index 41858b9e1e..b9f29d296b 100644 --- a/spec/system/admin/orders_spec.rb +++ b/spec/system/admin/orders_spec.rb @@ -934,8 +934,8 @@ describe ' fill_in "Order number", with: "R123456" tomselect_multiselect order_cycle.name, from: 'q[order_cycle_id_in][]' tomselect_multiselect distributor.name, from: 'q[distributor_id_in][]' - tomselect_search_and_select shipping_method.name, from: 'shipping_method_id' - tomselect_search_and_select "complete", from: 'q[state_eq]' + tomselect_select shipping_method.name, from: 'shipping_method_id' + tomselect_select "complete", from: 'q[state_eq]' fill_in "Email", with: user.email fill_in "First name begins with", with: "J" fill_in "Last name begins with", with: "D" diff --git a/spec/system/admin/subscriptions/crud_spec.rb b/spec/system/admin/subscriptions/crud_spec.rb index 274ecf823d..cb4c901639 100644 --- a/spec/system/admin/subscriptions/crud_spec.rb +++ b/spec/system/admin/subscriptions/crud_spec.rb @@ -233,7 +233,7 @@ describe 'Subscriptions' do before do visit admin_subscriptions_path page.find("#new-subscription").click - tomselect_search_and_select shop.name, from: "subscription[shop_id]" + tomselect_select shop.name, from: "subscription[shop_id]" click_button "Continue" end diff --git a/spec/system/admin/subscriptions/smoke_tests_spec.rb b/spec/system/admin/subscriptions/smoke_tests_spec.rb index cfd1e7a2a4..86ab504a4b 100644 --- a/spec/system/admin/subscriptions/smoke_tests_spec.rb +++ b/spec/system/admin/subscriptions/smoke_tests_spec.rb @@ -183,7 +183,7 @@ describe 'Subscriptions' do before do visit admin_subscriptions_path page.find("#new-subscription").click - tomselect_search_and_select shop.name, from: "subscription[shop_id]" + tomselect_select shop.name, from: "subscription[shop_id]" click_button "Continue" end