solidus_api 1.2.2 → 1.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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 +13 -2
- 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 +93 -67
- 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: 393d0d36bfd016ad4bd491a6e5e7f809a3bd8d33
|
4
|
+
data.tar.gz: 075176b4df3486e9c0da4b27da75e987b26a8b1f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1e1fe525cdf4e7fa9f8f4f6430f79e7c3688ce94e525f3cc5a312836908b8889014a9f5e9d6082f4cb776b16a59f07e4d7f67435944f2878a08394119c044f73
|
7
|
+
data.tar.gz: b98daeb6709274fd64bef47c3b69c3251d5d91d84dff7bb973e53476d6e4c9a279ae13a58e1cccaa6cf8bf1a1edf231209ec37410653e4c03af493ea9cc94cb8
|
@@ -27,8 +27,19 @@ module Spree
|
|
27
27
|
|
28
28
|
def create
|
29
29
|
authorize! :create, Order
|
30
|
-
|
31
|
-
|
30
|
+
|
31
|
+
if can?(:admin, Order)
|
32
|
+
@order = Spree::Core::Importer::Order.import(determine_order_user, order_params)
|
33
|
+
respond_with(@order, default_template: :show, status: 201)
|
34
|
+
else
|
35
|
+
@order = Spree::Order.create!(user: current_api_user, store: current_store)
|
36
|
+
if OrderUpdateAttributes.new(@order, order_params).apply
|
37
|
+
@order.update!
|
38
|
+
respond_with(@order, default_template: :show, status: 201)
|
39
|
+
else
|
40
|
+
invalid_resource!(@order)
|
41
|
+
end
|
42
|
+
end
|
32
43
|
end
|
33
44
|
|
34
45
|
def empty
|
@@ -163,6 +163,19 @@ module Spree
|
|
163
163
|
expect(response.status).to eq(200)
|
164
164
|
end
|
165
165
|
|
166
|
+
context "with disallowed payment method" do
|
167
|
+
it "returns not found" do
|
168
|
+
order.update_column(:state, "payment")
|
169
|
+
allow_any_instance_of(Spree::Gateway::Bogus).to receive(:source_required?).and_return(false)
|
170
|
+
@payment_method.update!(display_on: "back_end")
|
171
|
+
expect {
|
172
|
+
api_put :update, id: order.to_param, order_token: order.guest_token, order: { payments_attributes: [{ payment_method_id: @payment_method.id }] }
|
173
|
+
}.not_to change { Spree::Payment.count }
|
174
|
+
expect(response.status).to eq(404)
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
|
166
179
|
it "returns errors when source is required and missing" do
|
167
180
|
order.update_column(:state, "payment")
|
168
181
|
api_put :update, :id => order.to_param, :order_token => order.guest_token,
|
@@ -29,46 +29,62 @@ 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 }
|
51
|
+
|
52
|
+
context 'creating payment' do
|
53
|
+
let(:attributes) { super().merge(payments_attributes: [{ payment_method_id: payment_method.id }]) }
|
54
|
+
|
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
|
64
|
+
|
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
|
61
75
|
end
|
62
76
|
|
63
77
|
context "when the current user can administrate the order" do
|
64
|
-
|
78
|
+
stub_authorization! do |_|
|
79
|
+
can [:admin, :create], Spree::Order
|
80
|
+
end
|
65
81
|
|
66
82
|
it "it permits all params and allows overriding the user" do
|
67
|
-
expect(Spree::Core::Importer::Order).to receive(:import).
|
68
|
-
once.
|
69
|
-
with(target_user, { "user_id" => target_user.id, "created_at" => date_override, "email" => target_user.email}).
|
70
|
-
and_call_original
|
71
83
|
subject
|
84
|
+
order = Spree::Order.last
|
85
|
+
expect(order.user).to eq target_user
|
86
|
+
expect(order.email).to eq target_user.email
|
87
|
+
expect(order.created_at).to eq date_override
|
72
88
|
end
|
73
89
|
|
74
90
|
it { is_expected.to be_success }
|
@@ -81,41 +97,65 @@ module Spree
|
|
81
97
|
let(:can_admin) { false }
|
82
98
|
subject { api_put :update, id: order.to_param, order: order_params }
|
83
99
|
|
84
|
-
|
85
|
-
|
86
|
-
|
100
|
+
context "when the user cannot administer the order" do
|
101
|
+
stub_authorization! do |_|
|
102
|
+
can [:update], Spree::Order
|
103
|
+
end
|
87
104
|
|
88
|
-
|
89
|
-
|
90
|
-
|
105
|
+
it "updates the user's email" do
|
106
|
+
expect {
|
107
|
+
subject
|
108
|
+
}.to change { order.reload.email }.to("foo@foobar.com")
|
109
|
+
end
|
91
110
|
|
92
|
-
|
93
|
-
with(user.id).
|
94
|
-
and_return(user)
|
111
|
+
it { is_expected.to be_success }
|
95
112
|
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
113
|
+
it "does not associate users" do
|
114
|
+
expect {
|
115
|
+
subject
|
116
|
+
}.not_to change { order.reload.user }
|
117
|
+
end
|
100
118
|
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
119
|
+
it "does not change forbidden attributes" do
|
120
|
+
expect {
|
121
|
+
subject
|
122
|
+
}.to_not change{ order.reload.number }
|
123
|
+
end
|
124
|
+
|
125
|
+
context 'creating payment' do
|
126
|
+
let(:order_params) { super().merge(payments_attributes: [{ payment_method_id: payment_method.id }]) }
|
127
|
+
|
128
|
+
context "with allowed payment method" do
|
129
|
+
let!(:payment_method) { create(:check_payment_method, name: "allowed" ) }
|
130
|
+
it { is_expected.to be_success }
|
131
|
+
it "creates a payment" do
|
132
|
+
expect {
|
133
|
+
subject
|
134
|
+
}.to change { Spree::Payment.count }.by(1)
|
135
|
+
end
|
136
|
+
end
|
107
137
|
|
108
|
-
|
138
|
+
context "with disallowed payment method" do
|
139
|
+
let!(:payment_method) { create(:check_payment_method, name: "forbidden", display_on: "back_end") }
|
140
|
+
it { is_expected.to be_not_found }
|
141
|
+
it "creates no payments" do
|
142
|
+
expect {
|
143
|
+
subject
|
144
|
+
}.not_to change { Spree::Payment.count }
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
109
149
|
|
110
150
|
context "when the user can administer the order" do
|
111
|
-
|
151
|
+
stub_authorization! do |_|
|
152
|
+
can [:admin, :update], Spree::Order
|
153
|
+
end
|
112
154
|
|
113
155
|
it "will associate users" do
|
114
|
-
expect
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
subject
|
156
|
+
expect {
|
157
|
+
subject
|
158
|
+
}.to change { order.reload.user }.to(user)
|
119
159
|
end
|
120
160
|
|
121
161
|
it "updates the otherwise forbidden attributes" do
|
@@ -123,17 +163,6 @@ module Spree
|
|
123
163
|
to("anothernumber")
|
124
164
|
end
|
125
165
|
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
166
|
end
|
138
167
|
|
139
168
|
it "cannot view all orders" do
|
@@ -352,16 +381,13 @@ module Spree
|
|
352
381
|
|
353
382
|
# Regression test for https://github.com/spree/spree/issues/3404
|
354
383
|
it "can specify additional parameters for a line item" do
|
355
|
-
|
356
|
-
allow(order).to receive(:associate_user!)
|
357
|
-
allow(order).to receive_message_chain(:contents, :add).and_return(line_item = double('LineItem'))
|
358
|
-
expect(line_item).to receive(:update_attributes!).with("special" => true)
|
384
|
+
expect_any_instance_of(Spree::LineItem).to receive(:special=).with("foo")
|
359
385
|
|
360
386
|
allow(controller).to receive_messages(permitted_line_item_attributes: [:id, :variant_id, :quantity, :special])
|
361
387
|
api_post :create, :order => {
|
362
388
|
:line_items => {
|
363
389
|
"0" => {
|
364
|
-
:
|
390
|
+
variant_id: variant.to_param, quantity: 5, special: "foo"
|
365
391
|
}
|
366
392
|
}
|
367
393
|
}
|
@@ -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
@@ -30,6 +30,7 @@ Dir[File.dirname(__FILE__) + "/support/**/*.rb"].each {|f| require f}
|
|
30
30
|
|
31
31
|
require 'spree/testing_support/factories'
|
32
32
|
require 'spree/testing_support/preferences'
|
33
|
+
require 'spree/testing_support/authorization_helpers'
|
33
34
|
|
34
35
|
require 'spree/api/testing_support/caching'
|
35
36
|
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.2.
|
4
|
+
version: 1.2.3
|
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.2.
|
19
|
+
version: 1.2.3
|
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.2.
|
26
|
+
version: 1.2.3
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rabl
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -284,7 +284,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
284
284
|
version: '0'
|
285
285
|
requirements: []
|
286
286
|
rubyforge_project:
|
287
|
-
rubygems_version: 2.
|
287
|
+
rubygems_version: 2.6.11
|
288
288
|
signing_key:
|
289
289
|
specification_version: 4
|
290
290
|
summary: REST API for the Solidus e-commerce framework.
|