spree_api 2.3.13 → 2.4.0.rc1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +1 -43
  3. data/Gemfile +1 -1
  4. data/app/controllers/spree/api/addresses_controller.rb +1 -1
  5. data/app/controllers/spree/api/base_controller.rb +22 -9
  6. data/app/controllers/spree/api/checkouts_controller.rb +2 -2
  7. data/app/controllers/spree/api/countries_controller.rb +2 -2
  8. data/app/controllers/spree/api/credit_cards_controller.rb +1 -1
  9. data/app/controllers/spree/api/images_controller.rb +5 -0
  10. data/app/controllers/spree/api/inventory_units_controller.rb +1 -1
  11. data/app/controllers/spree/api/line_items_controller.rb +7 -7
  12. data/app/controllers/spree/api/option_types_controller.rb +2 -2
  13. data/app/controllers/spree/api/orders_controller.rb +17 -6
  14. data/app/controllers/spree/api/payments_controller.rb +3 -11
  15. data/app/controllers/spree/api/product_properties_controller.rb +2 -2
  16. data/app/controllers/spree/api/promotions_controller.rb +26 -0
  17. data/app/controllers/spree/api/properties_controller.rb +1 -1
  18. data/app/controllers/spree/api/return_authorizations_controller.rb +0 -10
  19. data/app/controllers/spree/api/shipments_controller.rb +71 -4
  20. data/app/controllers/spree/api/states_controller.rb +3 -3
  21. data/app/controllers/spree/api/stock_items_controller.rb +1 -1
  22. data/app/controllers/spree/api/stock_movements_controller.rb +1 -1
  23. data/app/controllers/spree/api/taxons_controller.rb +1 -1
  24. data/app/controllers/spree/api/variants_controller.rb +1 -2
  25. data/app/helpers/spree/api/api_helpers.rb +19 -5
  26. data/app/views/spree/api/images/index.v1.rabl +4 -0
  27. data/app/views/spree/api/products/show.v1.rabl +4 -1
  28. data/app/views/spree/api/promotions/handler.v1.rabl +2 -1
  29. data/app/views/spree/api/promotions/show.v1.rabl +2 -0
  30. data/app/views/spree/api/shipments/big.v1.rabl +48 -0
  31. data/app/views/spree/api/shipments/mine.v1.rabl +9 -0
  32. data/app/views/spree/api/shipments/small.v1.rabl +1 -5
  33. data/app/views/spree/api/shipping_rates/show.v1.rabl +2 -2
  34. data/app/views/spree/api/taxonomies/show.v1.rabl +2 -2
  35. data/app/views/spree/api/variants/big.v1.rabl +6 -1
  36. data/app/views/spree/api/variants/show.v1.rabl +1 -1
  37. data/app/views/spree/api/variants/small.v1.rabl +2 -3
  38. data/config/routes.rb +9 -0
  39. data/lib/spree/api/responders/rabl_template.rb +1 -1
  40. data/lib/spree/api/testing_support/helpers.rb +6 -6
  41. data/lib/spree/api/testing_support/setup.rb +2 -2
  42. data/spec/controllers/spree/api/addresses_controller_spec.rb +7 -7
  43. data/spec/controllers/spree/api/base_controller_spec.rb +66 -19
  44. data/spec/controllers/spree/api/checkouts_controller_spec.rb +54 -54
  45. data/spec/controllers/spree/api/classifications_controller_spec.rb +5 -5
  46. data/spec/controllers/spree/api/config_controller_spec.rb +9 -9
  47. data/spec/controllers/spree/api/countries_controller_spec.rb +11 -11
  48. data/spec/controllers/spree/api/credit_cards_controller_spec.rb +16 -16
  49. data/spec/controllers/spree/api/images_controller_spec.rb +37 -11
  50. data/spec/controllers/spree/api/inventory_units_controller_spec.rb +6 -6
  51. data/spec/controllers/spree/api/line_items_controller_spec.rb +34 -35
  52. data/spec/controllers/spree/api/option_types_controller_spec.rb +18 -18
  53. data/spec/controllers/spree/api/option_values_controller_spec.rb +21 -21
  54. data/spec/controllers/spree/api/orders_controller_spec.rb +177 -161
  55. data/spec/controllers/spree/api/payments_controller_spec.rb +52 -89
  56. data/spec/controllers/spree/api/product_properties_controller_spec.rb +21 -21
  57. data/spec/controllers/spree/api/products_controller_spec.rb +103 -60
  58. data/spec/controllers/spree/api/promotion_application_spec.rb +14 -12
  59. data/spec/controllers/spree/api/promotions_controller_spec.rb +64 -0
  60. data/spec/controllers/spree/api/properties_controller_spec.rb +25 -25
  61. data/spec/controllers/spree/api/return_authorizations_controller_spec.rb +42 -66
  62. data/spec/controllers/spree/api/shipments_controller_spec.rb +69 -21
  63. data/spec/controllers/spree/api/states_controller_spec.rb +18 -18
  64. data/spec/controllers/spree/api/stock_items_controller_spec.rb +26 -26
  65. data/spec/controllers/spree/api/stock_locations_controller_spec.rb +22 -22
  66. data/spec/controllers/spree/api/stock_movements_controller_spec.rb +16 -16
  67. data/spec/controllers/spree/api/taxonomies_controller_spec.rb +24 -24
  68. data/spec/controllers/spree/api/taxons_controller_spec.rb +39 -39
  69. data/spec/controllers/spree/api/unauthenticated_products_controller_spec.rb +5 -5
  70. data/spec/controllers/spree/api/users_controller_spec.rb +41 -41
  71. data/spec/controllers/spree/api/variants_controller_spec.rb +47 -37
  72. data/spec/controllers/spree/api/zones_controller_spec.rb +40 -18
  73. data/spec/models/spree/legacy_user_spec.rb +5 -5
  74. data/spec/requests/rabl_cache_spec.rb +9 -9
  75. data/spec/spec_helper.rb +1 -0
  76. metadata +14 -9
  77. data/spec/requests/ransackable_attributes_spec.rb +0 -79
