spree_api 2.4.0.rc2 → 2.4.0.rc3

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 (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
@@ -2,7 +2,7 @@ require 'shared_examples/protect_product_actions'
2
2
  require 'spec_helper'
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) }
@@ -11,12 +11,12 @@ module Spree
11
11
  context "without authentication" do
12
12
  before { Spree::Api::Config[:requires_authentication] = false }
13
13
 
14
- it "retreives a list of products" do
14
+ it "retrieves a list of products" do
15
15
  api_get :index
16
- json_response["products"].first.should have_attributes(attributes)
17
- json_response["count"].should == 1
18
- json_response["current_page"].should == 1
19
- json_response["pages"].should == 1
16
+ expect(json_response["products"].first).to have_attributes(attributes)
17
+ expect(json_response["count"]).to eq(1)
18
+ expect(json_response["current_page"]).to eq(1)
19
+ expect(json_response["pages"]).to eq(1)
20
20
  end
21
21
 
22
22
  it_behaves_like "modifying product actions are restricted"
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  module Spree
4
- describe Api::UsersController do
4
+ describe Api::UsersController, :type => :controller do
5
5
  render_views
6
6
 
7
7
  let(:user) { create(:user) }
@@ -12,13 +12,13 @@ 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
+ allow(controller).to receive_messages :try_spree_current_user => user
16
16
  end
17
17
 
18
18
  it "can get own details" do
19
19
  api_get :show, :id => user.id
20
20
 
21
- json_response['email'].should eq user.email
21
+ expect(json_response['email']).to eq user.email
22
22
  end
23
23
 
24
24
  it "cannot get other users details" do
@@ -29,19 +29,19 @@ module Spree
29
29
 
30
30
  it "can learn how to create a new user" do
31
31
  api_get :new
32
- json_response["attributes"].should == attributes.map(&:to_s)
32
+ expect(json_response["attributes"]).to eq(attributes.map(&:to_s))
33
33
  end
34
34
 
35
35
  it "can create a new user" do
36
36
  api_post :create, :user => { :email => 'new@example.com', :password => 'spree123', :password_confirmation => 'spree123' }
37
- json_response['email'].should eq 'new@example.com'
37
+ expect(json_response['email']).to eq 'new@example.com'
38
38
  end
39
39
 
40
40
  # there's no validations on LegacyUser?
41
41
  xit "cannot create a new user with invalid attributes" do
42
42
  api_post :create, :user => {}
43
- response.status.should == 422
44
- json_response["error"].should == "Invalid resource. Please fix errors and try again."
43
+ expect(response.status).to eq(422)
44
+ expect(json_response["error"]).to eq("Invalid resource. Please fix errors and try again.")
45
45
  errors = json_response["errors"]
46
46
  end
47
47
 
@@ -82,7 +82,7 @@ module Spree
82
82
 
83
83
  it "can delete itself" do
84
84
  api_delete :destroy, :id => user.id
85
- response.status.should == 204
85
+ expect(response.status).to eq(204)
86
86
  end
87
87
 
88
88
  it "cannot delete other user" do
@@ -94,9 +94,9 @@ module Spree
94
94
  2.times { create(:user) }
95
95
  api_get :index
96
96
 
97
- Spree.user_class.count.should eq 3
98
- json_response['count'].should eq 1
99
- json_response['users'].size.should eq 1
97
+ expect(Spree.user_class.count).to eq 3
98
+ expect(json_response['count']).to eq 1
99
+ expect(json_response['users'].size).to eq 1
100
100
  end
101
101
  end
102
102
 
@@ -104,48 +104,48 @@ module Spree
104
104
  sign_in_as_admin!
105
105
 
106
106
  it "gets all users" do
107
- Spree::LegacyUser.stub(:find_by).with(hash_including(:spree_api_key)) { current_api_user }
107
+ allow(Spree::LegacyUser).to receive(:find_by).with(hash_including(:spree_api_key)) { current_api_user }
108
108
 
109
109
  2.times { create(:user) }
110
110
 
111
111
  api_get :index
112
- Spree.user_class.count.should eq 2
113
- json_response['count'].should eq 2
114
- json_response['users'].size.should eq 2
112
+ expect(Spree.user_class.count).to eq 2
113
+ expect(json_response['count']).to eq 2
114
+ expect(json_response['users'].size).to eq 2
115
115
  end
116
116
 
117
117
  it 'can control the page size through a parameter' do
118
118
  2.times { create(:user) }
119
119
  api_get :index, :per_page => 1
120
- json_response['count'].should == 1
121
- json_response['current_page'].should == 1
122
- json_response['pages'].should == 2
120
+ expect(json_response['count']).to eq(1)
121
+ expect(json_response['current_page']).to eq(1)
122
+ expect(json_response['pages']).to eq(2)
123
123
  end
