solidus_api 1.2.3 → 1.3.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of solidus_api might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/Gemfile +2 -2
- data/Rakefile +1 -1
- data/app/controllers/spree/api/addresses_controller.rb +3 -2
- data/app/controllers/spree/api/base_controller.rb +10 -15
- data/app/controllers/spree/api/checkouts_controller.rb +56 -55
- data/app/controllers/spree/api/classifications_controller.rb +4 -4
- data/app/controllers/spree/api/config_controller.rb +6 -1
- data/app/controllers/spree/api/credit_cards_controller.rb +11 -11
- data/app/controllers/spree/api/images_controller.rb +13 -13
- data/app/controllers/spree/api/inventory_units_controller.rb +4 -4
- data/app/controllers/spree/api/line_items_controller.rb +27 -23
- data/app/controllers/spree/api/option_types_controller.rb +6 -5
- data/app/controllers/spree/api/option_values_controller.rb +12 -12
- data/app/controllers/spree/api/orders_controller.rb +6 -17
- data/app/controllers/spree/api/payments_controller.rb +15 -17
- data/app/controllers/spree/api/product_properties_controller.rb +13 -14
- data/app/controllers/spree/api/products_controller.rb +31 -28
- data/app/controllers/spree/api/promotions_controller.rb +9 -8
- data/app/controllers/spree/api/properties_controller.rb +9 -10
- data/app/controllers/spree/api/resource_controller.rb +9 -1
- data/app/controllers/spree/api/shipments_controller.rb +18 -18
- data/app/controllers/spree/api/states_controller.rb +8 -7
- data/app/controllers/spree/api/stock_items_controller.rb +2 -1
- data/app/controllers/spree/api/stock_locations_controller.rb +1 -1
- data/app/controllers/spree/api/stores_controller.rb +0 -1
- data/app/controllers/spree/api/taxonomies_controller.rb +7 -5
- data/app/controllers/spree/api/taxons_controller.rb +20 -19
- data/app/controllers/spree/api/users_controller.rb +1 -4
- data/app/controllers/spree/api/variants_controller.rb +19 -18
- data/app/controllers/spree/api/zones_controller.rb +3 -4
- data/app/helpers/spree/api/api_helpers.rb +7 -6
- data/app/models/spree/api_configuration.rb +1 -1
- data/app/views/spree/api/config/show.v1.rabl +2 -1
- data/app/views/spree/api/products/show.v1.rabl +1 -1
- data/db/migrate/20100107141738_add_api_key_to_spree_users.rb +1 -1
- data/db/migrate/20120411123334_resize_api_key_field.rb +1 -1
- data/lib/spree/api/engine.rb +8 -8
- data/lib/spree/api/responders/rabl_template.rb +1 -1
- data/lib/spree/api/testing_support/caching.rb +4 -4
- data/script/rails +0 -1
- data/solidus_api.gemspec +3 -3
- data/spec/controllers/spree/api/addresses_controller_spec.rb +12 -13
- data/spec/controllers/spree/api/base_controller_spec.rb +10 -11
- data/spec/controllers/spree/api/checkouts_controller_spec.rb +38 -59
- data/spec/controllers/spree/api/config_controller_spec.rb +4 -2
- data/spec/controllers/spree/api/countries_controller_spec.rb +5 -5
- data/spec/controllers/spree/api/credit_cards_controller_spec.rb +5 -5
- data/spec/controllers/spree/api/images_controller_spec.rb +20 -18
- data/spec/controllers/spree/api/inventory_units_controller_spec.rb +11 -11
- data/spec/controllers/spree/api/line_items_controller_spec.rb +20 -19
- data/spec/controllers/spree/api/option_types_controller_spec.rb +23 -24
- data/spec/controllers/spree/api/option_values_controller_spec.rb +28 -29
- data/spec/controllers/spree/api/orders_controller_spec.rb +157 -179
- data/spec/controllers/spree/api/payments_controller_spec.rb +35 -45
- data/spec/controllers/spree/api/product_properties_controller_spec.rb +14 -15
- data/spec/controllers/spree/api/products_controller_spec.rb +64 -70
- data/spec/controllers/spree/api/promotion_application_spec.rb +4 -4
- data/spec/controllers/spree/api/promotions_controller_spec.rb +1 -1
- data/spec/controllers/spree/api/properties_controller_spec.rb +15 -15
- data/spec/controllers/spree/api/resource_controller_spec.rb +31 -2
- data/spec/controllers/spree/api/return_authorizations_controller_spec.rb +31 -31
- data/spec/controllers/spree/api/shipments_controller_spec.rb +6 -8
- data/spec/controllers/spree/api/states_controller_spec.rb +11 -12
- data/spec/controllers/spree/api/stock_items_controller_spec.rb +10 -7
- data/spec/controllers/spree/api/stock_locations_controller_spec.rb +3 -4
- data/spec/controllers/spree/api/stock_movements_controller_spec.rb +2 -3
- data/spec/controllers/spree/api/store_credit_events_controller_spec.rb +0 -2
- data/spec/controllers/spree/api/stores_controller_spec.rb +1 -2
- data/spec/controllers/spree/api/taxonomies_controller_spec.rb +17 -18
- data/spec/controllers/spree/api/taxons_controller_spec.rb +22 -24
- data/spec/controllers/spree/api/unauthenticated_products_controller_spec.rb +1 -2
- data/spec/controllers/spree/api/users_controller_spec.rb +13 -15
- data/spec/controllers/spree/api/variants_controller_spec.rb +42 -37
- data/spec/controllers/spree/api/zones_controller_spec.rb +18 -18
- data/spec/features/checkout_spec.rb +2 -2
- data/spec/models/spree/legacy_user_spec.rb +5 -5
- data/spec/requests/api/address_books_spec.rb +10 -11
- data/spec/requests/rabl_cache_spec.rb +7 -7
- data/spec/requests/ransackable_attributes_spec.rb +5 -7
- data/spec/shared_examples/protect_product_actions.rb +3 -4
- data/spec/spec_helper.rb +8 -4
- data/spec/support/controller_hacks.rb +5 -5
- data/spec/support/have_attributes_matcher.rb +0 -4
- data/spec/test_views/spree/api/widgets/show.v1.rabl +1 -1
- metadata +9 -10
- data/app/models/spree/option_value_decorator.rb +0 -9
@@ -1,24 +1,24 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
module Spree
|
4
|
-
describe Api::TaxonsController, :
|
4
|
+
describe Api::TaxonsController, type: :controller do
|
5
5
|
render_views
|
6
6
|
|
7
7
|
let(:taxonomy) { create(:taxonomy) }
|
8
|
-
let(:taxon) { create(:taxon, :
|
9
|
-
let(:taxon2) { create(:taxon, :
|
8
|
+
let(:taxon) { create(:taxon, name: "Ruby", taxonomy: taxonomy) }
|
9
|
+
let(:taxon2) { create(:taxon, name: "Rails", taxonomy: taxonomy) }
|
10
10
|
let(:attributes) { ["id", "name", "pretty_name", "permalink", "parent_id", "taxonomy_id"] }
|
11
11
|
|
12
12
|
before do
|
13
13
|
stub_authentication!
|
14
|
-
taxon2.children << create(:taxon, :
|
14
|
+
taxon2.children << create(:taxon, name: "3.2.2", taxonomy: taxonomy)
|
15
15
|
taxon.children << taxon2
|
16
16
|
taxonomy.root.children << taxon
|
17
17
|
end
|
18
18
|
|
19
19
|
context "as a normal user" do
|
20
20
|
it "gets all taxons for a taxonomy" do
|
21
|
-
api_get :index, :
|
21
|
+
api_get :index, taxonomy_id: taxonomy.id
|
22
22
|
|
23
23
|
expect(json_response['taxons'].first['name']).to eq taxon.name
|
24
24
|
children = json_response['taxons'].first['taxons']
|
@@ -29,17 +29,17 @@ module Spree
|
|
29
29
|
|
30
30
|
# Regression test for https://github.com/spree/spree/issues/4112
|
31
31
|
it "does not include children when asked not to" do
|
32
|
-
api_get :index, :
|
32
|
+
api_get :index, taxonomy_id: taxonomy.id, without_children: 1
|
33
33
|
|
34
34
|
expect(json_response['taxons'].first['name']).to eq(taxon.name)
|
35
35
|
expect(json_response['taxons'].first['taxons']).to be_nil
|
36
36
|
end
|
37
37
|
|
38
38
|
it "paginates through taxons" do
|
39
|
-
new_taxon = create(:taxon, :
|
39
|
+
new_taxon = create(:taxon, name: "Go", taxonomy: taxonomy)
|
40
40
|
taxonomy.root.children << new_taxon
|
41
41
|
expect(taxonomy.root.children.count).to eql(2)
|
42
|
-
api_get :index, :
|
42
|
+
api_get :index, taxonomy_id: taxonomy.id, page: 1, per_page: 1
|
43
43
|
expect(json_response["count"]).to eql(1)
|
44
44
|
expect(json_response["total_count"]).to eql(2)
|
45
45
|
expect(json_response["current_page"]).to eql(1)
|
@@ -50,7 +50,7 @@ module Spree
|
|
50
50
|
describe 'searching' do
|
51
51
|
context 'with a name' do
|
52
52
|
before do
|
53
|
-
api_get :index, :
|
53
|
+
api_get :index, q: { name_cont: name }
|
54
54
|
end
|
55
55
|
|
56
56
|
context 'with one result' do
|
@@ -86,39 +86,39 @@ module Spree
|
|
86
86
|
end
|
87
87
|
|
88
88
|
it "gets a single taxon" do
|
89
|
-
api_get :show, :
|
89
|
+
api_get :show, id: taxon.id, taxonomy_id: taxonomy.id
|
90
90
|
|
91
91
|
expect(json_response['name']).to eq taxon.name
|
92
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
|
-
api_get :jstree, :
|
96
|
+
api_get :jstree, taxonomy_id: taxonomy.id, id: taxon.id
|
97
97
|
response = json_response.first
|
98
98
|
expect(response["data"]).to eq(taxon2.name)
|
99
|
-
expect(response["attr"]).to eq({ "name" => taxon2.name, "id" => taxon2.id})
|
99
|
+
expect(response["attr"]).to eq({ "name" => taxon2.name, "id" => taxon2.id })
|
100
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
|
-
api_get :new, :
|
104
|
+
api_get :new, taxonomy_id: taxonomy.id
|
105
105
|
expect(json_response["attributes"]).to eq(attributes.map(&:to_s))
|
106
106
|
required_attributes = json_response["required_attributes"]
|
107
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
|
111
|
-
api_post :create, :
|
111
|
+
api_post :create, taxonomy_id: taxonomy.id, taxon: { name: "Location" }
|
112
112
|
assert_unauthorized!
|
113
113
|
end
|
114
114
|
|
115
115
|
it "cannot update a taxon" do
|
116
|
-
api_put :update, :
|
116
|
+
api_put :update, taxonomy_id: taxonomy.id, id: taxon.id, taxon: { name: "I hacked your store!" }
|
117
117
|
assert_unauthorized!
|
118
118
|
end
|
119
119
|
|
120
120
|
it "cannot delete a taxon" do
|
121
|
-
api_delete :destroy, :
|
121
|
+
api_delete :destroy, taxonomy_id: taxonomy.id, id: taxon.id
|
122
122
|
assert_unauthorized!
|
123
123
|
end
|
124
124
|
end
|
@@ -127,12 +127,12 @@ module Spree
|
|
127
127
|
sign_in_as_admin!
|
128
128
|
|
129
129
|
it "can create" do
|
130
|
-
api_post :create, :
|
130
|
+
api_post :create, taxonomy_id: taxonomy.id, taxon: { name: "Colors" }
|
131
131
|
expect(json_response).to have_attributes(attributes)
|
132
132
|
expect(response.status).to eq(201)
|
133
133
|
|
134
134
|
expect(taxonomy.reload.root.children.count).to eq 2
|
135
|
-
taxon = Spree::Taxon.where(:
|
135
|
+
taxon = Spree::Taxon.where(name: 'Colors').first
|
136
136
|
|
137
137
|
expect(taxon.parent_id).to eq taxonomy.root.id
|
138
138
|
expect(taxon.taxonomy_id).to eq taxonomy.id
|
@@ -140,23 +140,22 @@ module Spree
|
|
140
140
|
|
141
141
|
it "can update the position in the list" do
|
142
142
|
taxonomy.root.children << taxon2
|
143
|
-
api_put :update, :
|
143
|
+
api_put :update, taxonomy_id: taxonomy.id, id: taxon.id, taxon: { parent_id: taxon.parent_id, child_index: 2 }
|
144
144
|
expect(response.status).to eq(200)
|
145
145
|
expect(taxonomy.reload.root.children[0]).to eql taxon2
|
146
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
|
-
api_post :create, :
|
150
|
+
api_post :create, taxonomy_id: taxonomy.id, taxon: {}
|
151
151
|
expect(response.status).to eq(422)
|
152
152
|
expect(json_response["error"]).to eq("Invalid resource. Please fix errors and try again.")
|
153
|
-
errors = json_response["errors"]
|
154
153
|
|
155
154
|
expect(taxonomy.reload.root.children.count).to eq 1
|
156
155
|
end
|
157
156
|
|
158
157
|
it "cannot create a new taxon with invalid taxonomy_id" do
|
159
|
-
api_post :create, :
|
158
|
+
api_post :create, taxonomy_id: 1000, taxon: { name: "Colors" }
|
160
159
|
expect(response.status).to eq(422)
|
161
160
|
expect(json_response["error"]).to eq("Invalid resource. Please fix errors and try again.")
|
162
161
|
|
@@ -168,10 +167,9 @@ module Spree
|
|
168
167
|
end
|
169
168
|
|
170
169
|
it "can destroy" do
|
171
|
-
api_delete :destroy, :
|
170
|
+
api_delete :destroy, taxonomy_id: taxonomy.id, id: taxon.id
|
172
171
|
expect(response.status).to eq(204)
|
173
172
|
end
|
174
173
|
end
|
175
|
-
|
176
174
|
end
|
177
175
|
end
|
@@ -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, :
|
5
|
+
describe Spree::Api::ProductsController, type: :controller do
|
6
6
|
render_views
|
7
7
|
|
8
8
|
let!(:product) { create(:product) }
|
@@ -23,4 +23,3 @@ module Spree
|
|
23
23
|
end
|
24
24
|
end
|
25
25
|
end
|
26
|
-
|
@@ -1,11 +1,11 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
module Spree
|
4
|
-
describe Api::UsersController, :
|
4
|
+
describe Api::UsersController, type: :controller do
|
5
5
|
render_views
|
6
6
|
|
7
7
|
let(:user) { create(:user, spree_api_key: SecureRandom.hex) }
|
8
|
-
let(:stranger) { create(:user, :
|
8
|
+
let(:stranger) { create(:user, email: 'stranger@example.com') }
|
9
9
|
let(:attributes) { [:id, :email, :created_at, :updated_at] }
|
10
10
|
|
11
11
|
context "as a normal user" do
|
@@ -28,19 +28,18 @@ module Spree
|
|
28
28
|
|
29
29
|
it "can create a new user" do
|
30
30
|
user_params = {
|
31
|
-
:
|
31
|
+
email: 'new@example.com', password: 'spree123', password_confirmation: 'spree123'
|
32
32
|
}
|
33
33
|
|
34
|
-
api_post :create, :
|
34
|
+
api_post :create, user: user_params, token: user.spree_api_key
|
35
35
|
expect(json_response['email']).to eq 'new@example.com'
|
36
36
|
end
|
37
37
|
|
38
38
|
# there's no validations on LegacyUser?
|
39
39
|
xit "cannot create a new user with invalid attributes" do
|
40
|
-
api_post :create, :
|
40
|
+
api_post :create, user: {}, token: user.spree_api_key
|
41
41
|
expect(response.status).to eq(422)
|
42
42
|
expect(json_response["error"]).to eq("Invalid resource. Please fix errors and try again.")
|
43
|
-
errors = json_response["errors"]
|
44
43
|
end
|
45
44
|
|
46
45
|
it "can update own details" do
|
@@ -74,7 +73,7 @@ module Spree
|
|
74
73
|
end
|
75
74
|
|
76
75
|
it "cannot update other users details" do
|
77
|
-
api_put :update, id: stranger.id, token: user.spree_api_key, user: { :
|
76
|
+
api_put :update, id: stranger.id, token: user.spree_api_key, user: { email: "mine@example.com" }
|
78
77
|
assert_not_found!
|
79
78
|
end
|
80
79
|
|
@@ -116,38 +115,37 @@ module Spree
|
|
116
115
|
|
117
116
|
it 'can control the page size through a parameter' do
|
118
117
|
2.times { create(:user) }
|
119
|
-
api_get :index, :
|
118
|
+
api_get :index, per_page: 1
|
120
119
|
expect(json_response['count']).to eq(1)
|
121
120
|
expect(json_response['current_page']).to eq(1)
|
122
121
|
expect(json_response['pages']).to eq(2)
|
123
122
|
end
|
124
123
|
|
125
124
|
it 'can query the results through a paramter' do
|
126
|
-
expected_result = create(:user, :
|
127
|
-
api_get :index, :
|
125
|
+
expected_result = create(:user, email: 'brian@spreecommerce.com')
|
126
|
+
api_get :index, q: { email_cont: 'brian' }
|
128
127
|
expect(json_response['count']).to eq(1)
|
129
128
|
expect(json_response['users'].first['email']).to eq expected_result.email
|
130
129
|
end
|
131
130
|
|
132
131
|
it "can create" do
|
133
|
-
api_post :create, :
|
132
|
+
api_post :create, user: { email: "new@example.com", password: 'spree123', password_confirmation: 'spree123' }
|
134
133
|
expect(json_response).to have_attributes(attributes)
|
135
134
|
expect(response.status).to eq(201)
|
136
135
|
end
|
137
136
|
|
138
137
|
it "can destroy user without orders" do
|
139
138
|
user.orders.destroy_all
|
140
|
-
api_delete :destroy, :
|
139
|
+
api_delete :destroy, id: user.id
|
141
140
|
expect(response.status).to eq(204)
|
142
141
|
end
|
143
142
|
|
144
143
|
it "cannot destroy user with orders" do
|
145
|
-
create(:completed_order_with_totals, :
|
146
|
-
api_delete :destroy, :
|
144
|
+
create(:completed_order_with_totals, user: user)
|
145
|
+
api_delete :destroy, id: user.id
|
147
146
|
expect(json_response["exception"]).to eq "Spree::Core::DestroyWithOrdersError"
|
148
147
|
expect(response.status).to eq(422)
|
149
148
|
end
|
150
|
-
|
151
149
|
end
|
152
150
|
end
|
153
151
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
module Spree
|
4
|
-
describe Api::VariantsController, :
|
4
|
+
describe Api::VariantsController, type: :controller do
|
5
5
|
render_views
|
6
6
|
|
7
7
|
let!(:product) { create(:product) }
|
@@ -20,7 +20,6 @@ module Spree
|
|
20
20
|
end
|
21
21
|
|
22
22
|
describe "#index" do
|
23
|
-
|
24
23
|
it "can see a paginated list of variants" do
|
25
24
|
api_get :index
|
26
25
|
first_variant = json_response["variants"].first
|
@@ -33,15 +32,15 @@ module Spree
|
|
33
32
|
|
34
33
|
it 'can control the page size through a parameter' do
|
35
34
|
create(:variant)
|
36
|
-
api_get :index, :
|
35
|
+
api_get :index, per_page: 1
|
37
36
|
expect(json_response['count']).to eq(1)
|
38
37
|
expect(json_response['current_page']).to eq(1)
|
39
38
|
expect(json_response['pages']).to eq(3)
|
40
39
|
end
|
41
40
|
|
42
41
|
it 'can query the results through a paramter' do
|
43
|
-
expected_result = create(:variant, :
|
44
|
-
api_get :index, :
|
42
|
+
expected_result = create(:variant, sku: 'FOOBAR')
|
43
|
+
api_get :index, q: { sku_cont: 'FOO' }
|
45
44
|
expect(json_response['count']).to eq(1)
|
46
45
|
expect(json_response['variants'].first['sku']).to eq expected_result.sku
|
47
46
|
end
|
@@ -50,26 +49,25 @@ module Spree
|
|
50
49
|
api_get :index
|
51
50
|
option_values = json_response["variants"].last["option_values"]
|
52
51
|
expect(option_values.first).to have_attributes([:name,
|
53
|
-
|
54
|
-
|
55
|
-
|
52
|
+
:presentation,
|
53
|
+
:option_type_name,
|
54
|
+
:option_type_id])
|
56
55
|
end
|
57
56
|
|
58
57
|
it "variants returned contain images data" do
|
59
|
-
variant.images.create!(:
|
58
|
+
variant.images.create!(attachment: image("thinking-cat.jpg"))
|
60
59
|
|
61
60
|
api_get :index
|
62
61
|
|
63
62
|
expect(json_response["variants"].last).to have_attributes([:images])
|
64
63
|
expect(json_response['variants'].first['images'].first).to have_attributes([:attachment_file_name,
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
64
|
+
:attachment_width,
|
65
|
+
:attachment_height,
|
66
|
+
:attachment_content_type,
|
67
|
+
:mini_url,
|
68
|
+
:small_url,
|
69
|
+
:product_url,
|
70
|
+
:large_url])
|
73
71
|
end
|
74
72
|
|
75
73
|
# Regression test for https://github.com/spree/spree/issues/2141
|
@@ -84,7 +82,7 @@ module Spree
|
|
84
82
|
end
|
85
83
|
|
86
84
|
it "is not returned even when show_deleted is passed" do
|
87
|
-
api_get :index, :
|
85
|
+
api_get :index, show_deleted: true
|
88
86
|
expect(json_response["variants"].count).to eq(0)
|
89
87
|
end
|
90
88
|
end
|
@@ -117,8 +115,8 @@ module Spree
|
|
117
115
|
|
118
116
|
context "pagination" do
|
119
117
|
it "can select the next page of variants" do
|
120
|
-
|
121
|
-
api_get :index, :
|
118
|
+
create(:variant)
|
119
|
+
api_get :index, page: 2, per_page: 1
|
122
120
|
expect(json_response["variants"].first).to have_attributes(show_attributes)
|
123
121
|
expect(json_response["total_count"]).to eq(3)
|
124
122
|
expect(json_response["current_page"]).to eq(2)
|
@@ -142,7 +140,6 @@ module Spree
|
|
142
140
|
end
|
143
141
|
|
144
142
|
describe "#show" do
|
145
|
-
|
146
143
|
subject { api_get :show, id: variant.to_param }
|
147
144
|
|
148
145
|
it "can see a single variant" do
|
@@ -151,22 +148,22 @@ module Spree
|
|
151
148
|
expect(json_response["stock_items"]).to be_present
|
152
149
|
option_values = json_response["option_values"]
|
153
150
|
expect(option_values.first).to have_attributes([:name,
|
154
|
-
|
155
|
-
|
156
|
-
|
151
|
+
:presentation,
|
152
|
+
:option_type_name,
|
153
|
+
:option_type_id])
|
157
154
|
end
|
158
155
|
|
159
156
|
it "can see a single variant with images" do
|
160
|
-
variant.images.create!(:
|
157
|
+
variant.images.create!(attachment: image("thinking-cat.jpg"))
|
161
158
|
|
162
159
|
subject
|
163
160
|
|
164
161
|
expect(json_response).to have_attributes(show_attributes + [:images])
|
165
162
|
option_values = json_response["option_values"]
|
166
163
|
expect(option_values.first).to have_attributes([:name,
|
167
|
-
|
168
|
-
|
169
|
-
|
164
|
+
:presentation,
|
165
|
+
:option_type_name,
|
166
|
+
:option_type_id])
|
170
167
|
end
|
171
168
|
|
172
169
|
context "variant doesn't have variant properties" do
|
@@ -204,24 +201,24 @@ module Spree
|
|
204
201
|
end
|
205
202
|
|
206
203
|
it "cannot create a new variant if not an admin" do
|
207
|
-
api_post :create, :
|
204
|
+
api_post :create, variant: { sku: "12345" }
|
208
205
|
assert_unauthorized!
|
209
206
|
end
|
210
207
|
|
211
208
|
it "cannot update a variant" do
|
212
|
-
api_put :update, :
|
209
|
+
api_put :update, id: variant.to_param, variant: { sku: "12345" }
|
213
210
|
assert_not_found!
|
214
211
|
end
|
215
212
|
|
216
213
|
it "cannot delete a variant" do
|
217
|
-
api_delete :destroy, :
|
214
|
+
api_delete :destroy, id: variant.to_param
|
218
215
|
assert_not_found!
|
219
216
|
expect { variant.reload }.not_to raise_error
|
220
217
|
end
|
221
218
|
|
222
219
|
context "as an admin" do
|
223
220
|
sign_in_as_admin!
|
224
|
-
let(:resource_scoping) { { :
|
221
|
+
let(:resource_scoping) { { product_id: variant.product.to_param } }
|
225
222
|
|
226
223
|
# Test for https://github.com/spree/spree/issues/2141
|
227
224
|
context "deleted variants" do
|
@@ -230,13 +227,13 @@ module Spree
|
|
230
227
|
end
|
231
228
|
|
232
229
|
it "are visible by admin" do
|
233
|
-
api_get :index, :
|
230
|
+
api_get :index, show_deleted: 1
|
234
231
|
expect(json_response["variants"].count).to eq(1)
|
235
232
|
end
|
236
233
|
end
|
237
234
|
|
238
235
|
it "can create a new variant" do
|
239
|
-
api_post :create, :
|
236
|
+
api_post :create, variant: { sku: "12345" }
|
240
237
|
expect(json_response).to have_attributes(new_attributes)
|
241
238
|
expect(response.status).to eq(201)
|
242
239
|
expect(json_response["sku"]).to eq("12345")
|
@@ -244,20 +241,28 @@ module Spree
|
|
244
241
|
expect(variant.product.variants.count).to eq(1)
|
245
242
|
end
|
246
243
|
|
244
|
+
it "creates new variants with nested option values" do
|
245
|
+
option_values = create_list(:option_value, 2)
|
246
|
+
expect do
|
247
|
+
api_post :create, variant: { sku: "12345",
|
248
|
+
option_value_ids: option_values.map(&:id) }
|
249
|
+
end.to change { Spree::OptionValuesVariant.count }.by(2)
|
250
|
+
end
|
251
|
+
|
247
252
|
it "can update a variant" do
|
248
|
-
api_put :update, :
|
253
|
+
api_put :update, id: variant.to_param, variant: { sku: "12345" }
|
249
254
|
expect(response.status).to eq(200)
|
250
255
|
end
|
251
256
|
|
252
257
|
it "can delete a variant" do
|
253
|
-
api_delete :destroy, :
|
258
|
+
api_delete :destroy, id: variant.to_param
|
254
259
|
expect(response.status).to eq(204)
|
255
260
|
expect { Spree::Variant.find(variant.id) }.to raise_error(ActiveRecord::RecordNotFound)
|
256
261
|
end
|
257
262
|
|
258
263
|
it 'variants returned contain cost price data' do
|
259
264
|
api_get :index
|
260
|
-
expect(json_response["variants"].first.
|
265
|
+
expect(json_response["variants"].first.key?(:cost_price)).to eq true
|
261
266
|
end
|
262
267
|
end
|
263
268
|
end
|
@@ -1,14 +1,14 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
module Spree
|
4
|
-
describe Api::ZonesController, :
|
4
|
+
describe Api::ZonesController, type: :controller do
|
5
5
|
render_views
|
6
6
|
|
7
7
|
let!(:attributes) { [:id, :name, :zone_members] }
|
8
8
|
|
9
9
|
before do
|
10
10
|
stub_authentication!
|
11
|
-
@zone = create(:zone, :
|
11
|
+
@zone = create(:zone, name: 'Europe')
|
12
12
|
end
|
13
13
|
|
14
14
|
it "gets list of zones" do
|
@@ -18,21 +18,21 @@ module Spree
|
|
18
18
|
|
19
19
|
it 'can control the page size through a parameter' do
|
20
20
|
create(:zone)
|
21
|
-
api_get :index, :
|
21
|
+
api_get :index, per_page: 1
|
22
22
|
expect(json_response['count']).to eq(1)
|
23
23
|
expect(json_response['current_page']).to eq(1)
|
24
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
|
-
expected_result = create(:zone, :
|
29
|
-
api_get :index, :
|
28
|
+
expected_result = create(:zone, name: 'South America')
|
29
|
+
api_get :index, q: { name_cont: 'south' }
|
30
30
|
expect(json_response['count']).to eq(1)
|
31
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
|
-
api_get :show, :
|
35
|
+
api_get :show, id: @zone.id
|
36
36
|
expect(json_response).to have_attributes(attributes)
|
37
37
|
expect(json_response['name']).to eq @zone.name
|
38
38
|
expect(json_response['zone_members'].size).to eq @zone.zone_members.count
|
@@ -43,12 +43,12 @@ module Spree
|
|
43
43
|
|
44
44
|
it "can create a new zone" do
|
45
45
|
params = {
|
46
|
-
:
|
47
|
-
:
|
48
|
-
:
|
46
|
+
zone: {
|
47
|
+
name: "North Pole",
|
48
|
+
zone_members: [
|
49
49
|
{
|
50
|
-
:
|
51
|
-
:
|
50
|
+
zoneable_type: "Spree::Country",
|
51
|
+
zoneable_id: 1
|
52
52
|
}
|
53
53
|
]
|
54
54
|
}
|
@@ -61,13 +61,13 @@ module Spree
|
|
61
61
|
end
|
62
62
|
|
63
63
|
it "updates a zone" do
|
64
|
-
params = { :
|
65
|
-
:
|
66
|
-
:
|
67
|
-
:
|
64
|
+
params = { id: @zone.id,
|
65
|
+
zone: {
|
66
|
+
name: "North Pole",
|
67
|
+
zone_members: [
|
68
68
|
{
|
69
|
-
:
|
70
|
-
:
|
69
|
+
zoneable_type: "Spree::Country",
|
70
|
+
zoneable_id: 1
|
71
71
|
}
|
72
72
|
]
|
73
73
|
}
|
@@ -80,7 +80,7 @@ module Spree
|
|
80
80
|
end
|
81
81
|
|
82
82
|
it "can delete a zone" do
|
83
|
-
api_delete :destroy, :
|
83
|
+
api_delete :destroy, id: @zone.id
|
84
84
|
expect(response.status).to eq(204)
|
85
85
|
expect { @zone.reload }.to raise_error(ActiveRecord::RecordNotFound)
|
86
86
|
end
|
@@ -52,7 +52,7 @@ module Spree
|
|
52
52
|
expect(response).to have_http_status(:created)
|
53
53
|
end
|
54
54
|
|
55
|
-
def add_promotion(
|
55
|
+
def add_promotion(_promotion)
|
56
56
|
expect {
|
57
57
|
put "/api/orders/#{@order.number}/apply_coupon_code", coupon_code: promotion_code.value
|
58
58
|
}.to change { @order.promotions.count }.by 1
|
@@ -92,7 +92,7 @@ module Spree
|
|
92
92
|
expect(@order.completed_at).to be_a ActiveSupport::TimeWithZone
|
93
93
|
expect(@order.item_total).to eq 600.00
|
94
94
|
expect(@order.total).to eq 600.00
|
95
|
-
expect(@order.adjustment_total).to eq
|
95
|
+
expect(@order.adjustment_total).to eq(-10.00)
|
96
96
|
expect(@order.shipment_total).to eq 10.00
|
97
97
|
expect(@order.user).to eq @user
|
98
98
|
expect(@order.bill_address).to eq bill_address
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
module Spree
|
4
|
-
describe LegacyUser, :
|
4
|
+
describe LegacyUser, type: :model do
|
5
5
|
let(:user) { LegacyUser.new }
|
6
6
|
|
7
7
|
it "can generate an API key" do
|
@@ -47,7 +47,7 @@ module Spree
|
|
47
47
|
end
|
48
48
|
|
49
49
|
context "roles_for_auto_api_key is defined" do
|
50
|
-
let
|
50
|
+
let(:role) { create(:role, name: 'hobbit') }
|
51
51
|
let(:undesired_role) { create(:role, name: "foo") }
|
52
52
|
|
53
53
|
before {
|
@@ -60,9 +60,9 @@ module Spree
|
|
60
60
|
end
|
61
61
|
|
62
62
|
context "for all roles" do
|
63
|
-
let
|
64
|
-
let
|
65
|
-
let
|
63
|
+
let(:role) { create(:role, name: 'hobbit') }
|
64
|
+
let(:other_role) { create(:role, name: 'wizard') }
|
65
|
+
let(:other_user) { create(:user) }
|
66
66
|
|
67
67
|
before {
|
68
68
|
user.clear_spree_api_key!
|