solidus_api 2.7.4 → 2.8.0

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
  SHA256:
3
- metadata.gz: bb8fffadf8fc2d9ea66ce07a309be1796007c2b3415fdc844a571ca157a00363
4
- data.tar.gz: 452378060d6e6f499a2e8804cecda66404543617276dda5c9b458ccf603f0e88
3
+ metadata.gz: f844a44dd5be31006970426fcce557d3fccfd72157f9d9f73136e8d54ed249b1
4
+ data.tar.gz: 8175fab98f6b3d9a9ce6726b4f101ed3175d10ff2309bc58f30900bab75dd676
5
5
  SHA512:
6
- metadata.gz: 17d1b0914d067ec7bcd0fa5b3528b00a02b921f11ac0ebf86a0dca17fdb3eb3f23967a2a291ffd1b41769e5745ef940a8595e7bd1f9758a1a52ee596fb66c937
7
- data.tar.gz: b77fd8584ade580c2afa0e9fbcb680e6039a2b677eb3b0469c941611d6d1713a1db58f0215b479502996da3cea2fff059f94557abe304813ee90c02aac8e48b2
6
+ metadata.gz: 6000ba487ac1332e9a5e5bc02fa9495c13bf6ce25ad0a15050263f771b86e8bf0ef2a3e424bb95a5c0ddaaa7ebd0930e9151b20aac4185ccc763944eba9f8e5a
7
+ data.tar.gz: e6c8f7a362d7f4f8ab4192cc4fd2ed9b1ab9768425c4d87fa0fb3f566e1a692a903845bd66fe7433cb716215fe6ae2da0ead5631552766d276f5e6a04b42b61b
data/README.md CHANGED
@@ -1,9 +1,11 @@
1
1
  # solidus\_api
2
2
 
3
- API contains controllers and rabl views implementing the REST API of solidus.
3
+ API contains the controllers and rabl views implementing the REST API of Solidus.
4
4
 
5
5
  ## Testing
6
6
 
7
- Run the tests
7
+ Run the API tests:
8
8
 
9
- bundle exec rspec
9
+ ```bash
10
+ bundle exec rspec
11
+ ```
@@ -7,6 +7,7 @@ module Spree
7
7
  class BaseController < ActionController::Base
8
8
  self.responder = Spree::Api::Responders::AppResponder
9
9
  respond_to :json
10
+ protect_from_forgery unless: -> { request.format.json? }
10
11
 
11
12
  include CanCan::ControllerAdditions
12
13
  include Spree::Core::ControllerHelpers::Store
@@ -99,10 +100,27 @@ module Spree
99
100
  end
100
101
 
101
102
  def api_key
102
- request.headers["X-Spree-Token"] || params[:token]
103
+ bearer_token || spree_token || params[:token]
103
104
  end
104
105
  helper_method :api_key
105
106
 
107
+ def bearer_token
108
+ pattern = /^Bearer /
109
+ header = request.headers["Authorization"]
110
+ header.gsub(pattern, '') if header.present? && header.match(pattern)
111
+ end
112
+
113
+ def spree_token
114
+ token = request.headers["X-Spree-Token"]
115
+ return unless token.present?
116
+
117
+ Spree::Deprecation.warn(
118
+ 'The custom X-Spree-Token request header is deprecated and will be removed in the next release.' \
119
+ ' Please use bearer token authorization header instead.'
120
+ )
121
+ token
122
+ end
123
+
106
124
  def order_token
107
125
  request.headers["X-Spree-Order-Token"] || params[:order_token]
108
126
  end
@@ -114,6 +114,7 @@ module Spree
114
114
 
115
115
  def after_update_attributes
116
116
  if params[:order] && params[:order][:coupon_code].present?
117
+ Spree::Deprecation.warn('This method is deprecated. Please use `Spree::Api::CouponCodesController#create` endpoint instead.')
117
118
  handler = PromotionHandler::Coupon.new(@order)
118
119
  handler.apply
