spree_api 2.4.0.rc2 → 2.4.0.rc3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/spree/api/base_controller.rb +4 -6
  3. data/app/controllers/spree/api/option_types_controller.rb +2 -2
  4. data/app/controllers/spree/api/orders_controller.rb +9 -1
  5. data/app/controllers/spree/api/return_authorizations_controller.rb +0 -9
  6. data/app/controllers/spree/api/taxons_controller.rb +3 -3
  7. data/app/helpers/spree/api/api_helpers.rb +0 -2
  8. data/app/views/spree/api/orders/show.v1.rabl +4 -0
  9. data/app/views/spree/api/products/show.v1.rabl +4 -0
  10. data/app/views/spree/api/shipments/small.v1.rabl +4 -0
  11. data/lib/spree/api/testing_support/helpers.rb +6 -6
  12. data/lib/spree/api/testing_support/setup.rb +2 -2
  13. data/spec/controllers/spree/api/addresses_controller_spec.rb +8 -8
  14. data/spec/controllers/spree/api/base_controller_spec.rb +22 -22
  15. data/spec/controllers/spree/api/checkouts_controller_spec.rb +53 -53
  16. data/spec/controllers/spree/api/classifications_controller_spec.rb +5 -5
  17. data/spec/controllers/spree/api/config_controller_spec.rb +9 -9
  18. data/spec/controllers/spree/api/countries_controller_spec.rb +11 -11
  19. data/spec/controllers/spree/api/credit_cards_controller_spec.rb +16 -16
  20. data/spec/controllers/spree/api/images_controller_spec.rb +21 -21
  21. data/spec/controllers/spree/api/inventory_units_controller_spec.rb +6 -6
  22. data/spec/controllers/spree/api/line_items_controller_spec.rb +33 -33
  23. data/spec/controllers/spree/api/option_types_controller_spec.rb +19 -19
  24. data/spec/controllers/spree/api/option_values_controller_spec.rb +23 -23
  25. data/spec/controllers/spree/api/orders_controller_spec.rb +186 -143
  26. data/spec/controllers/spree/api/payments_controller_spec.rb +39 -39
  27. data/spec/controllers/spree/api/product_properties_controller_spec.rb +21 -21
  28. data/spec/controllers/spree/api/products_controller_spec.rb +71 -66
  29. data/spec/controllers/spree/api/promotion_application_spec.rb +13 -13
  30. data/spec/controllers/spree/api/promotions_controller_spec.rb +1 -1
  31. data/spec/controllers/spree/api/properties_controller_spec.rb +25 -25
  32. data/spec/controllers/spree/api/return_authorizations_controller_spec.rb +27 -36
  33. data/spec/controllers/spree/api/shipments_controller_spec.rb +22 -22
  34. data/spec/controllers/spree/api/states_controller_spec.rb +18 -18
  35. data/spec/controllers/spree/api/stock_items_controller_spec.rb +26 -26
  36. data/spec/controllers/spree/api/stock_locations_controller_spec.rb +22 -22
  37. data/spec/controllers/spree/api/stock_movements_controller_spec.rb +16 -16
  38. data/spec/controllers/spree/api/taxonomies_controller_spec.rb +24 -24
  39. data/spec/controllers/spree/api/taxons_controller_spec.rb +39 -39
  40. data/spec/controllers/spree/api/unauthenticated_products_controller_spec.rb +6 -6
  41. data/spec/controllers/spree/api/users_controller_spec.rb +25 -25
  42. data/spec/controllers/spree/api/variants_controller_spec.rb +36 -36
  43. data/spec/controllers/spree/api/zones_controller_spec.rb +20 -20
  44. data/spec/models/spree/legacy_user_spec.rb +5 -5
  45. data/spec/requests/rabl_cache_spec.rb +9 -9
  46. data/spec/spec_helper.rb +0 -1
  47. data/spec/support/controller_hacks.rb +4 -0
  48. metadata +4 -4
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  module Spree
4
- describe Spree::Api::PaymentsController do
4
+ describe Spree::Api::PaymentsController, :type => :controller do
5
5
  render_views
6
6
  let!(:order) { create(:order) }
