Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix rubocop Rails/ResponseParseBody #13112

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 5 additions & 29 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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'
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/admin/bulk_line_items_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@

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
Expand Down
4 changes: 2 additions & 2 deletions spec/controllers/admin/customers_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ module Admin
it "allows me to update the customer" do
spree_put :update, format: :json, id: customer.id,
customer: { email: '[email protected]' }
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 '[email protected]'
end
Expand Down Expand Up @@ -243,7 +243,7 @@ def create_customer(enterprise)

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

Expand Down
10 changes: 5 additions & 5 deletions spec/controllers/admin/order_cycles_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def build_resource

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
Expand All @@ -196,7 +196,7 @@ def build_resource

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
Expand Down Expand Up @@ -271,7 +271,7 @@ def build_resource
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
Expand Down Expand Up @@ -384,7 +384,7 @@ def build_resource
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
Expand All @@ -401,7 +401,7 @@ def build_resource

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
Expand Down
8 changes: 4 additions & 4 deletions spec/controllers/admin/proxy_orders_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
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
Expand All @@ -57,7 +57,7 @@

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
Expand Down Expand Up @@ -116,7 +116,7 @@
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
Expand All @@ -128,7 +128,7 @@

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
Expand Down
6 changes: 3 additions & 3 deletions spec/controllers/admin/schedules_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@
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
Expand Down Expand Up @@ -258,7 +258,7 @@ def create_schedule(params)

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'
Expand Down
6 changes: 3 additions & 3 deletions spec/controllers/admin/stripe_accounts_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
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
Expand All @@ -128,7 +128,7 @@
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
Expand Down Expand Up @@ -171,7 +171,7 @@
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
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

Expand All @@ -47,7 +47,7 @@

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

Expand All @@ -59,7 +59,7 @@

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
Expand All @@ -74,7 +74,7 @@
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"
Expand All @@ -87,7 +87,7 @@
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"
Expand All @@ -102,7 +102,7 @@
"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"
Expand All @@ -118,7 +118,7 @@
"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"
Expand Down
Loading
Loading