solidus_api 1.0.7 → 1.1.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.

Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/spree/api/address_books_controller.rb +38 -0
  3. data/app/controllers/spree/api/addresses_controller.rb +19 -15
  4. data/app/controllers/spree/api/base_controller.rb +7 -28
  5. data/app/controllers/spree/api/checkouts_controller.rb +17 -8
  6. data/app/controllers/spree/api/option_values_controller.rb +1 -1
  7. data/app/controllers/spree/api/orders_controller.rb +13 -18
  8. data/app/controllers/spree/api/payments_controller.rb +0 -1
  9. data/app/controllers/spree/api/resource_controller.rb +75 -0
  10. data/app/controllers/spree/api/shipments_controller.rb +1 -0
  11. data/app/controllers/spree/api/stock_items_controller.rb +1 -3
  12. data/app/controllers/spree/api/stock_transfers_controller.rb +1 -0
  13. data/app/controllers/spree/api/users_controller.rb +13 -49
  14. data/app/controllers/spree/api/zones_controller.rb +7 -3
  15. data/app/helpers/spree/api/api_helpers.rb +9 -4
  16. data/app/views/spree/api/address_books/show.v1.rabl +4 -0
  17. data/app/views/spree/api/orders/show.v1.rabl +2 -2
  18. data/app/views/spree/api/variants/big.v1.rabl +3 -0
  19. data/config/locales/en.yml +0 -1
  20. data/config/routes.rb +3 -0
  21. data/lib/spree/api/testing_support/helpers.rb +1 -1
  22. data/lib/spree/api/testing_support/setup.rb +1 -4
  23. data/spec/controllers/spree/api/address_books_controller_spec.rb +60 -0
  24. data/spec/controllers/spree/api/addresses_controller_spec.rb +22 -9
  25. data/spec/controllers/spree/api/base_controller_spec.rb +0 -12
  26. data/spec/controllers/spree/api/checkouts_controller_spec.rb +107 -45
  27. data/spec/controllers/spree/api/credit_cards_controller_spec.rb +4 -11
  28. data/spec/controllers/spree/api/orders_controller_spec.rb +75 -105
  29. data/spec/controllers/spree/api/payments_controller_spec.rb +0 -11
  30. data/spec/controllers/spree/api/products_controller_spec.rb +2 -2
  31. data/spec/controllers/spree/api/resource_controller_spec.rb +157 -0
  32. data/spec/controllers/spree/api/shipments_controller_spec.rb +12 -13
  33. data/spec/controllers/spree/api/stock_items_controller_spec.rb +2 -2
  34. data/spec/controllers/spree/api/users_controller_spec.rb +2 -2
  35. data/spec/controllers/spree/api/variants_controller_spec.rb +32 -3
  36. data/spec/models/spree/legacy_user_spec.rb +8 -2
  37. data/spec/spec_helper.rb +8 -3
  38. data/spec/test_views/spree/api/widgets/index.v1.rabl +7 -0
  39. data/spec/test_views/spree/api/widgets/new.v1.rabl +2 -0
  40. data/spec/test_views/spree/api/widgets/show.v1.rabl +2 -0
  41. metadata +20 -9
  42. data/CHANGELOG.md +0 -1
  43. data/app/views/spree/api/shared/stock_location_required.v1.rabl +0 -2
@@ -38,9 +38,9 @@ describe Spree::Api::ShipmentsController, :type => :controller do
38
38
  shipment: { order_id: order.number },
39
39
  stock_location_id: stock_location.to_param
40
40
  }
41
- end
42
-
43
- subject do
41
+ end
42
+
43
+ subject do
44
44
  api_post :create, params
45
45
  end
46
46
 
@@ -139,18 +139,17 @@ describe Spree::Api::ShipmentsController, :type => :controller do
139
139
 
140
140
  describe '#mine' do
141
141
  subject do
142
- api_get :mine, format: 'json', params: params
142
+ api_get :mine, params
143
143
  end
