spree_api 1.2.0 → 1.2.2

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 (55) hide show
  1. data/app/controllers/spree/api/v1/addresses_controller.rb +2 -0
  2. data/app/controllers/spree/api/v1/base_controller.rb +12 -3
  3. data/app/controllers/spree/api/v1/countries_controller.rb +4 -1
  4. data/app/controllers/spree/api/v1/images_controller.rb +4 -1
  5. data/app/controllers/spree/api/v1/line_items_controller.rb +1 -1
  6. data/app/controllers/spree/api/v1/orders_controller.rb +10 -16
  7. data/app/controllers/spree/api/v1/payments_controller.rb +5 -1
  8. data/app/controllers/spree/api/v1/product_properties_controller.rb +64 -0
  9. data/app/controllers/spree/api/v1/products_controller.rb +2 -7
  10. data/app/controllers/spree/api/v1/return_authorizations_controller.rb +53 -0
  11. data/app/controllers/spree/api/v1/shipments_controller.rb +3 -0
  12. data/app/controllers/spree/api/v1/taxonomies_controller.rb +5 -2
  13. data/app/controllers/spree/api/v1/taxons_controller.rb +1 -1
  14. data/app/controllers/spree/api/v1/variants_controller.rb +21 -3
  15. data/app/controllers/spree/api/v1/zones_controller.rb +2 -2
  16. data/app/helpers/spree/api/api_helpers.rb +8 -0
  17. data/app/models/spree/api_configuration.rb +5 -0
  18. data/app/models/spree/order_decorator.rb +1 -0
  19. data/app/views/spree/api/v1/countries/index.rabl +7 -2
  20. data/app/views/spree/api/v1/countries/show.rabl +2 -2
  21. data/app/views/spree/api/v1/orders/index.rabl +1 -1
  22. data/app/views/spree/api/v1/orders/show.rabl +4 -1
  23. data/app/views/spree/api/v1/payments/index.rabl +7 -2
  24. data/app/views/spree/api/v1/product_properties/index.rabl +7 -0
  25. data/app/views/spree/api/v1/product_properties/new.rabl +2 -0
  26. data/app/views/spree/api/v1/product_properties/show.rabl +2 -0
  27. data/app/views/spree/api/v1/products/index.rabl +2 -1
  28. data/app/views/spree/api/v1/return_authorizations/index.rabl +7 -0
  29. data/app/views/spree/api/v1/return_authorizations/new.rabl +3 -0
  30. data/app/views/spree/api/v1/return_authorizations/show.rabl +2 -0
  31. data/app/views/spree/api/v1/taxonomies/index.rabl +7 -2
  32. data/app/views/spree/api/v1/variants/index.rabl +10 -3
  33. data/app/views/spree/api/v1/zones/index.rabl +7 -2
  34. data/config/routes.rb +3 -8
  35. data/lib/spree/api/engine.rb +4 -0
  36. data/spec/controllers/spree/api/v1/addresses_controller_spec.rb +29 -7
  37. data/spec/controllers/spree/api/v1/base_controller_spec.rb +1 -0
  38. data/spec/controllers/spree/api/v1/countries_controller_spec.rb +25 -1
  39. data/spec/controllers/spree/api/v1/images_controller_spec.rb +42 -21
  40. data/spec/controllers/spree/api/v1/line_items_controller_spec.rb +1 -1
  41. data/spec/controllers/spree/api/v1/orders_controller_spec.rb +51 -1
  42. data/spec/controllers/spree/api/v1/payments_controller_spec.rb +44 -3
  43. data/spec/controllers/spree/api/v1/product_properties_controller_spec.rb +117 -0
  44. data/spec/controllers/spree/api/v1/products_controller_spec.rb +33 -17
  45. data/spec/controllers/spree/api/v1/return_authorizations_controller_spec.rb +155 -0
  46. data/spec/controllers/spree/api/v1/shipments_controller_spec.rb +18 -3
  47. data/spec/controllers/spree/api/v1/taxonomies_controller_spec.rb +22 -3
  48. data/spec/controllers/spree/api/v1/taxons_controller_spec.rb +8 -3
  49. data/spec/controllers/spree/api/v1/unauthenticated_products_controller_spec.rb +26 -0
  50. data/spec/controllers/spree/api/v1/variants_controller_spec.rb +68 -4
  51. data/spec/controllers/spree/api/v1/zones_controller_spec.rb +46 -11
  52. data/spec/shared_examples/protect_product_actions.rb +17 -0
  53. data/spec/spec_helper.rb +5 -0
  54. data/spree_api.gemspec +0 -1
  55. metadata +28 -22