119
120
 
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Spree
4
+ module Api
5
+ class CouponCodesController < Spree::Api::BaseController
6
+ before_action :load_order
7
+ around_action :lock_order
8
+
9
+ def create
10
+ authorize! :update, @order, order_token
11
+
12
+ @order.coupon_code = params[:coupon_code]
13
+ @handler = PromotionHandler::Coupon.new(@order).apply
14
+
15
+ if @handler.successful?
16
+ render 'spree/api/promotions/handler', status: 200
17
+ else
18
+ logger.error("apply_coupon_code_error=#{@handler.error.inspect}")
19
+ render 'spree/api/promotions/handler', status: 422
20
+ end
21
+ end
22
+
23
+ def destroy
24
+ authorize! :update, @order, order_token
25
+
26
+ @order.coupon_code = params[:id]
27
+ @handler = PromotionHandler::Coupon.new(@order).remove
28
+
29
+ if @handler.successful?
30
+ render 'spree/api/promotions/handler', status: 200
31
+ else
32
+ logger.error("remove_coupon_code_error=#{@handler.error.inspect}")
33
+ render 'spree/api/promotions/handler', status: 422
34
+ end
35
+ end
36
+
37
+ private
38
+
39
+ def load_order
40
+ @order = Spree::Order.find_by!(number: params[:order_id])
41
+ end
42
+ end
43
+ end
44
+ end
@@ -51,7 +51,18 @@ module Spree
51
51
 
52
52
  def index
53
53
  authorize! :index, Order
54
- @orders = paginate(Spree::Order.ransack(params[:q]).result)
54
+ orders_includes = [
55
+ :user,
56
+ :payments,
57
+ :adjustments,
58
+ :line_items
59
+ ]
60
+ @orders = paginate(
61
+ Spree::Order
62
+ .ransack(params[:q])
63
+ .result
64
+ .includes(orders_includes)
65
+ )
55
66
  respond_with(@orders)
56
67
  end
57
68
 
@@ -92,6 +103,8 @@ module Spree
92
103
  end
93
104
 
94
105
  def apply_coupon_code
106
+ Spree::Deprecation.warn('This method is deprecated. Please use `Spree::Api::CouponCodesController#create` endpoint instead.')
107
+
95
108
  authorize! :update, @order, order_token
96
109
  @order.coupon_code = params[:coupon_code]
97
110
  @handler = PromotionHandler::Coupon.new(@order).apply
@@ -8,7 +8,16 @@ module Spree
8
8
  ids = params[:ids].split(",").flatten
9
9
  @products = product_scope.where(id: ids)
10
10
  else
11
- @products = product_scope.ransack(params[:q]).result
11
+ products_includes = [
12
+ :variants,
13
+ :option_types,
14
+ :product_properties,
15
+ { classifications: :taxon }
16
+ ]
17
+ @products = product_scope
18
+ .ransack(params[:q])
19
+ .result
20
+ .includes(products_includes)
12
21
  end
13
22
 
14
23
  @products = paginate(@products.distinct)
@@ -4,7 +4,7 @@ module Spree
4
4
  module Api
5
5
  class ReturnAuthorizationsController < Spree::Api::BaseController
6
6
  before_action :load_order
7
- around_action :lock_order, only: [:create, :update, :destroy, :add, :receive, :cancel]
7
+ around_action :lock_order, only: [:create, :update, :destroy, :cancel]
8
8
 
9
9
  rescue_from Spree::Order::InsufficientStock, with: :insufficient_stock_error
10
10
 
@@ -12,7 +12,12 @@ module Spree
12
12
  @taxons = Spree::Taxon.accessible_by(current_ability, :read).order(:taxonomy_id, :lft).ransack(params[:q]).result
13
13
  end
14
14
 
15
+ unless params[:without_children]
16
+ @taxons = @taxons.includes(:children)
17
+ end
18
+
15
19
  @taxons = paginate(@taxons)
20
+ preload_taxon_parents(@taxons)
16
21
  respond_with(@taxons)
17
22
  end
18
23
 
@@ -106,6 +111,16 @@ module Spree
106
111
  {}
107
112
  end
108
113
  end
