spree_api 2.0.13 → 2.1.0
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 +99 -1
- data/app/controllers/spree/api/addresses_controller.rb +5 -2
- data/app/controllers/spree/api/base_controller.rb +14 -21
- data/app/controllers/spree/api/checkouts_controller.rb +30 -27
- data/app/controllers/spree/api/config_controller.rb +6 -0
- data/app/controllers/spree/api/countries_controller.rb +7 -7
- data/app/controllers/spree/api/images_controller.rb +10 -8
- data/app/controllers/spree/api/inventory_units_controller.rb +7 -4
- data/app/controllers/spree/api/line_items_controller.rb +14 -14
- data/app/controllers/spree/api/option_types_controller.rb +14 -11
- data/app/controllers/spree/api/option_values_controller.rb +13 -11
- data/app/controllers/spree/api/orders_controller.rb +56 -53
- data/app/controllers/spree/api/payments_controller.rb +25 -33
- data/app/controllers/spree/api/product_properties_controller.rb +20 -13
- data/app/controllers/spree/api/products_controller.rb +11 -58
- data/app/controllers/spree/api/properties_controller.rb +19 -16
- data/app/controllers/spree/api/return_authorizations_controller.rb +30 -25
- data/app/controllers/spree/api/shipments_controller.rb +24 -19
- data/app/controllers/spree/api/states_controller.rb +9 -7
- data/app/controllers/spree/api/stock_items_controller.rb +9 -11
- data/app/controllers/spree/api/stock_locations_controller.rb +9 -7
- data/app/controllers/spree/api/stock_movements_controller.rb +7 -5
- data/app/controllers/spree/api/taxonomies_controller.rb +14 -8
- data/app/controllers/spree/api/taxons_controller.rb +25 -20
- data/app/controllers/spree/api/users_controller.rb +7 -5
- data/app/controllers/spree/api/variants_controller.rb +35 -33
- data/app/controllers/spree/api/zones_controller.rb +18 -17
- data/app/helpers/spree/api/api_helpers.rb +7 -6
- data/app/models/spree/option_value_decorator.rb +0 -4
- data/app/models/spree/order_decorator.rb +33 -54
- data/app/views/spree/api/adjustments/show.v1.rabl +2 -1
- data/app/views/spree/api/config/money.v1.rabl +6 -0
- data/app/views/spree/api/config/show.v1.rabl +2 -0
- data/app/views/spree/api/images/show.v1.rabl +0 -1
- data/app/views/spree/api/line_items/show.v1.rabl +3 -0
- data/app/views/spree/api/orders/index.v1.rabl +1 -1
- data/app/views/spree/api/orders/order.v1.rabl +6 -0
- data/app/views/spree/api/orders/payment.v1.rabl +1 -1
- data/app/views/spree/api/orders/show.v1.rabl +1 -1
- data/app/views/spree/api/payments/credit_over_limit.v1.rabl +1 -1
- data/app/views/spree/api/payments/new.v1.rabl +1 -0
- data/app/views/spree/api/products/index.v1.rabl +2 -2
- data/app/views/spree/api/products/show.v1.rabl +1 -0
- data/app/views/spree/api/shipments/show.v1.rabl +22 -5
- data/app/views/spree/api/shipping_rates/show.v1.rabl +2 -0
- data/app/views/spree/api/taxons/index.v1.rabl +2 -4
- data/app/views/spree/api/variants/index.v1.rabl +1 -1
- data/config/locales/en.yml +1 -3
- data/config/routes.rb +4 -1
- data/lib/spree/api/responders/rabl_template.rb +1 -1
- data/lib/spree/api/testing_support/helpers.rb +5 -0
- data/spec/controllers/spree/api/addresses_controller_spec.rb +2 -2
- data/spec/controllers/spree/api/checkouts_controller_spec.rb +32 -22
- data/spec/controllers/spree/api/config_controller_spec.rb +27 -0
- data/spec/controllers/spree/api/images_controller_spec.rb +2 -2
- data/spec/controllers/spree/api/inventory_units_controller_spec.rb +28 -24
- data/spec/controllers/spree/api/line_items_controller_spec.rb +25 -27
- data/spec/controllers/spree/api/option_types_controller_spec.rb +2 -2
- data/spec/controllers/spree/api/option_values_controller_spec.rb +2 -2
- data/spec/controllers/spree/api/orders_controller_spec.rb +130 -119
- data/spec/controllers/spree/api/payments_controller_spec.rb +77 -118
- data/spec/controllers/spree/api/products_controller_spec.rb +13 -143
- data/spec/controllers/spree/api/return_authorizations_controller_spec.rb +4 -19
- data/spec/controllers/spree/api/shipments_controller_spec.rb +3 -3
- data/spec/controllers/spree/api/states_controller_spec.rb +1 -1
- data/spec/controllers/spree/api/stock_items_controller_spec.rb +26 -62
- data/spec/controllers/spree/api/stock_locations_controller_spec.rb +29 -56
- data/spec/controllers/spree/api/stock_movements_controller_spec.rb +27 -51
- data/spec/controllers/spree/api/taxons_controller_spec.rb +18 -48
- data/spec/controllers/spree/api/users_controller_spec.rb +4 -6
- data/spec/controllers/spree/api/variants_controller_spec.rb +21 -38
- data/spec/controllers/spree/api/zones_controller_spec.rb +2 -2
- data/spec/models/spree/order_spec.rb +19 -111
- data/spec/spec_helper.rb +2 -26
- data/spec/support/controller_hacks.rb +1 -1
- data/spree_api.gemspec +1 -1
- metadata +19 -15
- data/app/models/spree/line_item_decorator.rb +0 -3
- data/app/views/spree/api/payments/update_forbidden.v1.rabl +0 -2
- data/db/migrate/20131017162334_add_index_to_user_spree_api_key.rb +0 -7
@@ -9,36 +9,40 @@ module Spree
|
|
9
9
|
@inventory_unit = create(:inventory_unit)
|
10
10
|
end
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
json_response['state'].should eq @inventory_unit.state
|
15
|
-
end
|
16
|
-
|
17
|
-
it "updates an inventory unit (only shipment is accessable by default)" do
|
18
|
-
api_put :update, :id => @inventory_unit.id,
|
19
|
-
:inventory_unit => { :shipment => nil }
|
20
|
-
json_response['shipment_id'].should be_nil
|
21
|
-
end
|
22
|
-
|
23
|
-
context 'fires state event' do
|
24
|
-
it 'if supplied with :fire param' do
|
25
|
-
api_put :update, :id => @inventory_unit.id,
|
26
|
-
:fire => 'ship',
|
27
|
-
:inventory_unit => { :shipment => nil }
|
12
|
+
context "as an admin" do
|
13
|
+
sign_in_as_admin!
|
28
14
|
|
29
|
-
|
15
|
+
it "gets an inventory unit" do
|
16
|
+
api_get :show, :id => @inventory_unit.id
|
17
|
+
json_response['state'].should eq @inventory_unit.state
|
30
18
|
end
|
31
19
|
|
32
|
-
it
|
20
|
+
it "updates an inventory unit (only shipment is accessable by default)" do
|
33
21
|
api_put :update, :id => @inventory_unit.id,
|
34
|
-
:
|
35
|
-
json_response['
|
22
|
+
:inventory_unit => { :shipment => nil }
|
23
|
+
json_response['shipment_id'].should be_nil
|
36
24
|
end
|
37
25
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
26
|
+
context 'fires state event' do
|
27
|
+
it 'if supplied with :fire param' do
|
28
|
+
api_put :update, :id => @inventory_unit.id,
|
29
|
+
:fire => 'ship',
|
30
|
+
:inventory_unit => { :shipment => nil }
|
31
|
+
|
32
|
+
json_response['state'].should eq 'shipped'
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'and returns exception if cannot fire' do
|
36
|
+
api_put :update, :id => @inventory_unit.id,
|
37
|
+
:fire => 'return'
|
38
|
+
json_response['exception'].should match /cannot transition to return/
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'and returns exception bad state' do
|
42
|
+
api_put :update, :id => @inventory_unit.id,
|
43
|
+
:fire => 'bad'
|
44
|
+
json_response['exception'].should match /cannot transition to bad/
|
45
|
+
end
|
42
46
|
end
|
43
47
|
end
|
44
48
|
end
|
@@ -7,20 +7,31 @@ module Spree
|
|
7
7
|
let!(:order) { create(:order_with_line_items) }
|
8
8
|
|
9
9
|
let(:product) { create(:product) }
|
10
|
-
let(:attributes) { [:id, :quantity, :price, :variant] }
|
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
|
+
|
13
17
|
it "can learn how to create a new line item" do
|
14
|
-
controller.stub :try_spree_current_user => current_api_user
|
15
18
|
api_get :new
|
16
19
|
json_response["attributes"].should == ["quantity", "price", "variant_id"]
|
17
20
|
required_attributes = json_response["required_attributes"]
|
18
21
|
required_attributes.should include("quantity", "variant_id")
|
19
22
|
end
|
20
23
|
|
24
|
+
context "authenticating with a token" do
|
25
|
+
it "can add a new line item to an existing order" do
|
26
|
+
api_post :create, :line_item => { :variant_id => product.master.to_param, :quantity => 1 }, :order_token => order.token
|
27
|
+
response.status.should == 201
|
28
|
+
json_response.should have_attributes(attributes)
|
29
|
+
json_response["variant"]["name"].should_not be_blank
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
21
33
|
context "as the order owner" do
|
22
34
|
before do
|
23
|
-
controller.stub :try_spree_current_user => current_api_user
|
24
35
|
Order.any_instance.stub :user => current_api_user
|
25
36
|
end
|
26
37
|
|
@@ -31,6 +42,16 @@ module Spree
|
|
31
42
|
json_response["variant"]["name"].should_not be_blank
|
32
43
|
end
|
33
44
|
|
45
|
+
it "increases a line item's quantity if it exists already" do
|
46
|
+
order.line_items.create(:variant_id => product.master.id, :quantity => 10)
|
47
|
+
api_post :create, :line_item => { :variant_id => product.master.to_param, :quantity => 1 }
|
48
|
+
response.status.should == 201
|
49
|
+
order.reload
|
50
|
+
order.line_items.count.should == 6 # 5 original due to factory, + 1 in this test
|
51
|
+
json_response.should have_attributes(attributes)
|
52
|
+
json_response["quantity"].should == 11
|
53
|
+
end
|
54
|
+
|
34
55
|
it "can update a line item on the order" do
|
35
56
|
line_item = order.line_items.first
|
36
57
|
api_put :update, :id => line_item.id, :line_item => { :quantity => 1000 }
|
@@ -44,33 +65,9 @@ module Spree
|
|
44
65
|
response.status.should == 204
|
45
66
|
lambda { line_item.reload }.should raise_error(ActiveRecord::RecordNotFound)
|
46
67
|
end
|
47
|
-
|
48
|
-
context "order contents changed after shipments were created" do
|
49
|
-
let!(:order) { Order.create }
|
50
|
-
let!(:line_item) { order.contents.add(product.master) }
|
51
|
-
|
52
|
-
before { order.create_proposed_shipments }
|
53
|
-
|
54
|
-
it "clear out shipments on create" do
|
55
|
-
expect(order.reload.shipments).not_to be_empty
|
56
|
-
api_post :create, :line_item => { :variant_id => product.master.to_param, :quantity => 1 }
|
57
|
-
expect(order.reload.shipments).to be_empty
|
58
|
-
end
|
59
|
-
|
60
|
-
it "clear out shipments on update" do
|
61
|
-
expect(order.reload.shipments).not_to be_empty
|
62
|
-
api_put :update, :id => line_item.id, :line_item => { :quantity => 1000 }
|
63
|
-
expect(order.reload.shipments).to be_empty
|
64
|
-
end
|
65
|
-
end
|
66
68
|
end
|
67
69
|
|
68
70
|
context "as just another user" do
|
69
|
-
before do
|
70
|
-
user = create(:user)
|
71
|
-
controller.stub :try_spree_current_user => user
|
72
|
-
end
|
73
|
-
|
74
71
|
it "cannot add a new line item to the order" do
|
75
72
|
api_post :create, :line_item => { :variant_id => product.master.to_param, :quantity => 1 }
|
76
73
|
assert_unauthorized!
|
@@ -90,5 +87,6 @@ module Spree
|
|
90
87
|
lambda { line_item.reload }.should_not raise_error
|
91
88
|
end
|
92
89
|
end
|
90
|
+
|
93
91
|
end
|
94
92
|
end
|
@@ -62,13 +62,13 @@ module Spree
|
|
62
62
|
:option_type => {
|
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
|
|
@@ -73,13 +73,13 @@ module Spree
|
|
73
73
|
:option_value => {
|
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
|
|
@@ -5,15 +5,17 @@ module Spree
|
|
5
5
|
render_views
|
6
6
|
|
7
7
|
let!(:order) { create(:order) }
|
8
|
-
let(:attributes) { [:number, :item_total, :total,
|
8
|
+
let(:attributes) { [:number, :item_total, :display_total, :total,
|
9
9
|
:state, :adjustment_total,
|
10
10
|
:user_id, :created_at, :updated_at,
|
11
11
|
:completed_at, :payment_total, :shipment_state,
|
12
|
-
:payment_state, :email, :special_instructions,
|
12
|
+
:payment_state, :email, :special_instructions,
|
13
|
+
:total_quantity, :display_item_total] }
|
13
14
|
|
14
|
-
let(:variant) { create(:variant) }
|
15
15
|
|
16
|
-
before
|
16
|
+
before do
|
17
|
+
stub_authentication!
|
18
|
+
end
|
17
19
|
|
18
20
|
it "cannot view all orders" do
|
19
21
|
api_get :index
|
@@ -29,6 +31,13 @@ module Spree
|
|
29
31
|
json_response["credit_cards"].should be_empty
|
30
32
|
end
|
31
33
|
|
34
|
+
it "orders contain the basic checkout steps" do
|
35
|
+
Order.any_instance.stub :user => current_api_user
|
36
|
+
api_get :show, :id => order.to_param
|
37
|
+
response.status.should == 200
|
38
|
+
json_response["checkout_steps"].should == ["address", "delivery", "complete"]
|
39
|
+
end
|
40
|
+
|
32
41
|
# Regression test for #1992
|
33
42
|
it "can view an order not in a standard state" do
|
34
43
|
Order.any_instance.stub :user => current_api_user
|
@@ -42,6 +51,11 @@ module Spree
|
|
42
51
|
assert_unauthorized!
|
43
52
|
end
|
44
53
|
|
54
|
+
it "can view an order if the token is known" do
|
55
|
+
api_get :show, :id => order.to_param, :order_token => order.token
|
56
|
+
response.status.should == 200
|
57
|
+
end
|
58
|
+
|
45
59
|
it "cannot cancel an order that doesn't belong to them" do
|
46
60
|
order.update_attribute(:completed_at, Time.now)
|
47
61
|
order.update_attribute(:shipment_state, "ready")
|
@@ -54,89 +68,68 @@ module Spree
|
|
54
68
|
assert_unauthorized!
|
55
69
|
end
|
56
70
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
71
|
+
let(:address_params) { { :country_id => Country.first.id, :state_id => State.first.id } }
|
72
|
+
let(:billing_address) { { :firstname => "Tiago", :lastname => "Motta", :address1 => "Av Paulista",
|
73
|
+
:city => "Sao Paulo", :zipcode => "1234567", :phone => "12345678",
|
74
|
+
:country_id => Country.first.id, :state_id => State.first.id} }
|
75
|
+
let(:shipping_address) { { :firstname => "Tiago", :lastname => "Motta", :address1 => "Av Paulista",
|
76
|
+
:city => "Sao Paulo", :zipcode => "1234567", :phone => "12345678",
|
77
|
+
:country_id => Country.first.id, :state_id => State.first.id} }
|
78
|
+
let!(:payment_method) { create(:payment_method) }
|
79
|
+
let(:current_api_user) do
|
80
|
+
user = Spree.user_class.new(:email => "spree@example.com")
|
81
|
+
user.generate_spree_api_key!
|
82
|
+
user
|
83
|
+
end
|
63
84
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
85
|
+
it "can create an order" do
|
86
|
+
variant = create(:variant)
|
87
|
+
api_post :create, :order => { :line_items => { "0" => { :variant_id => variant.to_param, :quantity => 5 } } }
|
88
|
+
response.status.should == 201
|
89
|
+
order = Order.last
|
90
|
+
order.line_items.count.should == 1
|
91
|
+
order.line_items.first.variant.should == variant
|
92
|
+
order.line_items.first.quantity.should == 5
|
93
|
+
json_response["token"].should_not be_blank
|
94
|
+
json_response["state"].should == "cart"
|
95
|
+
order.user.should == current_api_user
|
96
|
+
order.email.should == current_api_user.email
|
97
|
+
json_response["user_id"].should == current_api_user.id
|
98
|
+
end
|
77
99
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
100
|
+
# Regression test for #3404
|
101
|
+
it "can specify additional parameters for a line item" do
|
102
|
+
variant = create(:variant)
|
103
|
+
Order.should_receive(:create!).and_return(order = Spree::Order.new)
|
104
|
+
order.stub(:associate_user!)
|
105
|
+
order.stub_chain(:contents, :add).and_return(line_item = double('LineItem'))
|
106
|
+
line_item.should_receive(:update_attributes).with("special" => true)
|
107
|
+
|
108
|
+
controller.stub(permitted_line_item_attributes: [:id, :variant_id, :quantity, :special])
|
109
|
+
api_post :create, :order => {
|
110
|
+
:line_items => {
|
111
|
+
"0" => {
|
112
|
+
:variant_id => variant.to_param, :quantity => 5, :special => true
|
90
113
|
}
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
current_api_user.stub has_spree_role?: true
|
96
|
-
end
|
97
|
-
|
98
|
-
it "sets channel" do
|
99
|
-
api_post :create, :order => { channel: "amazon" }
|
100
|
-
expect(json_response['channel']).to eq "amazon"
|
101
|
-
end
|
102
|
-
|
103
|
-
it "doesnt persist any automatic tax adjustment" do
|
104
|
-
expect {
|
105
|
-
api_post :create, :order => order_params.merge(:import => true)
|
106
|
-
}.not_to change { Adjustment.count }
|
107
|
-
expect(response.status).to eq 201
|
108
|
-
end
|
109
|
-
|
110
|
-
context "provides sku rather than variant id" do
|
111
|
-
let(:order_params) do
|
112
|
-
{ :line_items => [{ :sku => variant.sku, :quantity => 1 }] }
|
113
|
-
end
|
114
|
-
|
115
|
-
it "still finds the variant by sku and persist order" do
|
116
|
-
api_post :create, :order => order_params
|
117
|
-
expect(json_response['line_items'].count).to eq 1
|
118
|
-
end
|
119
|
-
end
|
120
|
-
end
|
114
|
+
}
|
115
|
+
}
|
116
|
+
response.status.should == 201
|
117
|
+
end
|
121
118
|
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
119
|
+
# Regression test for #3404
|
120
|
+
it "does not update line item needlessly" do
|
121
|
+
variant = create(:variant)
|
122
|
+
Order.should_receive(:create!).and_return(order = Spree::Order.new)
|
123
|
+
order.stub(:associate_user!)
|
124
|
+
order.stub_chain(:contents, :add).and_return(line_item = double('LineItem'))
|
125
|
+
line_item.should_not_receive(:update_attributes)
|
126
|
+
api_post :create, :order => {
|
127
|
+
:line_items => {
|
128
|
+
"0" => {
|
129
|
+
:variant_id => variant.to_param, :quantity => 5
|
131
130
|
}
|
132
131
|
}
|
133
|
-
|
134
|
-
order = Order.last
|
135
|
-
order.line_items.count.should == 1
|
136
|
-
order.line_items.first.variant.should == variant
|
137
|
-
order.line_items.first.quantity.should == 5
|
138
|
-
order.line_items.first.price.should == order.line_items.first.variant.price
|
139
|
-
end
|
132
|
+
}
|
140
133
|
end
|
141
134
|
|
142
135
|
it "can create an order without any parameters" do
|
@@ -147,6 +140,8 @@ module Spree
|
|
147
140
|
end
|
148
141
|
|
149
142
|
context "working with an order" do
|
143
|
+
|
144
|
+
let(:variant) { create(:variant) }
|
150
145
|
let!(:line_item) { order.contents.add(variant, 1) }
|
151
146
|
let!(:payment_method) { create(:payment_method) }
|
152
147
|
|
@@ -173,15 +168,6 @@ module Spree
|
|
173
168
|
address
|
174
169
|
end
|
175
170
|
|
176
|
-
let(:address_params) { { :country_id => Country.first.id, :state_id => State.first.id } }
|
177
|
-
let(:billing_address) { { :firstname => "Tiago", :lastname => "Motta", :address1 => "Av Paulista",
|
178
|
-
:city => "Sao Paulo", :zipcode => "1234567", :phone => "12345678",
|
179
|
-
:country_id => Country.first.id, :state_id => State.first.id} }
|
180
|
-
let(:shipping_address) { { :firstname => "Tiago", :lastname => "Motta", :address1 => "Av Paulista",
|
181
|
-
:city => "Sao Paulo", :zipcode => "1234567", :phone => "12345678",
|
182
|
-
:country_id => Country.first.id, :state_id => State.first.id} }
|
183
|
-
let!(:payment_method) { create(:payment_method) }
|
184
|
-
|
185
171
|
it "updates quantities of existing line items" do
|
186
172
|
api_put :update, :id => order.to_param, :order => {
|
187
173
|
:line_items => {
|
@@ -194,18 +180,6 @@ module Spree
|
|
194
180
|
json_response['line_items'].first['quantity'].should == 10
|
195
181
|
end
|
196
182
|
|
197
|
-
it "cannot set a price for a line item" do
|
198
|
-
variant = create(:variant)
|
199
|
-
api_put :update, :id => order.to_param, :order => {
|
200
|
-
:line_items_attributes => { order.line_items.first.id =>
|
201
|
-
{ :variant_id => variant.id, :quantity => 2, :price => 0.44}
|
202
|
-
}
|
203
|
-
}
|
204
|
-
response.status.should == 200
|
205
|
-
json_response['line_items'].count.should == 1
|
206
|
-
expect(json_response['line_items'].first['price']).to eq(variant.price.to_s)
|
207
|
-
end
|
208
|
-
|
209
183
|
it "can add billing address" do
|
210
184
|
api_put :update, :id => order.to_param, :order => { :bill_address_attributes => billing_address }
|
211
185
|
|
@@ -223,7 +197,6 @@ module Spree
|
|
223
197
|
end
|
224
198
|
|
225
199
|
it "can add shipping address" do
|
226
|
-
pending "need to figure out how to get shipping methods for an order"
|
227
200
|
order.ship_address.should be_nil
|
228
201
|
|
229
202
|
api_put :update, :id => order.to_param, :order => { :ship_address_attributes => shipping_address }
|
@@ -257,15 +230,19 @@ module Spree
|
|
257
230
|
end
|
258
231
|
|
259
232
|
context "with a line item" do
|
260
|
-
|
261
|
-
create(:
|
262
|
-
order
|
233
|
+
let(:order_with_line_items) do
|
234
|
+
order = create(:order_with_line_items)
|
235
|
+
create(:adjustment, :adjustable => order)
|
236
|
+
order
|
263
237
|
end
|
264
238
|
|
265
239
|
it "can empty an order" do
|
266
|
-
|
240
|
+
order_with_line_items.adjustments.count.should be == 1
|
241
|
+
api_put :empty, :id => order_with_line_items.to_param
|
267
242
|
response.status.should == 200
|
268
|
-
|
243
|
+
order_with_line_items.reload
|
244
|
+
order_with_line_items.line_items.should be_empty
|
245
|
+
order_with_line_items.adjustments.should be_empty
|
269
246
|
end
|
270
247
|
|
271
248
|
it "can list its line items with images" do
|
@@ -281,6 +258,50 @@ module Spree
|
|
281
258
|
|
282
259
|
json_response['line_items'].first['variant'].should have_attributes([:product_id])
|
283
260
|
end
|
261
|
+
|
262
|
+
context "when in delivery" do
|
263
|
+
let!(:shipping_method) do
|
264
|
+
FactoryGirl.create(:shipping_method).tap do |shipping_method|
|
265
|
+
shipping_method.calculator.preferred_amount = 10
|
266
|
+
shipping_method.calculator.save
|
267
|
+
end
|
268
|
+
end
|
269
|
+
|
270
|
+
before do
|
271
|
+
order.ship_address = FactoryGirl.create(:address)
|
272
|
+
order.state = 'delivery'
|
273
|
+
order.save
|
274
|
+
end
|
275
|
+
|
276
|
+
it "returns available shipments for an order" do
|
277
|
+
api_get :show, :id => order.to_param
|
278
|
+
response.status.should == 200
|
279
|
+
json_response["shipments"].should_not be_empty
|
280
|
+
shipment = json_response["shipments"][0]
|
281
|
+
# Test for correct shipping method attributes
|
282
|
+
# Regression test for #3206
|
283
|
+
shipment["shipping_methods"].should_not be_nil
|
284
|
+
json_shipping_method = shipment["shipping_methods"][0]
|
285
|
+
json_shipping_method["id"].should == shipping_method.id
|
286
|
+
json_shipping_method["name"].should == shipping_method.name
|
287
|
+
json_shipping_method["zones"].should_not be_empty
|
288
|
+
json_shipping_method["shipping_categories"].should_not be_empty
|
289
|
+
|
290
|
+
# Test for correct shipping rates attributes
|
291
|
+
# Regression test for #3206
|
292
|
+
shipment["shipping_rates"].should_not be_nil
|
293
|
+
shipping_rate = shipment["shipping_rates"][0]
|
294
|
+
shipping_rate["name"].should == json_shipping_method["name"]
|
295
|
+
shipping_rate["cost"].should == "10.0"
|
296
|
+
shipping_rate["selected"].should be_true
|
297
|
+
shipping_rate["display_cost"].should == "$10.00"
|
298
|
+
|
299
|
+
shipment["stock_location_name"].should_not be_blank
|
300
|
+
manifest_item = shipment["manifest"][0]
|
301
|
+
manifest_item["quantity"].should == 1
|
302
|
+
manifest_item["variant"].should have_attributes([:id, :name, :sku, :price])
|
303
|
+
end
|
304
|
+
end
|
284
305
|
end
|
285
306
|
end
|
286
307
|
|
@@ -295,17 +316,6 @@ module Spree
|
|
295
316
|
end
|
296
317
|
end
|
297
318
|
|
298
|
-
it "responds with orders updated_at with miliseconds precision" do
|
299
|
-
if ActiveRecord::Base.connection.adapter_name == "Mysql2"
|
300
|
-
pending "MySQL does not support millisecond timestamps."
|
301
|
-
end
|
302
|
-
|
303
|
-
api_get :index
|
304
|
-
milisecond = order.updated_at.strftime("%L")
|
305
|
-
updated_at = json_response["orders"].first["updated_at"]
|
306
|
-
expect(updated_at.split("T").last).to have_content(milisecond)
|
307
|
-
end
|
308
|
-
|
309
319
|
context "with two orders" do
|
310
320
|
before { create(:order) }
|
311
321
|
|
@@ -365,3 +375,4 @@ module Spree
|
|
365
375
|
end
|
366
376
|
end
|
367
377
|
end
|
378
|
+
|