spree_api 1.3.5 → 2.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (91) hide show
  1. checksums.yaml +14 -6
  2. data/Rakefile +1 -1
  3. data/app/controllers/spree/api/addresses_controller.rb +0 -1
  4. data/app/controllers/spree/api/base_controller.rb +21 -9
  5. data/app/controllers/spree/api/checkouts_controller.rb +40 -20
  6. data/app/controllers/spree/api/countries_controller.rb +0 -1
  7. data/app/controllers/spree/api/inventory_units_controller.rb +1 -1
  8. data/app/controllers/spree/api/option_types_controller.rb +46 -0
  9. data/app/controllers/spree/api/option_values_controller.rb +56 -0
  10. data/app/controllers/spree/api/orders_controller.rb +1 -21
  11. data/app/controllers/spree/api/product_properties_controller.rb +0 -1
  12. data/app/controllers/spree/api/products_controller.rb +12 -27
  13. data/app/controllers/spree/api/properties_controller.rb +61 -0
  14. data/app/controllers/spree/api/shipments_controller.rb +51 -1
  15. data/app/controllers/spree/api/states_controller.rb +32 -0
  16. data/app/controllers/spree/api/stock_items_controller.rb +70 -0
  17. data/app/controllers/spree/api/stock_locations_controller.rb +45 -0
  18. data/app/controllers/spree/api/stock_movements_controller.rb +55 -0
  19. data/app/controllers/spree/api/taxonomies_controller.rb +5 -0
  20. data/app/controllers/spree/api/taxons_controller.rb +16 -2
  21. data/app/controllers/spree/api/variants_controller.rb +1 -1
  22. data/app/controllers/spree/api/zones_controller.rb +0 -1
  23. data/app/helpers/spree/api/api_helpers.rb +34 -7
  24. data/app/models/spree/api_configuration.rb +1 -2
  25. data/app/models/spree/line_item_decorator.rb +1 -1
  26. data/app/models/spree/order_decorator.rb +6 -169
  27. data/app/overrides/api_admin_user_edit_form.rb +7 -6
  28. data/app/views/spree/admin/users/_api_fields.html.erb +7 -8
  29. data/app/views/spree/api/addresses/show.v1.rabl +2 -2
  30. data/app/views/spree/api/adjustments/show.v1.rabl +2 -0
  31. data/app/views/spree/api/credit_cards/show.v1.rabl +2 -0
  32. data/app/views/spree/api/option_types/index.v1.rabl +3 -0
  33. data/app/views/spree/api/option_types/show.v1.rabl +5 -0
  34. data/app/views/spree/api/option_values/index.v1.rabl +3 -0
  35. data/app/views/spree/api/option_values/show.v1.rabl +2 -0
  36. data/app/views/spree/api/orders/could_not_apply_coupon.v1.rabl +2 -0
  37. data/app/views/spree/api/orders/delivery.v1.rabl +2 -2
  38. data/app/views/spree/api/orders/payment.v1.rabl +3 -0
  39. data/app/views/spree/api/orders/show.v1.rabl +8 -0
  40. data/app/views/spree/api/properties/index.v1.rabl +7 -0
  41. data/app/views/spree/api/properties/new.v1.rabl +2 -0
  42. data/app/views/spree/api/properties/show.v1.rabl +2 -0
  43. data/app/views/spree/api/shared/stock_location_required.v1.rabl +2 -0
  44. data/app/views/spree/api/shipments/show.v1.rabl +7 -0
  45. data/app/views/spree/api/states/index.v1.rabl +14 -0
  46. data/app/views/spree/api/states/show.v1.rabl +2 -0
  47. data/app/views/spree/api/stock_items/index.v1.rabl +7 -0
  48. data/app/views/spree/api/stock_items/show.v1.rabl +5 -0
  49. data/app/views/spree/api/stock_locations/index.v1.rabl +7 -0
  50. data/app/views/spree/api/stock_locations/show.v1.rabl +8 -0
  51. data/app/views/spree/api/stock_movements/index.v1.rabl +7 -0
  52. data/app/views/spree/api/stock_movements/show.v1.rabl +5 -0
  53. data/app/views/spree/api/taxonomies/jstree.rabl +8 -0
  54. data/app/views/spree/api/taxons/jstree.rabl +8 -0
  55. data/app/views/spree/api/variants/index.v1.rabl +14 -1
  56. data/app/views/spree/api/variants/variant.v1.rabl +0 -4
  57. data/config/locales/en.yml +1 -0
  58. data/config/routes.rb +29 -3
  59. data/lib/spree/api.rb +0 -2
  60. data/lib/spree/api/controller_setup.rb +6 -1
  61. data/lib/spree/api/testing_support/helpers.rb +1 -1
  62. data/lib/spree/api/testing_support/setup.rb +13 -0
  63. data/spec/controllers/spree/api/base_controller_spec.rb +14 -1
  64. data/spec/controllers/spree/api/checkouts_controller_spec.rb +59 -28
  65. data/spec/controllers/spree/api/line_items_controller_spec.rb +1 -5
  66. data/spec/controllers/spree/api/option_types_controller_spec.rb +116 -0
  67. data/spec/controllers/spree/api/option_values_controller_spec.rb +128 -0
  68. data/spec/controllers/spree/api/orders_controller_spec.rb +11 -93
  69. data/spec/controllers/spree/api/product_properties_controller_spec.rb +2 -2
  70. data/spec/controllers/spree/api/products_controller_spec.rb +18 -76
  71. data/spec/controllers/spree/api/properties_controller_spec.rb +89 -0
  72. data/spec/controllers/spree/api/return_authorizations_controller_spec.rb +1 -9
  73. data/spec/controllers/spree/api/shipments_controller_spec.rb +80 -5
  74. data/spec/controllers/spree/api/states_controller_spec.rb +76 -0
  75. data/spec/controllers/spree/api/stock_items_controller_spec.rb +88 -0
  76. data/spec/controllers/spree/api/stock_locations_controller_spec.rb +86 -0
  77. data/spec/controllers/spree/api/stock_movements_controller_spec.rb +72 -0
  78. data/spec/controllers/spree/api/taxonomies_controller_spec.rb +7 -0
  79. data/spec/controllers/spree/api/taxons_controller_spec.rb +29 -2
  80. data/spec/controllers/spree/api/unauthenticated_products_controller_spec.rb +1 -1
  81. data/spec/controllers/spree/api/variants_controller_spec.rb +5 -16
  82. data/spec/fixtures/thinking-cat.jpg +0 -0
  83. data/spec/models/spree/order_spec.rb +7 -328
  84. data/spec/spec_helper.rb +18 -2
  85. data/spree_api.gemspec +2 -1
  86. metadata +67 -16
  87. data/.rspec +0 -1
  88. data/app/controllers/spree/base_controller_decorator.rb +0 -15
  89. data/app/overrides/api_key_spree_layout.rb +0 -7
  90. data/app/views/spree/api/_key.html.erb +0 -4
  91. data/db/migrate/20131017162334_add_index_to_user_spree_api_key.rb +0 -7
