spree_api 2.0.13 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (81) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +99 -1
  3. data/app/controllers/spree/api/addresses_controller.rb +5 -2
  4. data/app/controllers/spree/api/base_controller.rb +14 -21
  5. data/app/controllers/spree/api/checkouts_controller.rb +30 -27
  6. data/app/controllers/spree/api/config_controller.rb +6 -0
  7. data/app/controllers/spree/api/countries_controller.rb +7 -7
  8. data/app/controllers/spree/api/images_controller.rb +10 -8
  9. data/app/controllers/spree/api/inventory_units_controller.rb +7 -4
  10. data/app/controllers/spree/api/line_items_controller.rb +14 -14
  11. data/app/controllers/spree/api/option_types_controller.rb +14 -11
  12. data/app/controllers/spree/api/option_values_controller.rb +13 -11
  13. data/app/controllers/spree/api/orders_controller.rb +56 -53
  14. data/app/controllers/spree/api/payments_controller.rb +25 -33
  15. data/app/controllers/spree/api/product_properties_controller.rb +20 -13
  16. data/app/controllers/spree/api/products_controller.rb +11 -58
  17. data/app/controllers/spree/api/properties_controller.rb +19 -16
  18. data/app/controllers/spree/api/return_authorizations_controller.rb +30 -25
  19. data/app/controllers/spree/api/shipments_controller.rb +24 -19
  20. data/app/controllers/spree/api/states_controller.rb +9 -7
  21. data/app/controllers/spree/api/stock_items_controller.rb +9 -11
  22. data/app/controllers/spree/api/stock_locations_controller.rb +9 -7
  23. data/app/controllers/spree/api/stock_movements_controller.rb +7 -5
  24. data/app/controllers/spree/api/taxonomies_controller.rb +14 -8
  25. data/app/controllers/spree/api/taxons_controller.rb +25 -20
  26. data/app/controllers/spree/api/users_controller.rb +7 -5
  27. data/app/controllers/spree/api/variants_controller.rb +35 -33
  28. data/app/controllers/spree/api/zones_controller.rb +18 -17
  29. data/app/helpers/spree/api/api_helpers.rb +7 -6
  30. data/app/models/spree/option_value_decorator.rb +0 -4
  31. data/app/models/spree/order_decorator.rb +33 -54
  32. data/app/views/spree/api/adjustments/show.v1.rabl +2 -1
  33. data/app/views/spree/api/config/money.v1.rabl +6 -0
  34. data/app/views/spree/api/config/show.v1.rabl +2 -0
  35. data/app/views/spree/api/images/show.v1.rabl +0 -1
  36. data/app/views/spree/api/line_items/show.v1.rabl +3 -0
  37. data/app/views/spree/api/orders/index.v1.rabl +1 -1
  38. data/app/views/spree/api/orders/order.v1.rabl +6 -0
  39. data/app/views/spree/api/orders/payment.v1.rabl +1 -1
  40. data/app/views/spree/api/orders/show.v1.rabl +1 -1
  41. data/app/views/spree/api/payments/credit_over_limit.v1.rabl +1 -1
  42. data/app/views/spree/api/payments/new.v1.rabl +1 -0
  43. data/app/views/spree/api/products/index.v1.rabl +2 -2
  44. data/app/views/spree/api/products/show.v1.rabl +1 -0
  45. data/app/views/spree/api/shipments/show.v1.rabl +22 -5
  46. data/app/views/spree/api/shipping_rates/show.v1.rabl +2 -0
  47. data/app/views/spree/api/taxons/index.v1.rabl +2 -4
  48. data/app/views/spree/api/variants/index.v1.rabl +1 -1
  49. data/config/locales/en.yml +1 -3
  50. data/config/routes.rb +4 -1
  51. data/lib/spree/api/responders/rabl_template.rb +1 -1
  52. data/lib/spree/api/testing_support/helpers.rb +5 -0
  53. data/spec/controllers/spree/api/addresses_controller_spec.rb +2 -2
  54. data/spec/controllers/spree/api/checkouts_controller_spec.rb +32 -22
  55. data/spec/controllers/spree/api/config_controller_spec.rb +27 -0
  56. data/spec/controllers/spree/api/images_controller_spec.rb +2 -2
  57. data/spec/controllers/spree/api/inventory_units_controller_spec.rb +28 -24
  58. data/spec/controllers/spree/api/line_items_controller_spec.rb +25 -27
  59. data/spec/controllers/spree/api/option_types_controller_spec.rb +2 -2
  60. data/spec/controllers/spree/api/option_values_controller_spec.rb +2 -2
  61. data/spec/controllers/spree/api/orders_controller_spec.rb +130 -119
  62. data/spec/controllers/spree/api/payments_controller_spec.rb +77 -118
  63. data/spec/controllers/spree/api/products_controller_spec.rb +13 -143
  64. data/spec/controllers/spree/api/return_authorizations_controller_spec.rb +4 -19
  65. data/spec/controllers/spree/api/shipments_controller_spec.rb +3 -3
  66. data/spec/controllers/spree/api/states_controller_spec.rb +1 -1
  67. data/spec/controllers/spree/api/stock_items_controller_spec.rb +26 -62
  68. data/spec/controllers/spree/api/stock_locations_controller_spec.rb +29 -56
  69. data/spec/controllers/spree/api/stock_movements_controller_spec.rb +27 -51
  70. data/spec/controllers/spree/api/taxons_controller_spec.rb +18 -48
  71. data/spec/controllers/spree/api/users_controller_spec.rb +4 -6
  72. data/spec/controllers/spree/api/variants_controller_spec.rb +21 -38
  73. data/spec/controllers/spree/api/zones_controller_spec.rb +2 -2
  74. data/spec/models/spree/order_spec.rb +19 -111
  75. data/spec/spec_helper.rb +2 -26
  76. data/spec/support/controller_hacks.rb +1 -1
  77. data/spree_api.gemspec +1 -1
  78. metadata +19 -15
  79. data/app/models/spree/line_item_decorator.rb +0 -3
  80. data/app/views/spree/api/payments/update_forbidden.v1.rabl +0 -2
  81. 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