114
+
115
+ def preload_taxon_parents(taxons)
116
+ parents = Spree::Taxon.none
117
+
118
+ taxons.map do |taxon|
119
+ parents = parents.or(taxon.ancestors)
120
+ end
121
+
122
+ Spree::Taxon.associate_parents(taxons + parents)
123
+ end
109
124
  end
110
125
  end
111
126
  end
@@ -8,7 +8,7 @@ json.cache! [I18n.locale, line_item] do
8
8
  json.variant do
9
9
  json.partial!("spree/api/variants/small", variant: line_item.variant)
10
10
  json.(line_item.variant, :product_id)
11
- json.images(line_item.variant.images) do |image|
11
+ json.images(line_item.variant.gallery.images) do |image|
12
12
  json.partial!("spree/api/images/image", image: image)
13
13
  end
14
14
  end
@@ -14,7 +14,7 @@ json.cache! [I18n.locale, shipment] do
14
14
  json.variant do
15
15
  json.partial!("spree/api/variants/small", variant: inventory_unit.variant)
16
16
  json.(inventory_unit.variant, :product_id)
17
- json.images(inventory_unit.variant.images) do |image|
17
+ json.images(inventory_unit.variant.gallery.images) do |image|
18
18
  json.partial!("spree/api/images/image", image: image)
19
19
  end
20
20
  end
@@ -17,7 +17,7 @@ json.cache! [I18n.locale, variant] do
17
17
  json.option_values(variant.option_values) do |option_value|
18
18
  json.(option_value, *option_value_attributes)
19
19
  end
20
- json.images(variant.images) do |image|
20
+ json.images(variant.gallery.images) do |image|
21
21
  json.partial!("spree/api/images/image", image: image)
22
22
  end
23
23
  end
data/config/routes.rb CHANGED
@@ -35,9 +35,7 @@ Spree::Core::Engine.routes.draw do
35
35
 
36
36
  resources :return_authorizations do
37
37
  member do
38
- put :add
39
38
  put :cancel
40
- put :receive
41
39
  end
42
40
  end
43
41
  end
@@ -69,6 +67,8 @@ Spree::Core::Engine.routes.draw do
69
67
  put :empty
70
68
  put :apply_coupon_code
71
69
  end
70
+
71
+ resources :coupon_codes, only: [:create, :destroy]
72
72
  end
73
73
 
74
74
  resources :zones
data/solidus_api.gemspec CHANGED
@@ -21,7 +21,7 @@ Gem::Specification.new do |gem|
21
21
  gem.required_ruby_version = '>= 2.2.2'
22
22
  gem.required_rubygems_version = '>= 1.8.23'
23
23
 
24
- gem.add_dependency 'jbuilder', '~> 2.6'
24
+ gem.add_dependency 'jbuilder', '~> 2.8'
25
25
  gem.add_dependency 'kaminari-activerecord', '~> 1.1'
26
26
  gem.add_dependency 'responders'
27
27
  gem.add_dependency 'solidus_core', gem.version
@@ -52,7 +52,7 @@ describe Spree::Api::BaseController, type: :controller do
52
52
  end
53
53
 
54
54
  it "with an invalid API key" do
55
- request.headers["X-Spree-Token"] = "fake_key"
55
+ request.headers["Authorization"] = "Bearer fake_key"
56
56
  get :index, params: {}
57
57
  expect(json_response).to eq({ "error" => "Invalid API key (fake_key) specified." })
58
58
  expect(response.status).to eq(401)
@@ -62,7 +62,7 @@ module Spree
62
62
 
63
63
  def add_promotion(_promotion)
64
64
  expect {
65
- put "/api/orders/#{@order.number}/apply_coupon_code",
65
+ post "/api/orders/#{@order.number}/coupon_codes",
66
66
  params: { coupon_code: promotion_code.value }
67
67
  }.to change { @order.promotions.count }.by 1
68
68
  expect(response).to have_http_status(:ok)
@@ -143,10 +143,6 @@ module Spree
143
143
  0 => { variant_id: variant_1.id, quantity: 2 },
144
144
  1 => { variant_id: variant_2.id, quantity: 2 }
145
145
  },
146
- # Would like to do this, but the save process from the orders controller
147
- # does not actually call what it needs to to apply this coupon code :(
148
- # coupon_code: promotion.code,
149
-
150
146
  # Would like to do this, but it puts the payment in a complete state,