7
7
  let!(:payment) { create(:payment, :order => order) }
@@ -18,30 +18,30 @@ module Spree
18
18
  context "as a user" do
19
19
  context "when the order belongs to the user" do
20
20
  before do
21
- Order.any_instance.stub :user => current_api_user
21
+ allow_any_instance_of(Order).to receive_messages :user => current_api_user
22
22
  end
23
23
 
24
24
  it "can view the payments for their order" do
25
25
  api_get :index
26
- json_response["payments"].first.should have_attributes(attributes)
26
+ expect(json_response["payments"].first).to have_attributes(attributes)
27
27
  end
28
28
 
29
29
  it "can learn how to create a new payment" do
30
30
  api_get :new
31
- json_response["attributes"].should == attributes.map(&:to_s)
32
- json_response["payment_methods"].should_not be_empty
33
- json_response["payment_methods"].first.should have_attributes([:id, :name, :description])
31
+ expect(json_response["attributes"]).to eq(attributes.map(&:to_s))
32
+ expect(json_response["payment_methods"]).not_to be_empty
33
+ expect(json_response["payment_methods"].first).to have_attributes([:id, :name, :description])
34
34
  end
35
35
 
36
36
  it "can create a new payment" do
37
37
  api_post :create, :payment => { :payment_method_id => PaymentMethod.first.id, :amount => 50 }
38
- response.status.should == 201
39
- json_response.should have_attributes(attributes)
38
+ expect(response.status).to eq(201)
39
+ expect(json_response).to have_attributes(attributes)
40
40
  end
41
41
 
42
42
  it "can view a pre-existing payment's details" do
43
43
  api_get :show, :id => payment.to_param
44
- json_response.should have_attributes(attributes)
44
+ expect(json_response).to have_attributes(attributes)
45
45
  end
46
46
 
47
47
  it "cannot update a payment" do
@@ -57,7 +57,7 @@ module Spree
57
57
 
58
58
  context "when the order does not belong to the user" do
59
59
  before do
60
- Order.any_instance.stub :user => stub_model(LegacyUser)
60
+ allow_any_instance_of(Order).to receive_messages :user => stub_model(LegacyUser)
61
61
  end
62
62
 
63
63
  it "cannot view payments for somebody else's order" do
@@ -67,7 +67,7 @@ module Spree
67
67
 
68
68
  it "can view the payments for an order given the order token" do
69
69
  api_get :index, :order_id => order.to_param, :order_token => order.guest_token
70
- json_response["payments"].first.should have_attributes(attributes)
70
+ expect(json_response["payments"].first).to have_attributes(attributes)
71
71
  end
72
72
  end
73
73
  end
@@ -77,8 +77,8 @@ module Spree
77
77
 
78
78
  it "can view the payments on any order" do
79
79
  api_get :index
80
- response.status.should == 200
81
- json_response["payments"].first.should have_attributes(attributes)
80
+ expect(response.status).to eq(200)
81
+ expect(json_response["payments"].first).to have_attributes(attributes)
82
82
  end
83
83
 
84
84
  context "multiple payments" do
@@ -86,20 +86,20 @@ module Spree
86
86
 
87
87
  it "can view all payments on an order" do
88
88
  api_get :index
89
- json_response["count"].should == 2
89
+ expect(json_response["count"]).to eq(2)
90
90
  end
91
91
 
92
92
  it 'can control the page size through a parameter' do
93
93
  api_get :index, :per_page => 1
94
- json_response['count'].should == 1
95
- json_response['current_page'].should == 1
96
- json_response['pages'].should == 2
94
+ expect(json_response['count']).to eq(1)
95
+ expect(json_response['current_page']).to eq(1)
96
+ expect(json_response['pages']).to eq(2)
97
97
  end
98
98
 
99
99
  it 'can query the results through a paramter' do
100
100
  api_get :index, :q => { :response_code_cont => '999' }
101
- json_response['count'].should == 1
102
- json_response['payments'].first['response_code'].should eq @payment.response_code
101
+ expect(json_response['count']).to eq(1)
102
+ expect(json_response['payments'].first['response_code']).to eq @payment.response_code
103
103
  end