144
144
 
145
145
  let(:params) { {} }
146
146
 
147
- before { subject }
148
-
149
147
  context "the current api user is authenticated and has orders" do
150
148
  let(:current_api_user) { shipped_order.user }
151
149
  let(:shipped_order) { create(:shipped_order) }
152
150
 
153
151
  it 'succeeds' do
152
+ subject
154
153
  expect(response.status).to eq 200
155
154
  end
156
155
 
@@ -160,6 +159,7 @@ describe Spree::Api::ShipmentsController, :type => :controller do
160
159
  let(:rendered_shipment_ids) { json_response['shipments'].map { |s| s['id'] } }
161
160
 
162
161
  it 'contains the shipments' do
162
+ subject
163
163
  expect(rendered_shipment_ids).to match_array current_api_user.orders.flat_map(&:shipments).map(&:id)
164
164
  end
165
165
  end
@@ -167,9 +167,10 @@ describe Spree::Api::ShipmentsController, :type => :controller do
167
167
  context 'with filtering' do
168
168
  let(:params) { {q: {order_completed_at_not_null: 1}} }
169
169
 
170
- let!(:incomplete_order) { create(:order, user: current_api_user) }
170
+ let!(:incomplete_order) { create(:order_with_line_items, user: current_api_user) }
171
171
 
172
172
  it 'filters' do
173
+ subject
173
174
  expect(assigns(:shipments).map(&:id)).to match_array current_api_user.orders.complete.flat_map(&:shipments).map(&:id)
174
175
  end
175
176
  end
@@ -179,6 +180,7 @@ describe Spree::Api::ShipmentsController, :type => :controller do
179
180
  let(:current_api_user) { nil }
180
181
 
181
182
  it "returns a 401" do
183
+ subject
182
184
  expect(response.status).to eq(401)
183
185
  end
184
186
  end
@@ -205,8 +207,7 @@ describe Spree::Api::ShipmentsController, :type => :controller do
205
207
 
206
208
  context "send_mailer not present" do
207
209
  it "sends the shipped shipments mailer" do
208
- with_test_mail { subject }
209
- expect(ActionMailer::Base.deliveries.size).to eq 1
210
+ expect { subject }.to change { ActionMailer::Base.deliveries.size }.by(1)
210
211
  expect(ActionMailer::Base.deliveries.last.subject).to match /Shipment Notification/
211
212
  end
212
213
  end
@@ -214,16 +215,14 @@ describe Spree::Api::ShipmentsController, :type => :controller do
214
215
  context "send_mailer set to false" do
215
216
  let(:send_mailer) { 'false' }
216
217
  it "does not send the shipped shipments mailer" do
217
- with_test_mail { subject }
218
- expect(ActionMailer::Base.deliveries.size).to eq 0
218
+ expect { subject }.to_not change { ActionMailer::Base.deliveries.size }
219
219
  end
220
220
  end
221
221
 
222
222
  context "send_mailer set to true" do
223
223
  let(:send_mailer) { 'true' }
224
224
  it "sends the shipped shipments mailer" do
225
- with_test_mail { subject }
226
- expect(ActionMailer::Base.deliveries.size).to eq 1
225
+ expect { subject }.to change { ActionMailer::Base.deliveries.size }.by(1)
227
226
  expect(ActionMailer::Base.deliveries.last.subject).to match /Shipment Notification/
228
227
  end
229
228
  end
@@ -55,7 +55,7 @@ module Spree
55
55
  }
56
56
 
57
57
  api_post :create, params
58
- expect(response.status).to eq(404)
58
+ expect(response.status).to eq(401)
59
59
  end
60
60
  end
61
61
 
@@ -85,7 +85,7 @@ module Spree
85
85
 
86
86
  it 'requires a stock_location_id to be passed as a parameter' do
87
87
  api_get :index
88
- expect(json_response['error']).to match(/stock_location_id parameter must be provided/)
88
+ expect(json_response['exception']).to eq('param is missing or the value is empty: stock_location_id')
89
89
  expect(response.status).to eq(422)
