solidus_api 1.2.3 → 1.3.0.beta1

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.
Files changed (87) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +2 -2
  3. data/Rakefile +1 -1
  4. data/app/controllers/spree/api/addresses_controller.rb +3 -2
  5. data/app/controllers/spree/api/base_controller.rb +10 -15
  6. data/app/controllers/spree/api/checkouts_controller.rb +56 -55
  7. data/app/controllers/spree/api/classifications_controller.rb +4 -4
  8. data/app/controllers/spree/api/config_controller.rb +6 -1
  9. data/app/controllers/spree/api/credit_cards_controller.rb +11 -11
  10. data/app/controllers/spree/api/images_controller.rb +13 -13
  11. data/app/controllers/spree/api/inventory_units_controller.rb +4 -4
  12. data/app/controllers/spree/api/line_items_controller.rb +27 -23
  13. data/app/controllers/spree/api/option_types_controller.rb +6 -5
  14. data/app/controllers/spree/api/option_values_controller.rb +12 -12
  15. data/app/controllers/spree/api/orders_controller.rb +6 -17
  16. data/app/controllers/spree/api/payments_controller.rb +15 -17
  17. data/app/controllers/spree/api/product_properties_controller.rb +13 -14
  18. data/app/controllers/spree/api/products_controller.rb +31 -28
  19. data/app/controllers/spree/api/promotions_controller.rb +9 -8
  20. data/app/controllers/spree/api/properties_controller.rb +9 -10
  21. data/app/controllers/spree/api/resource_controller.rb +9 -1
  22. data/app/controllers/spree/api/shipments_controller.rb +18 -18
  23. data/app/controllers/spree/api/states_controller.rb +8 -7
  24. data/app/controllers/spree/api/stock_items_controller.rb +2 -1
  25. data/app/controllers/spree/api/stock_locations_controller.rb +1 -1
  26. data/app/controllers/spree/api/stores_controller.rb +0 -1
  27. data/app/controllers/spree/api/taxonomies_controller.rb +7 -5
  28. data/app/controllers/spree/api/taxons_controller.rb +20 -19
  29. data/app/controllers/spree/api/users_controller.rb +1 -4
  30. data/app/controllers/spree/api/variants_controller.rb +19 -18
  31. data/app/controllers/spree/api/zones_controller.rb +3 -4
  32. data/app/helpers/spree/api/api_helpers.rb +7 -6
  33. data/app/models/spree/api_configuration.rb +1 -1
  34. data/app/views/spree/api/config/show.v1.rabl +2 -1
  35. data/app/views/spree/api/products/show.v1.rabl +1 -1
  36. data/db/migrate/20100107141738_add_api_key_to_spree_users.rb +1 -1
  37. data/db/migrate/20120411123334_resize_api_key_field.rb +1 -1
  38. data/lib/spree/api/engine.rb +8 -8
  39. data/lib/spree/api/responders/rabl_template.rb +1 -1
  40. data/lib/spree/api/testing_support/caching.rb +4 -4
  41. data/script/rails +0 -1
  42. data/solidus_api.gemspec +3 -3
  43. data/spec/controllers/spree/api/addresses_controller_spec.rb +12 -13
  44. data/spec/controllers/spree/api/base_controller_spec.rb +10 -11
  45. data/spec/controllers/spree/api/checkouts_controller_spec.rb +38 -59
  46. data/spec/controllers/spree/api/config_controller_spec.rb +4 -2
  47. data/spec/controllers/spree/api/countries_controller_spec.rb +5 -5
  48. data/spec/controllers/spree/api/credit_cards_controller_spec.rb +5 -5
  49. data/spec/controllers/spree/api/images_controller_spec.rb +20 -18
  50. data/spec/controllers/spree/api/inventory_units_controller_spec.rb +11 -11
  51. data/spec/controllers/spree/api/line_items_controller_spec.rb +20 -19
  52. data/spec/controllers/spree/api/option_types_controller_spec.rb +23 -24
  53. data/spec/controllers/spree/api/option_values_controller_spec.rb +28 -29
  54. data/spec/controllers/spree/api/orders_controller_spec.rb +157 -179
  55. data/spec/controllers/spree/api/payments_controller_spec.rb +35 -45
  56. data/spec/controllers/spree/api/product_properties_controller_spec.rb +14 -15
  57. data/spec/controllers/spree/api/products_controller_spec.rb +64 -70
  58. data/spec/controllers/spree/api/promotion_application_spec.rb +4 -4
  59. data/spec/controllers/spree/api/promotions_controller_spec.rb +1 -1
  60. data/spec/controllers/spree/api/properties_controller_spec.rb +15 -15
  61. data/spec/controllers/spree/api/resource_controller_spec.rb +31 -2
  62. data/spec/controllers/spree/api/return_authorizations_controller_spec.rb +31 -31
  63. data/spec/controllers/spree/api/shipments_controller_spec.rb +6 -8
  64. data/spec/controllers/spree/api/states_controller_spec.rb +11 -12
  65. data/spec/controllers/spree/api/stock_items_controller_spec.rb +10 -7
  66. data/spec/controllers/spree/api/stock_locations_controller_spec.rb +3 -4
  67. data/spec/controllers/spree/api/stock_movements_controller_spec.rb +2 -3
  68. data/spec/controllers/spree/api/store_credit_events_controller_spec.rb +0 -2
  69. data/spec/controllers/spree/api/stores_controller_spec.rb +1 -2
  70. data/spec/controllers/spree/api/taxonomies_controller_spec.rb +17 -18
  71. data/spec/controllers/spree/api/taxons_controller_spec.rb +22 -24
  72. data/spec/controllers/spree/api/unauthenticated_products_controller_spec.rb +1 -2
  73. data/spec/controllers/spree/api/users_controller_spec.rb +13 -15
  74. data/spec/controllers/spree/api/variants_controller_spec.rb +42 -37
  75. data/spec/controllers/spree/api/zones_controller_spec.rb +18 -18
  76. data/spec/features/checkout_spec.rb +2 -2
  77. data/spec/models/spree/legacy_user_spec.rb +5 -5
  78. data/spec/requests/api/address_books_spec.rb +10 -11
  79. data/spec/requests/rabl_cache_spec.rb +7 -7
  80. data/spec/requests/ransackable_attributes_spec.rb +5 -7
  81. data/spec/shared_examples/protect_product_actions.rb +3 -4
  82. data/spec/spec_helper.rb +8 -4
  83. data/spec/support/controller_hacks.rb +5 -5
  84. data/spec/support/have_attributes_matcher.rb +0 -4
  85. data/spec/test_views/spree/api/widgets/show.v1.rabl +1 -1
  86. metadata +9 -10
  87. data/app/models/spree/option_value_decorator.rb +0 -9
