diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index cacc26fc1c..8f01f0a726 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -34,10 +34,9 @@ Lint/EmptyClass: Exclude: - 'spec/lib/reports/report_loader_spec.rb' -# Offense count: 2 +# Offense count: 1 Lint/FloatComparison: Exclude: - - 'app/models/product_import/entry_validator.rb' - 'app/models/spree/gateway/pay_pal_express.rb' # Offense count: 1 @@ -50,13 +49,12 @@ Lint/NoReturnInBeginEndBlocks: Exclude: - 'app/controllers/payment_gateways/stripe_controller.rb' -# Offense count: 4 +# Offense count: 3 # This cop supports unsafe autocorrection (--autocorrect-all). Lint/RedundantDirGlobSort: Exclude: - 'engines/catalog/spec/spec_helper.rb' - 'engines/dfc_provider/spec/spec_helper.rb' - - 'spec/base_spec_helper.rb' - 'spec/system_helper.rb' # Offense count: 1 @@ -172,7 +170,7 @@ Metrics/ClassLength: - 'lib/reporting/reports/enterprise_fee_summary/scope.rb' - 'lib/reporting/reports/xero_invoices/base.rb' -# Offense count: 32 +# Offense count: 30 # Configuration parameters: AllowedMethods, AllowedPatterns, Max. Metrics/CyclomaticComplexity: Exclude: @@ -193,7 +191,6 @@ Metrics/CyclomaticComplexity: - 'app/models/spree/preferences/preferable_class_methods.rb' - 'app/models/spree/return_authorization.rb' - 'app/models/spree/tax_rate.rb' - - 'app/models/spree/variant.rb' - 'app/models/spree/zone.rb' - 'lib/open_food_network/enterprise_issue_validator.rb' - 'lib/reporting/reports/xero_invoices/base.rb' @@ -328,7 +325,7 @@ Naming/MethodParameterName: Exclude: - 'app/services/process_payment_intent.rb' -# Offense count: 28 +# Offense count: 26 # Configuration parameters: EnforcedStyle, CheckMethodNames, CheckSymbols, AllowedIdentifiers, AllowedPatterns. # SupportedStyles: snake_case, normalcase, non_integer # AllowedIdentifiers: capture3, iso8601, rfc1123_date, rfc822, rfc2822, rfc3339, x86_64 @@ -343,7 +340,7 @@ Naming/VariableNumber: - 'spec/models/spree/tax_rate_spec.rb' - 'spec/requests/api/orders_spec.rb' -# Offense count: 143 +# Offense count: 144 # This cop supports unsafe autocorrection (--autocorrect-all). # Configuration parameters: ResponseMethods. # ResponseMethods: response, last_response @@ -586,30 +583,9 @@ Rails/LexicallyScopedActionFilter: - 'app/controllers/spree/admin/return_authorizations_controller.rb' - 'app/controllers/spree/admin/search_controller.rb' - 'app/controllers/spree/admin/shipping_methods_controller.rb' - - 'app/controllers/spree/admin/users_controller.rb' - 'app/controllers/spree/admin/zones_controller.rb' - 'app/controllers/spree/users_controller.rb' -# Offense count: 56 -# This cop supports unsafe autocorrection (--autocorrect-all). -# Configuration parameters: Include. -# Include: spec/controllers/**/*.rb, spec/requests/**/*.rb, test/controllers/**/*.rb, test/integration/**/*.rb -Rails/ResponseParsedBody: - Exclude: - - 'spec/controllers/admin/bulk_line_items_controller_spec.rb' - - 'spec/controllers/admin/customers_controller_spec.rb' - - 'spec/controllers/admin/order_cycles_controller_spec.rb' - - 'spec/controllers/admin/proxy_orders_controller_spec.rb' - - 'spec/controllers/admin/schedules_controller_spec.rb' - - 'spec/controllers/admin/stripe_accounts_controller_spec.rb' - - 'spec/controllers/admin/subscription_line_items_controller_spec.rb' - - 'spec/controllers/admin/subscriptions_controller_spec.rb' - - 'spec/controllers/cart_controller_spec.rb' - - 'spec/controllers/line_items_controller_spec.rb' - - 'spec/controllers/spree/admin/search_controller_spec.rb' - - 'spec/controllers/spree/credit_cards_controller_spec.rb' - - 'spec/controllers/user_registrations_controller_spec.rb' - # Offense count: 7 # This cop supports unsafe autocorrection (--autocorrect-all). # Configuration parameters: EnforcedStyle. diff --git a/app/controllers/user_registrations_controller.rb b/app/controllers/user_registrations_controller.rb index 01e819af3d..fccaf43550 100644 --- a/app/controllers/user_registrations_controller.rb +++ b/app/controllers/user_registrations_controller.rb @@ -31,7 +31,7 @@ class UserRegistrationsController < Devise::RegistrationsController associate_user respond_to do |format| - format.js do + format.json do render json: { email: @user.email } end end @@ -51,7 +51,7 @@ class UserRegistrationsController < Devise::RegistrationsController def render_error(errors = {}) clean_up_passwords(resource) respond_to do |format| - format.js do + format.json do render json: errors, status: :unauthorized end end diff --git a/spec/controllers/admin/bulk_line_items_controller_spec.rb b/spec/controllers/admin/bulk_line_items_controller_spec.rb index dcca09f313..89303ca6d4 100644 --- a/spec/controllers/admin/bulk_line_items_controller_spec.rb +++ b/spec/controllers/admin/bulk_line_items_controller_spec.rb @@ -260,7 +260,7 @@ RSpec.describe Admin::BulkLineItemsController, type: :controller do it 'returns a JSON with the errors' do spree_put :update, params - expect(JSON.parse(response.body)['errors']).to eq(errors) + expect(response.parsed_body['errors']).to eq(errors) end it 'returns a 412 response' do diff --git a/spec/controllers/admin/customers_controller_spec.rb b/spec/controllers/admin/customers_controller_spec.rb index 3353dcb447..4a153c1410 100644 --- a/spec/controllers/admin/customers_controller_spec.rb +++ b/spec/controllers/admin/customers_controller_spec.rb @@ -162,7 +162,7 @@ module Admin it "allows me to update the customer" do spree_put :update, format: :json, id: customer.id, customer: { email: 'new.email@gmail.com' } - expect(JSON.parse(response.body)["id"]).to eq customer.id + expect(response.parsed_body["id"]).to eq customer.id expect(assigns(:customer)).to eq customer expect(customer.reload.email).to eq 'new.email@gmail.com' end @@ -243,7 +243,7 @@ module Admin it "renders the customer as json" do get :show, as: :json, params: { id: customer.id } - expect(JSON.parse(response.body)["id"]).to eq customer.id + expect(response.parsed_body["id"]).to eq customer.id end end diff --git a/spec/controllers/admin/order_cycles_controller_spec.rb b/spec/controllers/admin/order_cycles_controller_spec.rb index 35cefae5d1..300b7aba89 100644 --- a/spec/controllers/admin/order_cycles_controller_spec.rb +++ b/spec/controllers/admin/order_cycles_controller_spec.rb @@ -185,7 +185,7 @@ module Admin it "returns success: true and a valid edit path" do spree_post :create, params - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response['success']).to be true expect(json_response['edit_path']).to eq "/admin/order_cycles/1/incoming" end @@ -196,7 +196,7 @@ module Admin it "returns an errors hash" do spree_post :create, params - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response['errors']).to be end end @@ -271,7 +271,7 @@ module Admin it "returns an error message" do spree_put :update, params - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response['errors']).to be end end @@ -384,7 +384,7 @@ module Admin expect do spree_put :bulk_update, format: :json end.to change { oc.orders_open_at }.by(0) - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response['errors']) .to eq 'Hm, something went wrong. No order cycle data found.' end @@ -401,7 +401,7 @@ module Admin it "returns an error message" do spree_put :bulk_update, params - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response['errors']).to be_present end end diff --git a/spec/controllers/admin/proxy_orders_controller_spec.rb b/spec/controllers/admin/proxy_orders_controller_spec.rb index 7882fd96c4..78cb77d343 100644 --- a/spec/controllers/admin/proxy_orders_controller_spec.rb +++ b/spec/controllers/admin/proxy_orders_controller_spec.rb @@ -45,7 +45,7 @@ RSpec.describe Admin::ProxyOrdersController, type: :controller do context "when cancellation succeeds" do it 'renders the cancelled proxy_order as json' do get(:cancel, params:) - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response['state']).to eq "canceled" expect(json_response['id']).to eq proxy_order.id expect(proxy_order.reload.canceled_at).to be_within(5.seconds).of Time.zone.now @@ -57,7 +57,7 @@ RSpec.describe Admin::ProxyOrdersController, type: :controller do it "shows an error" do get(:cancel, params:) - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response['errors']).to eq ['Could not cancel the order'] end end @@ -116,7 +116,7 @@ RSpec.describe Admin::ProxyOrdersController, type: :controller do context "when resuming succeeds" do it 'renders the resumed proxy_order as json' do get(:resume, params:) - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response['state']).to eq "resumed" expect(json_response['id']).to eq proxy_order.id expect(proxy_order.reload.canceled_at).to be nil @@ -128,7 +128,7 @@ RSpec.describe Admin::ProxyOrdersController, type: :controller do it "shows an error" do get(:resume, params:) - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response['errors']).to eq ['Could not resume the order'] end end diff --git a/spec/controllers/admin/schedules_controller_spec.rb b/spec/controllers/admin/schedules_controller_spec.rb index c47b9e7bc8..01d85ab693 100644 --- a/spec/controllers/admin/schedules_controller_spec.rb +++ b/spec/controllers/admin/schedules_controller_spec.rb @@ -98,8 +98,8 @@ RSpec.describe Admin::SchedulesController, type: :controller do it "allows me to update basic information" do spree_put :update, format: :json, id: coordinated_schedule.id, schedule: { name: "my awesome schedule" } - expect(JSON.parse(response.body)["id"]).to eq coordinated_schedule.id - expect(JSON.parse(response.body)["name"]).to eq "my awesome schedule" + expect(response.parsed_body["id"]).to eq coordinated_schedule.id + expect(response.parsed_body["name"]).to eq "my awesome schedule" expect(assigns(:schedule)).to eq coordinated_schedule expect(coordinated_schedule.reload.name).to eq 'my awesome schedule' end @@ -258,7 +258,7 @@ RSpec.describe Admin::SchedulesController, type: :controller do it "returns an error message and prevents me from deleting the schedule" do expect { spree_delete :destroy, params }.not_to change { Schedule.count } - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response["errors"]) .to include 'This schedule cannot be deleted ' \ 'because it has associated subscriptions' diff --git a/spec/controllers/admin/stripe_accounts_controller_spec.rb b/spec/controllers/admin/stripe_accounts_controller_spec.rb index 97aa99a895..93774422fa 100644 --- a/spec/controllers/admin/stripe_accounts_controller_spec.rb +++ b/spec/controllers/admin/stripe_accounts_controller_spec.rb @@ -117,7 +117,7 @@ RSpec.describe Admin::StripeAccountsController, type: :controller do context "when Stripe is not enabled" do it "returns with a status of 'stripe_disabled'" do get(:status, params:) - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response["status"]).to eq "stripe_disabled" end end @@ -128,7 +128,7 @@ RSpec.describe Admin::StripeAccountsController, type: :controller do context "when no stripe account is associated with the specified enterprise" do it "returns with a status of 'account_missing'" do get(:status, params:) - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response["status"]).to eq "account_missing" end end @@ -171,7 +171,7 @@ RSpec.describe Admin::StripeAccountsController, type: :controller do context "which is connected" do it "returns with a status of 'connected'" do response = get(:status, params:) - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response["status"]).to eq "connected" # serializes required attrs expect(json_response["charges_enabled"]).to eq false diff --git a/spec/controllers/admin/subscription_line_items_controller_spec.rb b/spec/controllers/admin/subscription_line_items_controller_spec.rb index 0a015046f2..bf637d92b4 100644 --- a/spec/controllers/admin/subscription_line_items_controller_spec.rb +++ b/spec/controllers/admin/subscription_line_items_controller_spec.rb @@ -38,7 +38,7 @@ RSpec.describe Admin::SubscriptionLineItemsController, type: :controller do context "but no shop_id is provided" do it "returns an error" do spree_post :build, params - expect(JSON.parse(response.body)['errors']).to eq ['Unauthorised'] + expect(response.parsed_body['errors']).to eq ['Unauthorised'] end end @@ -47,7 +47,7 @@ RSpec.describe Admin::SubscriptionLineItemsController, type: :controller do it "returns an error" do spree_post :build, params - expect(JSON.parse(response.body)['errors']).to eq ['Unauthorised'] + expect(response.parsed_body['errors']).to eq ['Unauthorised'] end end @@ -59,7 +59,7 @@ RSpec.describe Admin::SubscriptionLineItemsController, type: :controller do it "returns an error" do spree_post :build, params - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response['errors']) .to eq ["#{shop.name} is not permitted to sell the selected product"] end @@ -74,7 +74,7 @@ RSpec.describe Admin::SubscriptionLineItemsController, type: :controller do it "returns a serialized subscription line item without a price estimate" do spree_post :build, params - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response['price_estimate']).to eq '?' expect(json_response['quantity']).to eq 2 expect(json_response['description']).to eq "#{variant.product.name} - 100g" @@ -87,7 +87,7 @@ RSpec.describe Admin::SubscriptionLineItemsController, type: :controller do it "returns a serialized subscription line item without a price estimate" do spree_post :build, params - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response['price_estimate']).to eq '?' expect(json_response['quantity']).to eq 2 expect(json_response['description']).to eq "#{variant.product.name} - 100g" @@ -102,7 +102,7 @@ RSpec.describe Admin::SubscriptionLineItemsController, type: :controller do "based on the variant" do spree_post :build, params - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response['price_estimate']).to eq 18.5 expect(json_response['quantity']).to eq 2 expect(json_response['description']).to eq "#{variant.product.name} - 100g" @@ -118,7 +118,7 @@ RSpec.describe Admin::SubscriptionLineItemsController, type: :controller do "based on the override" do spree_post :build, params - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response['price_estimate']).to eq 15.5 expect(json_response['quantity']).to eq 2 expect(json_response['description']).to eq "#{variant.product.name} - 100g" diff --git a/spec/controllers/admin/subscriptions_controller_spec.rb b/spec/controllers/admin/subscriptions_controller_spec.rb index b60052d8a3..b0afd0993d 100644 --- a/spec/controllers/admin/subscriptions_controller_spec.rb +++ b/spec/controllers/admin/subscriptions_controller_spec.rb @@ -67,7 +67,7 @@ RSpec.describe Admin::SubscriptionsController, type: :controller do it 'renders the collection as json' do get(:index, params:) - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response.count).to be 2 expect(json_response.pluck('id')).to include subscription.id, subscription2.id end @@ -77,7 +77,7 @@ RSpec.describe Admin::SubscriptionsController, type: :controller do it "restricts the list of subscriptions" do get(:index, params:) - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response.count).to be 1 ids = json_response.pluck('id') expect(ids).to include subscription2.id @@ -135,7 +135,7 @@ RSpec.describe Admin::SubscriptionsController, type: :controller do context 'when I submit insufficient params' do it 'returns errors' do expect{ spree_post :create, params }.not_to change{ Subscription.count } - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response['errors'].keys).to include 'schedule', 'customer', 'payment_method', 'shipping_method', 'begins_at' end @@ -169,7 +169,7 @@ RSpec.describe Admin::SubscriptionsController, type: :controller do it 'returns errors' do expect{ spree_post :create, params }.not_to change{ Subscription.count } - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response['errors'].keys).to include 'schedule', 'customer', 'payment_method', 'shipping_method', 'ends_at' end @@ -198,7 +198,7 @@ RSpec.describe Admin::SubscriptionsController, type: :controller do context 'where the specified variants are not available from the shop' do it 'returns an error' do expect{ spree_post :create, params }.not_to change{ Subscription.count } - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response['errors']['subscription_line_items']) .to eq ["#{variant.product.name} - #{variant.full_name} " \ "is not available from the selected schedule"] @@ -344,7 +344,7 @@ RSpec.describe Admin::SubscriptionsController, type: :controller do it 'returns errors' do expect{ spree_post :update, params }.not_to change{ Subscription.count } - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response['errors'].keys).to include 'payment_method', 'shipping_method' subscription.reload expect(subscription.payment_method).to eq payment_method @@ -388,7 +388,7 @@ RSpec.describe Admin::SubscriptionsController, type: :controller do it 'returns an error' do expect{ spree_post :update, params } .not_to change{ subscription.subscription_line_items.count } - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response['errors']['subscription_line_items']) .to eq ["#{product2.name} - #{variant2.full_name} " \ "is not available from the selected schedule"] @@ -464,7 +464,7 @@ RSpec.describe Admin::SubscriptionsController, type: :controller do it "renders an error, asking what to do" do spree_put :cancel, params expect(response.status).to be 409 - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response['errors']['open_orders']) .to eq 'Some orders for this subscription are currently open. ' \ 'The customer has already been notified that the order will be placed. ' \ @@ -477,7 +477,7 @@ RSpec.describe Admin::SubscriptionsController, type: :controller do it 'renders the cancelled subscription as json, and does not cancel the open order' do spree_put :cancel, params - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response['canceled_at']).not_to be nil expect(json_response['id']).to eq subscription.id expect(subscription.reload.canceled_at).to be_within(5.seconds).of Time.zone.now @@ -497,7 +497,7 @@ RSpec.describe Admin::SubscriptionsController, type: :controller do it 'renders the cancelled subscription as json, and cancels the open order' do spree_put :cancel, params - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response['canceled_at']).not_to be nil expect(json_response['id']).to eq subscription.id expect(subscription.reload.canceled_at).to be_within(5.seconds).of Time.zone.now @@ -511,7 +511,7 @@ RSpec.describe Admin::SubscriptionsController, type: :controller do context "when no associated orders are still 'open'" do it 'renders the cancelled subscription as json' do spree_put :cancel, params - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response['canceled_at']).not_to be nil expect(json_response['id']).to eq subscription.id expect(subscription.reload.canceled_at).to be_within(5.seconds).of Time.zone.now @@ -568,7 +568,7 @@ RSpec.describe Admin::SubscriptionsController, type: :controller do it "renders an error, asking what to do" do spree_put :pause, params expect(response.status).to be 409 - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response['errors']['open_orders']) .to eq 'Some orders for this subscription are currently open. ' \ 'The customer has already been notified that the order will be placed. ' \ @@ -581,7 +581,7 @@ RSpec.describe Admin::SubscriptionsController, type: :controller do it 'renders the paused subscription as json, and does not cancel the open order' do spree_put :pause, params - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response['paused_at']).not_to be nil expect(json_response['id']).to eq subscription.id expect(subscription.reload.paused_at).to be_within(5.seconds).of Time.zone.now @@ -601,7 +601,7 @@ RSpec.describe Admin::SubscriptionsController, type: :controller do it 'renders the paused subscription as json, and cancels the open order' do spree_put :pause, params - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response['paused_at']).not_to be nil expect(json_response['id']).to eq subscription.id expect(subscription.reload.paused_at).to be_within(5.seconds).of Time.zone.now @@ -615,7 +615,7 @@ RSpec.describe Admin::SubscriptionsController, type: :controller do context "when no associated orders are still 'open'" do it 'renders the paused subscription as json' do spree_put :pause, params - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response['paused_at']).not_to be nil expect(json_response['id']).to eq subscription.id expect(subscription.reload.paused_at).to be_within(5.seconds).of Time.zone.now @@ -673,7 +673,7 @@ RSpec.describe Admin::SubscriptionsController, type: :controller do context "when no associated orders are 'canceled'" do it 'renders the unpaused subscription as json, leaves the order untouched' do spree_put :unpause, params - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response['paused_at']).to be nil expect(json_response['id']).to eq subscription.id expect(subscription.reload.paused_at).to be nil @@ -691,7 +691,7 @@ RSpec.describe Admin::SubscriptionsController, type: :controller do it "renders a message, informing the user that canceled order can be resumed" do spree_put :unpause, params expect(response.status).to be 409 - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response['errors']['canceled_orders']) .to eq 'Some orders for this subscription can be resumed right now. ' \ 'You can resume them from the orders dropdown.' @@ -703,7 +703,7 @@ RSpec.describe Admin::SubscriptionsController, type: :controller do it 'renders the unpaused subscription as json, leaves the order untouched' do spree_put :unpause, params - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response['paused_at']).to be nil expect(json_response['id']).to eq subscription.id expect(subscription.reload.paused_at).to be nil @@ -717,7 +717,7 @@ RSpec.describe Admin::SubscriptionsController, type: :controller do context "when no associated orders are 'complete'" do it 'renders the unpaused subscription as json' do spree_put :unpause, params - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response['paused_at']).to be nil expect(json_response['id']).to eq subscription.id expect(subscription.reload.paused_at).to be nil diff --git a/spec/controllers/cart_controller_spec.rb b/spec/controllers/cart_controller_spec.rb index 07ac5c50e5..1d24d2572d 100644 --- a/spec/controllers/cart_controller_spec.rb +++ b/spec/controllers/cart_controller_spec.rb @@ -37,7 +37,7 @@ RSpec.describe CartController, type: :controller do post :populate, xhr: true, params: { use_route: :spree }, as: :json - data = JSON.parse(response.body) + data = response.parsed_body expect(data['stock_levels']).to eq('my_stock_levels') end end @@ -79,7 +79,7 @@ RSpec.describe CartController, type: :controller do it "returns the variant override stock levels of the variant in the order" do spree_post :populate, variants: { variant_in_the_order.id => 1 } - data = JSON.parse(response.body) + data = response.parsed_body expect(data['stock_levels'][variant_in_the_order.id.to_s]["on_hand"]).to eq 20 end @@ -91,7 +91,7 @@ RSpec.describe CartController, type: :controller do # This indicates that the VariantsStockLevels alternative calculation is never reached spree_post :populate, variants: { variant_not_in_the_order.id => 1 } - data = JSON.parse(response.body) + data = response.parsed_body expect(data['stock_levels'][variant_not_in_the_order.id.to_s]["on_hand"]).to eq 7 end end diff --git a/spec/controllers/line_items_controller_spec.rb b/spec/controllers/line_items_controller_spec.rb index 42949bdcc4..30be81e25e 100644 --- a/spec/controllers/line_items_controller_spec.rb +++ b/spec/controllers/line_items_controller_spec.rb @@ -24,7 +24,7 @@ RSpec.describe LineItemsController, type: :controller do it "lists items bought by the user from the same shop in the same order_cycle" do get :bought, format: :json expect(response.status).to eq 200 - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response.length).to eq completed_order.line_items.reload.count expect(json_response[0]['id']).to eq completed_order.line_items.first.id end diff --git a/spec/controllers/spree/admin/search_controller_spec.rb b/spec/controllers/spree/admin/search_controller_spec.rb index a62e38e6b9..e906371ee8 100644 --- a/spec/controllers/spree/admin/search_controller_spec.rb +++ b/spec/controllers/spree/admin/search_controller_spec.rb @@ -41,7 +41,7 @@ RSpec.describe Spree::Admin::SearchController, type: :controller do describe 'when search owned enterprises' do before do spree_get :customers, q: "test", distributor_id: enterprise.id - @results = JSON.parse(response.body) + @results = response.parsed_body end describe 'when search query matches the email or name' do @@ -63,7 +63,7 @@ RSpec.describe Spree::Admin::SearchController, type: :controller do describe 'when search in unmanaged enterprise' do before do spree_get :customers, q: "test", distributor_id: customer_3.enterprise_id - @results = JSON.parse(response.body) + @results = response.parsed_body end it 'returns empty array' do diff --git a/spec/controllers/spree/credit_cards_controller_spec.rb b/spec/controllers/spree/credit_cards_controller_spec.rb index f84fd0f7d5..943c222908 100644 --- a/spec/controllers/spree/credit_cards_controller_spec.rb +++ b/spec/controllers/spree/credit_cards_controller_spec.rb @@ -93,7 +93,7 @@ RSpec.describe Spree::CreditCardsController, type: :controller do it "doesn't save the card locally, and renders a flash error" do expect{ spree_post :new_from_token, params }.not_to change { Spree::CreditCard.count } - json_response = JSON.parse(response.body) + json_response = response.parsed_body flash_message = "There was a problem with your payment information: %s" % 'Bup-bow...' expect(json_response["flash"]["error"]).to eq flash_message end @@ -107,7 +107,7 @@ RSpec.describe Spree::CreditCardsController, type: :controller do it "renders a flash error" do spree_put :update, params - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response['flash']['error']).to eq 'Card could not be updated' end end @@ -129,7 +129,7 @@ RSpec.describe Spree::CreditCardsController, type: :controller do context "when the update completes successfully" do it "renders a serialized copy of the updated card" do expect{ spree_put :update, params }.to change { card.reload.is_default }.to(true) - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response['id']).to eq card.id expect(json_response['is_default']).to eq true end @@ -139,7 +139,7 @@ RSpec.describe Spree::CreditCardsController, type: :controller do before { params[:credit_card][:month] = 'some illegal month' } it "renders an error" do spree_put :update, params - json_response = JSON.parse(response.body) + json_response = response.parsed_body expect(json_response['flash']['error']).to eq 'Card could not be updated' end end diff --git a/spec/controllers/user_registrations_controller_spec.rb b/spec/controllers/user_registrations_controller_spec.rb index da2c29cc45..cc46a7e425 100644 --- a/spec/controllers/user_registrations_controller_spec.rb +++ b/spec/controllers/user_registrations_controller_spec.rb @@ -7,7 +7,7 @@ RSpec.describe UserRegistrationsController, type: :controller do @request.env["devise.mapping"] = Devise.mappings[:spree_user] end - describe "via ajax" do + describe "create" do render_views let(:user_params) do @@ -19,9 +19,9 @@ RSpec.describe UserRegistrationsController, type: :controller do end it "returns validation errors" do - post :create, xhr: true, params: { spree_user: {}, use_route: :spree } + post :create, params: { spree_user: {}, use_route: :spree }, as: :json expect(response.status).to eq(401) - json = JSON.parse(response.body) + json = response.parsed_body expect(json).to eq("email" => ["can't be blank"], "password" => ["can't be blank"]) end @@ -29,10 +29,10 @@ RSpec.describe UserRegistrationsController, type: :controller do allow(Spree::UserMailer).to receive(:confirmation_instructions).and_raise("Some error") expect(Alert).to receive(:raise) - post :create, xhr: true, params: { spree_user: user_params, use_route: :spree } + post :create, params: { spree_user: user_params, use_route: :spree }, as: :json expect(response.status).to eq(401) - json = JSON.parse(response.body) + json = response.parsed_body expect(json).to eq( "message" => 'Something went wrong while creating your account. Check your email address and try again.' @@ -40,16 +40,16 @@ RSpec.describe UserRegistrationsController, type: :controller do end it "returns 200 when registration succeeds" do - post :create, xhr: true, params: { spree_user: user_params, use_route: :spree } + post :create, params: { spree_user: user_params, use_route: :spree }, as: :json expect(response.status).to eq(200) - json = JSON.parse(response.body) + json = response.parsed_body expect(json).to eq("email" => "test@test.com") expect(controller.spree_current_user).to be_nil end it "sets user.locale from cookie on create" do cookies[:locale] = "pt" - post :create, xhr: true, params: { spree_user: user_params, use_route: :spree } + post :create, params: { spree_user: user_params, use_route: :spree }, as: :json expect(assigns[:user].locale).to eq("pt") end end