90
90
  end
91
91
 
@@ -78,9 +78,9 @@ module Spree
78
78
  assert_not_found!
79
79
  end
80
80
 
81
- it "can delete itself" do
81
+ it "cannot delete itself" do
82
82
  api_delete :destroy, id: user.id, token: user.spree_api_key
83
- expect(response.status).to eq(204)
83
+ expect(response.status).to eq(401)
84
84
  end
85
85
 
86
86
  it "cannot delete other user" do
@@ -12,7 +12,7 @@ module Spree
12
12
  end
13
13
 
14
14
  let!(:base_attributes) { Api::ApiHelpers.variant_attributes }
15
- let!(:show_attributes) { base_attributes.dup.push(:in_stock, :display_price) }
15
+ let!(:show_attributes) { base_attributes.dup.push(:in_stock, :display_price, :variant_properties) }
16
16
  let!(:new_attributes) { base_attributes }
17
17
 
18
18
  before do
@@ -143,8 +143,10 @@ module Spree
143
143
 
144
144
  describe "#show" do
145
145
 
146
+ subject { api_get :show, id: variant.to_param }
147
+
146
148
  it "can see a single variant" do
147
- api_get :show, :id => variant.to_param
149
+ subject
148
150
  expect(json_response).to have_attributes(show_attributes)
149
151
  expect(json_response["stock_items"]).to be_present
150
152
  option_values = json_response["option_values"]
@@ -157,7 +159,7 @@ module Spree
157
159
  it "can see a single variant with images" do
158
160
  variant.images.create!(:attachment => image("thinking-cat.jpg"))
159
161
 
160
- api_get :show, :id => variant.to_param
162
+ subject
161
163
 
162
164
  expect(json_response).to have_attributes(show_attributes + [:images])
163
165
  option_values = json_response["option_values"]
@@ -166,6 +168,33 @@ module Spree
166
168
  :option_type_name,
167
169
  :option_type_id])
168
170
  end
171
+
172
+ context "variant doesn't have variant properties" do
173
+ before { subject }
174
+
175
+ it "contains the expected attributes" do
176
+ expect(json_response).to have_attributes(show_attributes)
177
+ end
178
+
179
+ it "variant properties is an empty list" do
180
+ expect(json_response["variant_properties"]).to eq []
181
+ end
182
+ end
183
+
184
+ context "variant has variant properties" do
185
+ let!(:rule) { create(:variant_property_rule, product: variant.product, option_value: variant.option_values.first) }
186
+
187
+ before { subject }
188
+
189
+ it "contains the expected attributes" do
190
+ expect(json_response).to have_attributes(show_attributes)
191
+ end
192
+
193
+ it "variant properties is an array of variant property values" do
194
+ expected_attrs = [:id, :property_id, :value, :property_name]
195
+ expect(json_response["variant_properties"].first).to have_attributes(expected_attrs)
196
+ end
197
+ end
169
198
  end
170
199
 
171
200
  it "can learn how to create a new variant" do
@@ -15,9 +15,15 @@ module Spree
15
15
  end
16
16
 
17
17
  it "can clear an API key" do
18
+ user.spree_api_key = 'abc123'
18
19
  expect(user).to receive(:save!)
19
- user.clear_spree_api_key!
20
- expect(user.spree_api_key).to be_blank
20
+ expect { user.clear_spree_api_key! }.to change(user, :spree_api_key).to be_blank
21
+ end
22
+
23
+ it "can clear an api key without persisting" do
24
+ user.spree_api_key = 'abc123'
25
+ expect(user).not_to receive(:save!)
26
+ expect { user.clear_spree_api_key }.to change(user, :spree_api_key).to be_blank
21
27
  end
22
28
 
23
29
  context "admin role auto-api-key grant" do # so the admin user can do admin api actions
@@ -30,8 +30,6 @@ 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/mail'
34
- require 'spree/testing_support/authorization_helpers'
35
33
 