@@ -1,4 +1,5 @@
1
1
  require 'spec_helper'
2
+ require 'spree/promo/coupon_applicator'
2
3
 
3
4
  module Spree
4
5
  describe Api::CheckoutsController do
@@ -11,8 +12,9 @@ module Spree
11
12
  @state = create(:state)
12
13
  @country = @state.country
13
14
  country_zone.members.create(:zoneable => @country)
15
+ create(:stock_location)
14
16
 
15
- @shipping_method = create(:shipping_method, :zone => country_zone)
17
+ @shipping_method = create(:shipping_method, :zones => [country_zone])
16
18
  @payment_method = create(:payment_method)
17
19
  end
18
20
 
@@ -44,7 +46,7 @@ module Spree
44
46
  end
45
47
 
46
48
  context "PUT 'update'" do
47
- let(:order) { create(:order) }
49
+ let(:order) { create(:order_with_line_items) }
48
50
 
49
51
  before(:each) do
50
52
  Order.any_instance.stub(:confirmation_required? => true)
@@ -53,26 +55,24 @@ module Spree
53
55
 
54
56
  it "will return an error if the recently created order cannot transition from cart to address" do
55
57
  order.state.should eq "cart"
56
- order.email = nil # email is necessary to transition from cart to address
57
- order.save!
58
+ order.update_column(:email, nil) # email is necessary to transition from cart to address
58
59
 
