spree_api 2.1.12 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +51 -1
  3. data/app/controllers/spree/api/addresses_controller.rb +25 -10
  4. data/app/controllers/spree/api/base_controller.rb +18 -29
  5. data/app/controllers/spree/api/checkouts_controller.rb +23 -29
  6. data/app/controllers/spree/api/classifications_controller.rb +18 -0
  7. data/app/controllers/spree/api/line_items_controller.rb +13 -1
  8. data/app/controllers/spree/api/option_types_controller.rb +2 -2
  9. data/app/controllers/spree/api/option_values_controller.rb +1 -1
  10. data/app/controllers/spree/api/orders_controller.rb +12 -34
  11. data/app/controllers/spree/api/products_controller.rb +22 -23
  12. data/app/controllers/spree/api/taxons_controller.rb +9 -0
  13. data/app/controllers/spree/api/variants_controller.rb +1 -1
  14. data/app/helpers/spree/api/api_helpers.rb +5 -3
  15. data/app/models/spree/order_decorator.rb +2 -11
  16. data/app/views/spree/api/line_items/show.v1.rabl +4 -0
  17. data/app/views/spree/api/orders/order.v1.rabl +0 -1
  18. data/app/views/spree/api/products/show.v1.rabl +7 -10
  19. data/app/views/spree/api/promotions/handler.v1.rabl +4 -0
  20. data/app/views/spree/api/variants/index.v1.rabl +1 -1
  21. data/app/views/spree/api/variants/show.v1.rabl +2 -3
  22. data/app/views/spree/api/variants/variant.v1.rabl +2 -0
  23. data/app/views/spree/api/variants/{big_variant.v1.rabl → variant_full.v1.rabl} +0 -0
  24. data/config/routes.rb +6 -4
  25. data/lib/spree/api/controller_setup.rb +0 -1
  26. data/lib/spree/api/testing_support/helpers.rb +1 -0
  27. data/spec/controllers/spree/api/addresses_controller_spec.rb +57 -31
  28. data/spec/controllers/spree/api/base_controller_spec.rb +0 -36
  29. data/spec/controllers/spree/api/checkouts_controller_spec.rb +8 -41
  30. data/spec/controllers/spree/api/classifications_controller_spec.rb +38 -0
  31. data/spec/controllers/spree/api/line_items_controller_spec.rb +10 -21
  32. data/spec/controllers/spree/api/option_values_controller_spec.rb +0 -7
  33. data/spec/controllers/spree/api/orders_controller_spec.rb +24 -121
  34. data/spec/controllers/spree/api/products_controller_spec.rb +26 -48
  35. data/spec/controllers/spree/api/promotion_application_spec.rb +48 -0
  36. data/spec/controllers/spree/api/shipments_controller_spec.rb +1 -22
  37. data/spec/controllers/spree/api/unauthenticated_products_controller_spec.rb +1 -1
  38. data/spec/controllers/spree/api/users_controller_spec.rb +3 -2
  39. data/spec/controllers/spree/api/variants_controller_spec.rb +13 -7
  40. data/spec/models/spree/order_spec.rb +3 -28
  41. metadata +12 -7
  42. data/app/views/spree/api/orders/apply_coupon_code.v1.rabl +0 -7
@@ -0,0 +1,48 @@
1
+ require 'spec_helper'
2
+
3
+ module Spree::Api
4
+ describe OrdersController do
5
+ render_views
6
+
7
+ before do
8
+ stub_authentication!
9
+ end
10
+
11
+ context "with an available promotion" do
12
+ let!(:order) { create(:order_with_line_items, :line_items_count => 1) }
13
+ let!(:promotion) do
14
+ promotion = Spree::Promotion.create(name: "10% off", code: "10off")
15
+ calculator = Spree::Calculator::FlatPercentItemTotal.create(preferred_flat_percent: "10")
16
+ action = Spree::Promotion::Actions::CreateItemAdjustments.create(calculator: calculator)
17
+ promotion.actions << action
18
+ promotion
19
+ end
20
+
21
+ it "can apply a coupon code to the order" do
22
+ order.total.should == 110.00
23
+ api_put :apply_coupon_code, :id => order.to_param, :coupon_code => "10off", :order_token => order.token
24
+ response.status.should == 200
25
+ order.reload.total.should == 109.00
26
+ json_response["success"].should == "The coupon code was successfully applied to your order."
27
+ json_response["error"].should be_blank
28
+ json_response["successful"].should be_true
29
+ end
30
+
31
+ context "with an expired promotion" do
32
+ before do
33
+ promotion.starts_at = 2.weeks.ago
34
+ promotion.expires_at = 1.week.ago
35
+ promotion.save
36
+ end
37
+
38
+ it "fails to apply" do
39
+ api_put :apply_coupon_code, :id => order.to_param, :coupon_code => "10off", :order_token => order.token
40
+ response.status.should == 422
41
+ json_response["success"].should be_blank
42
+ json_response["error"].should == "The coupon code is expired"
43
+ json_response["successful"].should be_false
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -52,28 +52,7 @@ describe Spree::Api::ShipmentsController do
52
52
  response.status.should == 200