36
34
  require 'spree/api/testing_support/caching'
37
35
  require 'spree/api/testing_support/helpers'
@@ -41,12 +39,19 @@ RSpec.configure do |config|
41
39
  config.backtrace_exclusion_patterns = [/gems\/activesupport/, /gems\/actionpack/, /gems\/rspec/]
42
40
  config.color = true
43
41
  config.infer_spec_type_from_file_location!
42
+ config.expect_with :rspec do |c|
43
+ c.syntax = :expect
44
+ end
45
+ config.mock_with :rspec do |c|
46
+ c.syntax = :expect
47
+ end
44
48
 
45
49
  config.include FactoryGirl::Syntax::Methods
46
50
  config.include Spree::Api::TestingSupport::Helpers, :type => :controller
47
51
  config.extend Spree::Api::TestingSupport::Setup, :type => :controller
48
52
  config.include Spree::TestingSupport::Preferences
49
- config.include Spree::TestingSupport::Mail
53
+
54
+ config.extend WithModel
50
55
 
51
56
  config.fail_fast = ENV['FAIL_FAST'] || false
52
57
 
@@ -0,0 +1,7 @@
1
+ object false
2
+ child(@collection => :widgets) do
3
+ extends "spree/api/widgets/show"
4
+ end
5
+ node(:count) { @collection.count }
6
+ node(:current_page) { params[:page] || 1 }
7
+ node(:pages) { @collection.num_pages }
@@ -0,0 +1,2 @@
1
+ object false
2
+ node(:attributes) { [:name] }
@@ -0,0 +1,2 @@
1
+ object @object
2
+ attributes :name, :position
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.0.7
4
+ version: 1.1.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: 2017-12-12 00:00:00.000000000 Z
11
+ date: 2015-09-30 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.0.7
19
+ version: 1.1.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: 1.0.7
26
+ version: 1.1.0.beta1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rabl
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -65,10 +65,10 @@ extensions: []
65
65
  extra_rdoc_files: []
66
66
  files:
67
67
  - ".gitignore"
68
- - CHANGELOG.md
69
68
  - Gemfile
70
69
  - LICENSE
71
70
  - Rakefile
71
+ - app/controllers/spree/api/address_books_controller.rb
72
72
  - app/controllers/spree/api/addresses_controller.rb
73
73
  - app/controllers/spree/api/base_controller.rb
74
74
  - app/controllers/spree/api/checkouts_controller.rb
@@ -87,6 +87,7 @@ files:
87
87
  - app/controllers/spree/api/products_controller.rb
88
88
  - app/controllers/spree/api/promotions_controller.rb
89
89
  - app/controllers/spree/api/properties_controller.rb
90
+ - app/controllers/spree/api/resource_controller.rb
90
91
  - app/controllers/spree/api/return_authorizations_controller.rb
91
92
  - app/controllers/spree/api/shipments_controller.rb
92
93
  - app/controllers/spree/api/states_controller.rb
@@ -105,6 +106,7 @@ files:
105
106
  - app/helpers/spree/api/api_helpers.rb
106
107
  - app/models/spree/api_configuration.rb
107
108
  - app/models/spree/option_value_decorator.rb
109
+ - app/views/spree/api/address_books/show.v1.rabl
108
110
  - app/views/spree/api/addresses/show.v1.rabl
109
111
  - app/views/spree/api/adjustments/show.v1.rabl
110
112
  - app/views/spree/api/config/money.v1.rabl
@@ -157,7 +159,6 @@ files:
157
159
  - app/views/spree/api/return_authorizations/index.v1.rabl
158
160
  - app/views/spree/api/return_authorizations/new.v1.rabl
159
161
  - app/views/spree/api/return_authorizations/show.v1.rabl
160
- - app/views/spree/api/shared/stock_location_required.v1.rabl
161
162
  - app/views/spree/api/shipments/big.v1.rabl
