solidus_api 1.4.2 → 2.0.0.beta1
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/base_controller.rb +2 -3
- data/app/controllers/spree/api/inventory_units_controller.rb +1 -1
- data/app/controllers/spree/api/line_items_controller.rb +1 -1
- data/app/controllers/spree/api/option_types_controller.rb +1 -1
- data/app/controllers/spree/api/option_values_controller.rb +1 -1
- data/app/controllers/spree/api/orders_controller.rb +3 -13
- data/app/controllers/spree/api/payments_controller.rb +0 -1
- data/config/initializers/rails5_rabl_hacks.rb +12 -0
- data/db/migrate/20100107141738_add_api_key_to_spree_users.rb +1 -1
- data/db/migrate/20120411123334_resize_api_key_field.rb +1 -1
- data/db/migrate/20120530054546_rename_api_key_to_spree_api_key.rb +1 -1
- data/db/migrate/20131017162334_add_index_to_user_spree_api_key.rb +1 -1
- data/solidus_api.gemspec +1 -1
- data/spec/controllers/spree/api/base_controller_spec.rb +8 -7
- data/spec/controllers/spree/api/checkouts_controller_spec.rb +0 -13
- data/spec/controllers/spree/api/orders_controller_spec.rb +9 -56
- data/spec/controllers/spree/api/payments_controller_spec.rb +0 -11
- data/spec/features/checkout_spec.rb +14 -6
- data/spec/requests/api/address_books_spec.rb +30 -11
- data/spec/requests/rabl_cache_spec.rb +2 -2
- data/spec/requests/ransackable_attributes_spec.rb +6 -6
- data/spec/spec_helper.rb +2 -0
- data/spec/support/controller_hacks.rb +8 -1
- metadata +12 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6bdb449ae51b17c27435793ebdc4107e57044fcd
|
4
|
+
data.tar.gz: 5912114dc2bf082204c7a0ae720caeb892adbf8a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a72d35bef9dd506a1076c15d6ec5e8488983c47adc2dd453deff71e0766e93ef9d48dbe09e182a7d133e84d6db46d905d3e73940617c83cead9017838662820b
|
7
|
+
data.tar.gz: 8f78217ba3ac3d82313de4ddd920f92a91a2715572952a2bad074f25c95c473ef2bb62931c8a016d556908b0b8cbd8258a579e839cd6f1d01142c75c670572d4
|
@@ -73,8 +73,7 @@ module Spree
|
|
73
73
|
|
74
74
|
error_notifier.call(exception, self) if error_notifier
|
75
75
|
|
76
|
-
render
|
77
|
-
status: 422
|
76
|
+
render json: { exception: exception.message }, status: 422
|
78
77
|
end
|
79
78
|
|
80
79
|
def gateway_error(exception)
|
@@ -149,7 +148,7 @@ module Spree
|
|
149
148
|
def lock_order
|
150
149
|
OrderMutex.with_lock!(@order) { yield }
|
151
150
|
rescue Spree::OrderMutex::LockFailed => e
|
152
|
-
render
|
151
|
+
render plain: e.message, status: 409
|
153
152
|
end
|
154
153
|
|
155
154
|
def insufficient_stock_error(exception)
|
@@ -34,7 +34,7 @@ module Spree
|
|
34
34
|
|
35
35
|
unless inventory_unit.respond_to?(can_event) &&
|
36
36
|
inventory_unit.send(can_event)
|
37
|
-
render
|
37
|
+
render json: { exception: "cannot transition to #{@event}" },
|
38
38
|
status: 200
|
39
39
|
false
|
40
40
|
end
|
@@ -18,7 +18,7 @@ module Spree
|
|
18
18
|
params[:line_item][:quantity] || 1,
|
19
19
|
{
|
20
20
|
stock_location_quantities: params[:line_item][:stock_location_quantities]
|
21
|
-
}.merge(line_item_params[:options] || {})
|
21
|
+
}.merge(line_item_params[:options].to_h || {})
|
22
22
|
)
|
23
23
|
|
24
24
|
if @line_item.errors.empty?
|
@@ -27,24 +27,14 @@ module Spree
|
|
27
27
|
|
28
28
|
def create
|
29
29
|
authorize! :create, Order
|
30
|
-
|
31
|
-
|
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
|
30
|
+
@order = Spree::Core::Importer::Order.import(determine_order_user, order_params)
|
31
|
+
respond_with(@order, default_template: :show, status: 201)
|
42
32
|
end
|
43
33
|
|
44
34
|
def empty
|
45
35
|
authorize! :update, @order, order_token
|
46
36
|
@order.empty!
|
47
|
-
render
|
37
|
+
render plain: nil, status: 204
|
48
38
|
end
|
49
39
|
|
50
40
|
def index
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# As of 2016-08-17 rabl is broken on rails 5.
|
2
|
+
# This prevents errors when caching is enabled
|
3
|
+
if Rabl::VERSION == "0.13.0"
|
4
|
+
# Remove the broken redefinition of digest
|
5
|
+
Rabl::Digestor.class_eval do
|
6
|
+
class << self
|
7
|
+
remove_method :digest
|
8
|
+
end
|
9
|
+
end
|
10
|
+
else
|
11
|
+
raise "Remove this monkey patch"
|
12
|
+
end
|
data/solidus_api.gemspec
CHANGED
@@ -17,6 +17,6 @@ Gem::Specification.new do |gem|
|
|
17
17
|
gem.version = Spree.solidus_version
|
18
18
|
|
19
19
|
gem.add_dependency 'solidus_core', gem.version
|
20
|
-
gem.add_dependency 'rabl',
|
20
|
+
gem.add_dependency 'rabl', '0.13.0' # FIXME: update for proper rails 5 support
|
21
21
|
gem.add_dependency 'versioncake', '~> 3.0'
|
22
22
|
end
|
@@ -9,7 +9,7 @@ describe Spree::Api::BaseController, type: :controller do
|
|
9
9
|
rescue_from Spree::Order::InsufficientStock, with: :insufficient_stock_error
|
10
10
|
|
11
11
|
def index
|
12
|
-
render
|
12
|
+
render json: { "products" => [] }
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
@@ -51,13 +51,13 @@ describe Spree::Api::BaseController, type: :controller do
|
|
51
51
|
|
52
52
|
it "with an invalid API key" do
|
53
53
|
request.headers["X-Spree-Token"] = "fake_key"
|
54
|
-
get :index, {}
|
54
|
+
get :index, params: {}
|
55
55
|
expect(json_response).to eq({ "error" => "Invalid API key (fake_key) specified." })
|
56
56
|
expect(response.status).to eq(401)
|
57
57
|
end
|
58
58
|
|
59
59
|
it "using an invalid token param" do
|
60
|
-
get :index, token: "fake_key"
|
60
|
+
get :index, params: { token: "fake_key" }
|
61
61
|
expect(json_response).to eq({ "error" => "Invalid API key (fake_key) specified." })
|
62
62
|
end
|
63
63
|
end
|
@@ -66,8 +66,9 @@ describe Spree::Api::BaseController, type: :controller do
|
|
66
66
|
expect(subject).to receive(:authenticate_user).and_return(true)
|
67
67
|
expect(subject).to receive(:load_user_roles).and_return(true)
|
68
68
|
expect(subject).to receive(:index).and_raise("no joy")
|
69
|
-
get :index, token: "fake_key"
|
69
|
+
get :index, params: { token: "fake_key" }
|
70
70
|
expect(json_response).to eq({ "exception" => "no joy" })
|
71
|
+
expect(response.content_type).to eq("application/json")
|
71
72
|
end
|
72
73
|
|
73
74
|
it 'raises Exception' do
|
@@ -75,7 +76,7 @@ describe Spree::Api::BaseController, type: :controller do
|
|
75
76
|
expect(subject).to receive(:load_user_roles).and_return(true)
|
76
77
|
expect(subject).to receive(:index).and_raise(Exception.new("no joy"))
|
77
78
|
expect {
|
78
|
-
get :index, token: "fake_key"
|
79
|
+
get :index, params: { token: "fake_key" }
|
79
80
|
}.to raise_error(Exception, "no joy")
|
80
81
|
end
|
81
82
|
|
@@ -125,7 +126,7 @@ describe Spree::Api::BaseController, type: :controller do
|
|
125
126
|
before do
|
126
127
|
expect(subject).to receive(:authenticate_user).and_return(true)
|
127
128
|
expect(subject).to receive(:index).and_raise(Spree::Order::InsufficientStock)
|
128
|
-
get :index, token: "fake_key"
|
129
|
+
get :index, params: { token: "fake_key" }
|
129
130
|
end
|
130
131
|
|
131
132
|
it "should return a 422" do
|
@@ -146,7 +147,7 @@ describe Spree::Api::BaseController, type: :controller do
|
|
146
147
|
around_action :lock_order
|
147
148
|
|
148
149
|
def index
|
149
|
-
render
|
150
|
+
render json: { "products" => [] }
|
150
151
|
end
|
151
152
|
end
|
152
153
|
|
@@ -163,19 +163,6 @@ 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
|
-
|
179
166
|
it "returns errors when source is required and missing" do
|
180
167
|
order.update_column(:state, "payment")
|
181
168
|
api_put :update, id: order.to_param, order_token: order.guest_token,
|
@@ -32,9 +32,8 @@ 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 } }
|
36
35
|
|
37
|
-
subject { api_post :create, order:
|
36
|
+
subject { api_post :create, order: { user_id: target_user.id, created_at: date_override, email: target_user.email } }
|
38
37
|
|
39
38
|
context "when the current user cannot administrate the order" do
|
40
39
|
stub_authorization! do |_|
|
@@ -43,37 +42,12 @@ module Spree
|
|
43
42
|
|
44
43
|
it "does not include unpermitted params, or allow overriding the user", focus: true do
|
45
44
|
subject
|
46
|
-
expect(response).to be_success
|
47
45
|
order = Spree::Order.last
|
48
46
|
expect(order.user).to eq current_api_user
|
49
47
|
expect(order.email).to eq target_user.email
|
50
48
|
end
|
51
49
|
|
52
50
|
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
|
77
51
|
end
|
78
52
|
|
79
53
|
context "when the current user can administrate the order" do
|
@@ -123,30 +97,6 @@ module Spree
|
|
123
97
|
subject
|
124
98
|
}.to_not change{ order.reload.number }
|
125
99
|
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
|
150
100
|
end
|
151
101
|
|
152
102
|
context "when the user can administer the order" do
|
@@ -216,13 +166,13 @@ module Spree
|
|
216
166
|
end
|
217
167
|
|
218
168
|
it "returns orders in reverse chronological order by completed_at" do
|
219
|
-
order.update_columns completed_at: Time.current
|
169
|
+
order.update_columns completed_at: Time.current
|
220
170
|
|
221
|
-
order2 = Order.create user: order.user, completed_at: Time.current - 1.day,
|
171
|
+
order2 = Order.create user: order.user, completed_at: Time.current - 1.day, store: store
|
222
172
|
expect(order2.created_at).to be > order.created_at
|
223
|
-
order3 = Order.create user: order.user, completed_at: nil,
|
173
|
+
order3 = Order.create user: order.user, completed_at: nil, store: store
|
224
174
|
expect(order3.created_at).to be > order2.created_at
|
225
|
-
order4 = Order.create user: order.user, completed_at: nil,
|
175
|
+
order4 = Order.create user: order.user, completed_at: nil, store: store
|
226
176
|
expect(order4.created_at).to be > order3.created_at
|
227
177
|
|
228
178
|
request.env['SERVER_NAME'] = store.url
|
@@ -383,7 +333,10 @@ module Spree
|
|
383
333
|
|
384
334
|
# Regression test for https://github.com/spree/spree/issues/3404
|
385
335
|
it "can specify additional parameters for a line item" do
|
386
|
-
|
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"))
|
387
340
|
|
388
341
|
allow(controller).to receive_messages(permitted_line_item_attributes: [:id, :variant_id, :quantity, :special])
|
389
342
|
api_post :create, order: {
|
@@ -45,17 +45,6 @@ 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
|
59
48
|
end
|
60
49
|
|
61
50
|
context "payment source is required" do
|
@@ -24,7 +24,12 @@ module Spree
|
|
24
24
|
|
25
25
|
def login
|
26
26
|
expect {
|
27
|
-
post '/api/users',
|
27
|
+
post '/api/users', params: {
|
28
|
+
user: {
|
29
|
+
email: "featurecheckoutuser@example.com",
|
30
|
+
password: "featurecheckoutuser"
|
31
|
+
}
|
32
|
+
}
|
28
33
|
}.to change { Spree.user_class.count }.by 1
|
29
34
|
expect(response).to have_http_status(:created)
|
30
35
|
@user = Spree.user_class.find(parsed['id'])
|
@@ -34,27 +39,29 @@ module Spree
|
|
34
39
|
end
|
35
40
|
|
36
41
|
def create_order(order_params: {})
|
37
|
-
expect { post '/api/orders', order_params }.to change { Order.count }.by 1
|
42
|
+
expect { post '/api/orders', params: order_params }.to change { Order.count }.by 1
|
38
43
|
expect(response).to have_http_status(:created)
|
39
44
|
@order = Order.find(parsed['id'])
|
40
45
|
expect(@order.email).to eq "featurecheckoutuser@example.com"
|
41
46
|
end
|
42
47
|
|
43
48
|
def update_order(order_params: {})
|
44
|
-
put "/api/orders/#{@order.number}", order_params
|
49
|
+
put "/api/orders/#{@order.number}", params: order_params
|
45
50
|
expect(response).to have_http_status(:ok)
|
46
51
|
end
|
47
52
|
|
48
53
|
def create_line_item(variant, quantity = 1)
|
49
54
|
expect {
|
50
|
-
post "/api/orders/#{@order.number}/line_items",
|
55
|
+
post "/api/orders/#{@order.number}/line_items",
|
56
|
+
params: { line_item: { variant_id: variant.id, quantity: quantity } }
|
51
57
|
}.to change { @order.line_items.count }.by 1
|
52
58
|
expect(response).to have_http_status(:created)
|
53
59
|
end
|
54
60
|
|
55
61
|
def add_promotion(_promotion)
|
56
62
|
expect {
|
57
|
-
put "/api/orders/#{@order.number}/apply_coupon_code",
|
63
|
+
put "/api/orders/#{@order.number}/apply_coupon_code",
|
64
|
+
params: { coupon_code: promotion_code.value }
|
58
65
|
}.to change { @order.promotions.count }.by 1
|
59
66
|
expect(response).to have_http_status(:ok)
|
60
67
|
end
|
@@ -70,7 +77,8 @@ module Spree
|
|
70
77
|
|
71
78
|
def add_payment
|
72
79
|
expect {
|
73
|
-
post "/api/orders/#{@order.number}/payments",
|
80
|
+
post "/api/orders/#{@order.number}/payments",
|
81
|
+
params: { payment: { payment_method_id: payment_method.id } }
|
74
82
|
}.to change { @order.reload.payments.count }.by 1
|
75
83
|
expect(response).to have_http_status(:created)
|
76
84
|
expect(@order.payments.last.payment_method).to eq payment_method
|
@@ -38,7 +38,8 @@ module Spree
|
|
38
38
|
user.save_in_address_book(harry_address_attributes, true)
|
39
39
|
user.save_in_address_book(ron_address_attributes, false)
|
40
40
|
|
41
|
-
get "/api/users/#{user.id}/address_book",
|
41
|
+
get "/api/users/#{user.id}/address_book",
|
42
|
+
headers: { 'X-SPREE-TOKEN' => 'galleon' }
|
42
43
|
|
43
44
|
json_response = JSON.parse(response.body)
|
44
45
|
expect(response.status).to eq(200)
|
@@ -55,7 +56,9 @@ module Spree
|
|
55
56
|
harry_address_attributes['firstname'] = 'Ron'
|
56
57
|
|
57
58
|
expect {
|
58
|
-
put "/api/users/#{user.id}/address_book",
|
59
|
+
put "/api/users/#{user.id}/address_book",
|
60
|
+
params: { address_book: harry_address_attributes.merge('id' => address.id) },
|
61
|
+
headers: { 'X-SPREE-TOKEN' => 'galleon' }
|
59
62
|
}.to change { UserAddress.count }.from(1).to(2)
|
60
63
|
|
61
64
|
expect(response.status).to eq(200)
|
@@ -67,7 +70,9 @@ module Spree
|
|
67
70
|
user = create(:user, spree_api_key: 'galleon')
|
68
71
|
|
69
72
|
expect {
|
70
|
-
put "/api/users/#{user.id}/address_book",
|
73
|
+
put "/api/users/#{user.id}/address_book",
|
74
|
+
params: { address_book: harry_address_attributes },
|
75
|
+
headers: { 'X-SPREE-TOKEN' => 'galleon' }
|
71
76
|
}.to change { UserAddress.count }.by(1)
|
72
77
|
|
73
78
|
user_address = UserAddress.last
|
@@ -84,7 +89,9 @@ module Spree
|
|
84
89
|
address = user.save_in_address_book(harry_address_attributes, true)
|
85
90
|
|
86
91
|
expect {
|
87
|
-
put "/api/users/#{user.id}/address_book",
|
92
|
+
put "/api/users/#{user.id}/address_book",
|
93
|
+
params: { address_book: harry_address_attributes },
|
94
|
+
headers: { 'X-SPREE-TOKEN' => 'galleon' }
|
88
95
|
}.to_not change { UserAddress.count }
|
89
96
|
|
90
97
|
expect(response.status).to eq(200)
|
@@ -99,7 +106,9 @@ module Spree
|
|
99
106
|
user.save_in_address_book(address.attributes, false)
|
100
107
|
|
101
108
|
expect {
|
102
|
-
delete "/api/users/#{user.id}/address_book",
|
109
|
+
delete "/api/users/#{user.id}/address_book",
|
110
|
+
params: { address_id: address.id },
|
111
|
+
headers: { 'X-SPREE-TOKEN' => 'galleon' }
|
103
112
|
}.to change { user.reload.user_addresses.count }.from(1).to(0)
|
104
113
|
|
105
114
|
expect(response.status).to eq(200)
|
@@ -121,7 +130,8 @@ module Spree
|
|
121
130
|
other_user.save_in_address_book(harry_address_attributes, true)
|
122
131
|
other_user.save_in_address_book(ron_address_attributes, false)
|
123
132
|
|
124
|
-
get "/api/users/#{other_user.id}/address_book",
|
133
|
+
get "/api/users/#{other_user.id}/address_book",
|
134
|
+
headers: { 'X-SPREE-TOKEN' => 'galleon' }
|
125
135
|
|
126
136
|
json_response = JSON.parse(response.body)
|
127
137
|
expect(response.status).to eq(200)
|
@@ -138,7 +148,9 @@ module Spree
|
|
138
148
|
updated_harry_address = harry_address_attributes.merge('firstname' => 'Ron')
|
139
149
|
|
140
150
|
expect {
|
141
|
-
put "/api/users/#{other_user.id}/address_book",
|
151
|
+
put "/api/users/#{other_user.id}/address_book",
|
152
|
+
params: { address_book: updated_harry_address.merge('id' => address.id) },
|
153
|
+
headers: { 'X-SPREE-TOKEN' => 'galleon' }
|
142
154
|
}.to change { UserAddress.count }.from(1).to(2)
|
143
155
|
|
144
156
|
expect(response.status).to eq(200)
|
@@ -151,7 +163,9 @@ module Spree
|
|
151
163
|
other_user.save_in_address_book(address.attributes, false)
|
152
164
|
|
153
165
|
expect {
|
154
|
-
delete "/api/users/#{other_user.id}/address_book",
|
166
|
+
delete "/api/users/#{other_user.id}/address_book",
|
167
|
+
params: { address_id: address.id },
|
168
|
+
headers: { 'X-SPREE-TOKEN' => 'galleon' }
|
155
169
|
}.to change { other_user.reload.user_addresses.count }.from(1).to(0)
|
156
170
|
|
157
171
|
expect(response.status).to eq(200)
|
@@ -164,7 +178,8 @@ module Spree
|
|
164
178
|
other_user = create(:user)
|
165
179
|
other_user.save_in_address_book(harry_address_attributes, true)
|
166
180
|
|
167
|
-
get "/api/users/#{other_user.id}/address_book",
|
181
|
+
get "/api/users/#{other_user.id}/address_book",
|
182
|
+
headers: { 'X-SPREE-TOKEN' => 'galleon' }
|
168
183
|
|
169
184
|
expect(response.status).to eq(401)
|
170
185
|
end
|
@@ -176,7 +191,9 @@ module Spree
|
|
176
191
|
create(:user, spree_api_key: 'galleon')
|
177
192
|
|
178
193
|
expect {
|
179
|
-
put "/api/users/#{other_user.id}/address_book",
|
194
|
+
put "/api/users/#{other_user.id}/address_book",
|
195
|
+
params: { address_book: other_user_address.attributes.merge('address1' => 'Hogwarts') },
|
196
|
+
headers: { 'X-SPREE-TOKEN' => 'galleon' }
|
180
197
|
}.not_to change { UserAddress.count }
|
181
198
|
|
182
199
|
expect(response.status).to eq(401)
|
@@ -189,7 +206,9 @@ module Spree
|
|
189
206
|
create(:user, spree_api_key: 'galleon')
|
190
207
|
|
191
208
|
expect {
|
192
|
-
delete "/api/users/#{other_user.id}/address_book",
|
209
|
+
delete "/api/users/#{other_user.id}/address_book",
|
210
|
+
params: { address_id: address.id },
|
211
|
+
headers: { 'X-SPREE-TOKEN' => 'galleon' }
|
193
212
|
}.not_to change { other_user.user_addresses.count }
|
194
213
|
|
195
214
|
expect(response.status).to eq(401)
|
@@ -10,7 +10,7 @@ describe "Rabl Cache", type: :request, caching: true do
|
|
10
10
|
end
|
11
11
|
|
12
12
|
it "doesn't create a cache key collision for models with different rabl templates" do
|
13
|
-
get "/api/variants", token: user.spree_api_key
|
13
|
+
get "/api/variants", params: { token: user.spree_api_key }
|
14
14
|
expect(response.status).to eq(200)
|
15
15
|
|
16
16
|
# Make sure we get a non master variant
|
@@ -21,7 +21,7 @@ describe "Rabl Cache", type: :request, caching: true do
|
|
21
21
|
expect(variant_a['is_master']).to be false
|
22
22
|
expect(variant_a['stock_items']).not_to be_nil
|
23
23
|
|
24
|
-
get "/api/products/#{Spree::Product.first.id}", token: user.spree_api_key
|
24
|
+
get "/api/products/#{Spree::Product.first.id}", params: { token: user.spree_api_key }
|
25
25
|
expect(response.status).to eq(200)
|
26
26
|
variant_b = JSON.parse(response.body)['variants'].last
|
27
27
|
expect(variant_b['is_master']).to be false
|
@@ -7,7 +7,7 @@ describe "Ransackable Attributes" do
|
|
7
7
|
it "does not allow the filtering of variants by order attributes" do
|
8
8
|
2.times { create(:variant) }
|
9
9
|
|
10
|
-
get "/api/variants?q[orders_email_start]=#{order.email}", token: user.spree_api_key
|
10
|
+
get "/api/variants?q[orders_email_start]=#{order.email}", params: { token: user.spree_api_key }
|
11
11
|
|
12
12
|
variants_response = JSON.parse(response.body)
|
13
13
|
expect(variants_response['total_count']).to eq(Spree::Variant.count)
|
@@ -18,7 +18,7 @@ describe "Ransackable Attributes" do
|
|
18
18
|
it "does not allow the filtering of variants by user attributes" do
|
19
19
|
2.times { create(:variant) }
|
20
20
|
|
21
|
-
get "/api/variants?q[orders_user_email_start]=#{order.user.email}", token: user.spree_api_key
|
21
|
+
get "/api/variants?q[orders_user_email_start]=#{order.user.email}", params: { token: user.spree_api_key }
|
22
22
|
|
23
23
|
variants_response = JSON.parse(response.body)
|
24
24
|
expect(variants_response['total_count']).to eq(Spree::Variant.count)
|
@@ -31,7 +31,7 @@ describe "Ransackable Attributes" do
|
|
31
31
|
variant = create(:variant, product: product)
|
32
32
|
other_variant = create(:variant)
|
33
33
|
|
34
|
-
get "/api/variants?q[product_name_or_sku_cont]=fritos", token: user.spree_api_key
|
34
|
+
get "/api/variants?q[product_name_or_sku_cont]=fritos", params: { token: user.spree_api_key }
|
35
35
|
|
36
36
|
skus = JSON.parse(response.body)['variants'].map { |x| x['sku'] }
|
37
37
|
expect(skus).to include variant.sku
|
@@ -44,7 +44,7 @@ describe "Ransackable Attributes" do
|
|
44
44
|
create(:product, description: "special product")
|
45
45
|
create(:product)
|
46
46
|
|
47
|
-
get "/api/products?q[description_cont]=special", token: user.spree_api_key
|
47
|
+
get "/api/products?q[description_cont]=special", params: { token: user.spree_api_key }
|
48
48
|
|
49
49
|
products_response = JSON.parse(response.body)
|
50
50
|
expect(products_response['total_count']).to eq(Spree::Product.count)
|
@@ -54,7 +54,7 @@ describe "Ransackable Attributes" do
|
|
54
54
|
product = create(:product)
|
55
55
|
other_product = create(:product)
|
56
56
|
|
57
|
-
get "/api/products?q[id_eq]=#{product.id}", token: user.spree_api_key
|
57
|
+
get "/api/products?q[id_eq]=#{product.id}", params: { token: user.spree_api_key }
|
58
58
|
|
59
59
|
product_names = JSON.parse(response.body)['products'].map { |x| x['name'] }
|
60
60
|
expect(product_names).to include product.name
|
@@ -67,7 +67,7 @@ describe "Ransackable Attributes" do
|
|
67
67
|
product = create(:product, name: "Fritos")
|
68
68
|
other_product = create(:product)
|
69
69
|
|
70
|
-
get "/api/products?q[name_cont]=fritos", token: user.spree_api_key
|
70
|
+
get "/api/products?q[name_cont]=fritos", params: { token: user.spree_api_key }
|
71
71
|
|
72
72
|
product_names = JSON.parse(response.body)['products'].map { |x| x['name'] }
|
73
73
|
expect(product_names).to include product.name
|
data/spec/spec_helper.rb
CHANGED
@@ -36,6 +36,8 @@ require 'spree/api/testing_support/caching'
|
|
36
36
|
require 'spree/api/testing_support/helpers'
|
37
37
|
require 'spree/api/testing_support/setup'
|
38
38
|
|
39
|
+
ActiveJob::Base.queue_adapter = :inline
|
40
|
+
|
39
41
|
RSpec.configure do |config|
|
40
42
|
config.backtrace_exclusion_patterns = [/gems\/activesupport/, /gems\/actionpack/, /gems\/rspec/]
|
41
43
|
config.color = true
|
@@ -25,7 +25,14 @@ module ControllerHacks
|
|
25
25
|
|
26
26
|
def api_process(action, params = {}, session = nil, flash = nil, method = "get")
|
27
27
|
scoping = respond_to?(:resource_scoping) ? resource_scoping : {}
|
28
|
-
process(
|
28
|
+
process(
|
29
|
+
action,
|
30
|
+
method: method,
|
31
|
+
params: params.merge(scoping),
|
32
|
+
session: session,
|
33
|
+
flash: flash,
|
34
|
+
format: :json
|
35
|
+
)
|
29
36
|
end
|
30
37
|
end
|
31
38
|
|
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:
|
4
|
+
version: 2.0.0.beta1
|
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: 2016-08-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: solidus_core
|
@@ -16,34 +16,28 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - '='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 2.0.0.beta1
|
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:
|
26
|
+
version: 2.0.0.beta1
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rabl
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: 0.9.4.pre1
|
34
|
-
- - "<"
|
31
|
+
- - '='
|
35
32
|
- !ruby/object:Gem::Version
|
36
|
-
version: 0.
|
33
|
+
version: 0.13.0
|
37
34
|
type: :runtime
|
38
35
|
prerelease: false
|
39
36
|
version_requirements: !ruby/object:Gem::Requirement
|
40
37
|
requirements:
|
41
|
-
- -
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
version: 0.9.4.pre1
|
44
|
-
- - "<"
|
38
|
+
- - '='
|
45
39
|
- !ruby/object:Gem::Version
|
46
|
-
version: 0.
|
40
|
+
version: 0.13.0
|
47
41
|
- !ruby/object:Gem::Dependency
|
48
42
|
name: versioncake
|
49
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -198,6 +192,7 @@ files:
|
|
198
192
|
- app/views/spree/api/variants/small.v1.rabl
|
199
193
|
- app/views/spree/api/zones/index.v1.rabl
|
200
194
|
- app/views/spree/api/zones/show.v1.rabl
|
195
|
+
- config/initializers/rails5_rabl_hacks.rb
|
201
196
|
- config/locales/en.yml
|
202
197
|
- config/routes.rb
|
203
198
|
- db/migrate/20100107141738_add_api_key_to_spree_users.rb
|
@@ -279,12 +274,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
279
274
|
version: '0'
|
280
275
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
281
276
|
requirements:
|
282
|
-
- - "
|
277
|
+
- - ">"
|
283
278
|
- !ruby/object:Gem::Version
|
284
|
-
version:
|
279
|
+
version: 1.3.1
|
285
280
|
requirements: []
|
286
281
|
rubyforge_project:
|
287
|
-
rubygems_version: 2.
|
282
|
+
rubygems_version: 2.5.1
|
288
283
|
signing_key:
|
289
284
|
specification_version: 4
|
290
285
|
summary: REST API for the Solidus e-commerce framework.
|