151
147
  # which the order does not like when transitioning from confirm to complete
152
148
  # since it looks to process pending payments.
@@ -175,10 +171,6 @@ module Spree
175
171
  0 => { variant_id: variant_1.id, quantity: 2 },
176
172
  1 => { variant_id: variant_2.id, quantity: 2 }
177
173
  },
178
- # Would like to do this, but the save process from the orders controller
179
- # does not actually call what it needs to to apply this coupon code :(
180
- # coupon_code: promotion.code,
181
-
182
174
  # Would like to do this, but it puts the payment in a complete state,
183
175
  # which the order does not like when transitioning from confirm to complete
184
176
  # since it looks to process pending payments.
@@ -41,7 +41,7 @@ module Spree
41
41
  user.save_in_address_book(ron_address_attributes, false)
42
42
 
43
43
  get "/api/users/#{user.id}/address_book",
44
- headers: { 'X-SPREE-TOKEN' => 'galleon' }
44
+ headers: { Authorization: 'Bearer galleon' }
45
45
 
46
46
  json_response = JSON.parse(response.body)
47
47
  expect(response.status).to eq(200)
@@ -60,7 +60,7 @@ module Spree
60
60
  expect {
61
61
  put "/api/users/#{user.id}/address_book",
62
62
  params: { address_book: harry_address_attributes.merge('id' => address.id) },
63
- headers: { 'X-SPREE-TOKEN' => 'galleon' }
63
+ headers: { Authorization: 'Bearer galleon' }
64
64
  }.to change { UserAddress.count }.from(1).to(2)
65
65
 
66
66
  expect(response.status).to eq(200)
@@ -74,7 +74,7 @@ module Spree
74
74
  expect {
75
75
  put "/api/users/#{user.id}/address_book",
76
76
  params: { address_book: harry_address_attributes },
77
- headers: { 'X-SPREE-TOKEN' => 'galleon' }
77
+ headers: { Authorization: 'Bearer galleon' }
78
78
  }.to change { UserAddress.count }.by(1)
79
79
 
80
80
  user_address = UserAddress.last
@@ -93,7 +93,7 @@ module Spree
93
93
  expect {
94
94
  put "/api/users/#{user.id}/address_book",
95
95
  params: { address_book: harry_address_attributes },
96
- headers: { 'X-SPREE-TOKEN' => 'galleon' }
96
+ headers: { Authorization: 'Bearer galleon' }
97
97
  }.to_not change { UserAddress.count }
98
98
 
99
99
  expect(response.status).to eq(200)
@@ -110,7 +110,7 @@ module Spree
110
110
  expect {
111
111
  delete "/api/users/#{user.id}/address_book",
112
112
  params: { address_id: address.id },
113
- headers: { 'X-SPREE-TOKEN' => 'galleon' }
113
+ headers: { Authorization: 'Bearer galleon' }
114
114
  }.to change { user.reload.user_addresses.count }.from(1).to(0)
115
115
 
116
116
  expect(response.status).to eq(200)
@@ -131,7 +131,7 @@ module Spree
131
131
  other_user.save_in_address_book(ron_address_attributes, false)
132
132
 
133
133
  get "/api/users/#{other_user.id}/address_book",
134
- headers: { 'X-SPREE-TOKEN' => 'galleon' }
134
+ headers: { Authorization: 'Bearer galleon' }
135
135
 
136
136
  json_response = JSON.parse(response.body)
137
137
  expect(response.status).to eq(200)
@@ -150,7 +150,7 @@ module Spree
150
150
  expect {
151
151
  put "/api/users/#{other_user.id}/address_book",
152
152
  params: { address_book: updated_harry_address.merge('id' => address.id) },
153
- headers: { 'X-SPREE-TOKEN' => 'galleon' }
153
+ headers: { Authorization: 'Bearer galleon' }
154
154
  }.to change { UserAddress.count }.from(1).to(2)
155
155
 
156
156
  expect(response.status).to eq(200)