@@ -20,8 +20,23 @@ module Spree
20
20
  it "gets all taxonomies" do
21
21
  api_get :index
22
22
 
23
- json_response.first['taxonomy']['name'].should eq taxonomy.name
24
- json_response.first['taxonomy']['root']['taxons'].count.should eq 1
23
+ json_response["taxonomies"].first['taxonomy']['name'].should eq taxonomy.name
24
+ json_response["taxonomies"].first['taxonomy']['root']['taxons'].count.should eq 1
25
+ end
26
+
27
+ it 'can control the page size through a parameter' do
28
+ create(:taxonomy)
29
+ api_get :index, :per_page => 1
30
+ json_response['count'].should == 1
31
+ json_response['current_page'].should == 1
32
+ json_response['pages'].should == 2
33
+ end
34
+
35
+ it 'can query the results through a paramter' do
36
+ expected_result = create(:taxonomy, :name => 'Style')
37
+ api_get :index, :q => { :name_cont => 'style' }
38
+ json_response['count'].should == 1
39
+ json_response['taxonomies'].first['taxonomy']['name'].should eq expected_result.name
25
40
  end
26
41
 
27
42
  it "gets a single taxonomy" do
@@ -82,7 +97,11 @@ module Spree
82
97
  json_response["error"].should == "Invalid resource. Please fix errors and try again."
83
98
  errors = json_response["errors"]
84
99
  end
85
- end
86
100
 
101
+ it "can destroy" do
102
+ api_delete :destroy, :id => taxonomy.id
103
+ response.status.should == 204
104
+ end
105
+ end
87
106
  end
88
107
  end
@@ -4,9 +4,9 @@ module Spree
4
4
  describe Api::V1::TaxonsController do
5
5
  render_views
6
6
 
7
- let(:taxonomy) { Factory(:taxonomy) }
8
- let(:taxon) { Factory(:taxon, :name => "Ruby", :taxonomy => taxonomy) }
9
- let(:taxon2) { Factory(:taxon, :name => "Rails", :taxonomy => taxonomy) }
7
+ let(:taxonomy) { create(:taxonomy) }
8
+ let(:taxon) { create(:taxon, :name => "Ruby", :taxonomy => taxonomy) }
9
+ let(:taxon2) { create(:taxon, :name => "Rails", :taxonomy => taxonomy) }
10
10
  let(:attributes) { ["id", "name", "permalink", "position", "parent_id", "taxonomy_id"] }
11
11
 
12
12
  before do
@@ -76,6 +76,11 @@ module Spree
76
76
 
77
77
  taxon.reload.children.count.should eq 1
78
78
  end
79
+
80
+ it "can destroy" do
81
+ api_delete :destroy, :taxonomy_id => taxonomy.id, :id => taxon.id
82
+ response.status.should == 204
83
+ end
79
84
  end
80
85
 
81
86
  end
@@ -0,0 +1,26 @@
1
+ require 'shared_examples/protect_product_actions'
2
+ require 'spec_helper'
3
+
4
+ module Spree
5
+ describe Spree::Api::V1::ProductsController do
6
+ render_views
7
+
8
+ let!(:product) { create(:product) }
9
+ let(:attributes) { [:id, :name, :description, :price, :available_on, :permalink, :count_on_hand, :meta_description, :meta_keywords, :taxon_ids] }
10
+
11
+ context "without authentication" do
12
+ before { Spree::Api::Config[:requires_authentication] = false }
13
+
14
+ it "retreives a list of products" do
15
+ api_get :index
16
+ json_response["products"].first.should have_attributes(attributes)
17
+ json_response["count"].should == 1
18
+ json_response["current_page"].should == 1
19
+ json_response["pages"].should == 1
20
+ end
21
+
22
+ it_behaves_like "modifying product actions are restricted"
23
+ end
24
+ end
25
+ end
26
+
@@ -20,16 +20,68 @@ module Spree
20
20
  stub_authentication!