124
124
 
125
125
  it 'can query the results through a paramter' do
126
126
  expected_result = create(:user, :email => 'brian@spreecommerce.com')
127
127
  api_get :index, :q => { :email_cont => 'brian' }
128
- json_response['count'].should == 1
129
- json_response['users'].first['email'].should eq expected_result.email
128
+ expect(json_response['count']).to eq(1)
129
+ expect(json_response['users'].first['email']).to eq expected_result.email
130
130
  end
131
131
 
132
132
  it "can create" do
133
133
  api_post :create, :user => { :email => "new@example.com", :password => 'spree123', :password_confirmation => 'spree123' }
134
- json_response.should have_attributes(attributes)
135
- response.status.should == 201
134
+ expect(json_response).to have_attributes(attributes)
135
+ expect(response.status).to eq(201)
136
136
  end
137
137
 
138
138
  it "can destroy user without orders" do
139
139
  user.orders.destroy_all
140
140
  api_delete :destroy, :id => user.id
141
- response.status.should == 204
141
+ expect(response.status).to eq(204)
142
142
  end
143
143
 
144
144
  it "cannot destroy user with orders" do
145
145
  create(:completed_order_with_totals, :user => user)
146
146
  api_delete :destroy, :id => user.id
147
- json_response["exception"].should eq "Spree::Core::DestroyWithOrdersError"
148
- response.status.should == 422
147
+ expect(json_response["exception"]).to eq "Spree::Core::DestroyWithOrdersError"
148
+ expect(response.status).to eq(422)
149
149
  end
150
150
 
151
151
  end
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  module Spree
4
- describe Api::VariantsController do
4
+ describe Api::VariantsController, :type => :controller do
5
5
  render_views
6
6
 
7
7
  let!(:product) { create(:product) }
@@ -22,32 +22,32 @@ module Spree
22
22
  it "can see a paginated list of variants" do
23
23
  api_get :index
24
24
  first_variant = json_response["variants"].first
25
- first_variant.should have_attributes(show_attributes)
26
- first_variant["stock_items"].should be_present
27
- json_response["count"].should == 1
28
- json_response["current_page"].should == 1
29
- json_response["pages"].should == 1
25
+ expect(first_variant).to have_attributes(show_attributes)
26
+ expect(first_variant["stock_items"]).to be_present
27
+ expect(json_response["count"]).to eq(1)
28
+ expect(json_response["current_page"]).to eq(1)
29
+ expect(json_response["pages"]).to eq(1)
30
30
  end
31
31
 
32
32
  it 'can control the page size through a parameter' do
33
33
  create(:variant)
34
34
  api_get :index, :per_page => 1
35
- json_response['count'].should == 1
36
- json_response['current_page'].should == 1
37
- json_response['pages'].should == 3
35
+ expect(json_response['count']).to eq(1)
36
+ expect(json_response['current_page']).to eq(1)
37
+ expect(json_response['pages']).to eq(3)
38
38
  end
39
39
 
40
40
  it 'can query the results through a parameter' do
41
41
  expected_result = create(:variant, :sku => 'FOOBAR')
42
42
  api_get :index, :q => { :sku_cont => 'FOO' }
43
- json_response['count'].should == 1
44
- json_response['variants'].first['sku'].should eq expected_result.sku
43
+ expect(json_response['count']).to eq(1)
44
+ expect(json_response['variants'].first['sku']).to eq expected_result.sku
45
45
  end
46
46
 
47
47
  it "variants returned contain option values data" do
48
48
  api_get :index
49
49
  option_values = json_response["variants"].last["option_values"]