@@ -165,7 +165,7 @@ module Spree
165
165
  expect {
166
166
  delete "/api/users/#{other_user.id}/address_book",
167
167
  params: { address_id: address.id },
168
- headers: { 'X-SPREE-TOKEN' => 'galleon' }
168
+ headers: { Authorization: 'Bearer galleon' }
169
169
  }.to change { other_user.reload.user_addresses.count }.from(1).to(0)
170
170
 
171
171
  expect(response.status).to eq(200)
@@ -179,7 +179,7 @@ module Spree
179
179
  other_user.save_in_address_book(harry_address_attributes, true)
180
180
 
181
181
  get "/api/users/#{other_user.id}/address_book",
182
- headers: { 'X-SPREE-TOKEN' => 'galleon' }
182
+ headers: { Authorization: 'Bearer galleon' }
183
183
 
184
184
  expect(response.status).to eq(401)
185
185
  end
@@ -193,7 +193,7 @@ module Spree
193
193
  expect {
194
194
  put "/api/users/#{other_user.id}/address_book",
195
195
  params: { address_book: other_user_address.attributes.merge('address1' => 'Hogwarts') },
196
- headers: { 'X-SPREE-TOKEN' => 'galleon' }
196
+ headers: { Authorization: 'Bearer galleon' }
197
197
  }.not_to change { UserAddress.count }
198
198
 
199
199
  expect(response.status).to eq(401)
@@ -208,7 +208,7 @@ module Spree
208
208
  expect {
209
209
  delete "/api/users/#{other_user.id}/address_book",
210
210
  params: { address_id: address.id },
211
- headers: { 'X-SPREE-TOKEN' => 'galleon' }
211
+ headers: { Authorization: 'Bearer galleon' }
212
212
  }.not_to change { other_user.user_addresses.count }
213
213
 
214
214
  expect(response.status).to eq(401)
@@ -357,6 +357,7 @@ module Spree
357
357
  end
358
358
 
359
359
  it "can apply a coupon code to an order" do
360
+ expect(Spree::Deprecation).to receive(:warn)
360
361
  order.update_column(:state, "payment")
361
362
  expect(PromotionHandler::Coupon).to receive(:new).with(order).and_call_original
362
363
  expect_any_instance_of(PromotionHandler::Coupon).to receive(:apply).and_return({ coupon_applied?: true })
@@ -365,6 +366,7 @@ module Spree
365
366
  end
366
367
 
367
368
  it "renders error failing to apply coupon" do
369
+ expect(Spree::Deprecation).to receive(:warn)
368
370
  order.update_column(:state, "payment")
369
371
  put spree.api_checkout_path(order.to_param), params: { order_token: order.guest_token, order: { coupon_code: "foobar" } }
370
372
  expect(response.status).to eq(422)