104
104
  end
105
105
 
@@ -108,23 +108,23 @@ module Spree
108
108
  it "can update" do
109
109
  payment.update_attributes(:state => 'pending')
110
110
  api_put :update, :id => payment.to_param, :payment => { :amount => 2.01 }
111
- response.status.should == 200
112
- payment.reload.amount.should == 2.01
111
+ expect(response.status).to eq(200)
112
+ expect(payment.reload.amount).to eq(2.01)
113
113
  end
114
114
 
115
115
  context "update fails" do
116
116
  it "returns a 422 status when the amount is invalid" do
117
117
  payment.update_attributes(:state => 'pending')
118
118
  api_put :update, :id => payment.to_param, :payment => { :amount => 'invalid' }
119
- response.status.should == 422
120
- json_response["error"].should == "Invalid resource. Please fix errors and try again."
119
+ expect(response.status).to eq(422)
120
+ expect(json_response["error"]).to eq("Invalid resource. Please fix errors and try again.")
121
121
  end
122
122
 
123
123
  it "returns a 403 status when the payment is not pending" do
124
124
  payment.update_attributes(:state => 'completed')
125
125
  api_put :update, :id => payment.to_param, :payment => { :amount => 2.01 }
126
- response.status.should == 403
127
- json_response["error"].should == "This payment cannot be updated because it is completed."
126
+ expect(response.status).to eq(403)
127
+ expect(json_response["error"]).to eq("This payment cannot be updated because it is completed.")
128
128
  end
129
129
  end
130
130
  end
@@ -132,26 +132,26 @@ module Spree
132
132
  context "authorizing" do
133
133
  it "can authorize" do
134
134
  api_put :authorize, :id => payment.to_param
135
- response.status.should == 200
136
- payment.reload.state.should == "pending"
135
+ expect(response.status).to eq(200)
136
+ expect(payment.reload.state).to eq("pending")
137
137
  end
138
138
 
139
139
  context "authorization fails" do
140
140
  before do
141
141
  fake_response = double(:success? => false, :to_s => "Could not authorize card")
142
- Spree::Gateway::Bogus.any_instance.should_receive(:authorize).and_return(fake_response)
142
+ expect_any_instance_of(Spree::Gateway::Bogus).to receive(:authorize).and_return(fake_response)
143
143
  api_put :authorize, :id => payment.to_param
144
144
  end
145
145
 
146
146
  it "returns a 422 status" do
147
- response.status.should == 422
147
+ expect(response.status).to eq(422)
148
148
  expect(json_response["error"]).to eq "Invalid resource. Please fix errors and try again."
149
149
  expect(json_response["errors"]["base"][0]).to eq "Could not authorize card"
150
150
  end
151
151
 
152
152
  it "does not raise a stack level error" do
153
153
  skip "Investigate why a payment.reload after the request raises 'stack level too deep'"
154
- payment.reload.state.should == "failed"
154
+ expect(payment.reload.state).to eq("failed")
155
155
  end
156
156
  end
157
157
  end
@@ -159,19 +159,19 @@ module Spree
159
159
  context "capturing" do
160
160
  it "can capture" do
161
161
  api_put :capture, :id => payment.to_param
162
- response.status.should == 200
163
- payment.reload.state.should == "completed"
162
+ expect(response.status).to eq(200)
163
+ expect(payment.reload.state).to eq("completed")
164
164
  end
165
165
 
166
166
  context "capturing fails" do
167
167
  before do
168
168
  fake_response = double(:success? => false, :to_s => "Insufficient funds")
169
- Spree::Gateway::Bogus.any_instance.should_receive(:capture).and_return(fake_response)
169
+ expect_any_instance_of(Spree::Gateway::Bogus).to receive(:capture).and_return(fake_response)
170
170
  end
171
171
 
172
172
  it "returns a 422 status" do
173
173
  api_put :capture, :id => payment.to_param
174
- response.status.should == 422
174
+ expect(response.status).to eq(422)
175
175
  expect(json_response["error"]).to eq "Invalid resource. Please fix errors and try again."
