Run transpec and clean up rubocop issues in credit_card_controller and spec

This commit is contained in:
luisramos0
2018-11-15 11:03:40 +00:00
parent a234308a06
commit 9ba0fc268e
3 changed files with 18 additions and 21 deletions

View File

@@ -1453,7 +1453,6 @@ Rails/HttpStatus:
- 'app/controllers/shop_controller.rb'
- 'app/controllers/spree/admin/line_items_controller_decorator.rb'
- 'app/controllers/spree/admin/products_controller_decorator.rb'
- 'app/controllers/spree/credit_cards_controller.rb'
- 'app/controllers/spree/store_controller_decorator.rb'
- 'app/controllers/stripe/callbacks_controller.rb'
- 'app/controllers/stripe/webhooks_controller.rb'
@@ -1988,7 +1987,6 @@ Style/HashSyntax:
- 'spec/controllers/spree/admin/payments_controller_spec.rb'
- 'spec/controllers/spree/api/products_controller_spec.rb'
- 'spec/controllers/spree/api/variants_controller_spec.rb'
- 'spec/controllers/spree/credit_cards_controller_spec.rb'
- 'spec/controllers/spree/user_sessions_controller_spec.rb'
- 'spec/controllers/user_registrations_controller_spec.rb'
- 'spec/features/admin/bulk_order_management_spec.rb'
@@ -2268,7 +2266,6 @@ Style/RedundantReturn:
Exclude:
- 'app/controllers/admin/enterprise_fees_controller.rb'
- 'app/controllers/admin/enterprises_controller.rb'
- 'app/controllers/spree/credit_cards_controller.rb'
- 'app/models/enterprise_fee.rb'
- 'app/models/spree/adjustment_decorator.rb'
- 'app/models/spree/classification_decorator.rb'

View File

@@ -10,10 +10,10 @@ module Spree
render json: @credit_card, serializer: ::Api::CreditCardSerializer, status: :ok
else
message = t(:card_could_not_be_saved)
render json: { flash: { error: I18n.t(:spree_gateway_error_flash_for_checkout, error: message) } }, status: 400
render json: { flash: { error: I18n.t(:spree_gateway_error_flash_for_checkout, error: message) } }, status: :bad_request
end
rescue Stripe::CardError => e
return render json: { flash: { error: I18n.t(:spree_gateway_error_flash_for_checkout, error: e.message) } }, status: 400
render json: { flash: { error: I18n.t(:spree_gateway_error_flash_for_checkout, error: e.message) } }, status: :bad_request
end
def update
@@ -26,8 +26,8 @@ module Spree
else
update_failed
end
rescue ArgumentError => e
update_failed
rescue ArgumentError
update_failed
end
def destroy
@@ -81,7 +81,7 @@ module Spree
end
def update_failed
render json: { flash: { error: t(:card_could_not_be_updated) } }, status: 400
render json: { flash: { error: t(:card_could_not_be_updated) } }, status: :bad_request
end
end
end

View File

@@ -15,17 +15,17 @@ describe Spree::CreditCardsController, type: :controller do
let(:params) do
{
format: :json,
"exp_month" => 12,
"exp_year" => 2020,
"last4" => 4242,
"token" => token,
"cc_type" => "visa"
exp_month: 12,
exp_year: 2020,
last4: 4242,
token: token,
cc_type: "visa"
}
end
before do
stub_request(:post, "https://api.stripe.com/v1/customers")
.with(:body => { email: user.email, source: token })
.with(body: { email: user.email, source: token })
.to_return(response_mock)
end
@@ -36,10 +36,10 @@ describe Spree::CreditCardsController, type: :controller do
expect{ post :new_from_token, params }.to change(Spree::CreditCard, :count).by(1)
card = Spree::CreditCard.last
card.gateway_payment_profile_id.should eq "card_1AEEb"
card.gateway_customer_profile_id.should eq "cus_AZNMJ"
card.user_id.should eq user.id
card.last_digits.should eq "4242"
expect(card.gateway_payment_profile_id).to eq "card_1AEEb"
expect(card.gateway_customer_profile_id).to eq "cus_AZNMJ"
expect(card.user_id).to eq user.id
expect(card.last_digits).to eq "4242"
end
context "when saving the card locally fails" do
@@ -144,13 +144,13 @@ describe Spree::CreditCardsController, type: :controller do
card.update_attribute(:user_id, user.id)
stub_request(:get, "https://api.stripe.com/v1/customers/cus_AZNMJ").
to_return(:status => 200, :body => JSON.generate(id: "cus_AZNMJ"))
to_return(status: 200, body: JSON.generate(id: "cus_AZNMJ"))
end
context "where the request to destroy the Stripe customer fails" do
before do
stub_request(:delete, "https://api.stripe.com/v1/customers/cus_AZNMJ").
to_return(:status => 402, :body => JSON.generate(error: { message: 'Bup-bow!' }))
to_return(status: 402, body: JSON.generate(error: { message: 'Bup-bow!' }))
end
it "doesn't delete the card" do
@@ -163,7 +163,7 @@ describe Spree::CreditCardsController, type: :controller do
context "where the request to destroy the Stripe customer succeeds" do
before do
stub_request(:delete, "https://api.stripe.com/v1/customers/cus_AZNMJ").
to_return(:status => 200, :body => JSON.generate(deleted: true, id: "cus_AZNMJ"))
to_return(status: 200, body: JSON.generate(deleted: true, id: "cus_AZNMJ"))
end
it "deletes the card and redirects to account_path" do