@@ -1,13 +1,13 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  module Spree
4
- describe Api::ReturnAuthorizationsController, :type => :controller do
4
+ describe Api::ReturnAuthorizationsController do
5
5
  render_views
6
6
 
7
7
  let!(:order) { create(:shipped_order) }
8
8
 
9
9
  let(:product) { create(:product) }
10
- let(:attributes) { [:id, :reason, :amount, :state] }
10
+ let(:attributes) { [:id, :memo, :state] }
11
11
  let(:resource_scoping) { { :order_id => order.to_param } }
12
12
 
13
13
  before do
@@ -16,7 +16,7 @@ module Spree
16
16
 
17
17
  context "as the order owner" do
18
18
  before do
19
- allow_any_instance_of(Order).to receive_messages :user => current_api_user
19
+ Order.any_instance.stub :user => current_api_user
20
20
  end
21
21
 
22
22
  it "cannot see any return authorizations" do
@@ -57,129 +57,105 @@ module Spree
57
57
  FactoryGirl.create(:return_authorization, :order => order)
58
58
  return_authorization = order.return_authorizations.first
59
59
  api_get :show, :order_id => order.number, :id => return_authorization.id
60
- expect(response.status).to eq(200)
61
- expect(json_response).to have_attributes(attributes)
62
- expect(json_response["state"]).not_to be_blank
60
+ response.status.should == 200
61
+ json_response.should have_attributes(attributes)
62
+ json_response["state"].should_not be_blank
63
63
  end
64
64
 
65
65
  it "can get a list of return authorizations" do
66
66
  FactoryGirl.create(:return_authorization, :order => order)
67
67
  FactoryGirl.create(:return_authorization, :order => order)
68
68
  api_get :index, { :order_id => order.number }
69
- expect(response.status).to eq(200)
69
+ response.status.should == 200
70
70
  return_authorizations = json_response["return_authorizations"]
71
- expect(return_authorizations.first).to have_attributes(attributes)
72
- expect(return_authorizations.first).not_to eq(return_authorizations.last)
71
+ return_authorizations.first.should have_attributes(attributes)
72
+ return_authorizations.first.should_not == return_authorizations.last
73
73
  end
