solidus_api 1.0.0.pre → 1.0.0.pre2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of solidus_api might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8f7e1c99f480436edbb45f9d9e3d946879794a7f
4
- data.tar.gz: 8cca45deec26d1b9f7dcbf03eb66f2dfb0f8ba01
3
+ metadata.gz: 3552a542c49a1c8586fe3765f8e477a4d267a8d8
4
+ data.tar.gz: 31fb98454ac818493d461e32d2a2a5357d3bdb14
5
5
  SHA512:
6
- metadata.gz: 54ddece7d71fafe19fdb104acd90b823ca011dd2fdec6c0e6df56e3a396994336fa1d2adb973a18b51ef5b07ef5bc49ed3e32494ea2be31b1f99fc990bf9b5bc
7
- data.tar.gz: a7ff37cb7e28ffe0a6bbedb442a79256997cbf504623ae0f48b98fdb8dcc261236aa0f153bbf20d328352cb582f90dd683cfea90cad8025034ae7794681c1c68
6
+ metadata.gz: 06ed20f3ea44a9015f32606e3192f4a8591568665c6211ea642e145437d751aa0ddc65ff720a4ffa8444f5105de0a4f92b8ae68331428676ac5c4373f7e87550
7
+ data.tar.gz: fa71e4ecc89775eda5afcb323faa90efcdccf9fa08e91ab2b67cbe05bb833c7ede57f714373cef706b299a9db377b6b8e623edb70293d37fa3f563eec8db1299
@@ -184,6 +184,16 @@ module Spree
184
184
  render text: e.message, status: 409
185
185
  end
186
186
 
187
+ def insufficient_stock_error(exception)
188
+ render(
189
+ json: {
190
+ errors: [I18n.t(:quantity_is_not_available, :scope => "spree.api.order")],
191
+ type: 'insufficient_stock',
192
+ },
193
+ status: 422,
194
+ )
195
+ end
196
+
187
197
  end
188
198
  end
189
199
  end
@@ -124,10 +124,6 @@ module Spree
124
124
  return true if expected_total.blank?
125
125
  @order.total == BigDecimal(expected_total)
126
126
  end
127
-
128
- def insufficient_stock_error(exception)
129
- render json: { errors: [I18n.t(:quantity_is_not_available, :scope => "spree.api.order")], type: 'insufficient_stock' }, status: 422
130
- end
131
127
  end
132
128
  end
133
129
  end
@@ -4,6 +4,8 @@ module Spree
4
4
  before_filter :load_order
5
5
  around_filter :lock_order, only: [:create, :update, :destroy, :add, :receive, :cancel]
6
6
 
7
+ rescue_from Spree::Order::InsufficientStock, with: :insufficient_stock_error
8
+
7
9
  def create
8
10
  authorize! :create, ReturnAuthorization
9
11
  @return_authorization = @order.return_authorizations.build(return_authorization_params)
@@ -66,16 +66,20 @@ module Spree
66
66
  quantity = params[:quantity].to_i
67
67
 
68
68
  @shipment.order.contents.add(variant, quantity, {shipment: @shipment})
69
-
70
69
  respond_with(@shipment, default_template: :show)
71
70
  end
72
71
 
73
72
  def remove
74
73
  quantity = params[:quantity].to_i
75
74
 
76
- @shipment.order.contents.remove(variant, quantity, {shipment: @shipment})
77
- @shipment.reload if @shipment.persisted?
78
- respond_with(@shipment, default_template: :show)
75
+ if @shipment.pending?
76
+ @shipment.order.contents.remove(variant, quantity, {shipment: @shipment})
77
+ @shipment.reload if @shipment.persisted?
78
+ respond_with(@shipment, default_template: :show)
79
+ else
80
+ @shipment.errors.add(:base, :cannot_remove_items_shipment_state, state: @shipment.state)
81
+ invalid_resource!(@shipment)
82
+ end
79
83
  end
80
84
 
81
85
  def transfer_to_location
@@ -85,7 +89,7 @@ module Spree
85
89
  end
86
90
 
87
91
  def transfer_to_shipment
88
- @target_shipment = Spree::Shipment.find_by!(number: params[:target_shipment_number])
92
+ @target_shipment = Spree::Shipment.find_by!(number: params[:target_shipment_number])
89
93
  @original_shipment.transfer_to_shipment(@variant, @quantity, @target_shipment)
90
94
  render json: {success: true, message: Spree.t(:shipment_transfer_success)}, status: 201
91
95
  end
@@ -8,22 +8,10 @@ module Spree
8
8
  else
9
9
  super
10
10
  end
11
-
12
- rescue ActionView::MissingTemplate
13
- api_behavior
14
11
  end
15
12
 
16
13
  def template
