Skip to content

Commit

Permalink
Merge pull request solidusio#40 from solidusio/token_with_payment_met…
Browse files Browse the repository at this point in the history
…hod_id

Support tokens without specifying payment_method
  • Loading branch information
cbrunsdon authored Oct 27, 2016
2 parents 5245c73 + df3c377 commit 3328d70
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ def create
private

def load_gateway
@gateway = ::SolidusPaypalBraintree::Gateway.
where(active: true).
find(params[:payment_method_id])
if params[:payment_method_id]
@gateway = ::SolidusPaypalBraintree::Gateway.find_by!(id: params[:payment_method_id])
else
@gateway = ::SolidusPaypalBraintree::Gateway.find_by!(active: true)
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,32 @@

before { user.generate_spree_api_key! }

subject(:response) do
post :create, payment_method_id: gateway.id, token: user.spree_api_key
end
context 'with a payment method id' do
subject(:response) do
post :create, token: user.spree_api_key
end

it "returns a client token", aggregate_failures: true do
expect(response).to have_http_status(:success)
expect(response.content_type).to eq "application/json"
expect(json["client_token"]).to be_present
expect(json["client_token"]).to be_a String
expect(json["payment_method_id"]).to eq gateway.id
end

context 'with a payment method id' do
before do
create_gateway id: 3
end

subject(:response) do
post :create, token: user.spree_api_key, payment_method_id: 3
end

it "returns a client token", aggregate_failures: true do
expect(response).to have_http_status(:success)
expect(response.content_type).to eq "application/json"
expect(json["client_token"]).to be_present
expect(json["client_token"]).to be_a String
expect(json["payment_method_id"]).to eq gateway.id
it 'uses the selected gateway' do
expect(json["payment_method_id"]).to eq 3
end
end
end
end
end

0 comments on commit 3328d70

Please sign in to comment.