176
176
  expect(json_response["errors"]["base"][0]).to eq "Insufficient funds"
177
177
  end
@@ -181,19 +181,19 @@ module Spree
181
181
  context "purchasing" do
182
182
  it "can purchase" do
183
183
  api_put :purchase, :id => payment.to_param
184
- response.status.should == 200
185
- payment.reload.state.should == "completed"
184
+ expect(response.status).to eq(200)
185
+ expect(payment.reload.state).to eq("completed")
186
186
  end
187
187
 
188
188
  context "purchasing fails" do
189
189
  before do
190
190
  fake_response = double(:success? => false, :to_s => "Insufficient funds")
191
- Spree::Gateway::Bogus.any_instance.should_receive(:purchase).and_return(fake_response)
191
+ expect_any_instance_of(Spree::Gateway::Bogus).to receive(:purchase).and_return(fake_response)
192
192
  end
193
193
 
194
194
  it "returns a 422 status" do
195
195
  api_put :purchase, :id => payment.to_param
196
- response.status.should == 422
196
+ expect(response.status).to eq(422)
197
197
  expect(json_response["error"]).to eq "Invalid resource. Please fix errors and try again."
198
198
  expect(json_response["errors"]["base"][0]).to eq "Insufficient funds"
199
199
  end
@@ -210,7 +210,7 @@ module Spree
210
210
  context "voiding fails" do
211
211
  before do
212
212
  fake_response = double(success?: false, to_s: "NO REFUNDS")
213
- Spree::Gateway::Bogus.any_instance.should_receive(:void).and_return(fake_response)
213
+ expect_any_instance_of(Spree::Gateway::Bogus).to receive(:void).and_return(fake_response)
214
214
  end
215
215
 
216
216
  it "returns a 422 status" do
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
  require 'shared_examples/protect_product_actions'
3
3
 
4
4
  module Spree
5
- describe Spree::Api::ProductPropertiesController do
5
+ describe Spree::Api::ProductPropertiesController, :type => :controller do
6
6
  render_views
7
7
 
8
8
  let!(:product) { create(:product) }
@@ -23,40 +23,40 @@ module Spree
23
23
 
24
24
  it "can not see a list of product properties" do
25
25
  api_get :index
26
- response.status.should == 404
26
+ expect(response.status).to eq(404)
27
27
  end
28
28
  end
29
29
 
30
30
  it "can see a list of all product properties" do
31
31
  api_get :index
32
- json_response["product_properties"].count.should eq 2
33
- json_response["product_properties"].first.should have_attributes(attributes)
32
+ expect(json_response["product_properties"].count).to eq 2
33
+ expect(json_response["product_properties"].first).to have_attributes(attributes)
34
34
  end
35
35
 
36
36
  it "can control the page size through a parameter" do
37
37
  api_get :index, :per_page => 1
38
- json_response['product_properties'].count.should == 1
39
- json_response['current_page'].should == 1
40
- json_response['pages'].should == 2
38
+ expect(json_response['product_properties'].count).to eq(1)
39
+ expect(json_response['current_page']).to eq(1)
40
+ expect(json_response['pages']).to eq(2)
41
41
  end
42
42
 
43
43
  it 'can query the results through a parameter' do
44
44
  Spree::ProductProperty.last.update_attribute(:value, 'loose')
45
45
  property = Spree::ProductProperty.last
46
46
  api_get :index, :q => { :value_cont => 'loose' }
47
- json_response['count'].should == 1
48
- json_response['product_properties'].first['value'].should eq property.value
47
+ expect(json_response['count']).to eq(1)
48
+ expect(json_response['product_properties'].first['value']).to eq property.value
49
49
  end
50
50
 
51
51
  it "can see a single product_property" do
52
52
  api_get :show, :id => property_1.property_name
53
- json_response.should have_attributes(attributes)
53
+ expect(json_response).to have_attributes(attributes)
54
54
  end
55
55
 
56
56
  it "can learn how to create a new product property" do
57
57
  api_get :new
58
- json_response["attributes"].should == attributes.map(&:to_s)
59
- json_response["required_attributes"].should be_empty
58
+ expect(json_response["attributes"]).to eq(attributes.map(&:to_s))
59
+ expect(json_response["required_attributes"]).to be_empty
60
60
  end