17
- request.headers['X-Spree-Template'] || controller.params[:template] || options[:default_template]
18
- end
19
-
20
- def api_behavior
21
- if controller.params[:action] == "destroy"
22
- # Render a blank template
23
- super
24
- else
25
- # Do nothing and fallback to the default template
26
- end
14
+ options[:default_template]
27
15
  end
28
16
  end
29
17
  end
data/solidus_api.gemspec CHANGED
@@ -4,9 +4,10 @@ version = File.read(File.expand_path("../../SOLIDUS_VERSION", __FILE__)).strip
4
4
  Gem::Specification.new do |gem|
5
5
  gem.author = 'Solidus Team'
6
6
  gem.email = 'contact@solidus.io'
7
- gem.description = %q{Spree's API}
8
- gem.summary = %q{Spree's API}
9
- gem.homepage = ""
7
+ gem.homepage = 'http://solidus.io/'
8
+
9
+ gem.summary = %q{REST API for the Solidus e-commerce framework.}
10
+ gem.description = gem.summary
10
11
 
11
12
  gem.files = `git ls-files`.split($\)
12
13
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
@@ -6,6 +6,8 @@ end
6
6
  describe Spree::Api::BaseController, :type => :controller do
7
7
  render_views
8
8
  controller(Spree::Api::BaseController) do
9
+ rescue_from Spree::Order::InsufficientStock, with: :insufficient_stock_error
10
+
9
11
  def index
10
12
  render :text => { "products" => [] }.to_json
11
13
  end
@@ -131,6 +133,24 @@ describe Spree::Api::BaseController, :type => :controller do
131
133
  end
132
134
  end
133
135
 
136
+ context 'insufficient stock' do
137
+ before do
138
+ subject.should_receive(:authenticate_user).and_return(true)
139
+ subject.should_receive(:index).and_raise(Spree::Order::InsufficientStock)
140
+ get :index, :token => "fake_key"
141
+ end
142
+
143
+ it "should return a 422" do
144
+ expect(response.status).to eq(422)
145
+ end
146
+
147
+ it "returns an error message" do
148
+ expect(json_response).to eq(
149
+ {"errors" => ["Quantity is not available for items in your order"], "type" => "insufficient_stock"}
150
+ )
151
+ end
152
+ end
153
+
134
154
  context 'lock_order' do
135
155
  let!(:order) { create :order }
136
156
 
@@ -347,26 +347,6 @@ module Spree
347
347
  end
348
348
  end
349
349
  end
350
-
351
- context 'insufficient stock' do
352
- let(:order) { create(:order_with_line_items) }
353
- before do
354
- expect_any_instance_of(Spree::Order).to receive(:next!).and_raise(Spree::Order::InsufficientStock)
355
- end
356
-
357
- subject { api_put :next, :id => order.to_param, :order_token => order.guest_token }
358
-
359
- it "should return a 422" do
360
- expect(subject.status).to eq(422)
361
- end
362
-
363
- it "returns an error message" do
364
- subject
365
- expect(JSON.parse(response.body)).to eq(
366
- {"errors" => ["Quantity is not available for items in your order"], "type" => "insufficient_stock"}
367
- )
368
- end
369
- end
370
350
  end
371
351
 
372
352
  context "PUT 'advance'" do
@@ -318,20 +318,7 @@ module Spree
318
318
  :country_id => country.id} }
319
319
  let(:country) { create(:country, {name: "Brazil", iso_name: "BRAZIL", iso: "BR", iso3: "BRA", numcode: 76 })}
320
320
 
321
- before do
322
- allow_any_instance_of(Order).to receive_messages user: current_api_user
323
- order.next # Switch from cart to address
324
- order.bill_address = nil
325
- order.ship_address = nil
326
- order.save
327
- expect(order.state).to eq("address")
328
- end
329
-
330
- def clean_address(address)
331
- address.delete(:state)
332
- address.delete(:country)
333
- address
334
- end
321
+ before { allow_any_instance_of(Order).to receive_messages user: current_api_user }
335
322
 
336
323
  context "line_items hash not present in request" do
337
324
  it "responds successfully" do
@@ -401,15 +388,16 @@ module Spree
401
388
  end
402
389
 
403
390
  it "can add shipping address" do
404
- expect(order.ship_address).to be_nil
405
-
406
- api_put :update, :id => order.to_param, :order => { :ship_address_attributes => shipping_address }
391
+ order.update_attributes!(ship_address_id: nil)
407
392
 
408
- expect(order.reload.ship_address).not_to be_nil
393
+ expect {
394
+ api_put :update, :id => order.to_param, :order => { :ship_address_attributes => shipping_address }
395
+ }.to change { order.reload.ship_address }.from(nil)
409
396
  end
410
397
 
411
398
  it "receives error message if trying to add shipping address with errors" do
412
- expect(order.ship_address).to be_nil
399
+ order.update_attributes!(ship_address_id: nil)
400
+
413
401
  shipping_address[:firstname] = ""
