solidus_api 1.4.1 → 1.4.2

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: 4651ab7b34d25fed7f014a225351a74b4960cd7f
4
- data.tar.gz: 1d76620e82ac913f281fa452f5b5fe826effb344
3
+ metadata.gz: 487255d3c7c9a28a0e6b9ed4cc984f1ff0a0dc88
4
+ data.tar.gz: 94190cac19ab74bb6f10c2e588de1ebbbb75d9b5
5
5
  SHA512:
6
- metadata.gz: 5816d45928873c06da825f2b40ebc37e99ad4a67af339934240e9a6e4ca6095825396235931629d3d078bf2a49165e3417073e8dcff717cff3823043efd13cf5
7
- data.tar.gz: 92509558ca4f573c9678664f5c95493690a2073f55d03725d428f161b0a21dc5cf6ed302aaec9e063742b3ad72c79bcd94bba2a5382b9953fc618862a5eb2104
6
+ metadata.gz: 0435e1961c6ee011b4f6482f5848c452b69f6f43e54fb2c887e80f5c81dc9ccbae61eb9d581b824697736b20196e3945939543dc59275c785dad150c283556ff
7
+ data.tar.gz: 5dc3ba08436b3cc53028699bb81a9c8627d04427f18b0e5ee1d343e6e099b8c70fc8c075f877bfb2b8c42d4dfcdce6c46ee9a1b7b812285f3e556d48033457e2
@@ -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: 1.4.1
4
+ version: 1.4.2
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: 1.4.1
19
+ version: 1.4.2
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.4.1
26
+ version: 1.4.2
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rabl
29
29
  requirement: !ruby/object:Gem::Requirement