@@ -0,0 +1,105 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ module Spree
6
+ describe Api::CouponCodesController, type: :request do
7
+ let(:current_api_user) do
8
+ user = Spree.user_class.new(email: "spree@example.com")
9
+ user.generate_spree_api_key!
10
+ user
11
+ end
12
+
13
+ before do
14
+ stub_authentication!
15
+ end
16
+
17
+ describe '#create' do
18
+ let(:promo) { create(:promotion_with_item_adjustment, code: 'night_melody') }
19
+ let(:promo_code) { promo.codes.first }
20
+
21
+ before do
22
+ allow_any_instance_of(Order).to receive_messages user: current_api_user
23
+ end
24
+
25
+ context 'when successful' do
26
+ let(:order) { create(:order_with_line_items) }
27
+
28
+ it 'applies the coupon' do
29
+ post spree.api_order_coupon_codes_path(order), params: { coupon_code: promo_code.value }
30
+
31
+ expect(response.status).to eq(200)
32
+ expect(order.reload.promotions).to eq([promo])
33
+ expect(json_response).to eq({
34
+ "success" => I18n.t('spree.coupon_code_applied'),
35
+ "error" => nil,
36
+ "successful" => true,
37
+ "status_code" => "coupon_code_applied"
38
+ })
39
+ end
40
+ end
41
+
42
+ context 'when unsuccessful' do
43
+ let(:order) { create(:order) }
44
+
45
+ it 'returns an error' do
46
+ post spree.api_order_coupon_codes_path(order), params: { coupon_code: promo_code.value }
47
+
48
+ expect(response.status).to eq(422)
49
+ expect(order.reload.promotions).to eq([])
50
+ expect(json_response).to eq({
51
+ "success" => nil,
52
+ "error" => I18n.t('spree.coupon_code_unknown_error'),
53
+ "successful" => false,
54
+ "status_code" => "coupon_code_unknown_error"
55
+ })
56
+ end
57
+ end
58
+ end
59
+
60
+ describe '#destroy' do
61
+ let(:promo) {
62
+ create(:promotion_with_item_adjustment,
63
+ code: 'tenoff',
64
+ per_code_usage_limit: 5,
65
+ adjustment_rate: 10)
66
+ }
67
+
68
+ let(:promo_code) { promo.codes.first }
69
+ let(:order) { create(:order_with_line_items, user: current_api_user) }
70
+
71
+ before do
72
+ post spree.api_order_coupon_codes_path(order), params: { coupon_code: promo_code.value }
73
+ delete spree.api_order_coupon_code_path(order, promo_code.value)
74
+ end
75
+
76
+ context 'when successful' do
77
+ it 'removes the coupon' do
78
+ expect(response.status).to eq(200)
79
+ expect(order.reload.promotions).to eq([])
80
+ expect(json_response).to eq({
81
+ "success" => I18n.t('spree.coupon_code_removed'),
82
+ "error" => nil,
83
+ "successful" => true,
84
+ "status_code" => "coupon_code_removed"
85
+ })
86
+ end
87
+ end
88
+
89
+ context 'when unsuccessful' do
90
+ it 'returns an error' do
91
+ delete spree.api_order_coupon_code_path(order, promo_code.value)
92
+
93
+ expect(response.status).to eq(422)
94
+ expect(order.reload.promotions).to eq([])
95
+ expect(json_response).to eq({
96
+ "success" => nil,
97
+ "error" => I18n.t('spree.coupon_code_not_present'),
98
+ "successful" => false,
99
+ "status_code" => "coupon_code_not_present"
100
+ })
101
+ end
102
+ end
103
+ end
104
+ end
105
+ end
@@ -81,7 +81,9 @@ module Spree
81
81
  end
82
82
 
83
83
  it "can add a new line item to an existing order with options" do
84
- expect_any_instance_of(LineItem).to receive(:some_option=).with("foobar")
84
+ without_partial_double_verification do
85
+ expect_any_instance_of(LineItem).to receive(:some_option=).with("foobar")
86
+ end
85
87
  post spree.api_order_line_items_path(order),