50
- option_values.first.should have_attributes([:name,
50
+ expect(option_values.first).to have_attributes([:name,
51
51
  :presentation,
52
52
  :option_type_name,
53
53
  :option_type_id])
@@ -58,8 +58,8 @@ module Spree
58
58
 
59
59
  api_get :index
60
60
 
61
- json_response["variants"].last.should have_attributes([:images])
62
- json_response['variants'].first['images'].first.should have_attributes([:attachment_file_name,
61
+ expect(json_response["variants"].last).to have_attributes([:images])
62
+ expect(json_response['variants'].first['images'].first).to have_attributes([:attachment_file_name,
63
63
  :attachment_width,
64
64
  :attachment_height,
65
65
  :attachment_content_type,
@@ -83,12 +83,12 @@ module Spree
83
83
 
84
84
  it "is not returned in the results" do
85
85
  api_get :index
86
- json_response["variants"].count.should == 0
86
+ expect(json_response["variants"].count).to eq(0)
87
87
  end
88
88
 
89
89
  it "is not returned even when show_deleted is passed" do
90
90
  api_get :index, :show_deleted => true
91
- json_response["variants"].count.should == 0
91
+ expect(json_response["variants"].count).to eq(0)
92
92
  end
93
93
  end
94
94
 
@@ -96,19 +96,19 @@ module Spree
96
96
  it "can select the next page of variants" do
97
97
  second_variant = create(:variant)
98
98
  api_get :index, :page => 2, :per_page => 1
99
- json_response["variants"].first.should have_attributes(show_attributes)
100
- json_response["total_count"].should == 3
101
- json_response["current_page"].should == 2
102
- json_response["pages"].should == 3
99
+ expect(json_response["variants"].first).to have_attributes(show_attributes)
100
+ expect(json_response["total_count"]).to eq(3)
101
+ expect(json_response["current_page"]).to eq(2)
102
+ expect(json_response["pages"]).to eq(3)
103
103
  end
104
104
  end
105
105
 
106
106
  it "can see a single variant" do
107
107
  api_get :show, :id => variant.to_param
108
- json_response.should have_attributes(show_attributes)
109
- json_response["stock_items"].should be_present
108
+ expect(json_response).to have_attributes(show_attributes)
109
+ expect(json_response["stock_items"]).to be_present
110
110
  option_values = json_response["option_values"]
111
- option_values.first.should have_attributes([:name,
111
+ expect(option_values.first).to have_attributes([:name,
112
112
  :presentation,
113
113
  :option_type_name,
114
114
  :option_type_id])
@@ -119,9 +119,9 @@ module Spree
119
119
 
120
120
  api_get :show, :id => variant.to_param
121
121
 
122
- json_response.should have_attributes(show_attributes + [:images])
122
+ expect(json_response).to have_attributes(show_attributes + [:images])
123
123
  option_values = json_response["option_values"]
124
- option_values.first.should have_attributes([:name,
124
+ expect(option_values.first).to have_attributes([:name,
125
125
  :presentation,
126
126
  :option_type_name,
127
127
  :option_type_id])
@@ -129,8 +129,8 @@ module Spree
129
129
 
130
130
  it "can learn how to create a new variant" do
131
131
  api_get :new
132
- json_response["attributes"].should == new_attributes.map(&:to_s)
133
- json_response["required_attributes"].should be_empty
132
+ expect(json_response["attributes"]).to eq(new_attributes.map(&:to_s))
133
+ expect(json_response["required_attributes"]).to be_empty
134
134
  end
135
135
 
136
136
  it "cannot create a new variant if not an admin" do
@@ -146,7 +146,7 @@ module Spree
146
146
  it "cannot delete a variant" do
147
147
  api_delete :destroy, :id => variant.to_param
148
148
  assert_not_found!
149
- lambda { variant.reload }.should_not raise_error
149
+ expect { variant.reload }.not_to raise_error
150
150
  end
151
151
 
152
152
  context "as an admin" do
@@ -161,28 +161,28 @@ module Spree
161
161
 
162
162
  it "are visible by admin" do
163
163
  api_get :index, :show_deleted => 1
164
- json_response["variants"].count.should == 1
164
+ expect(json_response["variants"].count).to eq(1)
165
165
  end
166
166
  end
167
167
 
168
168
  it "can create a new variant" do
169
169
  api_post :create, :variant => { :sku => "12345" }
170
- json_response.should have_attributes(new_attributes)
171
- response.status.should == 201
172
- json_response["sku"].should == "12345"
170
+ expect(json_response).to have_attributes(new_attributes)
171
+ expect(response.status).to eq(201)
172
+ expect(json_response["sku"]).to eq("12345")
173
173
 
174
- variant.product.variants.count.should == 1
174
+ expect(variant.product.variants.count).to eq(1)
175
175
  end
176
176
 
177
177
  it "can update a variant" do
178
178
  api_put :update, :id => variant.to_param, :variant => { :sku => "12345" }
179
- response.status.should == 200
179
+ expect(response.status).to eq(200)
180
180
  end
181
181
 
182
182
  it "can delete a variant" do
183
183
  api_delete :destroy, :id => variant.to_param
184
- response.status.should == 204
185
- lambda { Spree::Variant.find(variant.id) }.should raise_error(ActiveRecord::RecordNotFound)
184
+ expect(response.status).to eq(204)
185
+ expect { Spree::Variant.find(variant.id) }.to raise_error(ActiveRecord::RecordNotFound)
186
186
  end
187
187
 
188
188
  it 'variants returned contain cost price data' do
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  module Spree
4
- describe Api::ZonesController do
4
+ describe Api::ZonesController, :type => :controller do
5
5
  render_views
6
6
 
7
7
  let!(:attributes) { [:id, :name, :zone_members] }
@@ -13,29 +13,29 @@ module Spree
13
13
 
14
14
  it "gets list of zones" do
15
15
  api_get :index
16
- json_response['zones'].first.should have_attributes(attributes)
16
+ expect(json_response['zones'].first).to have_attributes(attributes)
17
17
  end
18
18
 
19
19
  it 'can control the page size through a parameter' do
20
20
  create(:zone)
21
21
  api_get :index, :per_page => 1
22
- json_response['count'].should == 1
23
- json_response['current_page'].should == 1
24
- json_response['pages'].should == 2
22
+ expect(json_response['count']).to eq(1)
23
+ expect(json_response['current_page']).to eq(1)
24
+ expect(json_response['pages']).to eq(2)
25
25
  end
26
26
 
27
27
  it 'can query the results through a paramter' do
28
28
  expected_result = create(:zone, :name => 'South America')
29
29
  api_get :index, :q => { :name_cont => 'south' }
30
- json_response['count'].should == 1
31
- json_response['zones'].first['name'].should eq expected_result.name
30
+ expect(json_response['count']).to eq(1)
31
+ expect(json_response['zones'].first['name']).to eq expected_result.name
32
32
  end
33
33
 
34
34
  it "gets a zone" do
35
35
  api_get :show, :id => @zone.id
36
- json_response.should have_attributes(attributes)
37
- json_response['name'].should eq @zone.name
38
- json_response['zone_members'].size.should eq @zone.zone_members.count
36
+ expect(json_response).to have_attributes(attributes)
37
+ expect(json_response['name']).to eq @zone.name
38
+ expect(json_response['zone_members'].size).to eq @zone.zone_members.count
39
39
  end
40
40
 
41
41
  context "specifying a rabl template to use" do
@@ -50,13 +50,13 @@ module Spree
50
50
  it "uses the specified template" do
51
51
  request.headers['X-Spree-Template'] = 'show'
52
52
  api_get :custom_show, :id => @zone.id
53
- response.should render_template('spree/api/zones/show')
53
+ expect(response).to render_template('spree/api/zones/show')
54
54
  end
55
55
 
56
56
  it "falls back to the default template if the specified template does not exist" do
57
57
  request.headers['X-Spree-Template'] = 'invoice'
58
58
  api_get :show, :id => @zone.id
59
- response.should render_template('spree/api/zones/show')
59
+ expect(response).to render_template('spree/api/zones/show')
60
60
  end
61
61
  end
62
62
 
@@ -77,9 +77,9 @@ module Spree
77
77
  }
78
78
 
79
79
  api_post :create, params
80
- response.status.should == 201
81
- json_response.should have_attributes(attributes)
82
- json_response["zone_members"].should_not be_empty
80
+ expect(response.status).to eq(201)
81
+ expect(json_response).to have_attributes(attributes)
82
+ expect(json_response["zone_members"]).not_to be_empty
83
83
  end
84
84
 
85
85
  it "updates a zone" do
@@ -96,15 +96,15 @@ module Spree
96
96
  }
97
97
 
98
98
  api_put :update, params
99
- response.status.should == 200
100
- json_response['name'].should eq 'North Pole'
101
- json_response['zone_members'].should_not be_blank
99
+ expect(response.status).to eq(200)
100
+ expect(json_response['name']).to eq 'North Pole'
101
+ expect(json_response['zone_members']).not_to be_blank
102
102
  end
103
103
 
104
104
  it "can delete a zone" do
105
105
  api_delete :destroy, :id => @zone.id
106
- response.status.should == 204
107
- lambda { @zone.reload }.should raise_error(ActiveRecord::RecordNotFound)
106
+ expect(response.status).to eq(204)
107
+ expect { @zone.reload }.to raise_error(ActiveRecord::RecordNotFound)
108
108
  end
109
109
  end
110
110
  end
@@ -1,19 +1,19 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  module Spree
4
- describe LegacyUser do
4
+ describe LegacyUser, :type => :model do
5
5
  let(:user) { LegacyUser.new }
6
6
 
7
7
  it "can generate an API key" do
8
- user.should_receive(:save!)
8
+ expect(user).to receive(:save!)
9
9
  user.generate_spree_api_key!
10
- user.spree_api_key.should_not be_blank
10
+ expect(user.spree_api_key).not_to be_blank
11
11
  end
12
12
 
13
13
  it "can clear an API key" do
14
- user.should_receive(:save!)
14
+ expect(user).to receive(:save!)
15
15
  user.clear_spree_api_key!
16
- user.spree_api_key.should be_blank
16
+ expect(user.spree_api_key).to be_blank
17
17
  end
18
18
  end
19
19
  end