414
402
 
415
403
  api_put :update, :id => order.to_param, :order => { :ship_address_attributes => shipping_address }
@@ -442,19 +430,15 @@ module Spree
442
430
  end
443
431
 
444
432
  context "with a line item" do
445
- let(:order_with_line_items) do
446
- order = create(:order_with_line_items)
447
- create(:adjustment, order: order, adjustable: order)
448
- order
449
- end
433
+ let(:order) { create(:order_with_line_items) }
450
434
 
451
435
  it "can empty an order" do
452
- expect(order_with_line_items.adjustments.count).to eq(1)
453
- api_put :empty, :id => order_with_line_items.to_param
436
+ create(:adjustment, order: order, adjustable: order)
437
+ api_put :empty, :id => order.to_param
454
438
  expect(response.status).to eq(204)
455
- order_with_line_items.reload
456
- expect(order_with_line_items.line_items).to be_empty
457
- expect(order_with_line_items.adjustments).to be_empty
439
+ order.reload
440
+ expect(order.line_items).to be_empty
441
+ expect(order.adjustments).to be_empty
458
442
  end
459
443
 
460
444
  it "can list its line items with images" do
@@ -516,8 +500,6 @@ module Spree
516
500
  end
517
501
 
518
502
  before do
519
- order.bill_address = FactoryGirl.create(:address)
520
- order.ship_address = FactoryGirl.create(:address)
521
503
  order.next!
522
504
  order.save
523
505
  end
@@ -67,44 +67,6 @@ module Spree
67
67
  expect(json_response["per_page"]).to eq(Kaminari.config.default_per_page)
68
68
  end
69
69
 
70
- context "specifying a rabl template for a custom action" do
71
- before do
72
- Spree::Api::ProductsController.class_eval do
73
- def custom_show
74
- @product = find_product(params[:id])
75
- respond_with(@product)
76
- end
77
- end
78
- end
79
-
80
- def set_custom_route
81
- @routes = ActionDispatch::Routing::RouteSet.new.tap do |r|
82
- r.draw { get 'custom_show' => 'spree/api/products#custom_show' }
83
- end
84
- end
85
-
86
- it "uses the specified custom template through the request header" do
87
- set_custom_route
88
-
89
- request.headers['X-Spree-Template'] = 'show'
90
- api_get :custom_show, :id => product.id
91
- expect(response).to render_template('spree/api/products/show')
92
- end
93
-
94
- it "uses the specified custom template through the template URL parameter" do
95
- set_custom_route
96
-
97
- api_get :custom_show, :id => product.id, :template => 'show'
98
- expect(response).to render_template('spree/api/products/show')
99
- end
100
-
101
- it "falls back to the default template if the specified template does not exist" do
102
- request.headers['X-Spree-Template'] = 'invoice'
103
- api_get :show, :id => product.id
104
- expect(response).to render_template('spree/api/products/show')
105
- end
106
- end
107
-
108
70
  context "product has more than one price" do
109
71
  before { product.master.prices.create currency: "EUR", amount: 22 }
110
72
 
@@ -394,8 +356,8 @@ module Spree
394
356
  expect(json_response['variants'].count).to eq(2) # 2 variants
395
357
 
396
358
  variants = json_response['variants'].select { |v| !v['is_master'] }
397
- expect(variants.last['option_values'][0]['name']).to eq('small')
398
- expect(variants.last['option_values'][0]['option_type_name']).to eq('size')
359
+ size_option_value = variants.last['option_values'].detect{|x| x['option_type_name'] == 'size' }
360
+ expect(size_option_value['name']).to eq('small')
399
361
 
400
362
  expect(json_response['option_types'].count).to eq(2) # size, color
401
363
  end
@@ -17,9 +17,9 @@ module Spree
17
17
  shared_examples_for 'a return authorization creator' do
18
18
  it "can create a new return authorization" do
19
19
  stock_location = FactoryGirl.create(:stock_location)
20
- reason = FactoryGirl.create(:return_authorization_reason)
20
+ reason = FactoryGirl.create(:return_reason)
21
21
  rma_params = { :stock_location_id => stock_location.id,
22
- :return_authorization_reason_id => reason.id,
22
+ :return_reason_id => reason.id,
23
23
  :memo => "Defective" }
24
24
  api_post :create, :order_id => order.number, :return_authorization => rma_params
25
25
  response.status.should == 201
@@ -91,7 +91,7 @@ describe Spree::Api::ShipmentsController, :type => :controller do
91
91
  expect(response.status).to eq(422)
92
92
  end
93
93
 
94
- context 'for completed shipments' do
94
+ context 'for completed orders' do
95
95
  let(:order) { create :completed_order_with_totals }
96
96
  let!(:resource_scoping) { { id: order.shipments.first.to_param, shipment: { order_id: order.to_param } } }
