spree_api 2.3.13 → 2.4.0.rc1
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/CHANGELOG.md +1 -43
- data/Gemfile +1 -1
- data/app/controllers/spree/api/addresses_controller.rb +1 -1
- data/app/controllers/spree/api/base_controller.rb +22 -9
- data/app/controllers/spree/api/checkouts_controller.rb +2 -2
- data/app/controllers/spree/api/countries_controller.rb +2 -2
- data/app/controllers/spree/api/credit_cards_controller.rb +1 -1
- data/app/controllers/spree/api/images_controller.rb +5 -0
- data/app/controllers/spree/api/inventory_units_controller.rb +1 -1
- data/app/controllers/spree/api/line_items_controller.rb +7 -7
- data/app/controllers/spree/api/option_types_controller.rb +2 -2
- data/app/controllers/spree/api/orders_controller.rb +17 -6
- data/app/controllers/spree/api/payments_controller.rb +3 -11
- data/app/controllers/spree/api/product_properties_controller.rb +2 -2
- data/app/controllers/spree/api/promotions_controller.rb +26 -0
- data/app/controllers/spree/api/properties_controller.rb +1 -1
- data/app/controllers/spree/api/return_authorizations_controller.rb +0 -10
- data/app/controllers/spree/api/shipments_controller.rb +71 -4
- data/app/controllers/spree/api/states_controller.rb +3 -3
- data/app/controllers/spree/api/stock_items_controller.rb +1 -1
- data/app/controllers/spree/api/stock_movements_controller.rb +1 -1
- data/app/controllers/spree/api/taxons_controller.rb +1 -1
- data/app/controllers/spree/api/variants_controller.rb +1 -2
- data/app/helpers/spree/api/api_helpers.rb +19 -5
- data/app/views/spree/api/images/index.v1.rabl +4 -0
- data/app/views/spree/api/products/show.v1.rabl +4 -1
- data/app/views/spree/api/promotions/handler.v1.rabl +2 -1
- data/app/views/spree/api/promotions/show.v1.rabl +2 -0
- data/app/views/spree/api/shipments/big.v1.rabl +48 -0
- data/app/views/spree/api/shipments/mine.v1.rabl +9 -0
- data/app/views/spree/api/shipments/small.v1.rabl +1 -5
- data/app/views/spree/api/shipping_rates/show.v1.rabl +2 -2
- data/app/views/spree/api/taxonomies/show.v1.rabl +2 -2
- data/app/views/spree/api/variants/big.v1.rabl +6 -1
- data/app/views/spree/api/variants/show.v1.rabl +1 -1
- data/app/views/spree/api/variants/small.v1.rabl +2 -3
- data/config/routes.rb +9 -0
- data/lib/spree/api/responders/rabl_template.rb +1 -1
- 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 +66 -19
- data/spec/controllers/spree/api/checkouts_controller_spec.rb +54 -54
- 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 +37 -11
- data/spec/controllers/spree/api/inventory_units_controller_spec.rb +6 -6
- data/spec/controllers/spree/api/line_items_controller_spec.rb +34 -35
- 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 +177 -161
- data/spec/controllers/spree/api/payments_controller_spec.rb +52 -89
- data/spec/controllers/spree/api/product_properties_controller_spec.rb +21 -21
- data/spec/controllers/spree/api/products_controller_spec.rb +103 -60
- data/spec/controllers/spree/api/promotion_application_spec.rb +14 -12
- data/spec/controllers/spree/api/promotions_controller_spec.rb +64 -0
- data/spec/controllers/spree/api/properties_controller_spec.rb +25 -25
- data/spec/controllers/spree/api/return_authorizations_controller_spec.rb +42 -66
- data/spec/controllers/spree/api/shipments_controller_spec.rb +69 -21
- 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 +41 -41
- data/spec/controllers/spree/api/variants_controller_spec.rb +47 -37
- data/spec/controllers/spree/api/zones_controller_spec.rb +40 -18
- data/spec/models/spree/legacy_user_spec.rb +5 -5
- data/spec/requests/rabl_cache_spec.rb +9 -9
- data/spec/spec_helper.rb +1 -0
- metadata +14 -9
- data/spec/requests/ransackable_attributes_spec.rb +0 -79
@@ -1,89 +1,87 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
module Spree
|
4
|
-
describe Api::LineItemsController
|
4
|
+
describe Api::LineItemsController do
|
5
5
|
render_views
|
6
6
|
|
7
|
-
let!(:order) { create(:order_with_line_items) }
|
7
|
+
let!(:order) { create(:order_with_line_items, line_items_count: 1) }
|
8
8
|
|
9
9
|
let(:product) { create(:product) }
|
10
10
|
let(:attributes) { [:id, :quantity, :price, :variant, :total, :display_amount, :single_display_amount] }
|
11
11
|
let(:resource_scoping) { { :order_id => order.to_param } }
|
12
12
|
|
13
|
-
before do
|
14
|
-
stub_authentication!
|
15
|
-
end
|
16
|
-
|
17
13
|
it "can learn how to create a new line item" do
|
14
|
+
controller.stub :try_spree_current_user => current_api_user
|
18
15
|
api_get :new
|
19
|
-
|
16
|
+
json_response["attributes"].should == ["quantity", "price", "variant_id"]
|
20
17
|
required_attributes = json_response["required_attributes"]
|
21
|
-
|
18
|
+
required_attributes.should include("quantity", "variant_id")
|
22
19
|
end
|
23
20
|
|
24
21
|
context "authenticating with a token" do
|
25
22
|
it "can add a new line item to an existing order" do
|
26
23
|
api_post :create, :line_item => { :variant_id => product.master.to_param, :quantity => 1 }, :order_token => order.guest_token
|
27
|
-
|
28
|
-
|
29
|
-
|
24
|
+
response.status.should == 201
|
25
|
+
json_response.should have_attributes(attributes)
|
26
|
+
json_response["variant"]["name"].should_not be_blank
|
30
27
|
end
|
31
28
|
|
32
29
|
it "can add a new line item to an existing order with token in header" do
|
33
30
|
request.headers["X-Spree-Order-Token"] = order.guest_token
|
34
31
|
api_post :create, :line_item => { :variant_id => product.master.to_param, :quantity => 1 }
|
35
|
-
|
36
|
-
|
37
|
-
|
32
|
+
response.status.should == 201
|
33
|
+
json_response.should have_attributes(attributes)
|
34
|
+
json_response["variant"]["name"].should_not be_blank
|
38
35
|
end
|
39
36
|
end
|
40
37
|
|
41
38
|
context "as the order owner" do
|
42
39
|
before do
|
43
|
-
|
40
|
+
controller.stub :try_spree_current_user => current_api_user
|
41
|
+
Order.any_instance.stub :user => current_api_user
|
44
42
|
end
|
45
43
|
|
46
44
|
it "can add a new line item to an existing order" do
|
47
45
|
api_post :create, :line_item => { :variant_id => product.master.to_param, :quantity => 1 }
|
48
|
-
|
49
|
-
|
50
|
-
|
46
|
+
response.status.should == 201
|
47
|
+
json_response.should have_attributes(attributes)
|
48
|
+
json_response["variant"]["name"].should_not be_blank
|
51
49
|
end
|
52
50
|
|
53
51
|
it "default quantity to 1 if none is given" do
|
54
52
|
api_post :create, :line_item => { :variant_id => product.master.to_param }
|
55
|
-
|
56
|
-
|
53
|
+
response.status.should == 201
|
54
|
+
json_response.should have_attributes(attributes)
|
57
55
|
expect(json_response[:quantity]).to eq 1
|
58
56
|
end
|
59
57
|
|
60
58
|
it "increases a line item's quantity if it exists already" do
|
61
59
|
order.line_items.create(:variant_id => product.master.id, :quantity => 10)
|
62
60
|
api_post :create, :line_item => { :variant_id => product.master.to_param, :quantity => 1 }
|
63
|
-
|
61
|
+
response.status.should == 201
|
64
62
|
order.reload
|
65
|
-
|
66
|
-
|
67
|
-
|
63
|
+
order.line_items.count.should == 2 # 1 original due to factory, + 1 in this test
|
64
|
+
json_response.should have_attributes(attributes)
|
65
|
+
json_response["quantity"].should == 11
|
68
66
|
end
|
69
67
|
|
70
68
|
it "can update a line item on the order" do
|
71
69
|
line_item = order.line_items.first
|
72
70
|
api_put :update, :id => line_item.id, :line_item => { :quantity => 101 }
|
73
|
-
|
71
|
+
response.status.should == 200
|
74
72
|
order.reload
|
75
|
-
|
76
|
-
|
77
|
-
|
73
|
+
order.total.should == 1010 # 10 original due to factory, + 1000 in this test
|
74
|
+
json_response.should have_attributes(attributes)
|
75
|
+
json_response["quantity"].should == 101
|
78
76
|
end
|
79
77
|
|
80
78
|
it "can delete a line item on the order" do
|
81
79
|
line_item = order.line_items.first
|
82
80
|
api_delete :destroy, :id => line_item.id
|
83
|
-
|
81
|
+
response.status.should == 204
|
84
82
|
order.reload
|
85
|
-
|
86
|
-
|
83
|
+
order.line_items.count.should == 0 # 1 original due to factory, - 1 in this test
|
84
|
+
lambda { line_item.reload }.should raise_error(ActiveRecord::RecordNotFound)
|
87
85
|
end
|
88
86
|
|
89
87
|
context "order contents changed after shipments were created" do
|
@@ -112,8 +110,8 @@ module Spree
|
|
112
110
|
|
113
111
|
context "order is completed" do
|
114
112
|
before do
|
115
|
-
|
116
|
-
|
113
|
+
order.stub completed?: true
|
114
|
+
Order.stub_chain :includes, find_by!: order
|
117
115
|
end
|
118
116
|
|
119
117
|
it "doesn't destroy shipments or restart checkout flow" do
|
@@ -128,6 +126,7 @@ module Spree
|
|
128
126
|
context "as just another user" do
|
129
127
|
before do
|
130
128
|
user = create(:user)
|
129
|
+
controller.stub :try_spree_current_user => user
|
131
130
|
end
|
132
131
|
|
133
132
|
it "cannot add a new line item to the order" do
|
@@ -139,14 +138,14 @@ module Spree
|
|
139
138
|
line_item = order.line_items.first
|
140
139
|
api_put :update, :id => line_item.id, :line_item => { :quantity => 1000 }
|
141
140
|
assert_unauthorized!
|
142
|
-
|
141
|
+
line_item.reload.quantity.should_not == 1000
|
143
142
|
end
|
144
143
|
|
145
144
|
it "cannot delete a line item on the order" do
|
146
145
|
line_item = order.line_items.first
|
147
146
|
api_delete :destroy, :id => line_item.id
|
148
147
|
assert_unauthorized!
|
149
|
-
|
148
|
+
lambda { line_item.reload }.should_not raise_error
|
150
149
|
end
|
151
150
|
end
|
152
151
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
module Spree
|
4
|
-
describe Api::OptionTypesController
|
4
|
+
describe Api::OptionTypesController 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
|
-
|
17
|
-
|
16
|
+
option_values.count.should == 1
|
17
|
+
option_values.first.should 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
|
-
|
24
|
-
|
23
|
+
json_response.count.should == 1
|
24
|
+
json_response.first.should 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
|
-
|
33
|
-
|
32
|
+
json_response.count.should == 1
|
33
|
+
json_response.first.should 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
|
-
|
40
|
+
json_response.count.should == 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
|
-
|
47
|
+
json_response.should 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
|
-
|
66
|
+
option_type.reload.name.should == 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
|
+
lambda { option_type.reload }.should_not 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
|
-
|
84
|
-
|
83
|
+
json_response.should have_attributes(attributes)
|
84
|
+
response.status.should == 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
|
-
|
89
|
+
response.status.should == 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
|
-
|
97
|
+
response.status.should == 200
|
98
98
|
|
99
99
|
option_type.reload
|
100
|
-
|
100
|
+
option_type.name.should == "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
|
-
|
107
|
+
response.status.should == 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
|
-
|
112
|
+
response.status.should == 204
|
113
113
|
end
|
114
114
|
end
|
115
115
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
module Spree
|
4
|
-
describe Api::OptionValuesController
|
4
|
+
describe Api::OptionValuesController do
|
5
5
|
render_views
|
6
6
|
|
7
7
|
let(:attributes) { [:id, :name, :presentation, :option_type_name, :option_type_name] }
|
@@ -13,8 +13,8 @@ module Spree
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def check_option_values(option_values)
|
16
|
-
|
17
|
-
|
16
|
+
option_values.count.should == 1
|
17
|
+
option_values.first.should have_attributes([:id, :name, :presentation,
|
18
18
|
:option_type_name, :option_type_id])
|
19
19
|
end
|
20
20
|
|
@@ -26,8 +26,8 @@ module Spree
|
|
26
26
|
|
27
27
|
it "can retreive a list of all option values" do
|
28
28
|
api_get :index
|
29
|
-
|
30
|
-
|
29
|
+
json_response.count.should == 2
|
30
|
+
json_response.first.should have_attributes(attributes)
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
@@ -36,27 +36,27 @@ module Spree
|
|
36
36
|
|
37
37
|
it "can list all option values" do
|
38
38
|
api_get :index
|
39
|
-
|
40
|
-
|
39
|
+
json_response.count.should == 1
|
40
|
+
json_response.first.should have_attributes(attributes)
|
41
41
|
end
|
42
42
|
|
43
43
|
it "can search for an option type" do
|
44
44
|
create(:option_value, :name => "buzz")
|
45
45
|
api_get :index, :q => { :name_cont => option_value.name }
|
46
|
-
|
47
|
-
|
46
|
+
json_response.count.should == 1
|
47
|
+
json_response.first.should have_attributes(attributes)
|
48
48
|
end
|
49
49
|
|
50
50
|
it "can retreive a list of option types" do
|
51
51
|
option_value_1 = create(:option_value, :option_type => option_type)
|
52
52
|
option_value_2 = create(:option_value, :option_type => option_type)
|
53
53
|
api_get :index, :ids => [option_value.id, option_value_1.id]
|
54
|
-
|
54
|
+
json_response.count.should == 2
|
55
55
|
end
|
56
56
|
|
57
57
|
it "can list a single option value" do
|
58
58
|
api_get :show, :id => option_value.id
|
59
|
-
|
59
|
+
json_response.should have_attributes(attributes)
|
60
60
|
end
|
61
61
|
|
62
62
|
it "cannot create a new option value" do
|
@@ -74,13 +74,13 @@ module Spree
|
|
74
74
|
:name => "Option Value"
|
75
75
|
}
|
76
76
|
assert_not_found!
|
77
|
-
|
77
|
+
option_type.reload.name.should == original_name
|
78
78
|
end
|
79
79
|
|
80
80
|
it "cannot delete an option value" do
|
81
81
|
api_delete :destroy, :id => option_type.id
|
82
82
|
assert_not_found!
|
83
|
-
|
83
|
+
lambda { option_type.reload }.should_not raise_error
|
84
84
|
end
|
85
85
|
|
86
86
|
context "as an admin" do
|
@@ -91,13 +91,13 @@ module Spree
|
|
91
91
|
:name => "Option Value",
|
92
92
|
:presentation => "Option Value"
|
93
93
|
}
|
94
|
-
|
95
|
-
|
94
|
+
json_response.should have_attributes(attributes)
|
95
|
+
response.status.should == 201
|
96
96
|
end
|
97
97
|
|
98
98
|
it "cannot create an option type with invalid attributes" do
|
99
99
|
api_post :create, :option_value => {}
|
100
|
-
|
100
|
+
response.status.should == 422
|
101
101
|
end
|
102
102
|
|
103
103
|
it "can update an option value" do
|
@@ -105,14 +105,14 @@ module Spree
|
|
105
105
|
api_put :update, :id => option_value.id, :option_value => {
|
106
106
|
:name => "Option Value",
|
107
107
|
}
|
108
|
-
|
108
|
+
response.status.should == 200
|
109
109
|
|
110
110
|
option_value.reload
|
111
|
-
|
111
|
+
option_value.name.should == "Option Value"
|
112
112
|
end
|
113
113
|
|
114
114
|
it "permits the correct attributes" do
|
115
|
-
|
115
|
+
controller.should_receive(:permitted_option_value_attributes)
|
116
116
|
api_put :update, :id => option_value.id, :option_value => {
|
117
117
|
:name => ""
|
118
118
|
}
|
@@ -122,12 +122,12 @@ module Spree
|
|
122
122
|
api_put :update, :id => option_value.id, :option_value => {
|
123
123
|
:name => ""
|
124
124
|
}
|
125
|
-
|
125
|
+
response.status.should == 422
|
126
126
|
end
|
127
127
|
|
128
128
|
it "can delete an option value" do
|
129
129
|
api_delete :destroy, :id => option_value.id
|
130
|
-
|
130
|
+
response.status.should == 204
|
131
131
|
end
|
132
132
|
end
|
133
133
|
end
|