@@ -1,15 +1,17 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  module Spree
4
- describe Spree::Api::PaymentsController, :type => :controller do
4
+ describe Spree::Api::PaymentsController, type: :controller do
5
5
  render_views
6
6
  let!(:order) { create(:order) }
7
- let!(:payment) { create(:payment, :order => order) }
8
- let!(:attributes) { [:id, :source_type, :source_id, :amount, :display_amount,
9
- :payment_method_id, :state, :avs_response,
10
- :created_at, :updated_at] }
7
+ let!(:payment) { create(:payment, order: order) }
8
+ let!(:attributes) {
9
+ [:id, :source_type, :source_id, :amount, :display_amount,
10
+ :payment_method_id, :state, :avs_response,
11
+ :created_at, :updated_at]
12
+ }
11
13
 
12
- let(:resource_scoping) { { :order_id => order.to_param } }
14
+ let(:resource_scoping) { { order_id: order.to_param } }
13
15
 
14
16
  before do
15
17
  stub_authentication!
@@ -18,7 +20,7 @@ module Spree
18
20
  context "as a user" do
19
21
  context "when the order belongs to the user" do
20
22
  before do
21
- allow_any_instance_of(Order).to receive_messages :user => current_api_user
23
+ allow_any_instance_of(Order).to receive_messages user: current_api_user
22
24
  end
23
25
 
24
26
  it "can view the payments for their order" do
@@ -39,27 +41,16 @@ module Spree
39
41
  end
40
42
 
41
43
  it "can create a new payment" do
42
- api_post :create, :payment => { :payment_method_id => PaymentMethod.first.id, :amount => 50 }
44
+ api_post :create, payment: { payment_method_id: PaymentMethod.first.id, amount: 50 }
43
45
  expect(response.status).to eq(201)
44
46
  expect(json_response).to have_attributes(attributes)
45
47
  end
46
-
47
- context "disallowed payment method" do
48
- it "does not create a new payment" do
49
- PaymentMethod.first.update!(display_on: "back_end")
50
-
51
- expect {
52
- api_post :create, payment: { payment_method_id: PaymentMethod.first.id, amount: 50 }
53
- }.not_to change { Spree::Payment.count }
54
- expect(response.status).to eq(404)
55
- end
56
- end
57
48
  end