74
74
 
75
75
  it 'can control the page size through a parameter' do
76
76
  FactoryGirl.create(:return_authorization, :order => order)
77
77
  FactoryGirl.create(:return_authorization, :order => order)
78
78
  api_get :index, :order_id => order.number, :per_page => 1
79
- expect(json_response['count']).to eq(1)
80
- expect(json_response['current_page']).to eq(1)
81
- expect(json_response['pages']).to eq(2)
79
+ json_response['count'].should == 1
80
+ json_response['current_page'].should == 1
81
+ json_response['pages'].should == 2
82
82
  end
83
83
 
84
84
  it 'can query the results through a paramter' do
85
85
  FactoryGirl.create(:return_authorization, :order => order)
86
- expected_result = create(:return_authorization, :reason => 'damaged')
86
+ expected_result = create(:return_authorization, :memo => 'damaged')
87
87
  order.return_authorizations << expected_result
88
- api_get :index, :q => { :reason_cont => 'damage' }
89
- expect(json_response['count']).to eq(1)
90
- expect(json_response['return_authorizations'].first['reason']).to eq expected_result.reason
88
+ api_get :index, :q => { :memo_cont => 'damaged' }
89
+ json_response['count'].should == 1
90
+ json_response['return_authorizations'].first['memo'].should eq expected_result.memo
91
91
  end
92
92
 
93
93
  it "can learn how to create a new return authorization" do
94
94
  api_get :new
95
- expect(json_response["attributes"]).to eq(["id", "number", "state", "amount", "order_id", "reason", "created_at", "updated_at"])
95
+ json_response["attributes"].should == ["id", "number", "state", "order_id", "memo", "created_at", "updated_at"]
96
96
  required_attributes = json_response["required_attributes"]
97
- expect(required_attributes).to include("order")
97
+ required_attributes.should include("order")
98
98
  end
99
99
 
100
100
  it "can update a return authorization on the order" do
101
101
  FactoryGirl.create(:return_authorization, :order => order)
102
102
  return_authorization = order.return_authorizations.first
103
- api_put :update, :id => return_authorization.id, :return_authorization => { :amount => 19.99 }
104
- expect(response.status).to eq(200)
105
- expect(json_response).to have_attributes(attributes)
106
- end
107
-
108
- it "can add an inventory unit to a return authorization on the order" do
109
- FactoryGirl.create(:return_authorization, :order => order)
110
- return_authorization = order.return_authorizations.first
111
- inventory_unit = return_authorization.returnable_inventory.first
112
- expect(inventory_unit).to be
113
- expect(return_authorization.inventory_units).to be_empty
114
- api_put :add, :id => return_authorization.id, variant_id: inventory_unit.variant.id, quantity: 1
115
- expect(response.status).to eq(200)
116
- expect(json_response).to have_attributes(attributes)
117
- expect(return_authorization.reload.inventory_units).not_to be_empty
118
- end
119
-
120
- it "can mark a return authorization as received on the order with an inventory unit" do
121
- FactoryGirl.create(:new_return_authorization, :order => order, :stock_location_id => order.shipments.first.stock_location.id)
122
- return_authorization = order.return_authorizations.first
123
- expect(return_authorization.state).to eq("authorized")
124
-
125
- # prep (use a rspec context or a factory instead?)
126
- inventory_unit = return_authorization.returnable_inventory.first
127
- expect(inventory_unit).to be
128
- expect(return_authorization.inventory_units).to be_empty
129
- api_put :add, :id => return_authorization.id, variant_id: inventory_unit.variant.id, quantity: 1
130
- # end prep
131
-
132
- api_delete :receive, :id => return_authorization.id
133
- expect(response.status).to eq(200)
134
- expect(return_authorization.reload.state).to eq("received")
103
+ api_put :update, :id => return_authorization.id, :return_authorization => { :memo => "ABC" }
104
+ response.status.should == 200
105
+ json_response.should have_attributes(attributes)
135
106
  end