86
88
  params: {
87
89
  line_item: {
@@ -121,7 +123,9 @@ module Spree
121
123
  end
122
124
 
123
125
  it "can update a line item's options on the order" do
124
- expect_any_instance_of(LineItem).to receive(:some_option=).with("foobar")
126
+ without_partial_double_verification do
127
+ expect_any_instance_of(LineItem).to receive(:some_option=).with("foobar")
128
+ end
125
129
  line_item = order.line_items.first
126
130
  put spree.api_order_line_item_path(order, line_item),
127
131
  params: {
@@ -421,7 +421,9 @@ module Spree
421
421
 
422
422
  # Regression test for https://github.com/spree/spree/issues/3404
423
423
  it "can specify additional parameters for a line item" do
424
- expect_any_instance_of(Spree::LineItem).to receive(:special=).with("foo")
424
+ without_partial_double_verification do
425
+ expect_any_instance_of(Spree::LineItem).to receive(:special=).with("foo")
426
+ end
425
427
 
426
428
  allow_any_instance_of(Spree::Api::OrdersController).to receive_messages(permitted_line_item_attributes: [:id, :variant_id, :quantity, :special])
427
429
  post spree.api_orders_path, params: {
@@ -854,6 +856,8 @@ module Spree
854
856
  let(:order) { create(:order_with_line_items) }
855
857
 
856
858
  it 'applies the coupon' do
859
+ expect(Spree::Deprecation).to receive(:warn)
860
+
857
861
  put spree.apply_coupon_code_api_order_path(order), params: { coupon_code: promo_code.value }
858
862
 
859
863
  expect(response.status).to eq 200
@@ -871,6 +875,8 @@ module Spree
871
875
  let(:order) { create(:order) } # no line items to apply the code to
872
876
 
873
877
  it 'returns an error' do
878
+ expect(Spree::Deprecation).to receive(:warn)
879
+
874
880
  put spree.apply_coupon_code_api_order_path(order), params: { coupon_code: promo_code.value }
875
881
 
876
882
  expect(response.status).to eq 422
@@ -20,7 +20,7 @@ module Spree::Api
20
20
 
21
21
  it "can apply a coupon code to the order" do
22
22
  expect(order.total).to eq(110.00)
23
- put spree.apply_coupon_code_api_order_path(order), params: { coupon_code: "10off", order_token: order.guest_token }
23
+ post spree.api_order_coupon_codes_path(order), params: { coupon_code: "10off", order_token: order.guest_token }
24
24
  expect(response.status).to eq(200)
25
25
  expect(order.reload.total).to eq(109.00)
26
26
  expect(json_response["success"]).to eq("The coupon code was successfully applied to your order.")
@@ -37,7 +37,7 @@ module Spree::Api
37
37
  end
38
38
 
39
39
  it "fails to apply" do
40
- put spree.apply_coupon_code_api_order_path(order), params: { coupon_code: "10off", order_token: order.guest_token }
40
+ post spree.api_order_coupon_codes_path(order), params: { coupon_code: "10off", order_token: order.guest_token }
41
41
  expect(response.status).to eq(422)
42
42
  expect(json_response["success"]).to be_blank
43
43
  expect(json_response["error"]).to eq("The coupon code is expired")
@@ -262,7 +262,7 @@ describe Spree::Api::ShipmentsController, type: :request do
262
262
 
263
263
  it "returns success" do
264
264
  subject
265
- expect(response).to be_success
265
+ expect(response).to be_successful
266
266
  end
267
267
 
268
268
  it "returns rates available to user" do
@@ -7,7 +7,7 @@ describe Spree::Api::StoreCreditEventsController, type: :request do
7
7
 
8
8
  describe "GET mine" do
9
9
  subject do
10
- get spree.mine_api_store_credit_events_path(format: :json), headers: { 'X-Spree-Token' => api_key }
10
+ get spree.mine_api_store_credit_events_path(format: :json), headers: { Authorization: "Bearer #{api_key}" }
11
11
  end
12
12
 
13
13
  context "no current api user" do
@@ -4,16 +4,14 @@ require 'spec_helper'
4
4
 
5
5
  module Spree
6
6
  describe Api::TaxonsController, type: :request do
7
- let(:taxonomy) { create(:taxonomy) }
8
- let(:taxon) { create(:taxon, name: "Ruby", taxonomy: taxonomy) }
9
- let(:taxon2) { create(:taxon, name: "Rails", taxonomy: taxonomy) }
7
+ let!(:taxonomy) { create(:taxonomy) }
8
+ let!(:taxon) { create(:taxon, name: "Ruby", parent: taxonomy.root, taxonomy: taxonomy) }
9
+ let!(:taxon2) { create(:taxon, name: "Rails", parent: taxon, taxonomy: taxonomy) }
10
+ let!(:rails_v3_2_2) { create(:taxon, name: "3.2.2", parent: taxon2, taxonomy: taxonomy) }
10
11
  let(:attributes) { ["id", "name", "pretty_name", "permalink", "parent_id", "taxonomy_id"] }
11
12
 
12
13
  before do
13
14
  stub_authentication!
14
- taxon2.children << create(:taxon, name: "3.2.2", taxonomy: taxonomy)
15
- taxon.children << taxon2
16
- taxonomy.root.children << taxon
17
15
  end
18
16
 
19
17
  context "as a normal user" do
@@ -85,6 +83,24 @@ module Spree
85
83
  end
86
84
  end
87
85
 
86
+ context 'filtering by taxon ids' do
87
+ it 'returns only requested id' do
88
+ get spree.api_taxons_path, params: { ids: [rails_v3_2_2.id] }
89
+
90
+ expect(json_response['taxons'].size).to eq 1
91
+ end
92
+
93
+ it 'returns only requested ids' do
94
+ # We need a completly new branch to avoid having parent that can be preloaded from the rails ancestors
95
+ python = create(:taxon, name: "Python", parent: taxonomy.root, taxonomy: taxonomy)
96
+ python_3 = create(:taxon, name: "3.0", parent: python, taxonomy: taxonomy)
97
+
98
+ get spree.api_taxons_path, params: { ids: [rails_v3_2_2.id, python_3.id] }
99
+
100
+ expect(json_response['taxons'].size).to eq 2
101
+ end
102
+ end
103
+
88
104
  it "gets a single taxon" do
89
105
  get spree.api_taxonomy_taxon_path(taxonomy, taxon.id)
90
106
 
data/spec/spec_helper.rb CHANGED
@@ -26,6 +26,7 @@ require 'with_model'
26
26
  # in spec/support/ and its subdirectories.
27
27
  Dir[File.dirname(__FILE__) + "/support/**/*.rb"].each { |f| require f }
28
28
 
29
+ require 'spree/testing_support/partial_double_verification'
29
30
  require 'spree/testing_support/factories'
30
31
  require 'spree/testing_support/preferences'
31
32
  require 'spree/testing_support/authorization_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: 2.7.4
4
+ version: 2.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Solidus Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-10-23 00:00:00.000000000 Z
11
+ date: 2019-01-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jbuilder
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '2.6'
19
+ version: '2.8'
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.6'
26
+ version: '2.8'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: kaminari-activerecord
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - '='
60
60
  - !ruby/object:Gem::Version
61
- version: 2.7.4
61
+ version: 2.8.0
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - '='
67
67
  - !ruby/object:Gem::Version
68
- version: 2.7.4
68
+ version: 2.8.0
69
69
  description: REST API for the Solidus e-commerce framework.
70
70
  email: contact@solidus.io
71
71
  executables: []
@@ -83,6 +83,7 @@ files:
83
83
  - app/controllers/spree/api/classifications_controller.rb
84
84
  - app/controllers/spree/api/config_controller.rb
85
85
  - app/controllers/spree/api/countries_controller.rb
86
+ - app/controllers/spree/api/coupon_codes_controller.rb
86
87
  - app/controllers/spree/api/credit_cards_controller.rb
87
88
  - app/controllers/spree/api/images_controller.rb
88
89
  - app/controllers/spree/api/inventory_units_controller.rb
@@ -251,6 +252,7 @@ files:
251
252
  - spec/requests/spree/api/classifications_controller_spec.rb
252
253
  - spec/requests/spree/api/config_controller_spec.rb
253
254
  - spec/requests/spree/api/countries_controller_spec.rb
255
+ - spec/requests/spree/api/coupon_codes_controller_spec.rb
254
256
  - spec/requests/spree/api/credit_cards_controller_spec.rb
255
257
  - spec/requests/spree/api/images_controller_spec.rb
256
258
  - spec/requests/spree/api/inventory_units_controller_spec.rb
@@ -307,7 +309,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
307
309
  - !ruby/object:Gem::Version
308
310
  version: 1.8.23
309
311
  requirements: []
310
- rubygems_version: 3.0.6
312
+ rubyforge_project:
313
+ rubygems_version: 2.7.3
311
314
  signing_key:
312
315
  specification_version: 4
313
316
  summary: REST API for the Solidus e-commerce framework.
@@ -325,6 +328,7 @@ test_files:
325
328
  - spec/requests/spree/api/classifications_controller_spec.rb
326
329
  - spec/requests/spree/api/config_controller_spec.rb
327
330
  - spec/requests/spree/api/countries_controller_spec.rb
331
+ - spec/requests/spree/api/coupon_codes_controller_spec.rb
328
332
  - spec/requests/spree/api/credit_cards_controller_spec.rb
329
333
  - spec/requests/spree/api/images_controller_spec.rb
330
334
  - spec/requests/spree/api/inventory_units_controller_spec.rb