solidus_api 1.0.6 → 1.0.7
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of solidus_api might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/app/controllers/spree/api/orders_controller.rb +14 -11
- data/app/controllers/spree/api/payments_controller.rb +1 -0
- data/spec/controllers/spree/api/checkouts_controller_spec.rb +13 -0
- data/spec/controllers/spree/api/orders_controller_spec.rb +83 -73
- data/spec/controllers/spree/api/payments_controller_spec.rb +11 -0
- data/spec/spec_helper.rb +1 -0
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c108e552ec6ec720a0b101802d36eaf5d9aa4761
|
4
|
+
data.tar.gz: e376f6d8e98c28a0f193b012a3f9e62476adb5d4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3deada5b7463920279f00169107d3afd9279ab8f019928b7a109731f803b515327b4486e73d84e4e7d53746999741bb8e4a48328b1aaf019fa239c6f4feb7b87
|
7
|
+
data.tar.gz: 3907075dabb2ed39ce27230ddea643aa16a8c40b48252b4d545f7d8df9f75b08dcaadf54e7ab2e48a5d85e7fa645ab9d70872e5c944ad3e51b98e65e67b0a7da
|
@@ -28,20 +28,23 @@ module Spree
|
|
28
28
|
def create
|
29
29
|
authorize! :create, Order
|
30
30
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
31
|
+
if can?(:admin, Order)
|
32
|
+
order_user = if order_params[:user_id]
|
33
|
+
Spree.user_class.find(order_params[:user_id])
|
34
|
+
else
|
35
|
+
current_api_user
|
36
|
+
end
|
36
37
|
|
37
|
-
|
38
|
-
|
38
|
+
@order = Spree::Core::Importer::Order.import(order_user, order_params)
|
39
|
+
respond_with(@order, default_template: :show, status: 201)
|
39
40
|
else
|
40
|
-
|
41
|
+
@order = Spree::Order.create!(user: current_api_user, store: current_store)
|
42
|
+
if @order.contents.update_cart(order_params)
|
43
|
+
respond_with(@order, default_template: :show, status: 201)
|
44
|
+
else
|
45
|
+
invalid_resource!(@order)
|
46
|
+
end
|
41
47
|
end
|
42
|
-
|
43
|
-
@order = Spree::Core::Importer::Order.import(order_user, import_params)
|
44
|
-
respond_with(@order, default_template: :show, status: 201)
|
45
48
|
end
|
46
49
|
|
47
50
|
def empty
|
@@ -164,6 +164,19 @@ module Spree
|
|
164
164
|
expect(response.status).to eq(200)
|
165
165
|
end
|
166
166
|
|
167
|
+
context "with disallowed payment method" do
|
168
|
+
it "returns not found" do
|
169
|
+
order.update_column(:state, "payment")
|
170
|
+
allow_any_instance_of(Spree::Gateway::Bogus).to receive(:source_required?).and_return(false)
|
171
|
+
@payment_method.update!(display_on: "back_end")
|
172
|
+
expect {
|
173
|
+
api_put :update, id: order.to_param, order_token: order.guest_token, order: { payments_attributes: [{ payment_method_id: @payment_method.id }] }
|
174
|
+
}.not_to change { Spree::Payment.count }
|
175
|
+
expect(response.status).to eq(404)
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
|
167
180
|
it "returns errors when source is required and missing" do
|
168
181
|
order.update_column(:state, "payment")
|
169
182
|
api_put :update, :id => order.to_param, :order_token => order.guest_token,
|
@@ -29,49 +29,49 @@ module Spree
|
|
29
29
|
|
30
30
|
describe "POST create" do
|
31
31
|
let(:target_user) { create :user }
|
32
|
-
let(:date_override) {
|
32
|
+
let(:date_override) { Time.parse('2015-01-01') }
|
33
|
+
let(:attributes) { { user_id: target_user.id, created_at: date_override, email: target_user.email } }
|
33
34
|
|
34
|
-
|
35
|
-
allow_any_instance_of(Spree::Ability).to receive(:can?).
|
36
|
-
and_return(true)
|
37
|
-
|
38
|
-
allow_any_instance_of(Spree::Ability).to receive(:can?).
|
39
|
-
with(:admin, Spree::Order).
|
40
|
-
and_return(can_admin)
|
41
|
-
|
42
|
-
allow(Spree.user_class).to receive(:find).
|
43
|
-
with(target_user.id).
|
44
|
-
and_return(target_user)
|
45
|
-
end
|
46
|
-
|
47
|
-
subject { api_post :create, order: { user_id: target_user.id, created_at: date_override, email: target_user.email } }
|
35
|
+
subject { api_post :create, order: attributes }
|
48
36
|
|
49
37
|
context "when the current user cannot administrate the order" do
|
50
|
-
|
38
|
+
stub_authorization! do |_|
|
39
|
+
can :create, Spree::Order
|
40
|
+
end
|
51
41
|
|
52
42
|
it "does not include unpermitted params, or allow overriding the user", focus: true do
|
53
|
-
expect(Spree::Core::Importer::Order).to receive(:import).
|
54
|
-
once.
|
55
|
-
with(current_api_user, { "email" => target_user.email }).
|
56
|
-
and_call_original
|
57
43
|
subject
|
44
|
+
expect(response).to be_success
|
45
|
+
order = Spree::Order.last
|
46
|
+
expect(order.user).to eq current_api_user
|
47
|
+
expect(order.email).to eq target_user.email
|
58
48
|
end
|
59
49
|
|
60
50
|
it { is_expected.to be_success }
|
61
|
-
end
|
62
51
|
|
63
|
-
|
64
|
-
|
52
|
+
context 'creating payment' do
|
53
|
+
let(:attributes) { super().merge(payments_attributes: [{ payment_method_id: payment_method.id }]) }
|
65
54
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
55
|
+
context "with allowed payment method" do
|
56
|
+
let!(:payment_method) { create(:check_payment_method, name: "allowed" ) }
|
57
|
+
it { is_expected.to be_success }
|
58
|
+
it "creates a payment" do
|
59
|
+
expect {
|
60
|
+
subject
|
61
|
+
}.to change { Spree::Payment.count }.by(1)
|
62
|
+
end
|
63
|
+
end
|
73
64
|
|
74
|
-
|
65
|
+
context "with disallowed payment method" do
|
66
|
+
let!(:payment_method) { create(:check_payment_method, name: "forbidden", display_on: "back_end") }
|
67
|
+
it { is_expected.to be_not_found }
|
68
|
+
it "creates no payments" do
|
69
|
+
expect {
|
70
|
+
subject
|
71
|
+
}.not_to change { Spree::Payment.count }
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
75
|
end
|
76
76
|
end
|
77
77
|
|
@@ -81,41 +81,65 @@ module Spree
|
|
81
81
|
let(:can_admin) { false }
|
82
82
|
subject { api_put :update, id: order.to_param, order: order_params }
|
83
83
|
|
84
|
-
|
85
|
-
|
86
|
-
|
84
|
+
context "when the user cannot administer the order" do
|
85
|
+
stub_authorization! do |_|
|
86
|
+
can [:update], Spree::Order
|
87
|
+
end
|
87
88
|
|
88
|
-
|
89
|
-
|
90
|
-
|
89
|
+
it "updates the user's email" do
|
90
|
+
expect {
|
91
|
+
subject
|
92
|
+
}.to change { order.reload.email }.to("foo@foobar.com")
|
93
|
+
end
|
91
94
|
|
92
|
-
|
93
|
-
with(user.id).
|
94
|
-
and_return(user)
|
95
|
+
it { is_expected.to be_success }
|
95
96
|
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
97
|
+
it "does not associate users" do
|
98
|
+
expect {
|
99
|
+
subject
|
100
|
+
}.not_to change { order.reload.user }
|
101
|
+
end
|
100
102
|
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
103
|
+
it "does not change forbidden attributes" do
|
104
|
+
expect {
|
105
|
+
subject
|
106
|
+
}.to_not change{ order.reload.number }
|
107
|
+
end
|
108
|
+
|
109
|
+
context 'creating payment' do
|
110
|
+
let(:order_params) { super().merge(payments_attributes: [{ payment_method_id: payment_method.id }]) }
|
111
|
+
|
112
|
+
context "with allowed payment method" do
|
113
|
+
let!(:payment_method) { create(:check_payment_method, name: "allowed" ) }
|
114
|
+
it { is_expected.to be_success }
|
115
|
+
it "creates a payment" do
|
116
|
+
expect {
|
117
|
+
subject
|
118
|
+
}.to change { Spree::Payment.count }.by(1)
|
119
|
+
end
|
120
|
+
end
|
107
121
|
|
108
|
-
|
122
|
+
context "with disallowed payment method" do
|
123
|
+
let!(:payment_method) { create(:check_payment_method, name: "forbidden", display_on: "back_end") }
|
124
|
+
it { is_expected.to be_not_found }
|
125
|
+
it "creates no payments" do
|
126
|
+
expect {
|
127
|
+
subject
|
128
|
+
}.not_to change { Spree::Payment.count }
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
109
133
|
|
110
134
|
context "when the user can administer the order" do
|
111
|
-
|
135
|
+
stub_authorization! do |_|
|
136
|
+
can [:admin, :update], Spree::Order
|
137
|
+
end
|
112
138
|
|
113
139
|
it "will associate users" do
|
114
|
-
expect
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
subject
|
140
|
+
expect {
|
141
|
+
subject
|
142
|
+
}.to change { order.reload.user }.to(user)
|
119
143
|
end
|
120
144
|
|
121
145
|
it "updates the otherwise forbidden attributes" do
|
@@ -123,17 +147,6 @@ module Spree
|
|
123
147
|
to("anothernumber")
|
124
148
|
end
|
125
149
|
end
|
126
|
-
|
127
|
-
context "when the user cannot administer the order" do
|
128
|
-
it "does not associate users" do
|
129
|
-
expect(order).to_not receive(:associate_user!)
|
130
|
-
subject
|
131
|
-
end
|
132
|
-
|
133
|
-
it "does not change forbidden attributes" do
|
134
|
-
expect{subject}.to_not change{order.reload.number}
|
135
|
-
end
|
136
|
-
end
|
137
150
|
end
|
138
151
|
|
139
152
|
it "cannot view all orders" do
|
@@ -355,16 +368,13 @@ module Spree
|
|
355
368
|
|
356
369
|
# Regression test for #3404
|
357
370
|
it "can specify additional parameters for a line item" do
|
358
|
-
|
359
|
-
allow(order).to receive(:associate_user!)
|
360
|
-
allow(order).to receive_message_chain(:contents, :add).and_return(line_item = double('LineItem'))
|
361
|
-
expect(line_item).to receive(:update_attributes!).with("special" => true)
|
371
|
+
expect_any_instance_of(Spree::LineItem).to receive(:special=).with("foo")
|
362
372
|
|
363
373
|
allow(controller).to receive_messages(permitted_line_item_attributes: [:id, :variant_id, :quantity, :special])
|
364
374
|
api_post :create, :order => {
|
365
375
|
:line_items => {
|
366
376
|
"0" => {
|
367
|
-
:
|
377
|
+
variant_id: variant.to_param, quantity: 5, special: "foo"
|
368
378
|
}
|
369
379
|
}
|
370
380
|
}
|
@@ -43,6 +43,17 @@ module Spree
|
|
43
43
|
expect(response.status).to eq(201)
|
44
44
|
expect(json_response).to have_attributes(attributes)
|
45
45
|
end
|
46
|
+
|
47
|
+
context "disallowed payment method" do
|
48
|
+
it "does not create a new payment" do
|
49
|
+
PaymentMethod.first.update!(display_on: "back_end")
|
50
|
+
|
51
|
+
expect {
|
52
|
+
api_post :create, payment: { payment_method_id: PaymentMethod.first.id, amount: 50 }
|
53
|
+
}.not_to change { Spree::Payment.count }
|
54
|
+
expect(response.status).to eq(404)
|
55
|
+
end
|
56
|
+
end
|
46
57
|
end
|
47
58
|
|
48
59
|
context "payment source is required" do
|
data/spec/spec_helper.rb
CHANGED
@@ -31,6 +31,7 @@ Dir[File.dirname(__FILE__) + "/support/**/*.rb"].each {|f| require f}
|
|
31
31
|
require 'spree/testing_support/factories'
|
32
32
|
require 'spree/testing_support/preferences'
|
33
33
|
require 'spree/testing_support/mail'
|
34
|
+
require 'spree/testing_support/authorization_helpers'
|
34
35
|
|
35
36
|
require 'spree/api/testing_support/caching'
|
36
37
|
require 'spree/api/testing_support/helpers'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: solidus_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Solidus Team
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-12-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: solidus_core
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - '='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 1.0.
|
19
|
+
version: 1.0.7
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - '='
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 1.0.
|
26
|
+
version: 1.0.7
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rabl
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -278,7 +278,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
278
278
|
version: '0'
|
279
279
|
requirements: []
|
280
280
|
rubyforge_project:
|
281
|
-
rubygems_version: 2.
|
281
|
+
rubygems_version: 2.6.11
|
282
282
|
signing_key:
|
283
283
|
specification_version: 4
|
284
284
|
summary: REST API for the Solidus e-commerce framework.
|