61
61
 
62
62
  it "cannot create a new product property if not an admin" do
@@ -72,7 +72,7 @@ module Spree
72
72
  it "cannot delete a product property" do
73
73
  api_delete :destroy, :property_name => property_1.property_name
74
74
  assert_unauthorized!
75
- lambda { property_1.reload }.should_not raise_error
75
+ expect { property_1.reload }.not_to raise_error
76
76
  end
77
77
 
78
78
  context "as an admin" do
@@ -82,19 +82,19 @@ module Spree
82
82
  expect do
83
83
  api_post :create, :product_property => { :property_name => "My Property 3", :value => "my value 3" }
84
84
  end.to change(product.product_properties, :count).by(1)
85
- json_response.should have_attributes(attributes)
86
- response.status.should == 201
85
+ expect(json_response).to have_attributes(attributes)
86
+ expect(response.status).to eq(201)
87
87
  end
88
88
 
89
89
  it "can update a product property" do
90
90
  api_put :update, :id => property_1.property_name, :product_property => { :value => "my value 456" }
91
- response.status.should == 200
91
+ expect(response.status).to eq(200)
92
92
  end
93
93
 
94
94
  it "can delete a product property" do
95
95
  api_delete :destroy, :id => property_1.property_name
96
- response.status.should == 204
97
- lambda { property_1.reload }.should raise_error(ActiveRecord::RecordNotFound)
96
+ expect(response.status).to eq(204)
97
+ expect { property_1.reload }.to raise_error(ActiveRecord::RecordNotFound)
98
98
  end
99
99
  end
100
100
 
@@ -102,13 +102,13 @@ module Spree
102
102
  let(:resource_scoping) { { :product_id => product.id } }
103
103
  it "can see a list of all product properties" do
104
104
  api_get :index
105
- json_response["product_properties"].count.should eq 2
106
- json_response["product_properties"].first.should have_attributes(attributes)
105
+ expect(json_response["product_properties"].count).to eq 2
106
+ expect(json_response["product_properties"].first).to have_attributes(attributes)
107
107
  end
108
108
 
109
109
  it "can see a single product_property by id" do
110
110
  api_get :show, :id => property_1.id
111
- json_response.should have_attributes(attributes)
111
+ expect(json_response).to have_attributes(attributes)
112
112
  end
113
113
  end
114
114
 
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
  require 'shared_examples/protect_product_actions'
3
3
 
4
4
  module Spree
5
- describe Spree::Api::ProductsController do
5
+ describe Spree::Api::ProductsController, :type => :controller do
6
6
  render_views
7
7
 
8
8
  let!(:product) { create(:product) }
@@ -51,20 +51,20 @@ module Spree
51
51
 
52
52
  it "retrieves a list of products" do
53
53
  api_get :index
54
- json_response["products"].first.should have_attributes(show_attributes)
55
- json_response["total_count"].should == 1
56
- json_response["current_page"].should == 1
57
- json_response["pages"].should == 1
58
- json_response["per_page"].should == Kaminari.config.default_per_page
54
+ expect(json_response["products"].first).to have_attributes(show_attributes)
55
+ expect(json_response["total_count"]).to eq(1)
56
+ expect(json_response["current_page"]).to eq(1)
57
+ expect(json_response["pages"]).to eq(1)
58
+ expect(json_response["per_page"]).to eq(Kaminari.config.default_per_page)
59
59
  end
60
60
 
61
61
  it "retrieves a list of products by id" do
62
62
  api_get :index, :ids => [product.id]
63
- json_response["products"].first.should have_attributes(show_attributes)
64
- json_response["total_count"].should == 1
65
- json_response["current_page"].should == 1
66
- json_response["pages"].should == 1
67
- json_response["per_page"].should == Kaminari.config.default_per_page
63
+ expect(json_response["products"].first).to have_attributes(show_attributes)
64
+ expect(json_response["total_count"]).to eq(1)
65
+ expect(json_response["current_page"]).to eq(1)
66
+ expect(json_response["pages"]).to eq(1)
67
+ expect(json_response["per_page"]).to eq(Kaminari.config.default_per_page)
68
68
  end
