spree_api 2.3.4 → 2.3.5
Sign up to get free protection for your applications and to get access to all the features.
- 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::ClassificationsController do
|
4
|
+
describe Api::ClassificationsController, :type => :controller do
|
5
5
|
let(:taxon) do
|
6
6
|
taxon = create(:taxon)
|
7
7
|
3.times do
|
@@ -18,7 +18,7 @@ module Spree
|
|
18
18
|
context "as a user" do
|
19
19
|
it "cannot change the order of a product" do
|
20
20
|
api_put :update, :taxon_id => taxon, :product_id => taxon.products.first, :position => 1
|
21
|
-
response.status.
|
21
|
+
expect(response.status).to eq(401)
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
@@ -28,10 +28,10 @@ module Spree
|
|
28
28
|
it "can change the order a product" do
|
29
29
|
last_product = taxon.products.last
|
30
30
|
classification = taxon.classifications.find_by(:product_id => last_product.id)
|
31
|
-
classification.position.
|
31
|
+
expect(classification.position).to eq(3)
|
32
32
|
api_put :update, :taxon_id => taxon, :product_id => last_product, :position => 0
|
33
|
-
response.status.
|
34
|
-
classification.reload.position.
|
33
|
+
expect(response.status).to eq(200)
|
34
|
+
expect(classification.reload.position).to eq(1)
|
35
35
|
end
|
36
36
|
end
|
37
37
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
module Spree
|
4
|
-
describe Api::ConfigController do
|
4
|
+
describe Api::ConfigController, :type => :controller do
|
5
5
|
render_views
|
6
6
|
|
7
7
|
before do
|
@@ -10,18 +10,18 @@ module Spree
|
|
10
10
|
|
11
11
|
it "returns Spree::Money settings" do
|
12
12
|
api_get :money
|
13
|
-
response.
|
14
|
-
json_response["symbol"].
|
15
|
-
json_response["symbol_position"].
|
16
|
-
json_response["no_cents"].
|
17
|
-
json_response["decimal_mark"].
|
18
|
-
json_response["thousands_separator"].
|
13
|
+
expect(response).to be_success
|
14
|
+
expect(json_response["symbol"]).to eq("$")
|
15
|
+
expect(json_response["symbol_position"]).to eq("before")
|
16
|
+
expect(json_response["no_cents"]).to eq(false)
|
17
|
+
expect(json_response["decimal_mark"]).to eq(".")
|
18
|
+
expect(json_response["thousands_separator"]).to eq(",")
|
19
19
|
end
|
20
20
|
|
21
21
|
it "returns some configuration settings" do
|
22
22
|
api_get :show
|
23
|
-
response.
|
24
|
-
json_response["default_country_id"].
|
23
|
+
expect(response).to be_success
|
24
|
+
expect(json_response["default_country_id"]).to eq(Spree::Config[:default_country_id])
|
25
25
|
end
|
26
26
|
end
|
27
27
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
module Spree
|
4
|
-
describe Api::CountriesController do
|
4
|
+
describe Api::CountriesController, :type => :controller do
|
5
5
|
render_views
|
6
6
|
|
7
7
|
before do
|
@@ -12,7 +12,7 @@ module Spree
|
|
12
12
|
|
13
13
|
it "gets all countries" do
|
14
14
|
api_get :index
|
15
|
-
json_response['countries'].first['iso3'].
|
15
|
+
expect(json_response['countries'].first['iso3']).to eq @country.iso3
|
16
16
|
end
|
17
17
|
|
18
18
|
context "with two countries" do
|
@@ -20,29 +20,29 @@ module Spree
|
|
20
20
|
|
21
21
|
it "can view all countries" do
|
22
22
|
api_get :index
|
23
|
-
json_response['count'].
|
24
|
-
json_response['current_page'].
|
25
|
-
json_response['pages'].
|
23
|
+
expect(json_response['count']).to eq(2)
|
24
|
+
expect(json_response['current_page']).to eq(1)
|
25
|
+
expect(json_response['pages']).to eq(1)
|
26
26
|
end
|
27
27
|
|
28
28
|
it 'can query the results through a paramter' do
|
29
29
|
api_get :index, :q => { :name_cont => 'zam' }
|
30
|
-
json_response['count'].
|
31
|
-
json_response['countries'].first['name'].
|
30
|
+
expect(json_response['count']).to eq(1)
|
31
|
+
expect(json_response['countries'].first['name']).to eq @zambia.name
|
32
32
|
end
|
33
33
|
|
34
34
|
it 'can control the page size through a parameter' do
|
35
35
|
api_get :index, :per_page => 1
|
36
|
-
json_response['count'].
|
37
|
-
json_response['current_page'].
|
38
|
-
json_response['pages'].
|
36
|
+
expect(json_response['count']).to eq(1)
|
37
|
+
expect(json_response['current_page']).to eq(1)
|
38
|
+
expect(json_response['pages']).to eq(2)
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
42
|
it "includes states" do
|
43
43
|
api_get :show, :id => @country.id
|
44
44
|
states = json_response['states']
|
45
|
-
states.first['name'].
|
45
|
+
expect(states.first['name']).to eq @state.name
|
46
46
|
end
|
47
47
|
end
|
48
48
|
end
|
@@ -1,13 +1,13 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
module Spree
|
4
|
-
describe Api::CreditCardsController do
|
4
|
+
describe Api::CreditCardsController, :type => :controller do
|
5
5
|
render_views
|
6
6
|
|
7
7
|
let!(:admin_user) do
|
8
8
|
user = Spree.user_class.new(:email => "spree@example.com", :id => 1)
|
9
9
|
user.generate_spree_api_key!
|
10
|
-
user.
|
10
|
+
allow(user).to receive(:has_spree_role?).with('admin').and_return(true)
|
11
11
|
user
|
12
12
|
end
|
13
13
|
|
@@ -25,7 +25,7 @@ module Spree
|
|
25
25
|
|
26
26
|
it "the user id doesn't exist" do
|
27
27
|
api_get :index, user_id: 1000
|
28
|
-
response.status.
|
28
|
+
expect(response.status).to eq(404)
|
29
29
|
end
|
30
30
|
|
31
31
|
context "calling user is in admin role" do
|
@@ -37,18 +37,18 @@ module Spree
|
|
37
37
|
it "no credit cards exist for user" do
|
38
38
|
api_get :index, user_id: normal_user.id
|
39
39
|
|
40
|
-
response.status.
|
41
|
-
json_response["pages"].
|
40
|
+
expect(response.status).to eq(200)
|
41
|
+
expect(json_response["pages"]).to eq(0)
|
42
42
|
end
|
43
43
|
|
44
44
|
it "can view all credit cards for user" do
|
45
45
|
api_get :index, user_id: current_api_user.id
|
46
46
|
|
47
|
-
response.status.
|
48
|
-
json_response["pages"].
|
49
|
-
json_response["current_page"].
|
50
|
-
json_response["credit_cards"].length.
|
51
|
-
json_response["credit_cards"].first["id"].
|
47
|
+
expect(response.status).to eq(200)
|
48
|
+
expect(json_response["pages"]).to eq(1)
|
49
|
+
expect(json_response["current_page"]).to eq(1)
|
50
|
+
expect(json_response["credit_cards"].length).to eq(1)
|
51
|
+
expect(json_response["credit_cards"].first["id"]).to eq(card.id)
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
@@ -63,17 +63,17 @@ module Spree
|
|
63
63
|
it "can not view user" do
|
64
64
|
api_get :index, user_id: admin_user.id
|
65
65
|
|
66
|
-
response.status.
|
66
|
+
expect(response.status).to eq(404)
|
67
67
|
end
|
68
68
|
|
69
69
|
it "can view own credit cards" do
|
70
70
|
api_get :index, user_id: normal_user.id
|
71
71
|
|
72
|
-
response.status.
|
73
|
-
json_response["pages"].
|
74
|
-
json_response["current_page"].
|
75
|
-
json_response["credit_cards"].length.
|
76
|
-
json_response["credit_cards"].first["id"].
|
72
|
+
expect(response.status).to eq(200)
|
73
|
+
expect(json_response["pages"]).to eq(1)
|
74
|
+
expect(json_response["current_page"]).to eq(1)
|
75
|
+
expect(json_response["credit_cards"].length).to eq(1)
|
76
|
+
expect(json_response["credit_cards"].first["id"]).to eq(card.id)
|
77
77
|
end
|
78
78
|
end
|
79
79
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
module Spree
|
4
|
-
describe Spree::Api::ImagesController do
|
4
|
+
describe Spree::Api::ImagesController, :type => :controller do
|
5
5
|
render_views
|
6
6
|
|
7
7
|
let!(:product) { create(:product) }
|
@@ -17,32 +17,32 @@ module Spree
|
|
17
17
|
sign_in_as_admin!
|
18
18
|
|
19
19
|
it "can upload a new image for a variant" do
|
20
|
-
|
20
|
+
expect do
|
21
21
|
api_post :create,
|
22
22
|
:image => { :attachment => upload_image('thinking-cat.jpg'),
|
23
23
|
:viewable_type => 'Spree::Variant',
|
24
24
|
:viewable_id => product.master.to_param },
|
25
25
|
:product_id => product.id
|
26
|
-
response.status.
|
27
|
-
json_response.
|
28
|
-
end.
|
26
|
+
expect(response.status).to eq(201)
|
27
|
+
expect(json_response).to have_attributes(attributes)
|
28
|
+
end.to change(Image, :count).by(1)
|
29
29
|
end
|
30
30
|
|
31
31
|
context "working with an existing image" do
|
32
32
|
let!(:product_image) { product.master.images.create!(:attachment => image('thinking-cat.jpg')) }
|
33
33
|
|
34
34
|
it "can update image data" do
|
35
|
-
product_image.position.
|
35
|
+
expect(product_image.position).to eq(1)
|
36
36
|
api_post :update, :image => { :position => 2 }, :id => product_image.id, :product_id => product.id
|
37
|
-
response.status.
|
38
|
-
json_response.
|
39
|
-
product_image.reload.position.
|
37
|
+
expect(response.status).to eq(200)
|
38
|
+
expect(json_response).to have_attributes(attributes)
|
39
|
+
expect(product_image.reload.position).to eq(2)
|
40
40
|
end
|
41
41
|
|
42
42
|
it "can delete an image" do
|
43
43
|
api_delete :destroy, :id => product_image.id, :product_id => product.id
|
44
|
-
response.status.
|
45
|
-
|
44
|
+
expect(response.status).to eq(204)
|
45
|
+
expect { product_image.reload }.to raise_error(ActiveRecord::RecordNotFound)
|
46
46
|
end
|
47
47
|
end
|
48
48
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
module Spree
|
4
|
-
describe Api::InventoryUnitsController do
|
4
|
+
describe Api::InventoryUnitsController, :type => :controller do
|
5
5
|
render_views
|
6
6
|
|
7
7
|
before do
|
@@ -14,13 +14,13 @@ module Spree
|
|
14
14
|
|
15
15
|
it "gets an inventory unit" do
|
16
16
|
api_get :show, :id => @inventory_unit.id
|
17
|
-
json_response['state'].
|
17
|
+
expect(json_response['state']).to eq @inventory_unit.state
|
18
18
|
end
|
19
19
|
|
20
20
|
it "updates an inventory unit (only shipment is accessable by default)" do
|
21
21
|
api_put :update, :id => @inventory_unit.id,
|
22
22
|
:inventory_unit => { :shipment => nil }
|
23
|
-
json_response['shipment_id'].
|
23
|
+
expect(json_response['shipment_id']).to be_nil
|
24
24
|
end
|
25
25
|
|
26
26
|
context 'fires state event' do
|
@@ -29,19 +29,19 @@ module Spree
|
|
29
29
|
:fire => 'ship',
|
30
30
|
:inventory_unit => { :shipment => nil }
|
31
31
|
|
32
|
-
json_response['state'].
|
32
|
+
expect(json_response['state']).to eq 'shipped'
|
33
33
|
end
|
34
34
|
|
35
35
|
it 'and returns exception if cannot fire' do
|
36
36
|
api_put :update, :id => @inventory_unit.id,
|
37
37
|
:fire => 'return'
|
38
|
-
json_response['exception'].
|
38
|
+
expect(json_response['exception']).to match /cannot transition to return/
|
39
39
|
end
|
40
40
|
|
41
41
|
it 'and returns exception bad state' do
|
42
42
|
api_put :update, :id => @inventory_unit.id,
|
43
43
|
:fire => 'bad'
|
44
|
-
json_response['exception'].
|
44
|
+
expect(json_response['exception']).to match /cannot transition to bad/
|
45
45
|
end
|
46
46
|
end
|
47
47
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
module Spree
|
4
|
-
describe Api::LineItemsController do
|
4
|
+
describe Api::LineItemsController, :type => :controller do
|
5
5
|
render_views
|
6
6
|
|
7
7
|
let!(:order) { create(:order_with_line_items) }
|
@@ -11,77 +11,77 @@ module Spree
|
|
11
11
|
let(:resource_scoping) { { :order_id => order.to_param } }
|
12
12
|
|
13
13
|
it "can learn how to create a new line item" do
|
14
|
-
controller.
|
14
|
+
allow(controller).to receive_messages :try_spree_current_user => current_api_user
|
15
15
|
api_get :new
|
16
|
-
json_response["attributes"].
|
16
|
+
expect(json_response["attributes"]).to eq(["quantity", "price", "variant_id"])
|
17
17
|
required_attributes = json_response["required_attributes"]
|
18
|
-
required_attributes.
|
18
|
+
expect(required_attributes).to include("quantity", "variant_id")
|
19
19
|
end
|
20
20
|
|
21
21
|
context "authenticating with a token" do
|
22
22
|
it "can add a new line item to an existing order" do
|
23
23
|
api_post :create, :line_item => { :variant_id => product.master.to_param, :quantity => 1 }, :order_token => order.guest_token
|
24
|
-
response.status.
|
25
|
-
json_response.
|
26
|
-
json_response["variant"]["name"].
|
24
|
+
expect(response.status).to eq(201)
|
25
|
+
expect(json_response).to have_attributes(attributes)
|
26
|
+
expect(json_response["variant"]["name"]).not_to be_blank
|
27
27
|
end
|
28
28
|
|
29
29
|
it "can add a new line item to an existing order with token in header" do
|
30
30
|
request.headers["X-Spree-Order-Token"] = order.guest_token
|
31
31
|
api_post :create, :line_item => { :variant_id => product.master.to_param, :quantity => 1 }
|
32
|
-
response.status.
|
33
|
-
json_response.
|
34
|
-
json_response["variant"]["name"].
|
32
|
+
expect(response.status).to eq(201)
|
33
|
+
expect(json_response).to have_attributes(attributes)
|
34
|
+
expect(json_response["variant"]["name"]).not_to be_blank
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
38
|
context "as the order owner" do
|
39
39
|
before do
|
40
|
-
controller.
|
41
|
-
Order.
|
40
|
+
allow(controller).to receive_messages :try_spree_current_user => current_api_user
|
41
|
+
allow_any_instance_of(Order).to receive_messages :user => current_api_user
|
42
42
|
end
|
43
43
|
|
44
44
|
it "can add a new line item to an existing order" do
|
45
45
|
api_post :create, :line_item => { :variant_id => product.master.to_param, :quantity => 1 }
|
46
|
-
response.status.
|
47
|
-
json_response.
|
48
|
-
json_response["variant"]["name"].
|
46
|
+
expect(response.status).to eq(201)
|
47
|
+
expect(json_response).to have_attributes(attributes)
|
48
|
+
expect(json_response["variant"]["name"]).not_to be_blank
|
49
49
|
end
|
50
50
|
|
51
51
|
it "default quantity to 1 if none is given" do
|
52
52
|
api_post :create, :line_item => { :variant_id => product.master.to_param }
|
53
|
-
response.status.
|
54
|
-
json_response.
|
53
|
+
expect(response.status).to eq(201)
|
54
|
+
expect(json_response).to have_attributes(attributes)
|
55
55
|
expect(json_response[:quantity]).to eq 1
|
56
56
|
end
|
57
57
|
|
58
58
|
it "increases a line item's quantity if it exists already" do
|
59
59
|
order.line_items.create(:variant_id => product.master.id, :quantity => 10)
|
60
60
|
api_post :create, :line_item => { :variant_id => product.master.to_param, :quantity => 1 }
|
61
|
-
response.status.
|
61
|
+
expect(response.status).to eq(201)
|
62
62
|
order.reload
|
63
|
-
order.line_items.count.
|
64
|
-
json_response.
|
65
|
-
json_response["quantity"].
|
63
|
+
expect(order.line_items.count).to eq(6) # 5 original due to factory, + 1 in this test
|
64
|
+
expect(json_response).to have_attributes(attributes)
|
65
|
+
expect(json_response["quantity"]).to eq(11)
|
66
66
|
end
|
67
67
|
|
68
68
|
it "can update a line item on the order" do
|
69
69
|
line_item = order.line_items.first
|
70
70
|
api_put :update, :id => line_item.id, :line_item => { :quantity => 101 }
|
71
|
-
response.status.
|
71
|
+
expect(response.status).to eq(200)
|
72
72
|
order.reload
|
73
|
-
order.total.
|
74
|
-
json_response.
|
75
|
-
json_response["quantity"].
|
73
|
+
expect(order.total).to eq(1050) # 50 original due to factory, + 1000 in this test
|
74
|
+
expect(json_response).to have_attributes(attributes)
|
75
|
+
expect(json_response["quantity"]).to eq(101)
|
76
76
|
end
|
77
77
|
|
78
78
|
it "can delete a line item on the order" do
|
79
79
|
line_item = order.line_items.first
|
80
80
|
api_delete :destroy, :id => line_item.id
|
81
|
-
response.status.
|
81
|
+
expect(response.status).to eq(204)
|
82
82
|
order.reload
|
83
|
-
order.line_items.count.
|
84
|
-
|
83
|
+
expect(order.line_items.count).to eq(4) # 5 original due to factory, - 1 in this test
|
84
|
+
expect { line_item.reload }.to raise_error(ActiveRecord::RecordNotFound)
|
85
85
|
end
|
86
86
|
|
87
87
|
context "order contents changed after shipments were created" do
|
@@ -110,8 +110,8 @@ module Spree
|
|
110
110
|
|
111
111
|
context "order is completed" do
|
112
112
|
before do
|
113
|
-
order.
|
114
|
-
Order.
|
113
|
+
allow(order).to receive_messages completed?: true
|
114
|
+
allow(Order).to receive_message_chain :includes, find_by!: order
|
115
115
|
end
|
116
116
|
|
117
117
|
it "doesn't destroy shipments or restart checkout flow" do
|
@@ -126,7 +126,7 @@ module Spree
|
|
126
126
|
context "as just another user" do
|
127
127
|
before do
|
128
128
|
user = create(:user)
|
129
|
-
controller.
|
129
|
+
allow(controller).to receive_messages :try_spree_current_user => user
|
130
130
|
end
|
131
131
|
|
132
132
|
it "cannot add a new line item to the order" do
|
@@ -138,14 +138,14 @@ module Spree
|
|
138
138
|
line_item = order.line_items.first
|
139
139
|
api_put :update, :id => line_item.id, :line_item => { :quantity => 1000 }
|
140
140
|
assert_unauthorized!
|
141
|
-
line_item.reload.quantity.
|
141
|
+
expect(line_item.reload.quantity).not_to eq(1000)
|
142
142
|
end
|
143
143
|
|
144
144
|
it "cannot delete a line item on the order" do
|
145
145
|
line_item = order.line_items.first
|
146
146
|
api_delete :destroy, :id => line_item.id
|
147
147
|
assert_unauthorized!
|
148
|
-
|
148
|
+
expect { line_item.reload }.not_to raise_error
|
149
149
|
end
|
150
150
|
end
|
151
151
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
module Spree
|
4
|
-
describe Api::OptionTypesController do
|
4
|
+
describe Api::OptionTypesController, :type => :controller do
|
5
5
|
render_views
|
6
6
|
|
7
7
|
let(:attributes) { [:id, :name, :position, :presentation] }
|
@@ -13,15 +13,15 @@ module Spree
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def check_option_values(option_values)
|
16
|
-
option_values.count.
|
17
|
-
option_values.first.
|
16
|
+
expect(option_values.count).to eq(1)
|
17
|
+
expect(option_values.first).to have_attributes([:id, :name, :presentation,
|
18
18
|
:option_type_name, :option_type_id])
|
19
19
|
end
|
20
20
|
|
21
21
|
it "can list all option types" do
|
22
22
|
api_get :index
|
23
|
-
json_response.count.
|
24
|
-
json_response.first.
|
23
|
+
expect(json_response.count).to eq(1)
|
24
|
+
expect(json_response.first).to have_attributes(attributes)
|
25
25
|
|
26
26
|
check_option_values(json_response.first["option_values"])
|
27
27
|
end
|
@@ -29,22 +29,22 @@ module Spree
|
|
29
29
|
it "can search for an option type" do
|
30
30
|
create(:option_type, :name => "buzz")
|
31
31
|
api_get :index, :q => { :name_cont => option_type.name }
|
32
|
-
json_response.count.
|
33
|
-
json_response.first.
|
32
|
+
expect(json_response.count).to eq(1)
|
33
|
+
expect(json_response.first).to have_attributes(attributes)
|
34
34
|
end
|
35
35
|
|
36
36
|
it "can retreive a list of specific option types" do
|
37
37
|
option_type_1 = create(:option_type)
|
38
38
|
option_type_2 = create(:option_type)
|
39
39
|
api_get :index, :ids => "#{option_type.id},#{option_type_1.id}"
|
40
|
-
json_response.count.
|
40
|
+
expect(json_response.count).to eq(2)
|
41
41
|
|
42
42
|
check_option_values(json_response.first["option_values"])
|
43
43
|
end
|
44
44
|
|
45
45
|
it "can list a single option type" do
|
46
46
|
api_get :show, :id => option_type.id
|
47
|
-
json_response.
|
47
|
+
expect(json_response).to have_attributes(attributes)
|
48
48
|
check_option_values(json_response["option_values"])
|
49
49
|
end
|
50
50
|
|
@@ -63,13 +63,13 @@ module Spree
|
|
63
63
|
:name => "Option Type"
|
64
64
|
}
|
65
65
|
assert_not_found!
|
66
|
-
option_type.reload.name.
|
66
|
+
expect(option_type.reload.name).to eq(original_name)
|
67
67
|
end
|
68
68
|
|
69
69
|
it "cannot delete an option type" do
|
70
70
|
api_delete :destroy, :id => option_type.id
|
71
71
|
assert_not_found!
|
72
|
-
|
72
|
+
expect { option_type.reload }.not_to raise_error
|
73
73
|
end
|
74
74
|
|
75
75
|
context "as an admin" do
|
@@ -80,13 +80,13 @@ module Spree
|
|
80
80
|
:name => "Option Type",
|
81
81
|
:presentation => "Option Type"
|
82
82
|
}
|
83
|
-
json_response.
|
84
|
-
response.status.
|
83
|
+
expect(json_response).to have_attributes(attributes)
|
84
|
+
expect(response.status).to eq(201)
|
85
85
|
end
|
86
86
|
|
87
87
|
it "cannot create an option type with invalid attributes" do
|
88
88
|
api_post :create, :option_type => {}
|
89
|
-
response.status.
|
89
|
+
expect(response.status).to eq(422)
|
90
90
|
end
|
91
91
|
|
92
92
|
it "can update an option type" do
|
@@ -94,22 +94,22 @@ module Spree
|
|
94
94
|
api_put :update, :id => option_type.id, :option_type => {
|
95
95
|
:name => "Option Type",
|
96
96
|
}
|
97
|
-
response.status.
|
97
|
+
expect(response.status).to eq(200)
|
98
98
|
|
99
99
|
option_type.reload
|
100
|
-
option_type.name.
|
100
|
+
expect(option_type.name).to eq("Option Type")
|
101
101
|
end
|
102
102
|
|
103
103
|
it "cannot update an option type with invalid attributes" do
|
104
104
|
api_put :update, :id => option_type.id, :option_type => {
|
105
105
|
:name => ""
|
106
106
|
}
|
107
|
-
response.status.
|
107
|
+
expect(response.status).to eq(422)
|
108
108
|
end
|
109
109
|
|
110
110
|
it "can delete an option type" do
|
111
111
|
api_delete :destroy, :id => option_type.id
|
112
|
-
response.status.
|
112
|
+
expect(response.status).to eq(204)
|
113
113
|
end
|
114
114
|
end
|
115
115
|
end
|