97
97
 
@@ -119,6 +119,24 @@ describe Spree::Api::ShipmentsController, :type => :controller do
119
119
  end
120
120
  end
121
121
 
122
+ context "for shipped shipments" do
123
+ let(:order) { create :shipped_order }
124
+ let!(:resource_scoping) { { id: order.shipments.first.to_param, shipment: { order_id: order.to_param } } }
125
+
126
+ it 'adds a variant to a shipment' do
127
+ api_put :add, { variant_id: variant.to_param, quantity: 2 }
128
+ response.status.should == 200
129
+ json_response['manifest'].detect { |h| h['variant']['id'] == variant.id }["quantity"].should == 2
130
+ end
131
+
132
+ it 'cannot remove a variant from a shipment' do
133
+ api_put :remove, { variant_id: variant.to_param, quantity: 1 }
134
+ response.status.should == 422
135
+ expect(json_response['errors']['base'].join).to match /Cannot remove items/
136
+ end
137
+
138
+ end
139
+
122
140
  describe '#mine' do
123
141
  subject do
124
142
  api_get :mine, format: 'json', params: params
@@ -38,32 +38,6 @@ module Spree
38
38
  expect(json_response['zone_members'].size).to eq @zone.zone_members.count
39
39
  end
40
40
 
41
- context "specifying a rabl template to use" do
42
- before do
43
- Spree::Api::ZonesController.class_eval do
44
- def custom_show
45
- respond_with(zone)
46
- end
47
- end
48
- end
49
-
50
- it "uses the specified template" do
51
- @routes = ActionDispatch::Routing::RouteSet.new.tap do |r|
52
- r.draw { get 'custom_show' => 'spree/api/zones#custom_show' }
53
- end
54
-
55
- request.headers['X-Spree-Template'] = 'show'
56
- api_get :custom_show, :id => @zone.id
57
- expect(response).to render_template('spree/api/zones/show')
58
- end
59
-
60
- it "falls back to the default template if the specified template does not exist" do
61
- request.headers['X-Spree-Template'] = 'invoice'
62
- api_get :show, :id => @zone.id
63
- expect(response).to render_template('spree/api/zones/show')
64
- end
65
- end
66
-
67
41
  context "as an admin" do
68
42
  sign_in_as_admin!
69
43
 
data/spec/spec_helper.rb CHANGED
@@ -57,4 +57,10 @@ RSpec.configure do |config|
57
57
  end
58
58
 
59
59
  config.use_transactional_fixtures = true
60
+
61
+ config.example_status_persistence_file_path = "./spec/examples.txt"
62
+
63
+ config.order = :random
64
+
65
+ Kernel.srand config.seed
60
66
  end
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.0.pre
4
+ version: 1.0.0.pre2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Solidus Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-29 00:00:00.000000000 Z
11
+ date: 2015-07-20 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.0.pre
19
+ version: 1.0.0.pre2
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.0.pre
26
+ version: 1.0.0.pre2
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rabl
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -58,7 +58,7 @@ dependencies:
58
58
  - - "~>"
59
59
  - !ruby/object:Gem::Version
60
60
  version: 2.3.1
61
- description: Spree's API
61
+ description: REST API for the Solidus e-commerce framework.
62
62
  email: contact@solidus.io
63
63
  executables: []
64
64
  extensions: []
@@ -202,7 +202,6 @@ files:
202
202
  - app/views/spree/api/variants/small.v1.rabl
203
203
  - app/views/spree/api/zones/index.v1.rabl
204
204
  - app/views/spree/api/zones/show.v1.rabl
205
- - config/initializers/metal_load_paths.rb
206
205
  - config/locales/en.yml
207
206
  - config/routes.rb
208
207
  - db/migrate/20100107141738_add_api_key_to_spree_users.rb
@@ -264,7 +263,7 @@ files:
264
263
  - spec/support/controller_hacks.rb
265
264
  - spec/support/database_cleaner.rb
266
265
  - spec/support/have_attributes_matcher.rb
267
- homepage: ''
266
+ homepage: http://solidus.io/
268
267
  licenses: []
269
268
  metadata: {}
270
269
  post_install_message:
@@ -283,10 +282,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
283
282
  version: 1.3.1
284
283
  requirements: []
285
284
  rubyforge_project:
286
- rubygems_version: 2.2.0
285
+ rubygems_version: 2.4.5
287
286
  signing_key:
288
287
  specification_version: 4
289
- summary: Spree's API
288
+ summary: REST API for the Solidus e-commerce framework.
290
289
  test_files:
291
290
  - spec/controllers/spree/api/addresses_controller_spec.rb
292
291
  - spec/controllers/spree/api/base_controller_spec.rb
@@ -1 +0,0 @@
1
- Spree::Api::BaseController.append_view_path(ApplicationController.view_paths)