spree_api 2.3.4 → 2.3.5
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.
- checksums.yaml +4 -4
- data/app/controllers/spree/api/base_controller.rb +2 -2
- data/app/controllers/spree/api/option_types_controller.rb +2 -2
- data/app/controllers/spree/api/shipments_controller.rb +2 -2
- data/app/controllers/spree/api/taxons_controller.rb +1 -1
- data/app/helpers/spree/api/api_helpers.rb +0 -2
- data/app/views/spree/api/shipments/small.v1.rabl +4 -0
- data/app/views/spree/api/variants/small.v1.rabl +2 -0
- data/lib/spree/api/testing_support/helpers.rb +6 -6
- data/lib/spree/api/testing_support/setup.rb +2 -2
- data/spec/controllers/spree/api/addresses_controller_spec.rb +7 -7
- data/spec/controllers/spree/api/base_controller_spec.rb +20 -20
- data/spec/controllers/spree/api/checkouts_controller_spec.rb +53 -53
- data/spec/controllers/spree/api/classifications_controller_spec.rb +5 -5
- data/spec/controllers/spree/api/config_controller_spec.rb +9 -9
- data/spec/controllers/spree/api/countries_controller_spec.rb +11 -11
- data/spec/controllers/spree/api/credit_cards_controller_spec.rb +16 -16
- data/spec/controllers/spree/api/images_controller_spec.rb +11 -11
- data/spec/controllers/spree/api/inventory_units_controller_spec.rb +6 -6
- data/spec/controllers/spree/api/line_items_controller_spec.rb +33 -33
- data/spec/controllers/spree/api/option_types_controller_spec.rb +18 -18
- data/spec/controllers/spree/api/option_values_controller_spec.rb +21 -21
- data/spec/controllers/spree/api/orders_controller_spec.rb +170 -132
- data/spec/controllers/spree/api/payments_controller_spec.rb +46 -46
- data/spec/controllers/spree/api/product_properties_controller_spec.rb +21 -21
- data/spec/controllers/spree/api/products_controller_spec.rb +67 -67
- data/spec/controllers/spree/api/promotion_application_spec.rb +11 -11
- data/spec/controllers/spree/api/properties_controller_spec.rb +25 -25
- data/spec/controllers/spree/api/return_authorizations_controller_spec.rb +40 -40
- data/spec/controllers/spree/api/shipments_controller_spec.rb +53 -30
- data/spec/controllers/spree/api/states_controller_spec.rb +18 -18
- data/spec/controllers/spree/api/stock_items_controller_spec.rb +26 -26
- data/spec/controllers/spree/api/stock_locations_controller_spec.rb +22 -22
- data/spec/controllers/spree/api/stock_movements_controller_spec.rb +16 -16
- data/spec/controllers/spree/api/taxonomies_controller_spec.rb +24 -24
- data/spec/controllers/spree/api/taxons_controller_spec.rb +39 -39
- data/spec/controllers/spree/api/unauthenticated_products_controller_spec.rb +5 -5
- data/spec/controllers/spree/api/users_controller_spec.rb +25 -25
- data/spec/controllers/spree/api/variants_controller_spec.rb +36 -36
- data/spec/controllers/spree/api/zones_controller_spec.rb +20 -20
- data/spec/models/spree/legacy_user_spec.rb +5 -5
- data/spec/requests/rabl_cache_spec.rb +9 -9
- data/spec/spec_helper.rb +0 -1
- metadata +4 -4
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
module Spree
|
4
|
-
describe Api::TaxonsController do
|
4
|
+
describe Api::TaxonsController, :type => :controller do
|
5
5
|
render_views
|
6
6
|
|
7
7
|
let(:taxonomy) { create(:taxonomy) }
|
@@ -20,19 +20,19 @@ module Spree
|
|
20
20
|
it "gets all taxons for a taxonomy" do
|
21
21
|
api_get :index, :taxonomy_id => taxonomy.id
|
22
22
|
|
23
|
-
json_response['taxons'].first['name'].
|
23
|
+
expect(json_response['taxons'].first['name']).to eq taxon.name
|
24
24
|
children = json_response['taxons'].first['taxons']
|
25
|
-
children.count.
|
26
|
-
children.first['name'].
|
27
|
-
children.first['taxons'].count.
|
25
|
+
expect(children.count).to eq 1
|
26
|
+
expect(children.first['name']).to eq taxon2.name
|
27
|
+
expect(children.first['taxons'].count).to eq 1
|
28
28
|
end
|
29
29
|
|
30
30
|
# Regression test for #4112
|
31
31
|
it "does not include children when asked not to" do
|
32
32
|
api_get :index, :taxonomy_id => taxonomy.id, :without_children => 1
|
33
33
|
|
34
|
-
json_response['taxons'].first['name'].
|
35
|
-
json_response['taxons'].first['taxons'].
|
34
|
+
expect(json_response['taxons'].first['name']).to eq(taxon.name)
|
35
|
+
expect(json_response['taxons'].first['taxons']).to be_nil
|
36
36
|
end
|
37
37
|
|
38
38
|
it "paginates through taxons" do
|
@@ -57,8 +57,8 @@ module Spree
|
|
57
57
|
let(:name) { "Ruby" }
|
58
58
|
|
59
59
|
it "returns an array including the matching taxon" do
|
60
|
-
json_response['taxons'].count.
|
61
|
-
json_response['taxons'].first['name'].
|
60
|
+
expect(json_response['taxons'].count).to eq(1)
|
61
|
+
expect(json_response['taxons'].first['name']).to eq "Ruby"
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
@@ -66,8 +66,8 @@ module Spree
|
|
66
66
|
let(:name) { "Imaginary" }
|
67
67
|
|
68
68
|
it 'returns an empty array of taxons' do
|
69
|
-
json_response.keys.
|
70
|
-
json_response['taxons'].count.
|
69
|
+
expect(json_response.keys).to include('taxons')
|
70
|
+
expect(json_response['taxons'].count).to eq(0)
|
71
71
|
end
|
72
72
|
end
|
73
73
|
end
|
@@ -76,11 +76,11 @@ module Spree
|
|
76
76
|
it "gets all taxons" do
|
77
77
|
api_get :index
|
78
78
|
|
79
|
-
json_response['taxons'].first['name'].
|
79
|
+
expect(json_response['taxons'].first['name']).to eq taxonomy.root.name
|
80
80
|
children = json_response['taxons'].first['taxons']
|
81
|
-
children.count.
|
82
|
-
children.first['name'].
|
83
|
-
children.first['taxons'].count.
|
81
|
+
expect(children.count).to eq 1
|
82
|
+
expect(children.first['name']).to eq taxon.name
|
83
|
+
expect(children.first['taxons'].count).to eq 1
|
84
84
|
end
|
85
85
|
end
|
86
86
|
end
|
@@ -88,23 +88,23 @@ module Spree
|
|
88
88
|
it "gets a single taxon" do
|
89
89
|
api_get :show, :id => taxon.id, :taxonomy_id => taxonomy.id
|
90
90
|
|
91
|
-
json_response['name'].
|
92
|
-
json_response['taxons'].count.
|
91
|
+
expect(json_response['name']).to eq taxon.name
|
92
|
+
expect(json_response['taxons'].count).to eq 1
|
93
93
|
end
|
94
94
|
|
95
95
|
it "gets all taxons in JSTree form" do
|
96
96
|
api_get :jstree, :taxonomy_id => taxonomy.id, :id => taxon.id
|
97
97
|
response = json_response.first
|
98
|
-
response["data"].
|
99
|
-
response["attr"].
|
100
|
-
response["state"].
|
98
|
+
expect(response["data"]).to eq(taxon2.name)
|
99
|
+
expect(response["attr"]).to eq({ "name" => taxon2.name, "id" => taxon2.id})
|
100
|
+
expect(response["state"]).to eq("closed")
|
101
101
|
end
|
102
102
|
|
103
103
|
it "can learn how to create a new taxon" do
|
104
104
|
api_get :new, :taxonomy_id => taxonomy.id
|
105
|
-
json_response["attributes"].
|
105
|
+
expect(json_response["attributes"]).to eq(attributes.map(&:to_s))
|
106
106
|
required_attributes = json_response["required_attributes"]
|
107
|
-
required_attributes.
|
107
|
+
expect(required_attributes).to include("name")
|
108
108
|
end
|
109
109
|
|
110
110
|
it "cannot create a new taxon if not an admin" do
|
@@ -128,48 +128,48 @@ module Spree
|
|
128
128
|
|
129
129
|
it "can create" do
|
130
130
|
api_post :create, :taxonomy_id => taxonomy.id, :taxon => { :name => "Colors" }
|
131
|
-
json_response.
|
132
|
-
response.status.
|
131
|
+
expect(json_response).to have_attributes(attributes)
|
132
|
+
expect(response.status).to eq(201)
|
133
133
|
|
134
|
-
taxonomy.reload.root.children.count.
|
134
|
+
expect(taxonomy.reload.root.children.count).to eq 2
|
135
135
|
taxon = Spree::Taxon.where(:name => 'Colors').first
|
136
136
|
|
137
|
-
taxon.parent_id.
|
138
|
-
taxon.taxonomy_id.
|
137
|
+
expect(taxon.parent_id).to eq taxonomy.root.id
|
138
|
+
expect(taxon.taxonomy_id).to eq taxonomy.id
|
139
139
|
end
|
140
140
|
|
141
141
|
it "can update the position in the list" do
|
142
142
|
taxonomy.root.children << taxon2
|
143
143
|
api_put :update, :taxonomy_id => taxonomy.id, :id => taxon.id, :taxon => {:parent_id => taxon.parent_id, :child_index => 2 }
|
144
|
-
response.status.
|
145
|
-
taxonomy.reload.root.children[0].
|
146
|
-
taxonomy.reload.root.children[1].
|
144
|
+
expect(response.status).to eq(200)
|
145
|
+
expect(taxonomy.reload.root.children[0]).to eql taxon2
|
146
|
+
expect(taxonomy.reload.root.children[1]).to eql taxon
|
147
147
|
end
|
148
148
|
|
149
149
|
it "cannot create a new taxon with invalid attributes" do
|
150
150
|
api_post :create, :taxonomy_id => taxonomy.id, :taxon => {}
|
151
|
-
response.status.
|
152
|
-
json_response["error"].
|
151
|
+
expect(response.status).to eq(422)
|
152
|
+
expect(json_response["error"]).to eq("Invalid resource. Please fix errors and try again.")
|
153
153
|
errors = json_response["errors"]
|
154
154
|
|
155
|
-
taxonomy.reload.root.children.count.
|
155
|
+
expect(taxonomy.reload.root.children.count).to eq 1
|
156
156
|
end
|
157
157
|
|
158
158
|
it "cannot create a new taxon with invalid taxonomy_id" do
|
159
159
|
api_post :create, :taxonomy_id => 1000, :taxon => { :name => "Colors" }
|
160
|
-
response.status.
|
161
|
-
json_response["error"].
|
160
|
+
expect(response.status).to eq(422)
|
161
|
+
expect(json_response["error"]).to eq("Invalid resource. Please fix errors and try again.")
|
162
162
|
|
163
163
|
errors = json_response["errors"]
|
164
|
-
errors["taxonomy_id"].
|
165
|
-
errors["taxonomy_id"].first.
|
164
|
+
expect(errors["taxonomy_id"]).not_to be_nil
|
165
|
+
expect(errors["taxonomy_id"].first).to eq "Invalid taxonomy id."
|
166
166
|
|
167
|
-
taxonomy.reload.root.children.count.
|
167
|
+
expect(taxonomy.reload.root.children.count).to eq 1
|
168
168
|
end
|
169
169
|
|
170
170
|
it "can destroy" do
|
171
171
|
api_delete :destroy, :taxonomy_id => taxonomy.id, :id => taxon.id
|
172
|
-
response.status.
|
172
|
+
expect(response.status).to eq(204)
|
173
173
|
end
|
174
174
|
end
|
175
175
|
|
@@ -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) }
|
@@ -13,10 +13,10 @@ module Spree
|
|
13
13
|
|
14
14
|
it "retreives a list of products" do
|
15
15
|
api_get :index
|
16
|
-
json_response["products"].first.
|
17
|
-
json_response["count"].
|
18
|
-
json_response["current_page"].
|
19
|
-
json_response["pages"].
|
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.
|
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'].
|
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"].
|
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'].
|
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.
|
44
|
-
json_response["error"].
|
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.
|
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.
|
98
|
-
json_response['count'].
|
99
|
-
json_response['users'].size.
|
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.
|
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.
|
113
|
-
json_response['count'].
|
114
|
-
json_response['users'].size.
|
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'].
|
121
|
-
json_response['current_page'].
|
122
|
-
json_response['pages'].
|
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'].
|
129
|
-
json_response['users'].first['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.
|
135
|
-
response.status.
|
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.
|
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"].
|
148
|
-
response.status.
|
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.
|
26
|
-
first_variant["stock_items"].
|
27
|
-
json_response["count"].
|
28
|
-
json_response["current_page"].
|
29
|
-
json_response["pages"].
|
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'].
|
36
|
-
json_response['current_page'].
|
37
|
-
json_response['pages'].
|
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 paramter' do
|
41
41
|
expected_result = create(:variant, :sku => 'FOOBAR')
|
42
42
|
api_get :index, :q => { :sku_cont => 'FOO' }
|
43
|
-
json_response['count'].
|
44
|
-
json_response['variants'].first['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.
|
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.
|
62
|
-
json_response['variants'].first['images'].first.
|
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,
|
@@ -78,12 +78,12 @@ module Spree
|
|
78
78
|
|
79
79
|
it "is not returned in the results" do
|
80
80
|
api_get :index
|
81
|
-
json_response["variants"].count.
|
81
|
+
expect(json_response["variants"].count).to eq(0)
|
82
82
|
end
|
83
83
|
|
84
84
|
it "is not returned even when show_deleted is passed" do
|
85
85
|
api_get :index, :show_deleted => true
|
86
|
-
json_response["variants"].count.
|
86
|
+
expect(json_response["variants"].count).to eq(0)
|
87
87
|
end
|
88
88
|
end
|
89
89
|
|
@@ -91,19 +91,19 @@ module Spree
|
|
91
91
|
it "can select the next page of variants" do
|
92
92
|
second_variant = create(:variant)
|
93
93
|
api_get :index, :page => 2, :per_page => 1
|
94
|
-
json_response["variants"].first.
|
95
|
-
json_response["total_count"].
|
96
|
-
json_response["current_page"].
|
97
|
-
json_response["pages"].
|
94
|
+
expect(json_response["variants"].first).to have_attributes(show_attributes)
|
95
|
+
expect(json_response["total_count"]).to eq(3)
|
96
|
+
expect(json_response["current_page"]).to eq(2)
|
97
|
+
expect(json_response["pages"]).to eq(3)
|
98
98
|
end
|
99
99
|
end
|
100
100
|
|
101
101
|
it "can see a single variant" do
|
102
102
|
api_get :show, :id => variant.to_param
|
103
|
-
json_response.
|
104
|
-
json_response["stock_items"].
|
103
|
+
expect(json_response).to have_attributes(show_attributes)
|
104
|
+
expect(json_response["stock_items"]).to be_present
|
105
105
|
option_values = json_response["option_values"]
|
106
|
-
option_values.first.
|
106
|
+
expect(option_values.first).to have_attributes([:name,
|
107
107
|
:presentation,
|
108
108
|
:option_type_name,
|
109
109
|
:option_type_id])
|
@@ -114,9 +114,9 @@ module Spree
|
|
114
114
|
|
115
115
|
api_get :show, :id => variant.to_param
|
116
116
|
|
117
|
-
json_response.
|
117
|
+
expect(json_response).to have_attributes(show_attributes + [:images])
|
118
118
|
option_values = json_response["option_values"]
|
119
|
-
option_values.first.
|
119
|
+
expect(option_values.first).to have_attributes([:name,
|
120
120
|
:presentation,
|
121
121
|
:option_type_name,
|
122
122
|
:option_type_id])
|
@@ -124,8 +124,8 @@ module Spree
|
|
124
124
|
|
125
125
|
it "can learn how to create a new variant" do
|
126
126
|
api_get :new
|
127
|
-
json_response["attributes"].
|
128
|
-
json_response["required_attributes"].
|
127
|
+
expect(json_response["attributes"]).to eq(new_attributes.map(&:to_s))
|
128
|
+
expect(json_response["required_attributes"]).to be_empty
|
129
129
|
end
|
130
130
|
|
131
131
|
it "cannot create a new variant if not an admin" do
|
@@ -141,7 +141,7 @@ module Spree
|
|
141
141
|
it "cannot delete a variant" do
|
142
142
|
api_delete :destroy, :id => variant.to_param
|
143
143
|
assert_not_found!
|
144
|
-
|
144
|
+
expect { variant.reload }.not_to raise_error
|
145
145
|
end
|
146
146
|
|
147
147
|
context "as an admin" do
|
@@ -156,28 +156,28 @@ module Spree
|
|
156
156
|
|
157
157
|
it "are visible by admin" do
|
158
158
|
api_get :index, :show_deleted => 1
|
159
|
-
json_response["variants"].count.
|
159
|
+
expect(json_response["variants"].count).to eq(1)
|
160
160
|
end
|
161
161
|
end
|
162
162
|
|
163
163
|
it "can create a new variant" do
|
164
164
|
api_post :create, :variant => { :sku => "12345" }
|
165
|
-
json_response.
|
166
|
-
response.status.
|
167
|
-
json_response["sku"].
|
165
|
+
expect(json_response).to have_attributes(new_attributes)
|
166
|
+
expect(response.status).to eq(201)
|
167
|
+
expect(json_response["sku"]).to eq("12345")
|
168
168
|
|
169
|
-
variant.product.variants.count.
|
169
|
+
expect(variant.product.variants.count).to eq(1)
|
170
170
|
end
|
171
171
|
|
172
172
|
it "can update a variant" do
|
173
173
|
api_put :update, :id => variant.to_param, :variant => { :sku => "12345" }
|
174
|
-
response.status.
|
174
|
+
expect(response.status).to eq(200)
|
175
175
|
end
|
176
176
|
|
177
177
|
it "can delete a variant" do
|
178
178
|
api_delete :destroy, :id => variant.to_param
|
179
|
-
response.status.
|
180
|
-
|
179
|
+
expect(response.status).to eq(204)
|
180
|
+
expect { Spree::Variant.find(variant.id) }.to raise_error(ActiveRecord::RecordNotFound)
|
181
181
|
end
|
182
182
|
end
|
183
183
|
end
|