53
53
  json_response['stock_location_name'].should == stock_location.name
54
54
  end
55
-
56
- it "can unlock a shipment's adjustment when updating" do
57
- Spree::Calculator::FlatRate.any_instance.stub(:preferred_amount => 5)
58
- adjustment = order.adjustments.create(amount: 1, label: 'shipping')
59
- adjustment.source = shipment
60
- adjustment.originator = shipment.shipping_method
61
- adjustment.save!
62
-
63
- params = {
64
- order_id: order.number,
65
- id: order.shipments.first.to_param,
66
- shipment: {
67
- unlock: 'yes'
68
- }
69
- }
70
-
71
- api_put :update, params
72
- response.status.should == 200
73
- json_response.should have_attributes(attributes)
74
- shipment.reload.adjustment.amount.should == 5
75
- end
76
-
55
+
77
56
  it "can make a shipment ready" do
78
57
  Spree::Order.any_instance.stub(:paid? => true, :complete? => true)
79
58
  api_put :ready
@@ -6,7 +6,7 @@ module Spree
6
6
  render_views
7
7
 
8
8
  let!(:product) { create(:product) }
9
- let(:attributes) { [:id, :name, :description, :price, :available_on, :permalink, :meta_description, :meta_keywords, :taxon_ids] }
9
+ let(:attributes) { [:id, :name, :description, :price, :available_on, :slug, :meta_description, :meta_keywords, :taxon_ids] }
10
10
 
11
11
  context "without authentication" do
12
12
  before { Spree::Api::Config[:requires_authentication] = false }
@@ -12,7 +12,8 @@ module Spree
12
12
 
13
13
  context "as a normal user" do
14
14
  before do
15
- controller.stub :try_spree_current_user => user
15
+ Spree::LegacyUser.stub(:find_by).with(hash_including(:spree_api_key)) { user }
16
+ Spree::LegacyUser.stub :find_by_spree_api_key => user
16
17
  end
17
18
 
18
19
  it "can get own details" do
@@ -79,7 +80,7 @@ module Spree
79
80
  sign_in_as_admin!
80
81
 
81
82
  it "gets all users" do
82
- Spree::LegacyUser.stub :find_by_spree_api_key => current_api_user
83
+ Spree::LegacyUser.stub(:find_by).with(hash_including(:spree_api_key)) { current_api_user }
83
84
 
84
85
  2.times { create(:user) }
85
86
 
@@ -10,7 +10,10 @@ module Spree
10
10
  variant.option_values << create(:option_value)
11
11
  variant
12
12
  end
13
- let!(:attributes) { Api::ApiHelpers.variant_attributes }
13
+
14
+ let!(:base_attributes) { Api::ApiHelpers.variant_attributes }
15
+ let!(:show_attributes) { base_attributes.dup.push(:in_stock, :display_price) }
16
+ let!(:new_attributes) { base_attributes }
14
17
 
15
18
  before do
16
19
  stub_authentication!
@@ -18,7 +21,9 @@ module Spree
18
21
 
19
22
  it "can see a paginated list of variants" do
20
23
  api_get :index
21
- json_response["variants"].first.should have_attributes(attributes)
24
+ first_variant = json_response["variants"].first
25
+ first_variant.should have_attributes(show_attributes)
26
+ first_variant["stock_items"].should be_present
22
27
  json_response["count"].should == 1
23
28
  json_response["current_page"].should == 1
24
29
  json_response["pages"].should == 1
@@ -77,7 +82,7 @@ module Spree
77
82
  it "can select the next page of variants" do
78
83
  second_variant = create(:variant)
79
84
  api_get :index, :page => 2, :per_page => 1
80
- json_response["variants"].first.should have_attributes(attributes)
85
+ json_response["variants"].first.should have_attributes(show_attributes)
81
86
  json_response["total_count"].should == 3
82
87
  json_response["current_page"].should == 2
83
88
  json_response["pages"].should == 3
@@ -86,7 +91,8 @@ module Spree
86
91
 
87
92
  it "can see a single variant" do
88
93
  api_get :show, :id => variant.to_param
89
- json_response.should have_attributes(attributes)
94
+ json_response.should have_attributes(show_attributes)
95
+ json_response["stock_items"].should be_present
90
96
  option_values = json_response["option_values"]
