spree_api 2.4.0.rc2 → 2.4.0.rc3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/spree/api/base_controller.rb +4 -6
- data/app/controllers/spree/api/option_types_controller.rb +2 -2
- data/app/controllers/spree/api/orders_controller.rb +9 -1
- data/app/controllers/spree/api/return_authorizations_controller.rb +0 -9
- data/app/controllers/spree/api/taxons_controller.rb +3 -3
- data/app/helpers/spree/api/api_helpers.rb +0 -2
- data/app/views/spree/api/orders/show.v1.rabl +4 -0
- data/app/views/spree/api/products/show.v1.rabl +4 -0
- data/app/views/spree/api/shipments/small.v1.rabl +4 -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 +8 -8
- data/spec/controllers/spree/api/base_controller_spec.rb +22 -22
- 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 +21 -21
- 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 +19 -19
- data/spec/controllers/spree/api/option_values_controller_spec.rb +23 -23
- data/spec/controllers/spree/api/orders_controller_spec.rb +186 -143
- data/spec/controllers/spree/api/payments_controller_spec.rb +39 -39
- data/spec/controllers/spree/api/product_properties_controller_spec.rb +21 -21
- data/spec/controllers/spree/api/products_controller_spec.rb +71 -66
- data/spec/controllers/spree/api/promotion_application_spec.rb +13 -13
- data/spec/controllers/spree/api/promotions_controller_spec.rb +1 -1
- data/spec/controllers/spree/api/properties_controller_spec.rb +25 -25
- data/spec/controllers/spree/api/return_authorizations_controller_spec.rb +27 -36
- data/spec/controllers/spree/api/shipments_controller_spec.rb +22 -22
- 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 +6 -6
- 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
- data/spec/support/controller_hacks.rb +4 -0
- metadata +4 -4
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
module Spree::Api
|
4
|
-
describe OrdersController do
|
4
|
+
describe OrdersController, :type => :controller do
|
5
5
|
render_views
|
6
6
|
|
7
7
|
before do
|
@@ -19,14 +19,14 @@ module Spree::Api
|
|
19
19
|
end
|
20
20
|
|
21
21
|
it "can apply a coupon code to the order" do
|
22
|
-
order.total.
|
22
|
+
expect(order.total).to eq(110.00)
|
23
23
|
api_put :apply_coupon_code, :id => order.to_param, :coupon_code => "10off", :order_token => order.guest_token
|
24
|
-
response.status.
|
25
|
-
order.reload.total.
|
26
|
-
json_response["success"].
|
27
|
-
json_response["error"].
|
28
|
-
json_response["successful"].
|
29
|
-
json_response["status_code"].
|
24
|
+
expect(response.status).to eq(200)
|
25
|
+
expect(order.reload.total).to eq(109.00)
|
26
|
+
expect(json_response["success"]).to eq("The coupon code was successfully applied to your order.")
|
27
|
+
expect(json_response["error"]).to be_blank
|
28
|
+
expect(json_response["successful"]).to be true
|
29
|
+
expect(json_response["status_code"]).to eq("coupon_code_applied")
|
30
30
|
end
|
31
31
|
|
32
32
|
context "with an expired promotion" do
|
@@ -38,11 +38,11 @@ module Spree::Api
|
|
38
38
|
|
39
39
|
it "fails to apply" do
|
40
40
|
api_put :apply_coupon_code, :id => order.to_param, :coupon_code => "10off", :order_token => order.guest_token
|
41
|
-
response.status.
|
42
|
-
json_response["success"].
|
43
|
-
json_response["error"].
|
44
|
-
json_response["successful"].
|
45
|
-
json_response["status_code"].
|
41
|
+
expect(response.status).to eq(422)
|
42
|
+
expect(json_response["success"]).to be_blank
|
43
|
+
expect(json_response["error"]).to eq("The coupon code is expired")
|
44
|
+
expect(json_response["successful"]).to be false
|
45
|
+
expect(json_response["status_code"]).to eq("coupon_code_expired")
|
46
46
|
end
|
47
47
|
end
|
48
48
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
module Spree
|
3
|
-
describe Spree::Api::PropertiesController do
|
3
|
+
describe Spree::Api::PropertiesController, :type => :controller do
|
4
4
|
render_views
|
5
5
|
|
6
6
|
let!(:property_1) { Property.create!(:name => "foo", :presentation => "Foo") }
|
@@ -14,50 +14,50 @@ module Spree
|
|
14
14
|
|
15
15
|
it "can see a list of all properties" do
|
16
16
|
api_get :index
|
17
|
-
json_response["properties"].count.
|
18
|
-
json_response["properties"].first.
|
17
|
+
expect(json_response["properties"].count).to eq(2)
|
18
|
+
expect(json_response["properties"].first).to have_attributes(attributes)
|
19
19
|
end
|
20
20
|
|
21
21
|
it "can control the page size through a parameter" do
|
22
22
|
api_get :index, :per_page => 1
|
23
|
-
json_response['properties'].count.
|
24
|
-
json_response['current_page'].
|
25
|
-
json_response['pages'].
|
23
|
+
expect(json_response['properties'].count).to eq(1)
|
24
|
+
expect(json_response['current_page']).to eq(1)
|
25
|
+
expect(json_response['pages']).to eq(2)
|
26
26
|
end
|
27
27
|
|
28
28
|
it 'can query the results through a parameter' do
|
29
29
|
api_get :index, :q => { :name_cont => 'ba' }
|
30
|
-
json_response['count'].
|
31
|
-
json_response['properties'].first['presentation'].
|
30
|
+
expect(json_response['count']).to eq(1)
|
31
|
+
expect(json_response['properties'].first['presentation']).to eq property_2.presentation
|
32
32
|
end
|
33
33
|
|
34
34
|
it "retrieves a list of properties by id" do
|
35
35
|
api_get :index, :ids => [property_1.id]
|
36
|
-
json_response["properties"].first.
|
37
|
-
json_response["count"].
|
36
|
+
expect(json_response["properties"].first).to have_attributes(attributes)
|
37
|
+
expect(json_response["count"]).to eq(1)
|
38
38
|
end
|
39
39
|
|
40
40
|
it "retrieves a list of properties by ids string" do
|
41
41
|
api_get :index, :ids => [property_1.id, property_2.id].join(",")
|
42
|
-
json_response["properties"].first.
|
43
|
-
json_response["properties"][1].
|
44
|
-
json_response["count"].
|
42
|
+
expect(json_response["properties"].first).to have_attributes(attributes)
|
43
|
+
expect(json_response["properties"][1]).to have_attributes(attributes)
|
44
|
+
expect(json_response["count"]).to eq(2)
|
45
45
|
end
|
46
46
|
|
47
47
|
it "can see a single property" do
|
48
48
|
api_get :show, :id => property_1.id
|
49
|
-
json_response.
|
49
|
+
expect(json_response).to have_attributes(attributes)
|
50
50
|
end
|
51
51
|
|
52
52
|
it "can see a property by name" do
|
53
53
|
api_get :show, :id => property_1.name
|
54
|
-
json_response.
|
54
|
+
expect(json_response).to have_attributes(attributes)
|
55
55
|
end
|
56
56
|
|
57
57
|
it "can learn how to create a new property" do
|
58
58
|
api_get :new
|
59
|
-
json_response["attributes"].
|
60
|
-
json_response["required_attributes"].
|
59
|
+
expect(json_response["attributes"]).to eq(attributes.map(&:to_s))
|
60
|
+
expect(json_response["required_attributes"]).to be_empty
|
61
61
|
end
|
62
62
|
|
63
63
|
it "cannot create a new property if not an admin" do
|
@@ -73,29 +73,29 @@ module Spree
|
|
73
73
|
it "cannot delete a property" do
|
74
74
|
api_delete :destroy, :id => property_1.id
|
75
75
|
assert_unauthorized!
|
76
|
-
|
76
|
+
expect { property_1.reload }.not_to raise_error
|
77
77
|
end
|
78
78
|
|
79
79
|
context "as an admin" do
|
80
80
|
sign_in_as_admin!
|
81
81
|
|
82
82
|
it "can create a new property" do
|
83
|
-
Spree::Property.count.
|
83
|
+
expect(Spree::Property.count).to eq(2)
|
84
84
|
api_post :create, :property => { :name => "My Property 3", :presentation => "my value 3" }
|
85
|
-
json_response.
|
86
|
-
response.status.
|
87
|
-
Spree::Property.count.
|
85
|
+
expect(json_response).to have_attributes(attributes)
|
86
|
+
expect(response.status).to eq(201)
|
87
|
+
expect(Spree::Property.count).to eq(3)
|
88
88
|
end
|
89
89
|
|
90
90
|
it "can update a property" do
|
91
91
|
api_put :update, :id => property_1.name, :property => { :presentation => "my value 456" }
|
92
|
-
response.status.
|
92
|
+
expect(response.status).to eq(200)
|
93
93
|
end
|
94
94
|
|
95
95
|
it "can delete a property" do
|
96
96
|
api_delete :destroy, :id => property_1.name
|
97
|
-
response.status.
|
98
|
-
|
97
|
+
expect(response.status).to eq(204)
|
98
|
+
expect { property_1.reload }.to raise_error(ActiveRecord::RecordNotFound)
|
99
99
|
end
|
100
100
|
end
|
101
101
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
module Spree
|
4
|
-
describe Api::ReturnAuthorizationsController do
|
4
|
+
describe Api::ReturnAuthorizationsController, :type => :controller do
|
5
5
|
render_views
|
6
6
|
|
7
7
|
let!(:order) { create(:shipped_order) }
|
@@ -16,7 +16,7 @@ module Spree
|
|
16
16
|
|
17
17
|
context "as the order owner" do
|
18
18
|
before do
|
19
|
-
Order.
|
19
|
+
allow_any_instance_of(Order).to receive_messages :user => current_api_user
|
20
20
|
end
|
21
21
|
|
22
22
|
it "cannot see any return authorizations" do
|
@@ -57,28 +57,28 @@ module Spree
|
|
57
57
|
FactoryGirl.create(:return_authorization, :order => order)
|
58
58
|
return_authorization = order.return_authorizations.first
|
59
59
|
api_get :show, :order_id => order.number, :id => return_authorization.id
|
60
|
-
response.status.
|
61
|
-
json_response.
|
62
|
-
json_response["state"].
|
60
|
+
expect(response.status).to eq(200)
|
61
|
+
expect(json_response).to have_attributes(attributes)
|
62
|
+
expect(json_response["state"]).not_to be_blank
|
63
63
|
end
|
64
64
|
|
65
65
|
it "can get a list of return authorizations" do
|
66
66
|
FactoryGirl.create(:return_authorization, :order => order)
|
67
67
|
FactoryGirl.create(:return_authorization, :order => order)
|
68
68
|
api_get :index, { :order_id => order.number }
|
69
|
-
response.status.
|
69
|
+
expect(response.status).to eq(200)
|
70
70
|
return_authorizations = json_response["return_authorizations"]
|
71
|
-
return_authorizations.first.
|
72
|
-
return_authorizations.first.
|
71
|
+
expect(return_authorizations.first).to have_attributes(attributes)
|
72
|
+
expect(return_authorizations.first).not_to eq(return_authorizations.last)
|
73
73
|
end
|
74
74
|
|
75
75
|
it 'can control the page size through a parameter' do
|
76
76
|
FactoryGirl.create(:return_authorization, :order => order)
|
77
77
|
FactoryGirl.create(:return_authorization, :order => order)
|
78
78
|
api_get :index, :order_id => order.number, :per_page => 1
|
79
|
-
json_response['count'].
|
80
|
-
json_response['current_page'].
|
81
|
-
json_response['pages'].
|
79
|
+
expect(json_response['count']).to eq(1)
|
80
|
+
expect(json_response['current_page']).to eq(1)
|
81
|
+
expect(json_response['pages']).to eq(2)
|
82
82
|
end
|
83
83
|
|
84
84
|
it 'can query the results through a paramter' do
|
@@ -86,49 +86,40 @@ module Spree
|
|
86
86
|
expected_result = create(:return_authorization, :memo => 'damaged')
|
87
87
|
order.return_authorizations << expected_result
|
88
88
|
api_get :index, :q => { :memo_cont => 'damaged' }
|
89
|
-
json_response['count'].
|
90
|
-
json_response['return_authorizations'].first['memo'].
|
89
|
+
expect(json_response['count']).to eq(1)
|
90
|
+
expect(json_response['return_authorizations'].first['memo']).to eq expected_result.memo
|
91
91
|
end
|
92
92
|
|
93
93
|
it "can learn how to create a new return authorization" do
|
94
94
|
api_get :new
|
95
|
-
json_response["attributes"].
|
95
|
+
expect(json_response["attributes"]).to eq(["id", "number", "state", "order_id", "memo", "created_at", "updated_at"])
|
96
96
|
required_attributes = json_response["required_attributes"]
|
97
|
-
required_attributes.
|
97
|
+
expect(required_attributes).to include("order")
|
98
98
|
end
|
99
99
|
|
100
100
|
it "can update a return authorization on the order" do
|
101
101
|
FactoryGirl.create(:return_authorization, :order => order)
|
102
102
|
return_authorization = order.return_authorizations.first
|
103
103
|
api_put :update, :id => return_authorization.id, :return_authorization => { :memo => "ABC" }
|
104
|
-
response.status.
|
105
|
-
json_response.
|
106
|
-
end
|
107
|
-
|
108
|
-
it "cannot mark a return authorization as received on the order with no inventory units" do
|
109
|
-
FactoryGirl.create(:new_return_authorization, :order => order)
|
110
|
-
return_authorization = order.return_authorizations.first
|
111
|
-
return_authorization.state.should == "authorized"
|
112
|
-
api_delete :receive, :id => return_authorization.id
|
113
|
-
response.status.should == 422
|
114
|
-
return_authorization.reload.state.should == "authorized"
|
104
|
+
expect(response.status).to eq(200)
|
105
|
+
expect(json_response).to have_attributes(attributes)
|
115
106
|
end
|
116
107
|
|
117
108
|
it "can cancel a return authorization on the order" do
|
118
109
|
FactoryGirl.create(:new_return_authorization, :order => order)
|
119
110
|
return_authorization = order.return_authorizations.first
|
120
|
-
return_authorization.state.
|
111
|
+
expect(return_authorization.state).to eq("authorized")
|
121
112
|
api_delete :cancel, :id => return_authorization.id
|
122
|
-
response.status.
|
123
|
-
return_authorization.reload.state.
|
113
|
+
expect(response.status).to eq(200)
|
114
|
+
expect(return_authorization.reload.state).to eq("canceled")
|
124
115
|
end
|
125
116
|
|
126
117
|
it "can delete a return authorization on the order" do
|
127
118
|
FactoryGirl.create(:return_authorization, :order => order)
|
128
119
|
return_authorization = order.return_authorizations.first
|
129
120
|
api_delete :destroy, :id => return_authorization.id
|
130
|
-
response.status.
|
131
|
-
|
121
|
+
expect(response.status).to eq(204)
|
122
|
+
expect { return_authorization.reload }.to raise_error(ActiveRecord::RecordNotFound)
|
132
123
|
end
|
133
124
|
|
134
125
|
it "can add a new return authorization to an existing order" do
|
@@ -138,9 +129,9 @@ module Spree
|
|
138
129
|
:return_authorization_reason_id => reason.id,
|
139
130
|
:memo => "Defective" }
|
140
131
|
api_post :create, :order_id => order.number, :return_authorization => rma_params
|
141
|
-
response.status.
|
142
|
-
json_response.
|
143
|
-
json_response["state"].
|
132
|
+
expect(response.status).to eq(201)
|
133
|
+
expect(json_response).to have_attributes(attributes)
|
134
|
+
expect(json_response["state"]).not_to be_blank
|
144
135
|
end
|
145
136
|
end
|
146
137
|
|
@@ -155,7 +146,7 @@ module Spree
|
|
155
146
|
return_authorization = order.return_authorizations.first
|
156
147
|
api_put :update, :id => return_authorization.id, :return_authorization => { :memo => "ABC" }
|
157
148
|
assert_unauthorized!
|
158
|
-
return_authorization.reload.memo.
|
149
|
+
expect(return_authorization.reload.memo).not_to eq("ABC")
|
159
150
|
end
|
160
151
|
|
161
152
|
it "cannot delete a return authorization on the order" do
|
@@ -163,7 +154,7 @@ module Spree
|
|
163
154
|
return_authorization = order.return_authorizations.first
|
164
155
|
api_delete :destroy, :id => return_authorization.id
|
165
156
|
assert_unauthorized!
|
166
|
-
|
157
|
+
expect { return_authorization.reload }.not_to raise_error
|
167
158
|
end
|
168
159
|
end
|
169
160
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Spree::Api::ShipmentsController do
|
3
|
+
describe Spree::Api::ShipmentsController, :type => :controller do
|
4
4
|
render_views
|
5
5
|
let!(:shipment) { create(:shipment) }
|
6
6
|
let!(:attributes) { [:id, :tracking, :number, :cost, :shipped_at, :stock_location_name, :order_id, :shipping_rates, :shipping_methods] }
|
@@ -72,23 +72,23 @@ describe Spree::Api::ShipmentsController do
|
|
72
72
|
}
|
73
73
|
|
74
74
|
api_put :update, params
|
75
|
-
response.status.
|
76
|
-
json_response['stock_location_name'].
|
75
|
+
expect(response.status).to eq(200)
|
76
|
+
expect(json_response['stock_location_name']).to eq(stock_location.name)
|
77
77
|
end
|
78
78
|
|
79
79
|
it "can make a shipment ready" do
|
80
|
-
Spree::Order.
|
80
|
+
allow_any_instance_of(Spree::Order).to receive_messages(:paid? => true, :complete? => true)
|
81
81
|
api_put :ready
|
82
|
-
json_response.
|
83
|
-
json_response["state"].
|
84
|
-
shipment.reload.state.
|
82
|
+
expect(json_response).to have_attributes(attributes)
|
83
|
+
expect(json_response["state"]).to eq("ready")
|
84
|
+
expect(shipment.reload.state).to eq("ready")
|
85
85
|
end
|
86
86
|
|
87
87
|
it "cannot make a shipment ready if the order is unpaid" do
|
88
|
-
Spree::Order.
|
88
|
+
allow_any_instance_of(Spree::Order).to receive_messages(:paid? => false)
|
89
89
|
api_put :ready
|
90
|
-
json_response["error"].
|
91
|
-
response.status.
|
90
|
+
expect(json_response["error"]).to eq("Cannot ready shipment.")
|
91
|
+
expect(response.status).to eq(422)
|
92
92
|
end
|
93
93
|
|
94
94
|
context 'for completed shipments' do
|
@@ -97,16 +97,16 @@ describe Spree::Api::ShipmentsController do
|
|
97
97
|
|
98
98
|
it 'adds a variant to a shipment' do
|
99
99
|
api_put :add, { variant_id: variant.to_param, quantity: 2 }
|
100
|
-
response.status.
|
101
|
-
json_response['manifest'].detect { |h| h['variant']['id'] == variant.id }["quantity"].
|
100
|
+
expect(response.status).to eq(200)
|
101
|
+
expect(json_response['manifest'].detect { |h| h['variant']['id'] == variant.id }["quantity"]).to eq(2)
|
102
102
|
end
|
103
103
|
|
104
104
|
it 'removes a variant from a shipment' do
|
105
105
|
order.contents.add(variant, 2)
|
106
106
|
|
107
107
|
api_put :remove, { variant_id: variant.to_param, quantity: 1 }
|
108
|
-
response.status.
|
109
|
-
json_response['manifest'].detect { |h| h['variant']['id'] == variant.id }["quantity"].
|
108
|
+
expect(response.status).to eq(200)
|
109
|
+
expect(json_response['manifest'].detect { |h| h['variant']['id'] == variant.id }["quantity"]).to eq(1)
|
110
110
|
end
|
111
111
|
|
112
112
|
it 'removes a destroyed variant from a shipment' do
|
@@ -114,27 +114,27 @@ describe Spree::Api::ShipmentsController do
|
|
114
114
|
variant.destroy
|
115
115
|
|
116
116
|
api_put :remove, { variant_id: variant.to_param, quantity: 1 }
|
117
|
-
response.status.
|
118
|
-
json_response['manifest'].detect { |h| h['variant']['id'] == variant.id }["quantity"].
|
117
|
+
expect(response.status).to eq(200)
|
118
|
+
expect(json_response['manifest'].detect { |h| h['variant']['id'] == variant.id }["quantity"]).to eq(1)
|
119
119
|
end
|
120
120
|
end
|
121
121
|
|
122
122
|
context "can transition a shipment from ready to ship" do
|
123
123
|
before do
|
124
|
-
Spree::Order.
|
124
|
+
allow_any_instance_of(Spree::Order).to receive_messages(:paid? => true, :complete? => true)
|
125
125
|
# For the shipment notification email
|
126
126
|
Spree::Config[:mails_from] = "spree@example.com"
|
127
127
|
|
128
128
|
shipment.update!(shipment.order)
|
129
|
-
shipment.state.
|
130
|
-
Spree::ShippingRate.
|
129
|
+
expect(shipment.state).to eq("ready")
|
130
|
+
allow_any_instance_of(Spree::ShippingRate).to receive_messages(:cost => 5)
|
131
131
|
end
|
132
132
|
|
133
133
|
it "can transition a shipment from ready to ship" do
|
134
134
|
shipment.reload
|
135
135
|
api_put :ship, id: shipment.to_param, shipment: { tracking: "123123", order_id: shipment.order.to_param }
|
136
|
-
json_response.
|
137
|
-
json_response["state"].
|
136
|
+
expect(json_response).to have_attributes(attributes)
|
137
|
+
expect(json_response["state"]).to eq("shipped")
|
138
138
|
end
|
139
139
|
|
140
140
|
end
|
@@ -181,7 +181,7 @@ describe Spree::Api::ShipmentsController do
|
|
181
181
|
let(:current_api_user) { Spree.user_class.new }
|
182
182
|
|
183
183
|
it "returns a 401" do
|
184
|
-
response.status.
|
184
|
+
expect(response.status).to eq(401)
|
185
185
|
end
|
186
186
|
end
|
187
187
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
module Spree
|
4
|
-
describe Api::StatesController do
|
4
|
+
describe Api::StatesController, :type => :controller do
|
5
5
|
render_views
|
6
6
|
|
7
7
|
let!(:state) { create(:state, :name => "Victoria") }
|
@@ -13,37 +13,37 @@ module Spree
|
|
13
13
|
|
14
14
|
it "gets all states" do
|
15
15
|
api_get :index
|
16
|
-
json_response["states"].first.
|
17
|
-
json_response['states'].first['name'].
|
16
|
+
expect(json_response["states"].first).to have_attributes(attributes)
|
17
|
+
expect(json_response['states'].first['name']).to eq(state.name)
|
18
18
|
end
|
19
19
|
|
20
20
|
it "gets all the states for a particular country" do
|
21
21
|
api_get :index, :country_id => state.country.id
|
22
|
-
json_response["states"].first.
|
23
|
-
json_response['states'].first['name'].
|
22
|
+
expect(json_response["states"].first).to have_attributes(attributes)
|
23
|
+
expect(json_response['states'].first['name']).to eq(state.name)
|
24
24
|
end
|
25
25
|
|
26
26
|
context "pagination" do
|
27
27
|
before do
|
28
|
-
State.
|
29
|
-
@scope.
|
28
|
+
expect(State).to receive(:accessible_by).and_return(@scope = double)
|
29
|
+
allow(@scope).to receive_message_chain(:ransack, :result, :includes, :order).and_return(@scope)
|
30
30
|
end
|
31
31
|
|
32
32
|
it "does not paginate states results when asked not to do so" do
|
33
|
-
@scope.
|
34
|
-
@scope.
|
33
|
+
expect(@scope).not_to receive(:page)
|
34
|
+
expect(@scope).not_to receive(:per)
|
35
35
|
api_get :index
|
36
36
|
end
|
37
37
|
|
38
38
|
it "paginates when page parameter is passed through" do
|
39
|
-
@scope.
|
40
|
-
@scope.
|
39
|
+
expect(@scope).to receive(:page).with(1).and_return(@scope)
|
40
|
+
expect(@scope).to receive(:per).with(nil)
|
41
41
|
api_get :index, :page => 1
|
42
42
|
end
|
43
43
|
|
44
44
|
it "paginates when per_page parameter is passed through" do
|
45
|
-
@scope.
|
46
|
-
@scope.
|
45
|
+
expect(@scope).to receive(:page).with(nil).and_return(@scope)
|
46
|
+
expect(@scope).to receive(:per).with(25)
|
47
47
|
api_get :index, :per_page => 25
|
48
48
|
end
|
49
49
|
end
|
@@ -58,25 +58,25 @@ module Spree
|
|
58
58
|
state.save
|
59
59
|
|
60
60
|
api_get :index, :country_id => country.id
|
61
|
-
json_response["states"].first.
|
62
|
-
json_response["states"].count.
|
61
|
+
expect(json_response["states"].first).to have_attributes(attributes)
|
62
|
+
expect(json_response["states"].count).to eq(1)
|
63
63
|
json_response["states_required"] = true
|
64
64
|
end
|
65
65
|
|
66
66
|
it "can view all states" do
|
67
67
|
api_get :index
|
68
|
-
json_response["states"].first.
|
68
|
+
expect(json_response["states"].first).to have_attributes(attributes)
|
69
69
|
end
|
70
70
|
|
71
71
|
it 'can query the results through a paramter' do
|
72
72
|
api_get :index, :q => { :name_cont => 'Vic' }
|
73
|
-
json_response['states'].first['name'].
|
73
|
+
expect(json_response['states'].first['name']).to eq("Victoria")
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
77
77
|
it "can view a state" do
|
78
78
|
api_get :show, :id => state.id
|
79
|
-
json_response.
|
79
|
+
expect(json_response).to have_attributes(attributes)
|
80
80
|
end
|
81
81
|
end
|
82
82
|
end
|