59
- api_put :update, :id => order.to_param, :order_token => order.token
60
+ api_put :update, :id => order.to_param
60
61
 
61
- json_response['error'].should =~ /could not be transitioned/
62
- response.status.should == 422
62
+ # Order has not transitioned
63
+ json_response['state'].should == 'cart'
63
64
  end
64
65
 
65
66
  it "should transition a recently created order from cart do address" do
66
67
  order.state.should eq "cart"
67
68
  order.email.should_not be_nil
68
- api_put :update, :id => order.to_param, :order_token => order.token
69
+ api_put :update, :id => order.to_param
69
70
  order.reload.state.should eq "address"
70
71
  end
71
72
 
72
73
  it "will return an error if the order cannot transition" do
73
74
  order.update_column(:state, "address")
74
- api_put :update, :id => order.to_param, :order_token => order.token
75
- json_response['error'].should =~ /could not be transitioned/
75
+ api_put :update, :id => order.to_param
76
76
  response.status.should == 422
77
77
  end
78
78
 
@@ -89,9 +89,8 @@ module Spree
89
89
  :country_id => @country.id
90
90
  }
91
91
  api_put :update,
92
- :id => order.to_param, :order_token => order.token,
92
+ :id => order.to_param,
93
93
  :order => { :bill_address_attributes => billing_address, :ship_address_attributes => shipping_address }
94
-
95
94
  json_response['state'].should == 'delivery'
96
95
  json_response['bill_address']['firstname'].should == 'John'
97
96
  json_response['ship_address']['firstname'].should == 'John'
@@ -100,9 +99,9 @@ module Spree
100
99
 
101
100
  it "can update shipping method and transition from delivery to payment" do
102
101
  order.update_column(:state, "delivery")
103
- api_put :update, :id => order.to_param, :order_token => order.token,
104
- :order => { :shipping_method_id => @shipping_method.id }
105
-
102
+ shipment = create(:shipment, :order => order)
103
+ shipping_rate = shipment.shipping_rates.first
104
+ api_put :update, :id => order.to_param, :order => { :shipments_attributes => { "0" => { :selected_shipping_rate_id => shipping_rate.id, :id => shipment.id } } }
106
105
  json_response['shipments'][0]['shipping_method']['name'].should == @shipping_method.name
107
106
  json_response['state'].should == 'payment'
108
107
  response.status.should == 200
@@ -110,8 +109,7 @@ module Spree
110
109
 
111
110
  it "can update payment method and transition from payment to confirm" do
112
111
  order.update_column(:state, "payment")
113
- api_put :update, :id => order.to_param, :order_token => order.token,
114
- :order => { :payments_attributes => [{ :payment_method_id => @payment_method.id }] }
112
+ api_put :update, :id => order.to_param, :order => { :payments_attributes => [{ :payment_method_id => @payment_method.id }] }
115
113
  json_response['state'].should == 'confirm'
116
114
  json_response['payments'][0]['payment_method']['name'].should == @payment_method.name
117
115
  response.status.should == 200
@@ -120,34 +118,67 @@ module Spree
120
118
  it "can transition from confirm to complete" do
121
119
  order.update_column(:state, "confirm")
122
120
  Spree::Order.any_instance.stub(:payment_required? => false)
123
- api_put :update, :id => order.to_param, :order_token => order.token
121
+ api_put :update, :id => order.to_param
124
122
  json_response['state'].should == 'complete'
125
123
  response.status.should == 200
126
124
  end
127
125
 
128
126
  it "returns the order if the order is already complete" do
129
127
  order.update_column(:state, "complete")
130
- api_put :update, :id => order.to_param, :order_token => order.token
128
+ api_put :update, :id => order.to_param
131
129
  json_response['number'].should == order.number
132
130
  response.status.should == 200
133
131
  end
134
132
 
135
- it "can assign a user to the order" do
136
- user = create(:user)
137
- api_put :update, :id => order.to_param, :order_token => order.token, :order => { :user_id => user.id }
138
- json_response['user_id'].should == user.id
139
- response.status.should == 200
133
+ context "as an admin" do
134
+ sign_in_as_admin!
135
+ it "can assign a user to the order" do
136
+ user = create(:user)
137
+ # Need to pass email as well so that validations succeed
138
+ api_put :update, :id => order.to_param, :order => { :user_id => user.id, :email => "guest@spreecommerce.com" }
139
+ response.status.should == 200
140
+ json_response['user_id'].should == user.id
141
+ end
140
142
  end