21
21
  end
22
22
 
23
- it "can see a list of all variants" do
23
+ it "can see a paginated list of variants" do
24
24
  api_get :index
25
- json_response.first.should have_attributes(attributes)
26
- option_values = json_response.last["variant"]["option_values"]
25
+ json_response["variants"].first.should have_attributes(attributes)
26
+ json_response["count"].should == 1
27
+ json_response["current_page"].should == 1
28
+ json_response["pages"].should == 1
29
+ end
30
+
31
+ it 'can control the page size through a parameter' do
32
+ create(:variant)
33
+ api_get :index, :per_page => 1
34
+ json_response['count'].should == 1
35
+ json_response['current_page'].should == 1
36
+ json_response['pages'].should == 3
37
+ end
38
+
39
+ it 'can query the results through a paramter' do
40
+ expected_result = create(:variant, :sku => 'FOOBAR')
41
+ api_get :index, :q => { :sku_cont => 'FOO' }
42
+ json_response['count'].should == 1
43
+ json_response['variants'].first['variant']['sku'].should eq expected_result.sku
44
+ end
45
+
46
+ it "variants returned contain option values data" do
47
+ api_get :index
48
+ option_values = json_response["variants"].last["variant"]["option_values"]
27
49
  option_values.first.should have_attributes([:name,
28
50
  :presentation,
29
51
  :option_type_name,
30
52
  :option_type_id])
31
53
  end
32
54
 
55
+ # Regression test for #2141
56
+ context "a deleted variant" do
57
+ before do
58
+ variant.update_column(:deleted_at, Time.now)
59
+ end
60
+
61
+ it "is not returned in the results" do
62
+ api_get :index
63
+ json_response["variants"].count.should == 0
64
+ end
65
+
66
+ it "is not returned even when show_deleted is passed" do
67
+ api_get :index, :show_deleted => true
68
+ json_response["variants"].count.should == 0
69
+ end
70
+ end
71
+
72
+ context "pagination" do
73
+ default_per_page(1)
74
+
75
+ it "can select the next page of variants" do
76
+ second_variant = create(:variant)
77
+ api_get :index, :page => 2
78
+ json_response["variants"].first.should have_attributes(attributes)
79
+ json_response["total_count"].should == 3
80
+ json_response["current_page"].should == 2
81
+ json_response["pages"].should == 3
82
+ end
83
+ end
84
+
33
85
  it "can see a single variant" do
34
86
  api_get :show, :id => variant.to_param
35
87
  json_response.should have_attributes(attributes)
@@ -66,6 +118,18 @@ module Spree
66
118
  sign_in_as_admin!
67
119
  let(:resource_scoping) { { :product_id => variant.product.to_param } }
68
120
 
121
+ # Test for #2141
122
+ context "deleted variants" do
123
+ before do
124
+ variant.update_column(:deleted_at, Time.now)
125
+ end
126
+
127
+ it "are visible by admin" do
128
+ api_get :index, :show_deleted => 1
129
+ json_response["variants"].count.should == 1
130
+ end
131
+ end
132
+
69
133
  it "can create a new variant" do
70
134
  api_post :create, :variant => { :sku => "12345" }
71
135
  json_response.should have_attributes(attributes)
@@ -81,7 +145,7 @@ module Spree
81
145
 
82
146
  it "can delete a variant" do
83
147
  api_delete :destroy, :id => variant.to_param
84
- response.status.should == 200
148
+ response.status.should == 204
85
149
  lambda { variant.reload }.should raise_error(ActiveRecord::RecordNotFound)
86
150
  end
87
151
  end
@@ -13,7 +13,22 @@ module Spree
13
13
 
14
14
  it "gets list of zones" do
15
15
  api_get :index
