solidus_api 2.0.2 → 2.0.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6e09e5243261387fe313f353024f268327a5db42
4
- data.tar.gz: 9b90f3f2a3d9970b02fc535b780f74e3b6ec8a5c
3
+ metadata.gz: 78fbd4104f28d1ed8a435048a2ee5eb5028447e7
4
+ data.tar.gz: 75f60c3749c6be95085b9a9c0f97c46329cb6067
5
5
  SHA512:
6
- metadata.gz: bbf42a1e599ef926b89e5fd6fdcd6426b827f04558e58d9e004948d78fd01dfe6ad480cda2eaedb49df4a50284193de0682a8a9b51c2e93cc371eb8f60511bd4
7
- data.tar.gz: 4c9e17cdd43d161b84b95215402c9e1be146e5eace063b0c7632a977cb23cebbf3632821f7cc11283be95fa688132076d1ca7de822b4a5373b4dc2860dff0717
6
+ metadata.gz: c6f8c12cfcf3b7a8ea41c49d6e97b1cfe53057fdd9b848902abfd7e6e0a9bcdabc8fa64bb4724b17f522794d5405a0d6563ffb04d67044f3af4a4db675734c0f
7
+ data.tar.gz: 38cc8c501733db05e285e01c309f3ea5c5a0fa9050c4578d9bc42548853e26cabf4ba51a37d12d4b81106336f0edb88d0fe2366e2553c01413da1c3cbceb8bf6
@@ -27,8 +27,18 @@ module Spree
27
27
 
28
28
  def create
29
29
  authorize! :create, Order
30
- @order = Spree::Core::Importer::Order.import(determine_order_user, order_params)
31
- respond_with(@order, default_template: :show, status: 201)
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
+ respond_with(@order, default_template: :show, status: 201)
38
+ else
39
+ invalid_resource!(@order)
40
+ end
41
+ end
32
42
  end
33
43
 
34
44
  def empty
@@ -16,6 +16,7 @@ module Spree
16
16
  end
17
17
 
18
18
  def create
19
+ @order.validate_payments_attributes(payment_params)
19
20
  @payment = PaymentCreate.new(@order, payment_params).build
20
21
  if @payment.save
21
22
  respond_with(@payment, status: 201, default_template: :show)
@@ -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,
@@ -32,8 +32,9 @@ module Spree
32
32
  describe "POST create" do
33
33
  let(:target_user) { create :user }
34
34
  let(:date_override) { Time.parse('2015-01-01') }
35
+ let(:attributes) { { user_id: target_user.id, created_at: date_override, email: target_user.email } }
35
36
 
36
- subject { api_post :create, order: { user_id: target_user.id, created_at: date_override, email: target_user.email } }
37
+ subject { api_post :create, order: attributes }
37
38
 
38
39
  context "when the current user cannot administrate the order" do
39
40
  stub_authorization! do |_|
@@ -42,12 +43,37 @@ module Spree
42
43
 
43
44
  it "does not include unpermitted params, or allow overriding the user", focus: true do
44
45
  subject
46
+ expect(response).to be_success
45
47
  order = Spree::Order.last
46
48
  expect(order.user).to eq current_api_user
47
49
  expect(order.email).to eq target_user.email
48
50
  end
49
51
 
50
52
  it { is_expected.to be_success }
53
+
54
+ context 'creating payment' do
55
+ let(:attributes) { super().merge(payments_attributes: [{ payment_method_id: payment_method.id }]) }
56
+
57
+ context "with allowed payment method" do
58
+ let!(:payment_method) { create(:check_payment_method, name: "allowed" ) }
59
+ it { is_expected.to be_success }
60
+ it "creates a payment" do
61
+ expect {
62
+ subject
63
+ }.to change { Spree::Payment.count }.by(1)
64
+ end
65
+ end
66
+
67
+ context "with disallowed payment method" do
68
+ let!(:payment_method) { create(:check_payment_method, name: "forbidden", display_on: "back_end") }
69
+ it { is_expected.to be_not_found }
70
+ it "creates no payments" do
71
+ expect {
72
+ subject
73
+ }.not_to change { Spree::Payment.count }
74
+ end
75
+ end
76
+ end
51
77
  end
52
78
 
53
79
  context "when the current user can administrate the order" do
@@ -97,6 +123,30 @@ module Spree
97
123
  subject
98
124
  }.to_not change{ order.reload.number }
99
125
  end
126
+
127
+ context 'creating payment' do
128
+ let(:order_params) { super().merge(payments_attributes: [{ payment_method_id: payment_method.id }]) }
129
+
130
+ context "with allowed payment method" do
131
+ let!(:payment_method) { create(:check_payment_method, name: "allowed" ) }
132
+ it { is_expected.to be_success }
133
+ it "creates a payment" do
134
+ expect {
135
+ subject
136
+ }.to change { Spree::Payment.count }.by(1)
137
+ end
138
+ end
139
+
140
+ context "with disallowed payment method" do
141
+ let!(:payment_method) { create(:check_payment_method, name: "forbidden", display_on: "back_end") }
142
+ it { is_expected.to be_not_found }
143
+ it "creates no payments" do
144
+ expect {
145
+ subject
146
+ }.not_to change { Spree::Payment.count }
147
+ end
148
+ end
149
+ end
100
150
  end
101
151
 
102
152
  context "when the user can administer the order" do
@@ -333,10 +383,7 @@ module Spree
333
383
 
334
384
  # Regression test for https://github.com/spree/spree/issues/3404
335
385
  it "can specify additional parameters for a line item" do
336
- expect(Order).to receive(:create!).and_return(order = Spree::Order.new)
337
- allow(order).to receive(:associate_user!)
338
- allow(order).to receive_message_chain(:contents, :add).and_return(line_item = double('LineItem'))
339
- expect(line_item).to receive(:update_attributes!).with(hash_including("special" => "foo"))
386
+ expect_any_instance_of(Spree::LineItem).to receive(:special=).with("foo")
340
387
 
341
388
  allow(controller).to receive_messages(permitted_line_item_attributes: [:id, :variant_id, :quantity, :special])
342
389
  api_post :create, order: {
@@ -45,6 +45,17 @@ module Spree
45
45
  expect(response.status).to eq(201)
46
46
  expect(json_response).to have_attributes(attributes)
47
47
  end
48
+
49
+ context "disallowed payment method" do
50
+ it "does not create a new payment" do
51
+ PaymentMethod.first.update!(display_on: "back_end")
52
+
53
+ expect {
54
+ api_post :create, payment: { payment_method_id: PaymentMethod.first.id, amount: 50 }
55
+ }.not_to change { Spree::Payment.count }
56
+ expect(response.status).to eq(404)
57
+ end
58
+ end
48
59
  end
49
60
 
50
61
  context "payment source is required" do
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: 2.0.2
4
+ version: 2.0.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: 2017-06-08 00:00:00.000000000 Z
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: 2.0.2
19
+ version: 2.0.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: 2.0.2
26
+ version: 2.0.3
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rabl
29
29
  requirement: !ruby/object:Gem::Requirement