141
143
 
142
144
  it "can assign an email to the order" do
143
- api_put :update, :id => order.to_param, :order_token => order.token, :order => { :email => "guest@spreecommerce.com" }
145
+ api_put :update, :id => order.to_param, :order => { :email => "guest@spreecommerce.com" }
144
146
  json_response['email'].should == "guest@spreecommerce.com"
145
147
  response.status.should == 200
146
148
  end
147
149
 
148
- it "cannot update an order without authorization" do
149
- api_put :update, :id => order.to_param
150
- assert_unauthorized!
150
+ it "can apply a coupon code to an order" do
151
+ order.update_column(:state, "payment")
152
+ Spree::Promo::CouponApplicator.should_receive(:new).with(order).and_call_original
153
+ Spree::Promo::CouponApplicator.any_instance.should_receive(:apply).and_return({:coupon_applied? => true})
154
+ api_put :update, :id => order.to_param, :order => { :coupon_code => "foobar" }
155
+ end
156
+ end
157
+
158
+ context "PUT 'next'" do
159
+ let!(:order) { create(:order) }
160
+ it "can transition an order to the next state" do
161
+ order.update_column(:email, "spree@example.com")
162
+
163
+ api_put :next, :id => order.to_param
164
+ response.status.should == 200
165
+ json_response['state'].should == 'address'
166
+ end
167
+
168
+ it "cannot transition if order email is blank" do
169
+ order.update_column(:email, nil)
170
+
171
+ api_put :next, :id => order.to_param
172
+ response.status.should == 422
173
+ json_response['error'].should =~ /could not be transitioned/
174
+ end
175
+
176
+ it "can apply a coupon code to an order" do
177
+ order.update_column(:state, "payment")
178
+ Spree::Promo::CouponApplicator.should_receive(:new).with(order).and_call_original
179
+ coupon_result = { :coupon_applied? => true }
180
+ Spree::Promo::CouponApplicator.any_instance.should_receive(:apply).and_return(coupon_result)
181
+ api_put :update, :id => order.to_param, :order => { :coupon_code => "foobar" }
151
182
  end
152
183
  end
153
184
  end
@@ -4,11 +4,7 @@ module Spree
4
4
  describe Api::LineItemsController do
5
5
  render_views
6
6
 
7
- let!(:order) do
8
- order = create(:order)
9
- order.line_items << create(:line_item)
10
- order
11
- end
7
+ let!(:order) { create(:order_with_line_items) }
12
8
 
13
9
  let(:product) { create(:product) }
14
10
  let(:attributes) { [:id, :quantity, :price, :variant] }