16
- json_response.first.should have_attributes(attributes)
16
+ json_response['zones'].first.should have_attributes(attributes)
17
+ end
18
+
19
+ it 'can control the page size through a parameter' do
20
+ create(:zone)
21
+ api_get :index, :per_page => 1
22
+ json_response['count'].should == 1
23
+ json_response['current_page'].should == 1
24
+ json_response['pages'].should == 2
25
+ end
26
+
27
+ it 'can query the results through a paramter' do
28
+ expected_result = create(:zone, :name => 'South America')
29
+ api_get :index, :q => { :name_cont => 'south' }
30
+ json_response['count'].should == 1
31
+ json_response['zones'].first['zone']['name'].should eq expected_result.name
17
32
  end
18
33
 
19
34
  it "gets a zone" do
@@ -27,26 +42,46 @@ module Spree
27
42
  sign_in_as_admin!
28
43
 
29
44
  it "can create a new zone" do
30
- api_post :create, :zone => { :name => "North Pole",
31
- :zone_members => [ :zone_member => {
32
- :zoneable_id => 1 }] }
45
+ params = {
46
+ :zone => {
47
+ :name => "North Pole",
48
+ :zone_members => [
49
+ {
50
+ :zoneable_type => "Spree::Country",
51
+ :zoneable_id => 1
52
+ }
53
+ ]
54
+ }
55
+ }
56
+
57
+ api_post :create, params
33
58
  response.status.should == 201
34
59
  json_response.should have_attributes(attributes)
60
+ json_response["zone"]["zone_members"].should_not be_empty
35
61
  end
36
62
 
37
63
  it "updates a zone" do
38
- api_put :update, :id => @zone.id,
39
- :zone => { :name => "Americas",
40
- :zone_members => [ :zone_member => {
41
- :zoneable_type => 'Spree::Country',
42
- :zoneable_id => 1 }]}
64
+ params = { :id => @zone.id,
65
+ :zone => {
66
+ :name => "North Pole",
67
+ :zone_members => [
68
+ {
69
+ :zoneable_type => "Spree::Country",
70
+ :zoneable_id => 1
71
+ }
72
+ ]
73
+ }
74
+ }
75
+
76
+ api_put :update, params
43
77
  response.status.should == 200
44
- json_response['zone']['name'].should eq 'Americas'
78
+ json_response['zone']['name'].should eq 'North Pole'
79
+ json_response['zone']['zone_members'].should_not be_blank
45
80
  end
46
81
 
47
82
  it "can delete a zone" do
48
83
  api_delete :destroy, :id => @zone.id
49
- response.status.should == 200
84
+ response.status.should == 204
50
85
  lambda { @zone.reload }.should raise_error(ActiveRecord::RecordNotFound)
51
86
  end
52
87
  end
@@ -0,0 +1,17 @@
1
+ shared_examples "modifying product actions are restricted" do
2
+ it "cannot create a new product if not an admin" do
3
+ api_post :create, :product => { :name => "Brand new product!" }
4
+ assert_unauthorized!
5
+ end
6
+
7
+ it "cannot update a product" do
8
+ api_put :update, :id => product.to_param, :product => { :name => "I hacked your store!" }
9
+ assert_unauthorized!
10
+ end
11
+
12
+ it "cannot delete a product" do
13
+ api_delete :destroy, :id => product.to_param
14
+ assert_unauthorized!
15
+ end
16
+ end
17
+
data/spec/spec_helper.rb CHANGED
@@ -19,4 +19,9 @@ RSpec.configure do |config|
19
19
  config.include FactoryGirl::Syntax::Methods
20
20
  config.include Spree::Api::TestingSupport::Helpers, :type => :controller
21
21
  config.extend Spree::Api::TestingSupport::Setup, :type => :controller
22
+ config.include Spree::Core::TestingSupport::Preferences, :type => :controller
23
+
24
+ config.before do
25
+ Spree::Api::Config[:requires_authentication] = true
26
+ end
22
27
  end
data/spree_api.gemspec CHANGED
@@ -16,7 +16,6 @@ Gem::Specification.new do |gem|
16
16
  gem.version = version