136
107
 
137
108
  it "cannot mark a return authorization as received on the order with no inventory units" do
138
109
  FactoryGirl.create(:new_return_authorization, :order => order)
139
110
  return_authorization = order.return_authorizations.first
140
- expect(return_authorization.state).to eq("authorized")
111
+ return_authorization.state.should == "authorized"
141
112
  api_delete :receive, :id => return_authorization.id
142
- expect(response.status).to eq(422)
143
- expect(return_authorization.reload.state).to eq("authorized")
113
+ response.status.should == 422
114
+ return_authorization.reload.state.should == "authorized"
144
115
  end
145
116
 
146
117
  it "can cancel a return authorization on the order" do
147
118
  FactoryGirl.create(:new_return_authorization, :order => order)
148
119
  return_authorization = order.return_authorizations.first
149
- expect(return_authorization.state).to eq("authorized")
120
+ return_authorization.state.should == "authorized"
150
121
  api_delete :cancel, :id => return_authorization.id
151
- expect(response.status).to eq(200)
152
- expect(return_authorization.reload.state).to eq("canceled")
122
+ response.status.should == 200
123
+ return_authorization.reload.state.should == "canceled"
153
124
  end
154
125
 
155
126
  it "can delete a return authorization on the order" do
156
127
  FactoryGirl.create(:return_authorization, :order => order)
157
128
  return_authorization = order.return_authorizations.first
158
129
  api_delete :destroy, :id => return_authorization.id
159
- expect(response.status).to eq(204)
160
- expect { return_authorization.reload }.to raise_error(ActiveRecord::RecordNotFound)
130
+ response.status.should == 204
131
+ lambda { return_authorization.reload }.should raise_error(ActiveRecord::RecordNotFound)
161
132
  end
162
133
 
163
134
  it "can add a new return authorization to an existing order" do
164
- api_post :create, :order_id => order.number, :return_authorization => { :amount => 14.22, :reason => "Defective" }
165
- expect(response.status).to eq(201)
166
- expect(json_response).to have_attributes(attributes)
167
- expect(json_response["state"]).not_to be_blank
135
+ stock_location = FactoryGirl.create(:stock_location)
136
+ reason = FactoryGirl.create(:return_authorization_reason)
137
+ rma_params = { :stock_location_id => stock_location.id,
138
+ :return_authorization_reason_id => reason.id,
139
+ :memo => "Defective" }
140
+ api_post :create, :order_id => order.number, :return_authorization => rma_params
141
+ response.status.should == 201
142
+ json_response.should have_attributes(attributes)
143
+ json_response["state"].should_not be_blank
168
144
  end
169
145
  end
170
146
 
171
147
  context "as just another user" do
172
148
  it "cannot add a return authorization to the order" do
173
- api_post :create, :return_autorization => { :order_id => order.number, :amount => 14.22, :reason => "Defective" }
149
+ api_post :create, :return_autorization => { :order_id => order.number, :memo => "Defective" }
174
150
  assert_unauthorized!
175
151
  end
176
152
 
177
153
  it "cannot update a return authorization on the order" do
178
154
  FactoryGirl.create(:return_authorization, :order => order)
179
155
  return_authorization = order.return_authorizations.first
180
- api_put :update, :id => return_authorization.id, :return_authorization => { :amount => 19.99 }
156
+ api_put :update, :id => return_authorization.id, :return_authorization => { :memo => "ABC" }
181
157
  assert_unauthorized!
182
- expect(return_authorization.reload.amount).not_to eq(19.99)
158
+ return_authorization.reload.memo.should_not == "ABC"
183
159
  end
184
160
 
185
161
  it "cannot delete a return authorization on the order" do
@@ -187,7 +163,7 @@ module Spree
187
163
  return_authorization = order.return_authorizations.first
188
164
  api_delete :destroy, :id => return_authorization.id
189
165
  assert_unauthorized!
190
- expect { return_authorization.reload }.not_to raise_error
166
+ lambda { return_authorization.reload }.should_not raise_error
191
167
  end
192
168
  end