@@ -0,0 +1,116 @@
1
+ require 'spec_helper'
2
+
3
+ module Spree
4
+ describe Api::OptionTypesController do
5
+ render_views
6
+
7
+ let(:attributes) { [:id, :name, :position, :presentation] }
8
+ let!(:option_value) { create(:option_value) }
9
+ let!(:option_type) { option_value.option_type }
10
+
11
+ before do
12
+ stub_authentication!
13
+ end
14
+
15
+ def check_option_values(option_values)
16
+ option_values.count.should == 1
17
+ option_values.first.should have_attributes([:id, :name, :presentation,
18
+ :option_type_name, :option_type_id])
19
+ end
20
+
21
+ it "can list all option types" do
22
+ api_get :index
23
+ json_response.count.should == 1
24
+ json_response.first.should have_attributes(attributes)
25
+
26
+ check_option_values(json_response.first["option_values"])
27
+ end
28
+
29
+ it "can search for an option type" do
30
+ create(:option_type, :name => "buzz")
31
+ api_get :index, :q => { :name_cont => option_type.name }
32
+ json_response.count.should == 1
33
+ json_response.first.should have_attributes(attributes)
34
+ end
35
+
36
+ it "can retreive a list of specific option types" do
37
+ option_type_1 = create(:option_type)
38
+ option_type_2 = create(:option_type)
39
+ api_get :index, :ids => "#{option_type.id},#{option_type_1.id}"
40
+ json_response.count.should == 2
41
+
42
+ check_option_values(json_response.first["option_values"])
43
+ end
44
+
45
+ it "can list a single option type" do
46
+ api_get :show, :id => option_type.id
47
+ json_response.should have_attributes(attributes)
48
+ check_option_values(json_response["option_values"])
49
+ end
50
+
51
+ it "cannot create a new option type" do
52
+ api_post :create, :option_type => {
53
+ :name => "Option Type",
54
+ :presentation => "Option Type"
55
+ }
56
+ assert_unauthorized!
57
+ end
58
+
59
+ it "cannot alter an option type" do
60
+ original_name = option_type.name
61
+ api_put :update, :id => option_type.id,
62
+ :option_type => {
63
+ :name => "Option Type"
64
+ }
65
+ assert_unauthorized!
66
+ option_type.reload.name.should == original_name
67
+ end
68
+
69
+ it "cannot delete an option type" do
70
+ api_delete :destroy, :id => option_type.id
71
+ assert_unauthorized!
72
+ lambda { option_type.reload }.should_not raise_error(ActiveRecord::RecordNotFound)
73
+ end
74
+
75
+ context "as an admin" do
76
+ sign_in_as_admin!
77
+
78
+ it "can create an option type" do
79
+ api_post :create, :option_type => {
80
+ :name => "Option Type",
81
+ :presentation => "Option Type"
82
+ }
83
+ json_response.should have_attributes(attributes)
84
+ response.status.should == 201
85
+ end
86
+
87
+ it "cannot create an option type with invalid attributes" do
88
+ api_post :create, :option_type => {}
89
+ response.status.should == 422
90
+ end
91
+
92
+ it "can update an option type" do
93
+ original_name = option_type.name
94
+ api_put :update, :id => option_type.id, :option_type => {
95
+ :name => "Option Type",
96
+ }
97
+ response.status.should == 200
98
+
99
+ option_type.reload
100
+ option_type.name.should == "Option Type"
101
+ end
102
+
103
+ it "cannot update an option type with invalid attributes" do
104
+ api_put :update, :id => option_type.id, :option_type => {
105
+ :name => ""
106
+ }
107
+ response.status.should == 422
108
+ end
109
+
110
+ it "can delete an option type" do
111
+ api_delete :destroy, :id => option_type.id
112
+ response.status.should == 204
113
+ end
114
+ end
115
+ end
116
+ end
@@ -0,0 +1,128 @@
1
+ require 'spec_helper'
2
+
3
+ module Spree
4
+ describe Api::OptionValuesController do
5
+ render_views
6
+
7
+ let(:attributes) { [:id, :name, :presentation, :option_type_name, :option_type_name] }
8
+ let!(:option_value) { create(:option_value) }
9
+ let!(:option_type) { option_value.option_type }
10
+
11
+ before do
12
+ stub_authentication!
13
+ end
14
+
15
+ def check_option_values(option_values)
16
+ option_values.count.should == 1
17
+ option_values.first.should have_attributes([:id, :name, :presentation,
18
+ :option_type_name, :option_type_id])
19
+ end
20
+
21
+ context "without any option type scoping" do
22
+ before do
23
+ # Create another option value with a brand new option type
24
+ create(:option_value, :option_type => create(:option_type))
25
+ end
26
+
27
+ it "can retreive a list of all option values" do
28
+ api_get :index
29
+ json_response.count.should == 2
30
+ json_response.first.should have_attributes(attributes)
31
+ end
32
+ end
33
+
34
+ context "for a particular option type" do
35
+ let(:resource_scoping) { { :option_type_id => option_type.id } }
36
+
37
+ it "can list all option values" do
38
+ api_get :index
39
+ json_response.count.should == 1
40
+ json_response.first.should have_attributes(attributes)
41
+ end
42
+
43
+ it "can search for an option type" do
44
+ create(:option_value, :name => "buzz")
45
+ api_get :index, :q => { :name_cont => option_value.name }
46
+ json_response.count.should == 1
47
+ json_response.first.should have_attributes(attributes)
48
+ end
49
+
50
+ it "can retreive a list of option types" do
51
+ option_value_1 = create(:option_value, :option_type => option_type)
52
+ option_value_2 = create(:option_value, :option_type => option_type)
53
+ api_get :index, :ids => [option_value.id, option_value_1.id]
54
+ json_response.count.should == 2
55
+ end
56
+
57
+ it "can list a single option value" do
58
+ api_get :show, :id => option_value.id
59
+ json_response.should have_attributes(attributes)
60
+ end
61
+
62
+ it "cannot create a new option value" do
63
+ api_post :create, :option_value => {
64
+ :name => "Option Value",
65
+ :presentation => "Option Value"
66
+ }
67
+ assert_unauthorized!
68
+ end
69
+
70
+ it "cannot alter an option value" do
71
+ original_name = option_type.name
72
+ api_put :update, :id => option_type.id,
73
+ :option_value => {
74
+ :name => "Option Value"
75
+ }
76
+ assert_unauthorized!
77
+ option_type.reload.name.should == original_name
78
+ end
79
+
80
+ it "cannot delete an option value" do
81
+ api_delete :destroy, :id => option_type.id
82
+ assert_unauthorized!
83
+ lambda { option_type.reload }.should_not raise_error(ActiveRecord::RecordNotFound)
84
+ end
85
+
86
+ context "as an admin" do
87
+ sign_in_as_admin!
88
+
89
+ it "can create an option value" do
90
+ api_post :create, :option_value => {
91
+ :name => "Option Value",
92
+ :presentation => "Option Value"
93
+ }
94
+ json_response.should have_attributes(attributes)
95
+ response.status.should == 201
96
+ end
97
+
98
+ it "cannot create an option type with invalid attributes" do
99
+ api_post :create, :option_value => {}
100
+ response.status.should == 422
101
+ end
102
+
103
+ it "can update an option value" do
104
+ original_name = option_value.name
105
+ api_put :update, :id => option_value.id, :option_value => {
106
+ :name => "Option Value",
107
+ }
108
+ response.status.should == 200
109
+
110
+ option_value.reload
111
+ option_value.name.should == "Option Value"
112
+ end
113
+
114
+ it "cannot update an option value with invalid attributes" do
115
+ api_put :update, :id => option_value.id, :option_value => {
116
+ :name => ""
117
+ }
118
+ response.status.should == 422
119
+ end
120
+
121
+ it "can delete an option value" do
122
+ api_delete :destroy, :id => option_value.id
123
+ response.status.should == 204
124
+ end
125
+ end
126
+ end
127
+ end
128
+ end
@@ -11,9 +11,10 @@ module Spree
11
11
  :completed_at, :payment_total, :shipment_state,