17
17
 
18
18
  gem.add_dependency 'spree_core', version
19
- gem.add_dependency 'rabl', '0.6.5'
20
19
 
21
20
  gem.add_development_dependency 'rspec-rails', '2.9.0'
22
21
  gem.add_development_dependency 'database_cleaner'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spree_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.2.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,33 +9,22 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-30 00:00:00.000000000Z
12
+ date: 2012-11-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: spree_core
16
- requirement: &70196103586700 !ruby/object:Gem::Requirement
16
+ requirement: &70185208786720 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - =
20
20
  - !ruby/object:Gem::Version
21
- version: 1.2.0
21
+ version: 1.2.2
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70196103586700
25
- - !ruby/object:Gem::Dependency
26
- name: rabl
27
- requirement: &70196103585920 !ruby/object:Gem::Requirement
28
- none: false
29
- requirements:
30
- - - =
31
- - !ruby/object:Gem::Version
32
- version: 0.6.5
33
- type: :runtime
34
- prerelease: false
35
- version_requirements: *70196103585920
24
+ version_requirements: *70185208786720
36
25
  - !ruby/object:Gem::Dependency
37
26
  name: rspec-rails
38
- requirement: &70196103585220 !ruby/object:Gem::Requirement
27
+ requirement: &70185208785040 !ruby/object:Gem::Requirement
39
28
  none: false
40
29
  requirements:
41
30
  - - =
@@ -43,10 +32,10 @@ dependencies:
43
32
  version: 2.9.0
44
33
  type: :development
45
34
  prerelease: false
46
- version_requirements: *70196103585220
35
+ version_requirements: *70185208785040
47
36
  - !ruby/object:Gem::Dependency
48
37
  name: database_cleaner
49
- requirement: &70196103584480 !ruby/object:Gem::Requirement
38
+ requirement: &70185208804960 !ruby/object:Gem::Requirement
50
39
  none: false
51
40
  requirements:
52
41
  - - ! '>='
@@ -54,7 +43,7 @@ dependencies:
54
43
  version: '0'
55
44
  type: :development
56
45
  prerelease: false
57
- version_requirements: *70196103584480
46
+ version_requirements: *70185208804960
58
47
  description: Spree's API
59
48
  email:
60
49
  - ryan@spreecommerce.com
@@ -73,13 +62,16 @@ files:
73
62
  - app/controllers/spree/api/v1/line_items_controller.rb
74
63
  - app/controllers/spree/api/v1/orders_controller.rb
75
64
  - app/controllers/spree/api/v1/payments_controller.rb
65
+ - app/controllers/spree/api/v1/product_properties_controller.rb
76
66
  - app/controllers/spree/api/v1/products_controller.rb
67
+ - app/controllers/spree/api/v1/return_authorizations_controller.rb
77
68
  - app/controllers/spree/api/v1/shipments_controller.rb
78
69
  - app/controllers/spree/api/v1/taxonomies_controller.rb
79
70
  - app/controllers/spree/api/v1/taxons_controller.rb
80
71
  - app/controllers/spree/api/v1/variants_controller.rb
81
72
  - app/controllers/spree/api/v1/zones_controller.rb
82
73
  - app/helpers/spree/api/api_helpers.rb
74
+ - app/models/spree/api_configuration.rb
83
75
  - app/models/spree/line_item_decorator.rb
84
76
  - app/models/spree/option_value_decorator.rb
85
77
  - app/models/spree/order_decorator.rb
@@ -112,10 +104,16 @@ files:
112
104
  - app/views/spree/api/v1/payments/index.rabl
113
105
  - app/views/spree/api/v1/payments/new.rabl
114
106
  - app/views/spree/api/v1/payments/show.rabl
107
+ - app/views/spree/api/v1/product_properties/index.rabl
108
+ - app/views/spree/api/v1/product_properties/new.rabl
109
+ - app/views/spree/api/v1/product_properties/show.rabl
115
110
  - app/views/spree/api/v1/products/index.rabl
116
111
  - app/views/spree/api/v1/products/new.rabl
117
112
  - app/views/spree/api/v1/products/product.rabl
