spree_api 3.0.1 → 3.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ef00fcd9a6f5ff3573c20c99509035edf9b49e66
4
- data.tar.gz: 8b036132ce0f23d36d5cb58e283187ee17519066
3
+ metadata.gz: 4dd12818d3a505303fcaeea073d198b09e8a21b5
4
+ data.tar.gz: d0dcafde824a488a304aae6e1b3c2401b09c98e9
5
5
  SHA512:
6
- metadata.gz: 70a31fa7caf0a0107ad2141582fa3ee166666789ff1202bf6082d72e7b8509af7a4f014cc1c7efc4985cf9e8bda1dbacaf93df443746b59b1ffca76d78865d5b
7
- data.tar.gz: ce8f5e35409bb3593a2db354456761ab3dfdea846a454c94e1590039d8ef1a249f183f6ff48e0773112a2fd6cea7e5f8122f13285c7aa82690ee89e10f0e0514
6
+ metadata.gz: f9bb3abab9f4bb837f665ff4f73f889e3b18f692eea3573c1f9a95fe887c10f7863b40a38fbbdb86238a35ed575e2e0667e45897a6e03e199d712fade6ce468e
7
+ data.tar.gz: 22801dae757bcfc7bdce03f9fc77b6cefb3d1ef20bc8dbb19cde12527e731399ad9a0351a8d5a3d2030c17c3e714c41188389ca83079d3a8da465af486e8b8c2
@@ -26,7 +26,7 @@ module Spree
26
26
 
27
27
  def update
28
28
  authorize! params[:action], @payment
29
- if ! @payment.pending?
29
+ if !@payment.editable?
30
30
  render 'update_forbidden', status: 403
31
31
  elsif @payment.update_attributes(payment_params)
32
32
  respond_with(@payment, default_template: :show)
@@ -94,11 +94,7 @@ module Spree
94
94
 
95
95
  private
96
96
  def product_params
97
- product_params = params.require(:product).permit(permitted_product_attributes)
98
- if product_params[:taxon_ids].present?
99
- product_params[:taxon_ids] = product_params[:taxon_ids].split(',')
100
- end
101
- product_params
97
+ params.require(:product).permit(permitted_product_attributes)
102
98
  end
103
99
 
104
100
  def variants_params
@@ -25,9 +25,8 @@ child :payments => :payments do
25
25
  end
26
26
 
27
27
  child :source => :source do
28
- attributes *payment_source_attributes
29
28
  if @current_user_roles.include?('admin')
30
- attributes *payment_source_attributes.concat([:gateway_customer_profile_id, :gateway_payment_profile_id])
29
+ attributes *payment_source_attributes + [:gateway_customer_profile_id, :gateway_payment_profile_id]
31
30
  else
32
31
  attributes *payment_source_attributes
33
32
  end
@@ -1,4 +1,5 @@
1
1
  require 'rails/engine'
2
+ require 'versioncake'
2
3
 
3
4
  module Spree
4
5
  module Api
@@ -16,8 +17,8 @@ module Spree
16
17
  config.json_engine = ActiveSupport::JSON
17
18
  end
18
19
 
19
- config.view_versions = [1]
20
- config.view_version_extraction_strategy = :http_header
20
+ config.versioncake.supported_version_numbers = [1]
21
+ config.versioncake.extraction_strategy = :http_header
21
22
 
22
23
  initializer "spree.api.environment", :before => :load_config_initializers do |app|
23
24
  Spree::Api::Config = Spree::ApiConfiguration.new
@@ -13,7 +13,7 @@ module Spree
13
13
  end
14
14
 
15
15
  def template
16
- request.headers['X-Spree-Template'] || controller.params[:template] || options[:default_template]
16
+ options[:default_template]
17
17
  end
18
18
 
19
19
  def api_behavior
@@ -105,26 +105,37 @@ module Spree
105
105
 
106
106
  context "for a given payment" do
107
107
  context "updating" do
108
- it "can update" do
109
- payment.update_attributes(:state => 'pending')
110
- api_put :update, :id => payment.to_param, :payment => { :amount => 2.01 }
111
- expect(response.status).to eq(200)
112
- expect(payment.reload.amount).to eq(2.01)
108
+ context "when the state is checkout" do
109
+ it "can update" do
110
+ payment.update_attributes(state: 'checkout')
111
+ api_put(:update, id: payment.to_param, payment: { amount: 2.01 })
112
+ expect(response.status).to be(200)
113
+ expect(payment.reload.amount).to eq(2.01)
114
+ end
115
+ end
116
+
117
+ context "when the state is pending" do
118
+ it "can update" do
119
+ payment.update_attributes(state: 'pending')
120
+ api_put(:update, id: payment.to_param, payment: { amount: 2.01 })
121
+ expect(response.status).to be(200)
122
+ expect(payment.reload.amount).to eq(2.01)
123
+ end
113
124
  end
114
125
 
115
126
  context "update fails" do
116
127
  it "returns a 422 status when the amount is invalid" do
117
- payment.update_attributes(:state => 'pending')
118
- api_put :update, :id => payment.to_param, :payment => { :amount => 'invalid' }
119
- expect(response.status).to eq(422)
120
- expect(json_response["error"]).to eq("Invalid resource. Please fix errors and try again.")
128
+ payment.update_attributes(state: 'pending')
129
+ api_put(:update, id: payment.to_param, payment: { amount: 'invalid' })
130
+ expect(response.status).to be(422)
131
+ expect(json_response['error']).to eql('Invalid resource. Please fix errors and try again.')
121
132
  end
122
133
 
123
134
  it "returns a 403 status when the payment is not pending" do