12
12
  :payment_state, :email, :special_instructions] }
13
13
 
14
- let(:variant) { create(:variant) }
15
14
 
16
- before { stub_authentication! }
15
+ before do
16
+ stub_authentication!
17
+ end
17
18
 
18
19
  it "cannot view all orders" do
19
20
  api_get :index
@@ -25,6 +26,8 @@ module Spree
25
26
  api_get :show, :id => order.to_param
26
27
  response.status.should == 200
27
28
  json_response.should have_attributes(attributes)
29
+ json_response["adjustments"].should be_empty
30
+ json_response["credit_cards"].should be_empty
28
31
  end
29
32
 
30
33
  # Regression test for #1992
@@ -63,50 +66,6 @@ module Spree
63
66
  json_response["state"].should == "cart"
64
67
  end
65
68
 
66
- context "import" do
67
- let(:tax_rate) { create(:tax_rate, amount: 0.05, calculator: Calculator::DefaultTax.create) }
68
- let(:other_variant) { create(:variant) }
69
-
70
- # line items come in as an array when importing orders or when
71
- # creating both an order an a line item at once
72
- let(:order_params) do
73
- {
74
- :line_items => [
75
- { :variant_id => variant.to_param, :quantity => 5 },
76
- { :variant_id => other_variant.to_param, :quantity => 5 }
77
- ]
78
- }
79
- end
80
-
81
- before do
82
- Zone.stub default_tax: tax_rate.zone
83
- current_api_user.stub has_spree_role?: true
84
- end
85
-
86
- it "sets channel" do
87
- api_post :create, :order => { channel: "amazon" }
88
- expect(json_response['channel']).to eq "amazon"
89
- end
90
-
91
- it "doesnt persist any automatic tax adjustment" do
92
- expect {
93
- api_post :create, :order => order_params.merge(:import => true)
94
- }.not_to change { Adjustment.count }
95
- expect(response.status).to eq 201
96
- end
97
-
98
- context "provides sku rather than variant id" do
99
- let(:order_params) do
100
- { :line_items => [{ :sku => variant.sku, :quantity => 1 }] }
101
- end
102
-
103
- it "still finds the variant by sku and persist order" do
104
- api_post :create, :order => order_params
105
- expect(json_response['line_items'].count).to eq 1
106
- end
107
- end
108
- end
109
-
110
69
  it "can create an order without any parameters" do