69
69
 
70
70
  context "specifying a rabl template for a custom action" do
@@ -80,18 +80,18 @@ module Spree
80
80
  it "uses the specified custom template through the request header" do
81
81
  request.headers['X-Spree-Template'] = 'show'
82
82
  api_get :custom_show, :id => product.id
83
- response.should render_template('spree/api/products/show')
83
+ expect(response).to render_template('spree/api/products/show')
84
84
  end
85
85
 
86
86
  it "uses the specified custom template through the template URL parameter" do
87
87
  api_get :custom_show, :id => product.id, :template => 'show'
88
- response.should render_template('spree/api/products/show')
88
+ expect(response).to render_template('spree/api/products/show')
89
89
  end
90
90
 
91
91
  it "falls back to the default template if the specified template does not exist" do
92
92
  request.headers['X-Spree-Template'] = 'invoice'
93
93
  api_get :show, :id => product.id
94
- response.should render_template('spree/api/products/show')
94
+ expect(response).to render_template('spree/api/products/show')
95
95
  end
96
96
  end
97
97
 
@@ -107,64 +107,64 @@ module Spree
107
107
  it "retrieves a list of products by ids string" do
108
108
  second_product = create(:product)
109
109
  api_get :index, :ids => [product.id, second_product.id].join(",")
110
- json_response["products"].first.should have_attributes(show_attributes)
111
- json_response["products"][1].should have_attributes(show_attributes)
112
- json_response["total_count"].should == 2
113
- json_response["current_page"].should == 1
114
- json_response["pages"].should == 1
115
- json_response["per_page"].should == Kaminari.config.default_per_page
110
+ expect(json_response["products"].first).to have_attributes(show_attributes)
111
+ expect(json_response["products"][1]).to have_attributes(show_attributes)
112
+ expect(json_response["total_count"]).to eq(2)
113
+ expect(json_response["current_page"]).to eq(1)
114
+ expect(json_response["pages"]).to eq(1)
115
+ expect(json_response["per_page"]).to eq(Kaminari.config.default_per_page)
116
116
  end
117
117
 
118
118
  it "does not return inactive products when queried by ids" do
119
119
  api_get :index, :ids => [inactive_product.id]
120
- json_response["count"].should == 0
120
+ expect(json_response["count"]).to eq(0)
121
121
  end
122
122
 
123
123
  it "does not list unavailable products" do
124
124
  api_get :index
125
- json_response["products"].first["name"].should_not eq("inactive")
125
+ expect(json_response["products"].first["name"]).not_to eq("inactive")
126
126
  end
127
127
 
128
128
  context "pagination" do
129
129
  it "can select the next page of products" do
130
130
  second_product = create(:product)
131
131
  api_get :index, :page => 2, :per_page => 1
132
- json_response["products"].first.should have_attributes(show_attributes)
133
- json_response["total_count"].should == 2
134
- json_response["current_page"].should == 2
135
- json_response["pages"].should == 2
132
+ expect(json_response["products"].first).to have_attributes(show_attributes)
133
+ expect(json_response["total_count"]).to eq(2)
134
+ expect(json_response["current_page"]).to eq(2)
135
+ expect(json_response["pages"]).to eq(2)
136
136
  end
137
137
 
138
138
  it 'can control the page size through a parameter' do
139
139
  create(:product)
140
140
  api_get :index, :per_page => 1
141
- json_response['count'].should == 1
142
- json_response['total_count'].should == 2
143
- json_response['current_page'].should == 1
144
- json_response['pages'].should == 2
141
+ expect(json_response['count']).to eq(1)
142
+ expect(json_response['total_count']).to eq(2)
143
+ expect(json_response['current_page']).to eq(1)
144
+ expect(json_response['pages']).to eq(2)
145
145
  end
146
146
  end
147
147
 
148
148
  context "jsonp" do
149
149
  it "retrieves a list of products of jsonp" do
150
150
  api_get :index, {:callback => 'callback'}