162
163
  - app/views/spree/api/shipments/cannot_ready_shipment.v1.rabl
163
164
  - app/views/spree/api/shipments/mine.v1.rabl
@@ -214,6 +215,7 @@ files:
214
215
  - lib/spree_api.rb
215
216
  - script/rails
216
217
  - solidus_api.gemspec
218
+ - spec/controllers/spree/api/address_books_controller_spec.rb
217
219
  - spec/controllers/spree/api/addresses_controller_spec.rb
218
220
  - spec/controllers/spree/api/base_controller_spec.rb
219
221
  - spec/controllers/spree/api/checkouts_controller_spec.rb
@@ -233,6 +235,7 @@ files:
233
235
  - spec/controllers/spree/api/promotion_application_spec.rb
234
236
  - spec/controllers/spree/api/promotions_controller_spec.rb
235
237
  - spec/controllers/spree/api/properties_controller_spec.rb
238
+ - spec/controllers/spree/api/resource_controller_spec.rb
236
239
  - spec/controllers/spree/api/return_authorizations_controller_spec.rb
237
240
  - spec/controllers/spree/api/shipments_controller_spec.rb
238
241
  - spec/controllers/spree/api/states_controller_spec.rb
@@ -259,6 +262,9 @@ files:
259
262
  - spec/support/controller_hacks.rb
260
263
  - spec/support/database_cleaner.rb
261
264
  - spec/support/have_attributes_matcher.rb
265
+ - spec/test_views/spree/api/widgets/index.v1.rabl
266
+ - spec/test_views/spree/api/widgets/new.v1.rabl
267
+ - spec/test_views/spree/api/widgets/show.v1.rabl
262
268
  homepage: http://solidus.io/
263
269
  licenses: []
264
270
  metadata: {}
@@ -273,16 +279,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
273
279
  version: '0'
274
280
  required_rubygems_version: !ruby/object:Gem::Requirement
275
281
  requirements:
276
- - - ">="
282
+ - - ">"
277
283
  - !ruby/object:Gem::Version
278
- version: '0'
284
+ version: 1.3.1
279
285
  requirements: []
280
286
  rubyforge_project:
281
- rubygems_version: 2.6.11
287
+ rubygems_version: 2.4.5
282
288
  signing_key:
283
289
  specification_version: 4
284
290
  summary: REST API for the Solidus e-commerce framework.
285
291
  test_files:
292
+ - spec/controllers/spree/api/address_books_controller_spec.rb
286
293
  - spec/controllers/spree/api/addresses_controller_spec.rb
287
294
  - spec/controllers/spree/api/base_controller_spec.rb
288
295
  - spec/controllers/spree/api/checkouts_controller_spec.rb
@@ -302,6 +309,7 @@ test_files:
302
309
  - spec/controllers/spree/api/promotion_application_spec.rb
303
310
  - spec/controllers/spree/api/promotions_controller_spec.rb
304
311
  - spec/controllers/spree/api/properties_controller_spec.rb
312
+ - spec/controllers/spree/api/resource_controller_spec.rb
305
313
  - spec/controllers/spree/api/return_authorizations_controller_spec.rb
306
314
  - spec/controllers/spree/api/shipments_controller_spec.rb
307
315
  - spec/controllers/spree/api/states_controller_spec.rb
@@ -328,3 +336,6 @@ test_files:
328
336
  - spec/support/controller_hacks.rb
329
337
  - spec/support/database_cleaner.rb
330
338
  - spec/support/have_attributes_matcher.rb
339
+ - spec/test_views/spree/api/widgets/index.v1.rabl
340
+ - spec/test_views/spree/api/widgets/new.v1.rabl
341
+ - spec/test_views/spree/api/widgets/show.v1.rabl
@@ -1 +0,0 @@
1
- ## Spree 2.4.0 (unreleased) ##
@@ -1,2 +0,0 @@
1
- object false
2
- node(:error) { I18n.t(:stock_location_required, scope: "spree.api") }