193
169
  end
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Spree::Api::ShipmentsController, :type => :controller do
3
+ describe Spree::Api::ShipmentsController do
4
4
  render_views
5
5
  let!(:shipment) { create(:shipment) }
6
6
  let!(:attributes) { [:id, :tracking, :number, :cost, :shipped_at, :stock_location_name, :order_id, :shipping_rates, :shipping_methods] }
@@ -72,23 +72,23 @@ describe Spree::Api::ShipmentsController, :type => :controller do
72
72
  }
73
73
 
74
74
  api_put :update, params
75
- expect(response.status).to eq(200)
76
- expect(json_response['stock_location_name']).to eq(stock_location.name)
75
+ response.status.should == 200
76
+ json_response['stock_location_name'].should == stock_location.name
77
77
  end
78
78
 
79
79
  it "can make a shipment ready" do
80
- allow_any_instance_of(Spree::Order).to receive_messages(:paid? => true, :complete? => true)
80
+ Spree::Order.any_instance.stub(:paid? => true, :complete? => true)
81
81
  api_put :ready
82
- expect(json_response).to have_attributes(attributes)
83
- expect(json_response["state"]).to eq("ready")
84
- expect(shipment.reload.state).to eq("ready")
82
+ json_response.should have_attributes(attributes)
83
+ json_response["state"].should == "ready"
84
+ shipment.reload.state.should == "ready"
85
85
  end
86
86
 
87
87
  it "cannot make a shipment ready if the order is unpaid" do
88
- allow_any_instance_of(Spree::Order).to receive_messages(:paid? => false)
88
+ Spree::Order.any_instance.stub(:paid? => false)
89
89
  api_put :ready
90
- expect(json_response["error"]).to eq("Cannot ready shipment.")
91
- expect(response.status).to eq(422)
90
+ json_response["error"].should == "Cannot ready shipment."
91
+ response.status.should == 422
92
92
  end
93
93
 
94
94
  context 'for completed shipments' do
@@ -97,16 +97,16 @@ describe Spree::Api::ShipmentsController, :type => :controller do
97
97
 
98
98
  it 'adds a variant to a shipment' do
99
99
  api_put :add, { variant_id: variant.to_param, quantity: 2 }
100
- expect(response.status).to eq(200)
101
- expect(json_response['manifest'].detect { |h| h['variant']['id'] == variant.id }["quantity"]).to eq(2)
100
+ response.status.should == 200
101
+ json_response['manifest'].detect { |h| h['variant']['id'] == variant.id }["quantity"].should == 2
102
102
  end
103
103
 
104
104
  it 'removes a variant from a shipment' do
105
105
  order.contents.add(variant, 2)
106
106
 
107
107
  api_put :remove, { variant_id: variant.to_param, quantity: 1 }
108
- expect(response.status).to eq(200)
109
- expect(json_response['manifest'].detect { |h| h['variant']['id'] == variant.id }["quantity"]).to eq(1)
108
+ response.status.should == 200
109
+ json_response['manifest'].detect { |h| h['variant']['id'] == variant.id }["quantity"].should == 1
110
110
  end
111
111
 
112
112
  it 'removes a destroyed variant from a shipment' do
@@ -114,29 +114,77 @@ describe Spree::Api::ShipmentsController, :type => :controller do
114
114
  variant.destroy
115
115
 
116
116
  api_put :remove, { variant_id: variant.to_param, quantity: 1 }
117
- expect(response.status).to eq(200)
118
- expect(json_response['manifest'].detect { |h| h['variant']['id'] == variant.id }["quantity"]).to eq(1)
117
+ response.status.should == 200
118
+ json_response['manifest'].detect { |h| h['variant']['id'] == variant.id }["quantity"].should == 1
119
119
  end
120
120
  end
121
121
 
122
122
  context "can transition a shipment from ready to ship" do
123
123
  before do
124
- allow_any_instance_of(Spree::Order).to receive_messages(:paid? => true, :complete? => true)
124
+ Spree::Order.any_instance.stub(:paid? => true, :complete? => true)
125
125
  # For the shipment notification email