58
49
 
59
50
  context "payment source is required" do
60
51
  context "no source is provided" do
61
52
  it "returns errors" do
62
- api_post :create, :payment => { :payment_method_id => PaymentMethod.first.id, :amount => 50 }
53
+ api_post :create, payment: { payment_method_id: PaymentMethod.first.id, amount: 50 }
63
54
  expect(response.status).to eq(422)
64
55
  expect(json_response['error']).to eq("Invalid resource. Please fix errors and try again.")
65
56
  expect(json_response['errors']['source']).to eq(["can't be blank"])
@@ -68,7 +59,7 @@ module Spree
68
59
 
69
60
  context "source is provided" do
70
61
  it "can create a new payment" do
71
- api_post :create, :payment => { :payment_method_id => PaymentMethod.first.id, :amount => 50, source_attributes: {gateway_payment_profile_id: 1} }
62
+ api_post :create, payment: { payment_method_id: PaymentMethod.first.id, amount: 50, source_attributes: { gateway_payment_profile_id: 1 } }
72
63
  expect(response.status).to eq(201)
73
64
  expect(json_response).to have_attributes(attributes)
74
65
  end
@@ -76,33 +67,33 @@ module Spree
76
67
  end
77
68
 
78
69
  it "can view a pre-existing payment's details" do
79
- api_get :show, :id => payment.to_param
70
+ api_get :show, id: payment.to_param
80
71
  expect(json_response).to have_attributes(attributes)
81
72
  end
82
73
 
83
74
  it "cannot update a payment" do
84
- api_put :update, :id => payment.to_param, :payment => { :amount => 2.01 }
75
+ api_put :update, id: payment.to_param, payment: { amount: 2.01 }
85
76
  assert_unauthorized!
86
77
  end
87
78
 
88
79
  it "cannot authorize a payment" do
89
- api_put :authorize, :id => payment.to_param
80
+ api_put :authorize, id: payment.to_param
90
81
  assert_unauthorized!
91
82
  end
92
83
  end
93
84
 
94
85
  context "when the order does not belong to the user" do
95
86
  before do
96
- allow_any_instance_of(Order).to receive_messages :user => stub_model(LegacyUser)
87
+ allow_any_instance_of(Order).to receive_messages user: stub_model(LegacyUser)
97
88
  end
98
89
 
99
90
  it "cannot view payments for somebody else's order" do
100
- api_get :index, :order_id => order.to_param
91
+ api_get :index, order_id: order.to_param
101
92
  assert_unauthorized!
102
93
  end
103
94
 
104
95
  it "can view the payments for an order given the order token" do
105
- api_get :index, :order_id => order.to_param, :order_token => order.guest_token
96
+ api_get :index, order_id: order.to_param, order_token: order.guest_token
106
97
  expect(json_response["payments"].first).to have_attributes(attributes)
107
98
  end
108
99
  end
@@ -118,7 +109,7 @@ module Spree
118
109
  end
119
110
 
120
111
  context "multiple payments" do
121
- before { @payment = create(:payment, :order => order) }
112
+ before { @payment = create(:payment, order: order) }
122
113
 
123
114
  it "can view all payments on an order" do
124
115
  api_get :index
@@ -126,7 +117,7 @@ module Spree
126
117
  end
127
118
 
128
119
  it 'can control the page size through a parameter' do
129
- api_get :index, :per_page => 1
120
+ api_get :index, per_page: 1
130
121
  expect(json_response['count']).to eq(1)
131
122
  expect(json_response['current_page']).to eq(1)
132
123
  expect(json_response['pages']).to eq(2)
@@ -136,23 +127,23 @@ module Spree
136
127
  context "for a given payment" do
137
128
  context "updating" do
138
129
  it "can update" do
139
- payment.update_attributes(:state => 'pending')
140
- api_put :update, :id => payment.to_param, :payment => { :amount => 2.01 }
130
+ payment.update_attributes(state: 'pending')
131
+ api_put :update, id: payment.to_param, payment: { amount: 2.01 }
141
132
  expect(response.status).to eq(200)
142
133
  expect(payment.reload.amount).to eq(2.01)
143
134
  end
144
135
 
145
136
  context "update fails" do
146
137
  it "returns a 422 status when the amount is invalid" do