151
- response.body.should =~ /^callback\(.*\)$/
152
- response.header['Content-Type'].should include('application/javascript')
151
+ expect(response.body).to match(/^callback\(.*\)$/)
152
+ expect(response.header['Content-Type']).to include('application/javascript')
153
153
  end
154
154
 
155
155
  # Regression test for #4332
156
156
  it "does not escape quotes" do
157
157
  api_get :index, {:callback => 'callback'}
158
- response.body.should =~ /^callback\({"count":1,"total_count":1/
159
- response.header['Content-Type'].should include('application/javascript')
158
+ expect(response.body).to match(/^callback\({"count":1,"total_count":1/)
159
+ expect(response.header['Content-Type']).to include('application/javascript')
160
160
  end
161
161
  end
162
162
 
163
163
  it "can search for products" do
164
164
  create(:product, :name => "The best product in the world")
165
165
  api_get :index, :q => { :name_cont => "best" }
166
- json_response["products"].first.should have_attributes(show_attributes)
167
- json_response["count"].should == 1
166
+ expect(json_response["products"].first).to have_attributes(show_attributes)
167
+ expect(json_response["count"]).to eq(1)
168
168
  end
169
169
 
170
170
  it "gets a single product" do
@@ -172,15 +172,18 @@ module Spree
172
172
  product.variants.create!
173
173
  product.variants.first.images.create!(:attachment => image("thinking-cat.jpg"))
174
174
  product.set_property("spree", "rocks")
175
+ product.taxons << create(:taxon)
176
+
175
177
  api_get :show, :id => product.to_param
176
- json_response.should have_attributes(show_attributes)
177
- json_response['variants'].first.should have_attributes([:name,
178
+
179
+ expect(json_response).to have_attributes(show_attributes)
180
+ expect(json_response['variants'].first).to have_attributes([:name,
178
181
  :is_master,
179
182
  :price,
180
183
  :images,
181
184
  :in_stock])
182
185
 
183
- json_response['variants'].first['images'].first.should have_attributes([:attachment_file_name,
186
+ expect(json_response['variants'].first['images'].first).to have_attributes([:attachment_file_name,
184
187
  :attachment_width,
185
188
  :attachment_height,
186
189
  :attachment_content_type,
@@ -189,9 +192,11 @@ module Spree
189
192
  :product_url,
190
193
  :large_url])
191
194
 
192
- json_response["product_properties"].first.should have_attributes([:value,
195
+ expect(json_response["product_properties"].first).to have_attributes([:value,
193
196
  :product_id,
194
197
  :property_name])
198
+
199
+ expect(json_response["taxons"].first).to have_attributes([:id, :name, :pretty_name, :permalink, :taxonomy_id, :parent_id])
195
200
  end
196
201
 
197
202
  context "tracking is disabled" do
@@ -215,11 +220,11 @@ module Spree
215
220
 
216
221
  specify do
217
222
  api_get :show, :id => product.to_param
218
- json_response["slug"].should =~ /and-1-ways/
223
+ expect(json_response["slug"]).to match(/and-1-ways/)
219
224
  product.destroy
220
225
 
221
226
  api_get :show, :id => other_product.id
222
- json_response["slug"].should =~ /droids/
227
+ expect(json_response["slug"]).to match(/droids/)
223
228
  end
224
229
  end
225
230
 
@@ -235,11 +240,11 @@ module Spree
235
240
 
236
241
  it "can learn how to create a new product" do
237
242
  api_get :new
238
- json_response["attributes"].should == new_attributes.map(&:to_s)
243
+ expect(json_response["attributes"]).to eq(new_attributes.map(&:to_s))
239
244
  required_attributes = json_response["required_attributes"]
240
- required_attributes.should include("name")
241
- required_attributes.should include("price")
242
- required_attributes.should include("shipping_category_id")
245
+ expect(required_attributes).to include("name")
246
+ expect(required_attributes).to include("price")
247
+ expect(required_attributes).to include("shipping_category_id")
243
248
  end
244
249
 
245
250
  it_behaves_like "modifying product actions are restricted"
@@ -253,10 +258,10 @@ module Spree
253
258
 
254
259
  it "can see all products" do
255
260
  api_get :index
256
- json_response["products"].count.should == 2
257
- json_response["count"].should == 2
258
- json_response["current_page"].should == 1
259
- json_response["pages"].should == 1
261
+ expect(json_response["products"].count).to eq(2)
262
+ expect(json_response["count"]).to eq(2)
263
+ expect(json_response["current_page"]).to eq(1)
264
+ expect(json_response["pages"]).to eq(1)
260
265
  end
261
266
 
262
267
  # Regression test for #1626
@@ -267,12 +272,12 @@ module Spree
267
272
 
268
273
  it "does not include deleted products" do
269
274
  api_get :index
270
- json_response["products"].count.should == 2
275
+ expect(json_response["products"].count).to eq(2)
271
276
  end
272
277
 
273
278
  it "can include deleted products" do
274
279
  api_get :index, :show_deleted => 1
275
- json_response["products"].count.should == 3
280
+ expect(json_response["products"].count).to eq(3)
276
281
  end
277
282
  end
278
283
 
@@ -281,8 +286,8 @@ module Spree
281
286
  api_post :create, :product => { :name => "The Other Product",
282
287
  :price => 19.99,
283
288
  :shipping_category_id => create(:shipping_category).id }
284
- json_response.should have_attributes(base_attributes)
285
- response.status.should == 201
289
+ expect(json_response).to have_attributes(base_attributes)
290
+ expect(response.status).to eq(201)
286
291
  end
287
292
 
288
293
  it "creates with embedded variants" do
@@ -361,25 +366,25 @@ module Spree
361
366
 
362
367
  it "can still create a product" do
363
368
  api_post :create, :product => product_data, :token => "fake"
364
- json_response.should have_attributes(show_attributes)
365
- response.status.should == 201
369
+ expect(json_response).to have_attributes(show_attributes)
370
+ expect(response.status).to eq(201)
366
371
  end
367
372
  end
368
373
 
369
374
  it "cannot create a new product with invalid attributes" do
370
375
  api_post :create, :product => {}
371
- response.status.should == 422
372
- json_response["error"].should == "Invalid resource. Please fix errors and try again."
376
+ expect(response.status).to eq(422)
377
+ expect(json_response["error"]).to eq("Invalid resource. Please fix errors and try again.")
373
378
  errors = json_response["errors"]
374
379
  errors.delete("slug") # Don't care about this one.
375
- errors.keys.should =~ ["name", "price", "shipping_category_id"]
380
+ expect(errors.keys).to match_array(["name", "price", "shipping_category_id"])
376
381
  end
377
382
  end
378
383
 
379
384
  context 'updating a product' do
380
385
  it "can update a product" do
381
386
  api_put :update, :id => product.to_param, :product => { :name => "New and Improved Product!" }
382
- response.status.should == 200
387
+ expect(response.status).to eq(200)
383
388
  end
384
389
 
385
390
  it "can create new option types on a product" do
@@ -424,9 +429,9 @@ module Spree
424
429
 
425
430
  it "cannot update a product with an invalid attribute" do
426
431
  api_put :update, :id => product.to_param, :product => { :name => "" }
427
- response.status.should == 422
428
- json_response["error"].should == "Invalid resource. Please fix errors and try again."
429
- json_response["errors"]["name"].should == ["can't be blank"]
432
+ expect(response.status).to eq(422)
433
+ expect(json_response["error"]).to eq("Invalid resource. Please fix errors and try again.")
434
+ expect(json_response["errors"]["name"]).to eq(["can't be blank"])
430
435
  end
431
436
 
432
437
  # Regression test for #4123
@@ -443,10 +448,10 @@ module Spree
443
448
  end
444
449
 
445
450
  it "can delete a product" do
446
- product.deleted_at.should be_nil
451
+ expect(product.deleted_at).to be_nil
447
452
  api_delete :destroy, :id => product.to_param
448
- response.status.should == 204
449
- product.reload.deleted_at.should_not be_nil
453
+ expect(response.status).to eq(204)
454
+ expect(product.reload.deleted_at).not_to be_nil
450
455
  end
451
456
  end
452
457
  end