126
126
  Spree::Config[:mails_from] = "spree@example.com"
127
127
 
128
128
  shipment.update!(shipment.order)
129
- expect(shipment.state).to eq("ready")
130
- allow_any_instance_of(Spree::ShippingRate).to receive_messages(:cost => 5)
129
+ shipment.state.should == "ready"
130
+ Spree::ShippingRate.any_instance.stub(:cost => 5)
131
131
  end
132
132
 
133
133
  it "can transition a shipment from ready to ship" do
134
134
  shipment.reload
135
135
  api_put :ship, id: shipment.to_param, shipment: { tracking: "123123", order_id: shipment.order.to_param }
136
- expect(json_response).to have_attributes(attributes)
137
- expect(json_response["state"]).to eq("shipped")
136
+ json_response.should have_attributes(attributes)
137
+ json_response["state"].should == "shipped"
138
138
  end
139
139
 
140
140
  end
141
+
142
+ describe '#mine' do
143
+ subject do
144
+ api_get :mine, format: 'json', params: params
145
+ end
146
+
147
+ let(:params) { {} }
148
+
149
+ before { subject }
150
+
151
+ context "the current api user is authenticated and has orders" do
152
+ let(:current_api_user) { shipped_order.user }
153
+ let(:shipped_order) { create(:shipped_order) }
154
+
155
+ it 'succeeds' do
156
+ expect(response.status).to eq 200
157
+ end
158
+
159
+ describe 'json output' do
160
+ render_views
161
+
162
+ let(:rendered_shipment_ids) { json_response['shipments'].map { |s| s['id'] } }
163
+
164
+ it 'contains the shipments' do
165
+ expect(rendered_shipment_ids).to match_array current_api_user.orders.flat_map(&:shipments).map(&:id)
166
+ end
167
+ end
168
+
169
+ context 'with filtering' do
170
+ let(:params) { {q: {order_completed_at_not_null: 1}} }
171
+
172
+ let!(:incomplete_order) { create(:order, user: current_api_user) }
173
+
174
+ it 'filters' do
175
+ expect(assigns(:shipments).map(&:id)).to match_array current_api_user.orders.complete.flat_map(&:shipments).map(&:id)
176
+ end
177
+ end
178
+ end
179
+
180
+ context "the current api user is not persisted" do
181
+ let(:current_api_user) { Spree.user_class.new }
182
+
183
+ it "returns a 401" do
184
+ response.status.should == 401
185
+ end
186
+ end
187
+ end
188
+
141
189
  end
142
190
  end
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  module Spree
4
- describe Api::StatesController, :type => :controller do
4
+ describe Api::StatesController do
5
5
  render_views
6
6
 
7
7
  let!(:state) { create(:state, :name => "Victoria") }
@@ -13,37 +13,37 @@ module Spree
13
13
 
14
14
  it "gets all states" do
15
15
  api_get :index
16
- expect(json_response["states"].first).to have_attributes(attributes)
17
- expect(json_response['states'].first['name']).to eq(state.name)
16
+ json_response["states"].first.should have_attributes(attributes)
17
+ json_response['states'].first['name'].should eq(state.name)
18
18
  end
19
19
 
20
20
  it "gets all the states for a particular country" do
21
21
  api_get :index, :country_id => state.country.id
22
- expect(json_response["states"].first).to have_attributes(attributes)
23
- expect(json_response['states'].first['name']).to eq(state.name)
22
+ json_response["states"].first.should have_attributes(attributes)
23
+ json_response['states'].first['name'].should eq(state.name)
24
24
  end
25
25
 
26
26
  context "pagination" do
27
27
  before do
28
- expect(State).to receive(:accessible_by).and_return(@scope = double)
29
- allow(@scope).to receive_message_chain(:ransack, :result, :includes, :order).and_return(@scope)
28
+ State.should_receive(:accessible_by).and_return(@scope = double)
29
+ @scope.stub_chain(:ransack, :result, :includes, :order).and_return(@scope)
30
30
  end
31
31
 
32
32
  it "does not paginate states results when asked not to do so" do