124
- payment.update_attributes(:state => 'completed')
125
- api_put :update, :id => payment.to_param, :payment => { :amount => 2.01 }
126
- expect(response.status).to eq(403)
127
- expect(json_response["error"]).to eq("This payment cannot be updated because it is completed.")
135
+ payment.update_attributes(state: 'completed')
136
+ api_put(:update, id: payment.to_param, payment: { amount: 2.01 })
137
+ expect(response.status).to be(403)
138
+ expect(json_response['error']).to eql('This payment cannot be updated because it is completed.')
128
139
  end
129
140
  end
130
141
  end
@@ -67,45 +67,6 @@ module Spree
67
67
  expect(json_response["per_page"]).to eq(Kaminari.config.default_per_page)
68
68
  end
69
69
 
70
- context "specifying a rabl template for a custom action" do
71
- before do
72
- Spree::Api::ProductsController.class_eval do
73
- def custom_show
74
- @product = find_product(params[:id])
75
- respond_with(@product)
76
- end
77
- end
78
- end
79
-
80
- def set_custom_route
81
- @routes = ActionDispatch::Routing::RouteSet.new.tap do |r|
82
- r.draw { get 'custom_show' => 'spree/api/products#custom_show' }
83
- end
84
- end
85
-
86
- it "uses the specified custom template through the request header" do
87
- set_custom_route
88
-
89
- request.headers['X-Spree-Template'] = 'show'
90
- api_get :custom_show, :id => product.id
91
- expect(response).to render_template('spree/api/products/show')
92
- end
93
-
94
- it "uses the specified custom template through the template URL parameter" do
95
- set_custom_route
96
-
97
- api_get :custom_show, :id => product.id, :template => 'show'
98
- expect(response).to render_template('spree/api/products/show')
99
- end
100
-
101
- it "falls back to the default template if the specified template does not exist" do
102
- request.headers['X-Spree-Template'] = 'invoice'
103
-
104
- api_get :show, :id => product.id
105
- expect(response).to render_template('spree/api/products/show')
106
- end
107
- end
108
-
109
70
  context "product has more than one price" do
110
71
  before { product.master.prices.create currency: "EUR", amount: 22 }
111
72
 
@@ -345,16 +306,9 @@ module Spree
345
306
  expect(json_response['shipping_category_id']).to eq shipping_id
346
307
  end
347
308
 
348
- it "puts the created product in the given taxon" do
349
- product_data[:taxon_ids] = taxon_1.id.to_s
350
- api_post :create, :product => product_data
351
- expect(json_response["taxon_ids"]).to eq([taxon_1.id,])
352
- end
353
-
354
- # Regression test for #4123
355
309
  it "puts the created product in the given taxons" do
356
- product_data[:taxon_ids] = [taxon_1.id, taxon_2.id].join(',')
357
- api_post :create, :product => product_data
310
+ product_data[:taxon_ids] = [taxon_1.id, taxon_2.id]
311
+ api_post :create, product: product_data
358
312
  expect(json_response["taxon_ids"]).to eq([taxon_1.id, taxon_2.id])
359
313
  end
360
314
 
@@ -438,16 +392,9 @@ module Spree
438
392
  expect(json_response["errors"]["name"]).to eq(["can't be blank"])
439
393
  end
440
394
 
441
- # Regression test for #4123
442
- it "puts the created product in the given taxon" do
443
- api_put :update, :id => product.to_param, :product => {:taxon_ids => taxon_1.id.to_s}
444
- expect(json_response["taxon_ids"]).to eq([taxon_1.id,])
445
- end
446
-
447
- # Regression test for #4123
448
- it "puts the created product in the given taxons" do
449
- api_put :update, :id => product.to_param, :product => {:taxon_ids => [taxon_1.id, taxon_2.id].join(',')}
450
- expect(json_response["taxon_ids"]).to eq([taxon_1.id, taxon_2.id])
395
+ it "puts the updated product in the given taxons" do
396
+ api_put :update, id: product.to_param, product: { taxon_ids: [taxon_1.id, taxon_2.id] }
397
+ expect(json_response["taxon_ids"].to_set).to eql([taxon_1.id, taxon_2.id].to_set)
451
398
  end
452
399
  end
453
400
 
@@ -38,32 +38,6 @@ module Spree
38
38
  expect(json_response['zone_members'].size).to eq @zone.zone_members.count
39
39
  end
40
40
 
41
- context "specifying a rabl template to use" do
42
- before do
43
- Spree::Api::ZonesController.class_eval do
44
- def custom_show
45
- respond_with(zone)
46
- end
47
- end
48
- end
49
-
50
- it "uses the specified template" do
51
- @routes = ActionDispatch::Routing::RouteSet.new.tap do |r|
52
- r.draw { get 'custom_show' => 'spree/api/zones#custom_show' }
53
- end
54
-
55
- request.headers['X-Spree-Template'] = 'show'
56
- api_get :custom_show, :id => @zone.id
57
- expect(response).to render_template('spree/api/zones/show')
58
- end
59
-
60
- it "falls back to the default template if the specified template does not exist" do
61
- request.headers['X-Spree-Template'] = 'invoice'
62
- api_get :show, :id => @zone.id
63
- expect(response).to render_template('spree/api/zones/show')
64
- end
65
- end
66
-
67
41
  context "as an admin" do
68
42
  sign_in_as_admin!
69
43
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spree_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.1
4
+ version: 3.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Bigg
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-05 00:00:00.000000000 Z
11
+ date: 2015-07-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: spree_core
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 3.0.1
19
+ version: 3.0.2
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 3.0.1
26
+ version: 3.0.2
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rabl
29
29
  requirement: !ruby/object:Gem::Requirement