91
97
  option_values.first.should have_attributes([:name,
92
98
  :presentation,
@@ -99,7 +105,7 @@ module Spree
99
105
 
100
106
  api_get :show, :id => variant.to_param
101
107
 
102
- json_response.should have_attributes(attributes + [:images])
108
+ json_response.should have_attributes(show_attributes + [:images])
103
109
  option_values = json_response["option_values"]
104
110
  option_values.first.should have_attributes([:name,
105
111
  :presentation,
@@ -109,7 +115,7 @@ module Spree
109
115
 
110
116
  it "can learn how to create a new variant" do
111
117
  api_get :new
112
- json_response["attributes"].should == attributes.map(&:to_s)
118
+ json_response["attributes"].should == new_attributes.map(&:to_s)
113
119
  json_response["required_attributes"].should be_empty
114
120
  end
115
121
 
@@ -147,7 +153,7 @@ module Spree
147
153
 
148
154
  it "can create a new variant" do
149
155
  api_post :create, :variant => { :sku => "12345" }
150
- json_response.should have_attributes(attributes)
156
+ json_response.should have_attributes(new_attributes)
151
157
  response.status.should == 201
152
158
  json_response["sku"].should == "12345"
153
159
 
@@ -8,7 +8,7 @@ module Spree
8
8
 
9
9
  let(:user) { stub_model(LegacyUser, :email => 'fox@mudler.com') }
10
10
  let(:shipping_method) { create(:shipping_method) }
11
- let(:payment_method) { create(:payment_method) }
11
+ let(:payment_method) { create(:check_payment_method) }
12
12
 
13
13
  let(:product) { product = Spree::Product.create(:name => 'Test',
14
14
  :sku => 'TEST-1',
@@ -206,7 +206,7 @@ module Spree
206
206
  end
207
207
  end
208
208
 
209
- context "shippments" do
209
+ context "shipments" do
210
210
  let(:params) do
211
211
  { :shipments_attributes => [
212
212
  { :tracking => '123456789',
@@ -258,7 +258,7 @@ module Spree
258
258
  { label: 'Promotion Discount', amount: -3.00 }] }
259
259
 
260
260
  order = Order.build_from_api(user, params)
261
- order.adjustments.all?(&:finalized?).should be_true
261
+ order.adjustments.all?(&:closed?).should be_true
262
262
  order.adjustments.first.label.should eq 'Shipping Discount'
263
263
  order.adjustments.first.amount.should eq -4.99
264
264
  end
@@ -297,30 +297,5 @@ module Spree
297
297
  expect(Order.count).to eq count
298
298
  end
299
299
  end
300
-
301
- context "import param and tax adjustments" do
302
- let!(:tax_rate) { create(:tax_rate, amount: 0.05, calculator: Calculator::DefaultTax.create) }
303
- let(:other_variant) { create(:variant) }
304
-
305
- let(:line_item_attributes) do
306
- line_items.merge({ "1" => { :variant_id => other_variant.id, :quantity => 5 }})
307
- end
308
-
309
- before { Zone.stub default_tax: tax_rate.zone }
310
-
311
- it "doesnt create any tax ajustments when importing order" do
312
- params = { import: true, line_items_attributes: line_item_attributes }
313
- expect {
314
- Order.build_from_api(user, params)
315
- }.not_to change { Adjustment.count }
316
- end
317
-
318
- it "does create tax adjustments if not importing order" do
319
- params = { import: false, line_items_attributes: line_item_attributes }
320
- expect {
321
- Order.build_from_api(user, params)
322
- }.to change { Adjustment.count }
323
- end
324
- end
325
300
  end
326
301
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spree_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.12
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Bigg
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-23 00:00:00.000000000 Z
11
+ date: 2014-02-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: spree_core
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 2.1.12
19
+ version: 2.2.0
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.1.12
26
+ version: 2.2.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rabl
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -67,6 +67,7 @@ files:
67
67
  - app/controllers/spree/api/addresses_controller.rb
68
68
  - app/controllers/spree/api/base_controller.rb
69
69
  - app/controllers/spree/api/checkouts_controller.rb
70
+ - app/controllers/spree/api/classifications_controller.rb
70
71
  - app/controllers/spree/api/config_controller.rb
71
72
  - app/controllers/spree/api/countries_controller.rb
72
73
  - app/controllers/spree/api/images_controller.rb
@@ -119,7 +120,6 @@ files:
119
120
  - app/views/spree/api/option_values/index.v1.rabl
120
121
  - app/views/spree/api/option_values/show.v1.rabl
121
122
  - app/views/spree/api/orders/address.v1.rabl
122
- - app/views/spree/api/orders/apply_coupon_code.v1.rabl
123
123
  - app/views/spree/api/orders/canceled.v1.rabl
124
124
  - app/views/spree/api/orders/cart.v1.rabl
125
125
  - app/views/spree/api/orders/complete.v1.rabl
@@ -144,6 +144,7 @@ files:
144
144
  - app/views/spree/api/products/new.v1.rabl
145
145
  - app/views/spree/api/products/product.v1.rabl
146
146
  - app/views/spree/api/products/show.v1.rabl
147
+ - app/views/spree/api/promotions/handler.v1.rabl
147
148
  - app/views/spree/api/properties/index.v1.rabl
148
149
  - app/views/spree/api/properties/new.v1.rabl
149
150
  - app/views/spree/api/properties/show.v1.rabl
@@ -175,11 +176,11 @@ files:
175
176
  - app/views/spree/api/users/index.v1.rabl
176
177
  - app/views/spree/api/users/new.v1.rabl
177
178
  - app/views/spree/api/users/show.v1.rabl
178
- - app/views/spree/api/variants/big_variant.v1.rabl
179
179
  - app/views/spree/api/variants/index.v1.rabl
180
180
  - app/views/spree/api/variants/new.v1.rabl
181
181
  - app/views/spree/api/variants/show.v1.rabl
182
182
  - app/views/spree/api/variants/variant.v1.rabl
183
+ - app/views/spree/api/variants/variant_full.v1.rabl
183
184
  - app/views/spree/api/zones/index.v1.rabl
184
185
  - app/views/spree/api/zones/show.v1.rabl
185
186
  - config/initializers/metal_load_paths.rb
@@ -202,6 +203,7 @@ files:
202
203
  - spec/controllers/spree/api/addresses_controller_spec.rb
203
204
  - spec/controllers/spree/api/base_controller_spec.rb
204
205
  - spec/controllers/spree/api/checkouts_controller_spec.rb
206
+ - spec/controllers/spree/api/classifications_controller_spec.rb
205
207
  - spec/controllers/spree/api/config_controller_spec.rb
206
208
  - spec/controllers/spree/api/countries_controller_spec.rb
207
209
  - spec/controllers/spree/api/images_controller_spec.rb
@@ -213,6 +215,7 @@ files:
213
215
  - spec/controllers/spree/api/payments_controller_spec.rb
214
216
  - spec/controllers/spree/api/product_properties_controller_spec.rb
215
217
  - spec/controllers/spree/api/products_controller_spec.rb
218
+ - spec/controllers/spree/api/promotion_application_spec.rb
216
219
  - spec/controllers/spree/api/properties_controller_spec.rb
217
220
  - spec/controllers/spree/api/return_authorizations_controller_spec.rb
218
221
  - spec/controllers/spree/api/shipments_controller_spec.rb
@@ -254,7 +257,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
254
257
  version: '0'
255
258
  requirements: []
256
259
  rubyforge_project:
257
- rubygems_version: 2.2.2
260
+ rubygems_version: 2.2.0
258
261
  signing_key:
259
262
  specification_version: 4
260
263
  summary: Spree's API
@@ -262,6 +265,7 @@ test_files:
262
265
  - spec/controllers/spree/api/addresses_controller_spec.rb
263
266
  - spec/controllers/spree/api/base_controller_spec.rb
264
267
  - spec/controllers/spree/api/checkouts_controller_spec.rb
268
+ - spec/controllers/spree/api/classifications_controller_spec.rb
265
269
  - spec/controllers/spree/api/config_controller_spec.rb
266
270
  - spec/controllers/spree/api/countries_controller_spec.rb
267
271
  - spec/controllers/spree/api/images_controller_spec.rb
@@ -273,6 +277,7 @@ test_files:
273
277
  - spec/controllers/spree/api/payments_controller_spec.rb
274
278
  - spec/controllers/spree/api/product_properties_controller_spec.rb
275
279
  - spec/controllers/spree/api/products_controller_spec.rb
280
+ - spec/controllers/spree/api/promotion_application_spec.rb
276
281
  - spec/controllers/spree/api/properties_controller_spec.rb
277
282
  - spec/controllers/spree/api/return_authorizations_controller_spec.rb
278
283
  - spec/controllers/spree/api/shipments_controller_spec.rb
@@ -1,7 +0,0 @@
1
- object @coupon_result
2
-
3
- # Mimic of eventual payload in Spree Core to keep contract the same when we upgrade.
4
- # https://github.com/spree/spree/blob/master/api/app/views/spree/api/promotions/handler.v1.rabl
5
- node(:success) { @coupon_result.success }
6
- node(:error) { @coupon_result.error }
7
- node(:successful) { @coupon_result.coupon_applied? }