147
- payment.update_attributes(:state => 'pending')
148
- api_put :update, :id => payment.to_param, :payment => { :amount => 'invalid' }
138
+ payment.update_attributes(state: 'pending')
139
+ api_put :update, id: payment.to_param, payment: { amount: 'invalid' }
149
140
  expect(response.status).to eq(422)
150
141
  expect(json_response["error"]).to eq("Invalid resource. Please fix errors and try again.")
151
142
  end
152
143
 
153
144
  it "returns a 403 status when the payment is not pending" do
154
- payment.update_attributes(:state => 'completed')
155
- api_put :update, :id => payment.to_param, :payment => { :amount => 2.01 }
145
+ payment.update_attributes(state: 'completed')
146
+ api_put :update, id: payment.to_param, payment: { amount: 2.01 }
156
147
  expect(response.status).to eq(403)
157
148
  expect(json_response["error"]).to eq("This payment cannot be updated because it is completed.")
158
149
  end
@@ -161,16 +152,16 @@ module Spree
161
152
 
162
153
  context "authorizing" do
163
154
  it "can authorize" do
164
- api_put :authorize, :id => payment.to_param
155
+ api_put :authorize, id: payment.to_param
165
156
  expect(response.status).to eq(200)
166
157
  expect(payment.reload.state).to eq("pending")
167
158
  end
168
159
 
169
160
  context "authorization fails" do
170
161
  before do
171
- fake_response = double(:success? => false, :to_s => "Could not authorize card")
162
+ fake_response = double(success?: false, to_s: "Could not authorize card")
172
163
  expect_any_instance_of(Spree::Gateway::Bogus).to receive(:authorize).and_return(fake_response)
173
- api_put :authorize, :id => payment.to_param
164
+ api_put :authorize, id: payment.to_param
174
165
  end
175
166
 
176
167
  it "returns a 422 status" do
@@ -188,19 +179,19 @@ module Spree
188
179
 
189
180
  context "capturing" do
190
181
  it "can capture" do
191
- api_put :capture, :id => payment.to_param
182
+ api_put :capture, id: payment.to_param
192
183
  expect(response.status).to eq(200)
193
184
  expect(payment.reload.state).to eq("completed")
194
185
  end
195
186
 
196
187
  context "capturing fails" do
197
188
  before do
198
- fake_response = double(:success? => false, :to_s => "Insufficient funds")
189
+ fake_response = double(success?: false, to_s: "Insufficient funds")
199
190
  expect_any_instance_of(Spree::Gateway::Bogus).to receive(:capture).and_return(fake_response)
200
191
  end
201
192
 
202
193
  it "returns a 422 status" do
203
- api_put :capture, :id => payment.to_param
194
+ api_put :capture, id: payment.to_param
204
195
  expect(response.status).to eq(422)
205
196
  expect(json_response["error"]).to eq "Invalid resource. Please fix errors and try again."
206
197
  expect(json_response["errors"]["base"][0]).to eq "Insufficient funds"
@@ -210,19 +201,19 @@ module Spree
210
201
 
211
202
  context "purchasing" do
212
203
  it "can purchase" do
213
- api_put :purchase, :id => payment.to_param
204
+ api_put :purchase, id: payment.to_param
214
205
  expect(response.status).to eq(200)
215
206
  expect(payment.reload.state).to eq("completed")
216
207
  end
217
208
 
218
209
  context "purchasing fails" do
219
210
  before do
220
- fake_response = double(:success? => false, :to_s => "Insufficient funds")
211
+ fake_response = double(success?: false, to_s: "Insufficient funds")
221
212
  expect_any_instance_of(Spree::Gateway::Bogus).to receive(:purchase).and_return(fake_response)
222
213
  end
223
214
 
224
215
  it "returns a 422 status" do
225
- api_put :purchase, :id => payment.to_param
216
+ api_put :purchase, id: payment.to_param
226
217
  expect(response.status).to eq(422)
227
218
  expect(json_response["error"]).to eq "Invalid resource. Please fix errors and try again."
228
219
  expect(json_response["errors"]["base"][0]).to eq "Insufficient funds"
@@ -252,7 +243,6 @@ module Spree
252
243
  end
253
244
  end
254
245
  end
255
-
256
246
  end
257
247
  end
258
248
  end
@@ -2,15 +2,15 @@ require 'spec_helper'
2
2
  require 'shared_examples/protect_product_actions'
3
3
 
4
4
  module Spree
5
- describe Spree::Api::ProductPropertiesController, :type => :controller do
5
+ describe Spree::Api::ProductPropertiesController, type: :controller do
6
6
  render_views
7
7
 
8
8
  let!(:product) { create(:product) }