33
- expect(@scope).not_to receive(:page)
34
- expect(@scope).not_to receive(:per)
33
+ @scope.should_not_receive(:page)
34
+ @scope.should_not_receive(:per)
35
35
  api_get :index
36
36
  end
37
37
 
38
38
  it "paginates when page parameter is passed through" do
39
- expect(@scope).to receive(:page).with(1).and_return(@scope)
40
- expect(@scope).to receive(:per).with(nil)
39
+ @scope.should_receive(:page).with(1).and_return(@scope)
40
+ @scope.should_receive(:per).with(nil)
41
41
  api_get :index, :page => 1
42
42
  end
43
43
 
44
44
  it "paginates when per_page parameter is passed through" do
45
- expect(@scope).to receive(:page).with(nil).and_return(@scope)
46
- expect(@scope).to receive(:per).with(25)
45
+ @scope.should_receive(:page).with(nil).and_return(@scope)
46
+ @scope.should_receive(:per).with(25)
47
47
  api_get :index, :per_page => 25
48
48
  end
49
49
  end
@@ -58,25 +58,25 @@ module Spree
58
58
  state.save
59
59
 
60
60
  api_get :index, :country_id => country.id
61
- expect(json_response["states"].first).to have_attributes(attributes)
62
- expect(json_response["states"].count).to eq(1)
61
+ json_response["states"].first.should have_attributes(attributes)
62
+ json_response["states"].count.should == 1
63
63
  json_response["states_required"] = true
64
64
  end
65
65
 
66
66
  it "can view all states" do
67
67
  api_get :index
68
- expect(json_response["states"].first).to have_attributes(attributes)
68
+ json_response["states"].first.should have_attributes(attributes)
69
69
  end
70
70
 
71
71
  it 'can query the results through a paramter' do
72
72
  api_get :index, :q => { :name_cont => 'Vic' }
73
- expect(json_response['states'].first['name']).to eq("Victoria")
73
+ json_response['states'].first['name'].should eq("Victoria")
74
74
  end
75
75
  end
76
76
 
77
77
  it "can view a state" do
78
78
  api_get :show, :id => state.id
79
- expect(json_response).to have_attributes(attributes)
79
+ json_response.should have_attributes(attributes)
80
80
  end
81
81
  end
82
82
  end
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  module Spree
4
- describe Api::StockItemsController, :type => :controller do
4
+ describe Api::StockItemsController do
5
5
  render_views
6
6
 
7
7
  let!(:stock_location) { create(:stock_location_with_items) }
@@ -16,12 +16,12 @@ module Spree
16
16
  context "as a normal user" do
17
17
  it "cannot list stock items for a stock location" do
18
18
  api_get :index, stock_location_id: stock_location.to_param
19
- expect(response.status).to eq(404)
19
+ response.status.should == 404
20
20
  end
21
21
 
22
22
  it "cannot see a stock item" do
23
23
  api_get :show, stock_location_id: stock_location.to_param, id: stock_item.to_param
24
- expect(response.status).to eq(404)
24
+ response.status.should == 404
25
25
  end
26
26
 
27
27
  it "cannot create a stock item" do
@@ -35,17 +35,17 @@ module Spree
35
35
  }
36
36
 
37
37
  api_post :create, params
38
- expect(response.status).to eq(404)
38
+ response.status.should == 404
39
39
  end
40
40
 
41
41
  it "cannot update a stock item" do
42
42
  api_put :update, stock_location_id: stock_location.to_param, stock_item_id: stock_item.to_param
43
- expect(response.status).to eq(404)
43
+ response.status.should == 404
44
44
  end
45
45
 
46
46
  it "cannot destroy a stock item" do
47
47
  api_delete :destroy, stock_location_id: stock_location.to_param, stock_item_id: stock_item.to_param
48
- expect(response.status).to eq(404)
48
+ response.status.should == 404
49
49
  end
50
50
  end
51
51
 
@@ -54,33 +54,33 @@ module Spree
54
54
 
55
55
  it 'cannot list of stock items' do
56
56
  api_get :index, stock_location_id: stock_location.to_param
