From 2a3176f7f50621f780772e2d7be6a823bdd90090 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 8 Dec 2020 21:24:15 +0000 Subject: [PATCH 01/17] Bump capybara from 2.18.0 to 3.15.1 Bumps [capybara](https://github.com/teamcapybara/capybara) from 2.18.0 to 3.15.1. - [Release notes](https://github.com/teamcapybara/capybara/releases) - [Changelog](https://github.com/teamcapybara/capybara/blob/master/History.md) - [Commits](https://github.com/teamcapybara/capybara/compare/2.18.0...3.15.1) Signed-off-by: dependabot[bot] --- Gemfile.lock | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 1f8af10df8..fbb64ca107 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -132,13 +132,14 @@ GEM builder (3.2.4) byebug (11.0.1) cancan (1.6.10) - capybara (2.18.0) + capybara (3.15.1) addressable mini_mime (>= 0.1.3) - nokogiri (>= 1.3.3) - rack (>= 1.0.0) - rack-test (>= 0.5.4) - xpath (>= 2.0, < 4.0) + nokogiri (~> 1.8) + rack (>= 1.6.0) + rack-test (>= 0.6.3) + regexp_parser (~> 1.2) + xpath (~> 3.2) childprocess (3.0.0) chronic (0.10.2) chunky_png (1.3.14) @@ -551,6 +552,7 @@ GEM nokogiri (~> 1.5) optimist (~> 3.0) redcarpet (3.5.0) + regexp_parser (1.8.2) request_store (1.5.0) rack (>= 1.4) responders (2.4.1) From 7a27741cf5f78455079d96c8ab01718f47f0a9a3 Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Tue, 8 Dec 2020 22:15:54 +0000 Subject: [PATCH 02/17] Remove unnecessary capybara version control in Gemfile --- Gemfile | 2 +- Gemfile.lock | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile b/Gemfile index 25b549f0ab..3c5622c524 100644 --- a/Gemfile +++ b/Gemfile @@ -126,7 +126,7 @@ group :test, :development do # Pretty printed test output gem 'atomic' gem 'awesome_print' - gem 'capybara', '>= 2.18.0' # 3.0 requires rack 1.6 that only works with Rails 4.2 + gem 'capybara' gem 'database_cleaner', require: false gem "factory_bot_rails", '4.10.0', require: false gem 'fuubar', '~> 2.5.0' diff --git a/Gemfile.lock b/Gemfile.lock index fbb64ca107..ea747d518b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -740,7 +740,7 @@ DEPENDENCIES bugsnag byebug (~> 11.0.0) cancan (~> 1.6.10) - capybara (>= 2.18.0) + capybara catalog! coffee-rails (~> 4.2.2) combine_pdf From b58fddf098f2620b453791ce54df0da4b855fbc3 Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Thu, 10 Dec 2020 22:59:37 +0000 Subject: [PATCH 03/17] Adapt matcher to capybara v3 --- spec/features/consumer/shopping/orders_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/features/consumer/shopping/orders_spec.rb b/spec/features/consumer/shopping/orders_spec.rb index f13269f9da..980d51893d 100644 --- a/spec/features/consumer/shopping/orders_spec.rb +++ b/spec/features/consumer/shopping/orders_spec.rb @@ -188,6 +188,6 @@ feature "Order Management", js: true do end def be_confirmed_order_page - have_content /Order #\w+ Confirmed PAID/ + have_content "Order ##{order.number} Confirmed" end end From 80e59a920e27d6338429047ee512aac95edf6d45 Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Thu, 10 Dec 2020 23:01:01 +0000 Subject: [PATCH 04/17] Adpat matcher to capybara v3 --- spec/views/spree/shared/_order_details.html.haml_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/views/spree/shared/_order_details.html.haml_spec.rb b/spec/views/spree/shared/_order_details.html.haml_spec.rb index 60e95ac0f6..76777a363f 100644 --- a/spec/views/spree/shared/_order_details.html.haml_spec.rb +++ b/spec/views/spree/shared/_order_details.html.haml_spec.rb @@ -21,7 +21,7 @@ describe "spree/shared/_order_details.html.haml" do render - expect(rendered).to have_content("Paying via: Bartering") + expect(rendered).to have_content("Paying via:\nBartering") end it "displays payment methods safely" do @@ -29,7 +29,7 @@ describe "spree/shared/_order_details.html.haml" do render - expect(rendered).to have_content("Paying via: Barter→ing") + expect(rendered).to have_content("Paying via:\nBarter→ing") end it "shows the last used payment method" do @@ -51,6 +51,6 @@ describe "spree/shared/_order_details.html.haml" do render - expect(rendered).to have_content("Paying via: Credit") + expect(rendered).to have_content("Paying via:\nCredit") end end From 773f733c8ea39005f34a832ff7e908c0102d0646 Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Thu, 10 Dec 2020 23:05:15 +0000 Subject: [PATCH 05/17] Adapt matchers to capybara v3 --- spec/views/spree/admin/orders/edit.html.haml_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/views/spree/admin/orders/edit.html.haml_spec.rb b/spec/views/spree/admin/orders/edit.html.haml_spec.rb index 8a8c5b03f8..4394065394 100644 --- a/spec/views/spree/admin/orders/edit.html.haml_spec.rb +++ b/spec/views/spree/admin/orders/edit.html.haml_spec.rb @@ -31,9 +31,9 @@ describe "spree/admin/orders/edit.html.haml" do it "displays order shipping costs, transaction fee and order total" do render - expect(rendered).to have_content("Shipping: UPS Ground $6.00") - expect(rendered).to have_content("Transaction fee: $10.00") - expect(rendered).to have_content("Order Total $36.00") + expect(rendered).to have_content("Shipping Method\nUPS Ground $6.00") + expect(rendered).to have_content("Transaction fee:\n\n$10.00") + expect(rendered).to have_content("Order Total\n$36.00") end end end From fd5adab0d5e5df55879a5b8bbd64a3129c44f3ff Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Thu, 10 Dec 2020 23:27:56 +0000 Subject: [PATCH 06/17] Adapt matchers to capybara v3 --- spec/features/consumer/account_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/features/consumer/account_spec.rb b/spec/features/consumer/account_spec.rb index a721235773..84cb4e3731 100644 --- a/spec/features/consumer/account_spec.rb +++ b/spec/features/consumer/account_spec.rb @@ -65,8 +65,8 @@ feature ' href: "#{distributor2.permalink}/shop", count: 1) expect(page).not_to have_content distributor_without_orders.name - expect(page).to have_content distributor1.name + " " + "Balance due" - expect(page).to have_content distributor_credit.name + " Credit" + expect(page).to have_content distributor1.name + "\n" + "Balance due" + expect(page).to have_content distributor_credit.name + "\nCredit" # It reveals table of orders for distributors when clicked expand_active_table_node distributor1.name @@ -98,7 +98,7 @@ feature ' context "without any completed orders" do it "displays an appropriate message" do visit "/account" - expect(page).to have_content { t :you_have_no_orders_yet } + expect(page).to have_content I18n.t(:you_have_no_orders_yet) end end end From 5ae955c27f50428d063492122689ab0531e1243d Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Thu, 10 Dec 2020 23:35:34 +0000 Subject: [PATCH 07/17] Adapt matchers to capybara v3 --- spec/features/consumer/registration_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/features/consumer/registration_spec.rb b/spec/features/consumer/registration_spec.rb index e3557c88ab..25d442bf76 100644 --- a/spec/features/consumer/registration_spec.rb +++ b/spec/features/consumer/registration_spec.rb @@ -42,7 +42,7 @@ feature "Registration", js: true do expect(URI.parse(current_url).path).to eq registration_path # Done reading introduction - page.has_content? + expect(page).to have_text "What do I get?" click_button "Let's get started!" expect(page).to have_content 'Woot!' @@ -53,7 +53,7 @@ feature "Registration", js: true do fill_in 'enterprise_address', with: '123 Abc Street' fill_in 'enterprise_city', with: 'Northcote' fill_in 'enterprise_zipcode', with: '3070' - expect(page).to have_select('enterprise_country', options: %w(Albania Australia), selected: 'Australia') + expect(page).to have_select('enterprise_country', options: ["Albania", "Australia"], selected: 'Australia') select 'Vic', from: 'enterprise_state' click_button "Continue" expect(page).to have_content 'Who is responsible for managing My Awesome Enterprise?' From b287d67f6b6c521a0a7070bc53421266aa34a5d1 Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Thu, 10 Dec 2020 23:36:40 +0000 Subject: [PATCH 08/17] Adapt matchers to capybara v3 --- spec/features/consumer/account/settings_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/features/consumer/account/settings_spec.rb b/spec/features/consumer/account/settings_spec.rb index 11dee72750..d178ea5493 100644 --- a/spec/features/consumer/account/settings_spec.rb +++ b/spec/features/consumer/account/settings_spec.rb @@ -33,7 +33,7 @@ feature "Account Settings", js: true do expect(enqueued_jobs.last.to_s).to match "new@email.com" - expect(find(".alert-box.success").text.strip).to eq "#{I18n.t('spree.account_updated')} ×" + expect(find(".alert-box.success").text.strip).to eq "#{I18n.t('spree.account_updated')}\n×" user.reload expect(user.email).to eq 'old@email.com' expect(user.unconfirmed_email).to eq 'new@email.com' From 6d37a15488db8952c9c2f4c47c10f43da513df38 Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Fri, 11 Dec 2020 00:02:22 +0000 Subject: [PATCH 09/17] Adapt matchers to capybara v3 --- spec/features/admin/order_cycles/complex_editing_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/features/admin/order_cycles/complex_editing_spec.rb b/spec/features/admin/order_cycles/complex_editing_spec.rb index 4b9aa275fc..ea5b3d536a 100644 --- a/spec/features/admin/order_cycles/complex_editing_spec.rb +++ b/spec/features/admin/order_cycles/complex_editing_spec.rb @@ -27,7 +27,7 @@ feature ' expect(page.find('#order_cycle_name').value).to eq(oc.name) expect(page.find('#order_cycle_orders_open_at').value).to eq(oc.orders_open_at.to_s) expect(page.find('#order_cycle_orders_close_at').value).to eq(oc.orders_close_at.to_s) - expect(page).to have_content "COORDINATOR #{oc.coordinator.name}" + expect(page).to have_content "COORDINATOR\n#{oc.coordinator.name}" click_button 'Next' From ed4a7bd3618071bf231cc90cdaa79bd812f57c62 Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Fri, 11 Dec 2020 00:09:34 +0000 Subject: [PATCH 10/17] Adapt matchers to capybara v3 --- spec/features/admin/product_import_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/features/admin/product_import_spec.rb b/spec/features/admin/product_import_spec.rb index 6443489cf4..e1b93d1e69 100644 --- a/spec/features/admin/product_import_spec.rb +++ b/spec/features/admin/product_import_spec.rb @@ -534,8 +534,8 @@ feature "Product Import", js: true do proceed_to_validation # Check that all rows are validated. - heading = "120 #{I18n.t('admin.product_import.import.products_to_create')}" - find(".panel-header", text: heading).click + heading = I18n.t('admin.product_import.import.products_to_create') + find(".header-description", text: heading).click expect(page).to have_content "Imported Product 10" expect(page).to have_content "Imported Product 60" expect(page).to have_content "Imported Product 110" From c92e8de51f119190de434ef33655f4b65b81ae63 Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Fri, 11 Dec 2020 00:13:46 +0000 Subject: [PATCH 11/17] Adapt matchers to capybara v3 --- spec/features/consumer/shopping/variant_overrides_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/features/consumer/shopping/variant_overrides_spec.rb b/spec/features/consumer/shopping/variant_overrides_spec.rb index 4eefb7c114..ce8efc02ae 100644 --- a/spec/features/consumer/shopping/variant_overrides_spec.rb +++ b/spec/features/consumer/shopping/variant_overrides_spec.rb @@ -60,8 +60,8 @@ feature "shopping with variant overrides defined", js: true do it "calculates fees correctly" do page.find("#variant-#{product1_variant1.id} .graph-button").click - expect(page).to have_selector 'li', text: "#{with_currency(55.55)} Item cost" - expect(page).to have_selector 'li', text: "#{with_currency(5.56)} Packing fee" + expect(page).to have_selector 'li', text: "#{with_currency(55.55)}\nItem cost" + expect(page).to have_selector 'li', text: "#{with_currency(5.56)}\nPacking fee" expect(page).to have_selector 'li', text: "= #{with_currency(61.11)}" end From f19946af8d4d9cde5cc50de74f66c933ae0016f5 Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Fri, 11 Dec 2020 00:16:31 +0000 Subject: [PATCH 12/17] Remove unnecessary test step that is breaking in capybara v3 --- spec/features/admin/variant_overrides_spec.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/spec/features/admin/variant_overrides_spec.rb b/spec/features/admin/variant_overrides_spec.rb index fcf5931c73..309bdca9e8 100644 --- a/spec/features/admin/variant_overrides_spec.rb +++ b/spec/features/admin/variant_overrides_spec.rb @@ -304,7 +304,6 @@ feature " # Clearing values manually fill_in "variant-overrides-#{variant.id}-price", with: '' - fill_in "variant-overrides-#{variant.id}-count_on_hand", with: '' select_on_demand variant, :use_producer_settings fill_in "variant-overrides-#{variant.id}-default_stock", with: '' within "tr#v_#{variant.id}" do From 26165cc08d70c577eece5ad092b3b86e1bd233d3 Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Fri, 11 Dec 2020 00:20:58 +0000 Subject: [PATCH 13/17] Adapt matcher to capybara v3 --- spec/features/admin/bulk_product_update_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/features/admin/bulk_product_update_spec.rb b/spec/features/admin/bulk_product_update_spec.rb index 93c1aa9823..3692cb26c1 100644 --- a/spec/features/admin/bulk_product_update_spec.rb +++ b/spec/features/admin/bulk_product_update_spec.rb @@ -329,7 +329,7 @@ feature ' expect(page).to have_field "variant_price", with: "3.0" expect(page).to have_field "variant_unit_value_with_description", with: "250 (bottle)" expect(page).to have_field "variant_on_hand", with: "9" - expect(page).to have_selector "span[name='on_hand']", "9" + expect(page).to have_selector "span[name='on_hand']", text: "9" select "Volume (L)", from: "variant_unit_with_scale" fill_in "variant_sku", with: "NEWSKU" From 62715a80609dadd1fe6e84a11601f0513871282e Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Fri, 11 Dec 2020 00:21:46 +0000 Subject: [PATCH 14/17] Adapt matcher to capybara v3 --- spec/features/consumer/account/settings_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/features/consumer/account/settings_spec.rb b/spec/features/consumer/account/settings_spec.rb index d178ea5493..99abb4e52d 100644 --- a/spec/features/consumer/account/settings_spec.rb +++ b/spec/features/consumer/account/settings_spec.rb @@ -49,7 +49,7 @@ feature "Account Settings", js: true do fill_in 'user_password_confirmation', with: 'NewPassword' click_button I18n.t(:update) - expect(find(".alert-box.success").text.strip).to eq "#{I18n.t('spree.account_updated')} ×" + expect(find(".alert-box.success").text.strip).to eq "#{I18n.t('spree.account_updated')}\n×" expect(user.reload.encrypted_password).to_not eq initial_password end From 480dfdf9613d7ec8887edf38991ef5953873cb1e Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Thu, 3 Dec 2020 00:37:11 +0000 Subject: [PATCH 15/17] Handle redirect case For some reason the process is now working correctly, the authorization step succeeds and a redirect link is stored in the payment with state pending. The payment state is correctly left at pending. Here we add a check for the redirect path sent by stripe and fail the authorization if there is one (it means the payment would need an extra auth step only available in the frontoffice now and probably through email to customer at some point in the future). For some reason the flash with the authorization failure message is not showing up for the user --- app/controllers/spree/admin/payments_controller.rb | 4 +++- spec/features/admin/payments_stripe_spec.rb | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/controllers/spree/admin/payments_controller.rb b/app/controllers/spree/admin/payments_controller.rb index 0b5732caa1..8b5f42c472 100644 --- a/app/controllers/spree/admin/payments_controller.rb +++ b/app/controllers/spree/admin/payments_controller.rb @@ -135,7 +135,9 @@ module Spree return unless @payment.payment_method.class == Spree::Gateway::StripeSCA @payment.authorize! - raise Spree::Core::GatewayError, I18n.t('authorization_failure') unless @payment.pending? + return if @payment.pending? && @payment.cvv_response_message.nil? + + raise Spree::Core::GatewayError, I18n.t('authorization_failure') end end end diff --git a/spec/features/admin/payments_stripe_spec.rb b/spec/features/admin/payments_stripe_spec.rb index 1a3d6047bf..f030d32451 100644 --- a/spec/features/admin/payments_stripe_spec.rb +++ b/spec/features/admin/payments_stripe_spec.rb @@ -78,8 +78,8 @@ feature ' click_button "Update" expect(page).to have_link "StripeSCA" - expect(page).to have_content "PROCESSING" - expect(OrderPaymentFinder.new(order.reload).last_payment.state).to eq "processing" + expect(page).to have_content "PENDING" + expect(OrderPaymentFinder.new(order.reload).last_payment.state).to eq "pending" end end end From ada25fa2b28dcc6ae4e242d307fc309e1c20ba65 Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Thu, 3 Dec 2020 00:10:15 +0000 Subject: [PATCH 16/17] Improve stripe spec I am not sure why this was passing without these stubbed requests for the second order, but now they were correctly failing. This commit fixes the spec. --- spec/features/consumer/shopping/checkout_stripe_spec.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spec/features/consumer/shopping/checkout_stripe_spec.rb b/spec/features/consumer/shopping/checkout_stripe_spec.rb index e3a32718aa..2346c2299c 100644 --- a/spec/features/consumer/shopping/checkout_stripe_spec.rb +++ b/spec/features/consumer/shopping/checkout_stripe_spec.rb @@ -228,6 +228,8 @@ feature "Check out with Stripe", js: true do new_order = create(:order, user: user, order_cycle: order_cycle, distributor: distributor, bill_address_id: nil, ship_address_id: nil) set_order(new_order) add_product_to_cart(new_order, product, quantity: 10) + stub_payment_intents_post_request order: new_order + stub_successful_capture_request order: new_order # Checkout with saved card visit checkout_path From 367622cea8f09ec75f53620a48d16c3a02433f8c Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Sat, 12 Dec 2020 00:01:40 +0000 Subject: [PATCH 17/17] Capybara v3 is not cleaning up the html into text so the permissions that are inside html li elements are not matched with the matcher have_table_row when there are multiple permissions. So, in this case, we need to do the work ourselves: looking up the correct row and then asserting the permissions are the ones required --- .../admin/enterprise_relationships_spec.rb | 32 +++++++++++++------ 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/spec/features/admin/enterprise_relationships_spec.rb b/spec/features/admin/enterprise_relationships_spec.rb index b99341fb46..3dd2c24f99 100644 --- a/spec/features/admin/enterprise_relationships_spec.rb +++ b/spec/features/admin/enterprise_relationships_spec.rb @@ -26,10 +26,9 @@ feature ' # Then I should see the relationships within('table#enterprise-relationships') do - expect(page).to have_relationship e1, e2, ['to add to order cycle'] - expect(page).to have_relationship e2, e3, ['to manage products'] - expect(page).to have_relationship e3, e4, - ['to add to order cycle', 'to manage products'] + expect(page).to have_relationship e1, e2, 'to add to order cycle' + expect(page).to have_relationship e2, e3, 'to manage products' + expect_relationship_with_permissions e3, e4, ['to add to order cycle', 'to manage products'] end end @@ -50,7 +49,7 @@ feature ' # Wait for row to appear since have_relationship doesn't wait expect(page).to have_selector 'tr', count: 2 - expect(page).to have_relationship e1, e2, ['to add to order cycle', 'to add products to inventory', 'to edit profile'] + expect_relationship_with_permissions e1, e2, ['to add to order cycle', 'to add products to inventory', 'to edit profile'] er = EnterpriseRelationship.where(parent_id: e1, child_id: e2).first expect(er).to be_present expect(er.permissions.map(&:name)).to match_array ['add_to_order_cycle', 'edit_profile', 'create_variant_overrides'] @@ -79,7 +78,7 @@ feature ' er = create(:enterprise_relationship, parent: e1, child: e2, permissions_list: [:add_to_order_cycle]) visit admin_enterprise_relationships_path - expect(page).to have_relationship e1, e2, ['to add to order cycle'] + expect(page).to have_relationship e1, e2, 'to add to order cycle' accept_alert do first("a.delete-enterprise-relationship").click @@ -119,9 +118,24 @@ feature ' private - def have_relationship(parent, child, perms = []) - perms = perms.join(' ') + def have_relationship(parent, child, permission = "") + have_table_row [parent.name, 'permits', child.name, permission, ''] + end - have_table_row [parent.name, 'permits', child.name, perms, ''] + def expect_relationship_with_permissions(parent, child, permissions = []) + tr = find_relationship(parent, child) + td = tr.find('td:nth-child(4)') + permissions.each_with_index do |permission, index| + expect(td.find("li:nth-child(#{index + 1})").text).to eq permission + end + end + + def find_relationship(parent, child) + page.all('tr').each do |tr| + return tr if tr.find('td:first-child').text == parent.name && + tr.find('td:nth-child(2)').text == "permits" && + tr.find('td:nth-child(3)').text == child.name + end + raise "relationship not found" end end