- it "gets an inventory unit" do
13
- api_get :show, :id => @inventory_unit.id
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
- json_response['state'].should eq 'shipped'
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 'and returns exception if cannot fire' do
20
+ it "updates an inventory unit (only shipment is accessable by default)" do
33
21
  api_put :update, :id => @inventory_unit.id,
34
- :fire => 'return'
35
- json_response['exception'].should match /cannot transition to return/
22
+ :inventory_unit => { :shipment => nil }
23
+ json_response['shipment_id'].should be_nil
36
24
  end
37
25
 
38
- it 'and returns exception bad state' do
39
- api_put :update, :id => @inventory_unit.id,
40
- :fire => 'bad'
41
- json_response['exception'].should match /cannot transition to bad/
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
- assert_unauthorized!
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
- assert_unauthorized!
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
- assert_unauthorized!
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
- assert_unauthorized!
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, :token] }
12
+ :payment_state, :email, :special_instructions,
13
+ :total_quantity, :display_item_total] }
13
14
 
14
- let(:variant) { create(:variant) }
15
15
 
16
- before { stub_authentication! }
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
- context "create order" do
58
- let(:current_api_user) do
59
- user = Spree.user_class.new(:email => "spree@example.com")
60
- user.generate_spree_api_key!
61
- user
62
- end
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
- it "can create an order" do
65
- variant = create(:variant)
66
- api_post :create, :order => { :line_items => { "0" => { :variant_id => variant.to_param, :quantity => 5 } } }
67
- response.status.should == 201
68
- order = Order.last
69
- order.line_items.count.should == 1
70
- order.line_items.first.variant.should == variant
71
- order.line_items.first.quantity.should == 5
72
- json_response["state"].should == "cart"
73
- order.user.should == current_api_user
74
- order.email == current_api_user.email
75
- json_response["user_id"].should == current_api_user.id
76
- end
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
- context "import" do
79
- let(:tax_rate) { create(:tax_rate, amount: 0.05, calculator: Calculator::DefaultTax.create) }
80
- let(:other_variant) { create(:variant) }
81
-
82
- # line items come in as an array when importing orders or when
83
- # creating both an order an a line item at once
84
- let(:order_params) do
85
- {
86
- :line_items => [
87
- { :variant_id => variant.to_param, :quantity => 5 },
88
- { :variant_id => other_variant.to_param, :quantity => 5 }
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
- end
92
-
93
- before do
94
- Zone.stub default_tax: tax_rate.zone
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
- it "cannot create an order with an abitrary price for the line item" do
123
- variant = create(:variant)
124
- api_post :create, :order => {
125
- :line_items => {
126
- "0" => {
127
- :variant_id => variant.to_param,
128
- :quantity => 5,
129
- :price => 0.44
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
- response.status.should == 201
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
- before do
261
- create(:line_item, :order => order)
262
- order.reload
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
- api_put :empty, :id => order.to_param
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
- order.reload.line_items.should be_empty
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
+