57
- expect(json_response['stock_items'].first).to have_attributes(attributes)
58
- expect(json_response['stock_items'].first['variant']['sku']).to include 'SKU'
57
+ json_response['stock_items'].first.should have_attributes(attributes)
58
+ json_response['stock_items'].first['variant']['sku'].should include 'SKU'
59
59
  end
60
60
 
61
61
  it 'requires a stock_location_id to be passed as a parameter' do
62
62
  api_get :index
63
- expect(json_response['error']).to match(/stock_location_id parameter must be provided/)
64
- expect(response.status).to eq(422)
63
+ json_response['error'].should =~ /stock_location_id parameter must be provided/
64
+ response.status.should == 422
65
65
  end
66
66
 
67
67
  it 'can control the page size through a parameter' do
68
68
  api_get :index, stock_location_id: stock_location.to_param, per_page: 1
69
- expect(json_response['count']).to eq(1)
70
- expect(json_response['current_page']).to eq(1)
69
+ json_response['count'].should == 1
70
+ json_response['current_page'].should == 1
71
71
  end
72
72
 
73
73
  it 'can query the results through a paramter' do
74
74
  stock_item.update_column(:count_on_hand, 30)
75
75
  api_get :index, stock_location_id: stock_location.to_param, q: { count_on_hand_eq: '30' }
76
- expect(json_response['count']).to eq(1)
77
- expect(json_response['stock_items'].first['count_on_hand']).to eq 30
76
+ json_response['count'].should == 1
77
+ json_response['stock_items'].first['count_on_hand'].should eq 30
78
78
  end
79
79
 
80
80
  it 'gets a stock item' do
81
81
  api_get :show, stock_location_id: stock_location.to_param, id: stock_item.to_param
82
- expect(json_response).to have_attributes(attributes)
83
- expect(json_response['count_on_hand']).to eq stock_item.count_on_hand
82
+ json_response.should have_attributes(attributes)
83
+ json_response['count_on_hand'].should eq stock_item.count_on_hand
84
84
  end
85
85
 
86
86
  it 'can create a new stock item' do
@@ -97,12 +97,12 @@ module Spree
97
97
  }
98
98
 
99
99
  api_post :create, params
100
- expect(response.status).to eq(201)
101
- expect(json_response).to have_attributes(attributes)
100
+ response.status.should == 201
101
+ json_response.should have_attributes(attributes)
102
102
  end
103
103
 
104
104
  it 'can update a stock item to add new inventory' do
105
- expect(stock_item.count_on_hand).to eq(10)
105
+ stock_item.count_on_hand.should == 10
106
106
  params = {
107
107
  id: stock_item.to_param,
108
108
  stock_item: {
@@ -111,12 +111,12 @@ module Spree
111
111
  }
112
112
 
113
113
  api_put :update, params
114
- expect(response.status).to eq(200)
115
- expect(json_response['count_on_hand']).to eq 50
114
+ response.status.should == 200
115
+ json_response['count_on_hand'].should eq 50
116
116
  end
117
117
 
118
118
  it 'can set a stock item to modify the current inventory' do
119
- expect(stock_item.count_on_hand).to eq(10)
119
+ stock_item.count_on_hand.should == 10
120
120
 
121
121
  params = {
122
122
  id: stock_item.to_param,
@@ -127,14 +127,14 @@ module Spree
127
127
  }
128
128
 
129
129
  api_put :update, params
130
- expect(response.status).to eq(200)
131
- expect(json_response['count_on_hand']).to eq 40
130
+ response.status.should == 200
131
+ json_response['count_on_hand'].should eq 40
132
132
  end
133
133
 
134
134
  it 'can delete a stock item' do
135
135
  api_delete :destroy, id: stock_item.to_param
136
- expect(response.status).to eq(204)
137
- expect { Spree::StockItem.find(stock_item.id) }.to raise_error(ActiveRecord::RecordNotFound)
136
+ response.status.should == 204
137
+ lambda { Spree::StockItem.find(stock_item.id) }.should raise_error(ActiveRecord::RecordNotFound)
138
138
  end
139
139
  end
140
140
  end