mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-12 23:27:48 +00:00
12620 - fix Rails/ResponseParsedBody
This commit is contained in:
@@ -625,26 +625,6 @@ Rails/LexicallyScopedActionFilter:
|
||||
- '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: 1
|
||||
# This cop supports unsafe autocorrection (--autocorrect-all).
|
||||
Rails/RootPathnameMethods:
|
||||
|
||||
@@ -263,7 +263,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
|
||||
|
||||
@@ -166,7 +166,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
|
||||
@@ -247,7 +247,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
|
||||
|
||||
|
||||
@@ -182,7 +182,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
|
||||
@@ -193,7 +193,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
|
||||
@@ -269,7 +269,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
|
||||
@@ -377,7 +377,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
|
||||
@@ -394,7 +394,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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -98,8 +98,10 @@ 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"
|
||||
|
||||
response_body = response.parsed_body
|
||||
expect(response_body["id"]).to eq coordinated_schedule.id
|
||||
expect(response_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 +260,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'
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -96,7 +96,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
|
||||
@@ -110,7 +110,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
|
||||
@@ -132,7 +132,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
|
||||
@@ -142,7 +142,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
|
||||
|
||||
@@ -21,7 +21,7 @@ RSpec.describe UserRegistrationsController, type: :controller do
|
||||
it "returns validation errors" do
|
||||
post :create, xhr: true, params: { spree_user: {}, use_route: :spree }
|
||||
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
|
||||
|
||||
@@ -32,7 +32,7 @@ RSpec.describe UserRegistrationsController, type: :controller do
|
||||
post :create, xhr: true, params: { spree_user: user_params, use_route: :spree }
|
||||
|
||||
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.'
|
||||
@@ -42,7 +42,7 @@ RSpec.describe UserRegistrationsController, type: :controller do
|
||||
it "returns 200 when registration succeeds" do
|
||||
post :create, xhr: true, params: { spree_user: user_params, use_route: :spree }
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user