9
- let!(:property_1) {product.product_properties.create(:property_name => "My Property 1", :value => "my value 1", :position => 0)}
10
- let!(:property_2) {product.product_properties.create(:property_name => "My Property 2", :value => "my value 2", :position => 1)}
9
+ let!(:property_1) { product.product_properties.create(property_name: "My Property 1", value: "my value 1", position: 0) }
10
+ let!(:property_2) { product.product_properties.create(property_name: "My Property 2", value: "my value 2", position: 1) }
11
11
 
12
12
  let(:attributes) { [:id, :product_id, :property_id, :value, :property_name] }
13
- let(:resource_scoping) { { :product_id => product.to_param } }
13
+ let(:resource_scoping) { { product_id: product.to_param } }
14
14
 
15
15
  before do
16
16
  stub_authentication!
@@ -34,7 +34,7 @@ module Spree
34
34
  end
35
35
 
36
36
  it "can control the page size through a parameter" do
37
- api_get :index, :per_page => 1
37
+ api_get :index, per_page: 1
38
38
  expect(json_response['product_properties'].count).to eq(1)
39
39
  expect(json_response['current_page']).to eq(1)
40
40
  expect(json_response['pages']).to eq(2)
@@ -43,13 +43,13 @@ module Spree
43
43
  it 'can query the results through a parameter' do
44
44
  Spree::ProductProperty.last.update_attribute(:value, 'loose')
45
45
  property = Spree::ProductProperty.last
46
- api_get :index, :q => { :value_cont => 'loose' }
46
+ api_get :index, q: { value_cont: 'loose' }
47
47
  expect(json_response['count']).to eq(1)
48
48
  expect(json_response['product_properties'].first['value']).to eq property.value
49
49
  end
50
50
 
51
51
  it "can see a single product_property" do
52
- api_get :show, :id => property_1.property_name
52
+ api_get :show, id: property_1.property_name
53
53
  expect(json_response).to have_attributes(attributes)
54
54
  end
55
55
 
@@ -60,12 +60,12 @@ module Spree
60
60
  end
61
61
 
62
62
  it "cannot create a new product property if not an admin" do
63
- api_post :create, :product_property => { :property_name => "My Property 3" }
63
+ api_post :create, product_property: { property_name: "My Property 3" }
64
64
  assert_unauthorized!
65
65
  end
66
66
 
67
67
  it "cannot update a product property" do
68
- api_put :update, :id => property_1.property_name, :product_property => { :value => "my value 456" }
68
+ api_put :update, id: property_1.property_name, product_property: { value: "my value 456" }
69
69
  assert_unauthorized!
70
70
  end
71
71
 
@@ -80,26 +80,26 @@ module Spree
80
80
 
81
81
  it "can create a new product property" do
82
82
  expect do
83
- api_post :create, :product_property => { :property_name => "My Property 3", :value => "my value 3" }
83
+ api_post :create, product_property: { property_name: "My Property 3", value: "my value 3" }
84
84
  end.to change(product.product_properties, :count).by(1)
85
85
  expect(json_response).to have_attributes(attributes)
86
86
  expect(response.status).to eq(201)
87
87
  end
88
88
 
89
89
  it "can update a product property" do
90
- api_put :update, :id => property_1.property_name, :product_property => { :value => "my value 456" }
90
+ api_put :update, id: property_1.property_name, product_property: { value: "my value 456" }
91
91
  expect(response.status).to eq(200)
92
92
  end
93
93
 
94
94
  it "can delete a product property" do
95
- api_delete :destroy, :id => property_1.property_name
95
+ api_delete :destroy, id: property_1.property_name
96
96
  expect(response.status).to eq(204)
97
97
  expect { property_1.reload }.to raise_error(ActiveRecord::RecordNotFound)
98
98
  end
99
99
  end
100
100
 
101
101
  context "with product identified by id" do
102
- let(:resource_scoping) { { :product_id => product.id } }
102
+ let(:resource_scoping) { { product_id: product.id } }
103
103
  it "can see a list of all product properties" do
104
104
  api_get :index
105
105
  expect(json_response["product_properties"].count).to eq 2
@@ -107,10 +107,9 @@ module Spree
107
107
  end
108
108
 
109
109
  it "can see a single product_property by id" do
110
- api_get :show, :id => property_1.id
110
+ api_get :show, id: property_1.id
111
111
  expect(json_response).to have_attributes(attributes)
112
112
  end
113
113
  end
114
-
115
114
  end
116
115
  end