111
70
  lambda { api_post :create }.should_not raise_error(NoMethodError)
112
71
  response.status.should == 201
@@ -114,25 +73,6 @@ module Spree
114
73
  json_response["state"].should == "cart"
115
74
  end
116
75
 
117
- it "cannot create an order with an abitrary price for the line item" do
118
- variant = create(:variant)
119
- api_post :create, :order => {
120
- :line_items => {
121
- "0" => {
122
- :variant_id => variant.to_param,
123
- :quantity => 5,
124
- :price => 0.44
125
- }
126
- }
127
- }
128
- response.status.should == 201
129
- order = Order.last
130
- order.line_items.count.should == 1
131
- order.line_items.first.variant.should == variant
132
- order.line_items.first.quantity.should == 5
133
- order.line_items.first.price.should == order.line_items.first.variant.price
134
- end
135
-
136
76
  context "working with an order" do
137
77
  before do
138
78
  Order.any_instance.stub :user => current_api_user
@@ -155,23 +95,10 @@ module Spree
155
95
  let(:shipping_address) { { :firstname => "Tiago", :lastname => "Motta", :address1 => "Av Paulista",
156
96
  :city => "Sao Paulo", :zipcode => "1234567", :phone => "12345678",
157
97
  :country_id => Country.first.id, :state_id => State.first.id} }
158
- let!(:shipping_method) { create(:shipping_method) }
159
98
  let!(:payment_method) { create(:payment_method) }
160
99
 
161
- it "can not update line item prices" do
162
- order.line_items << create(:line_item)
163
- api_put :update,
164
- :id => order.to_param,
165
- :order => {
166
- :line_items => {
167
- order.line_items.first.id =>
168
- {
169
- :variant_id => create(:variant).id,
170
- :quantity => 2,
171
- :price => 0.44
172
- }
173
- }
174
- }
100
+ it "can add line items" do
101
+ api_put :update, :id => order.to_param, :order => { :line_items => [{:variant_id => create(:variant).id, :quantity => 2}] }
175
102
 
176
103
  response.status.should == 200
177
104
  json_response['item_total'].to_f.should_not == order.item_total.to_f
@@ -197,6 +124,7 @@ module Spree
197
124
  end
198
125
 
199
126
  it "can add shipping address" do
127
+ pending "need to figure out how to get shipping methods for an order"
200
128
  order.ship_address.should be_nil
201
129
 
202
130
  api_put :update, :id => order.to_param, :order => { :ship_address_attributes => shipping_address }
@@ -217,7 +145,8 @@ module Spree
217
145
 
218
146
  context "with a line item" do
219
147
  before do
220
- order.line_items << create(:line_item)
148
+ create(:line_item, :order => order)
149
+ order.reload
221
150
  end
222
151
 
223
152
  it "can empty an order" do
@@ -253,14 +182,6 @@ module Spree
253
182
  end
254
183
  end
255
184
 
256
- it "responds with orders updated_at with miliseconds precision" do
257
- api_get :index
258
- milisecond = order.updated_at.strftime("%L")
259
- updated_at = json_response["orders"].first["updated_at"]
260
-
261
- expect(updated_at.split("T").last).to have_content(milisecond)
262
- end
263
-
264
185
  context "with two orders" do
265
186
  before { create(:order) }
266
187
 
@@ -304,10 +225,7 @@ module Spree
304
225
 
305
226
  context "can cancel an order" do
306
227
  before do
307
- Spree::MailMethod.create!(
308
- :environment => Rails.env,
309
- :preferred_mails_from => "spree@example.com"
310
- )
228
+ Spree::Config[:mails_from] = "spree@example.com"
311
229
 
312
230
  order.completed_at = Time.now
313
231
  order.state = 'complete'