118
113
  - app/views/spree/api/v1/products/show.rabl
114
+ - app/views/spree/api/v1/return_authorizations/index.rabl
115
+ - app/views/spree/api/v1/return_authorizations/new.rabl
116
+ - app/views/spree/api/v1/return_authorizations/show.rabl
119
117
  - app/views/spree/api/v1/shipments/show.rabl
120
118
  - app/views/spree/api/v1/taxonomies/index.rabl
121
119
  - app/views/spree/api/v1/taxonomies/nested.rabl
@@ -152,15 +150,19 @@ files:
152
150
  - spec/controllers/spree/api/v1/line_items_controller_spec.rb
153
151
  - spec/controllers/spree/api/v1/orders_controller_spec.rb
154
152
  - spec/controllers/spree/api/v1/payments_controller_spec.rb
153
+ - spec/controllers/spree/api/v1/product_properties_controller_spec.rb
155
154
  - spec/controllers/spree/api/v1/products_controller_spec.rb
155
+ - spec/controllers/spree/api/v1/return_authorizations_controller_spec.rb
156
156
  - spec/controllers/spree/api/v1/shipments_controller_spec.rb
157
157
  - spec/controllers/spree/api/v1/taxonomies_controller_spec.rb
158
158
  - spec/controllers/spree/api/v1/taxons_controller_spec.rb
159
+ - spec/controllers/spree/api/v1/unauthenticated_products_controller_spec.rb
159
160
  - spec/controllers/spree/api/v1/variants_controller_spec.rb
160
161
  - spec/controllers/spree/api/v1/zones_controller_spec.rb
161
162
  - spec/fixtures/thinking-cat.jpg
162
163
  - spec/models/spree/legacy_user_spec.rb
163
164
  - spec/models/spree/order_spec.rb
165
+ - spec/shared_examples/protect_product_actions.rb
164
166
  - spec/spec_helper.rb
165
167
  - spec/support/controller_hacks.rb
166
168
  - spec/support/database_cleaner.rb
@@ -180,7 +182,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
180
182
  version: '0'
181
183
  segments:
182
184
  - 0
183
- hash: 1643031983782340233
185
+ hash: 2313245839499120062
184
186
  required_rubygems_version: !ruby/object:Gem::Requirement
185
187
  none: false
186
188
  requirements:
@@ -189,7 +191,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
189
191
  version: '0'
190
192
  segments:
191
193
  - 0
192
- hash: 1643031983782340233
194
+ hash: 2313245839499120062
193
195
  requirements: []
194
196
  rubyforge_project:
195
197
  rubygems_version: 1.8.10
@@ -204,15 +206,19 @@ test_files:
204
206
  - spec/controllers/spree/api/v1/line_items_controller_spec.rb
205
207
  - spec/controllers/spree/api/v1/orders_controller_spec.rb
206
208
  - spec/controllers/spree/api/v1/payments_controller_spec.rb
209
+ - spec/controllers/spree/api/v1/product_properties_controller_spec.rb
207
210
  - spec/controllers/spree/api/v1/products_controller_spec.rb
211
+ - spec/controllers/spree/api/v1/return_authorizations_controller_spec.rb
208
212
  - spec/controllers/spree/api/v1/shipments_controller_spec.rb
209
213
  - spec/controllers/spree/api/v1/taxonomies_controller_spec.rb
210
214
  - spec/controllers/spree/api/v1/taxons_controller_spec.rb
215
+ - spec/controllers/spree/api/v1/unauthenticated_products_controller_spec.rb
211
216
  - spec/controllers/spree/api/v1/variants_controller_spec.rb
212
217
  - spec/controllers/spree/api/v1/zones_controller_spec.rb
213
218
  - spec/fixtures/thinking-cat.jpg
214
219
  - spec/models/spree/legacy_user_spec.rb
215
220
  - spec/models/spree/order_spec.rb
221
+ - spec/shared_examples/protect_product_actions.rb
216
222
  - spec/spec_helper.rb
217
223
  - spec/support/controller_hacks.rb
218
224
  - spec/support/database_cleaner.rb