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
@@ -13,76 +13,40 @@ module Spree
13
13
  stub_authentication!
14
14
  end
15
15
 
16
- context "as a normal user" do
17
- it "cannot list stock items for a stock location" do
18
- api_get :index, stock_location_id: stock_location.to_param
19
- response.status.should == 401
20
- end
21
-
22
- it "cannot see a stock item" do
23
- api_get :show, stock_location_id: stock_location.to_param, id: stock_item.to_param
24
- response.status.should == 401
25
- end
16
+ it 'gets list of stock items' do
17
+ api_get :index, stock_location_id: stock_location.to_param
18
+ json_response['stock_items'].first.should have_attributes(attributes)
19
+ json_response['stock_items'].first['variant']['sku'].should eq 'ABC'
20
+ end
26
21
 
27
- it "cannot create a stock item" do
28
- variant = create(:variant)
29
- params = {
30
- stock_location_id: stock_location.to_param,
31
- stock_item: {
32
- variant_id: variant.id,
33
- count_on_hand: '20'
34
- }
35
- }
22
+ it 'requires a stock_location_id to be passed as a parameter' do
23
+ api_get :index
24
+ json_response['error'].should =~ /stock_location_id parameter must be provided/
25
+ response.status.should == 422
26
+ end
36
27
 
37
- api_post :create, params
38
- response.status.should == 401
39
- end
28
+ it 'can control the page size through a parameter' do
29
+ api_get :index, stock_location_id: stock_location.to_param, per_page: 1
30
+ json_response['count'].should == 1
31
+ json_response['current_page'].should == 1
32
+ end
40
33
 
41
- it "cannot update a stock item" do
42
- api_put :update, stock_location_id: stock_location.to_param, stock_item_id: stock_item.to_param
43
- response.status.should == 401
44
- end
34
+ it 'can query the results through a paramter' do
35
+ stock_item.update_column(:count_on_hand, 30)
36
+ api_get :index, stock_location_id: stock_location.to_param, q: { count_on_hand_eq: '30' }
37
+ json_response['count'].should == 1
38
+ json_response['stock_items'].first['count_on_hand'].should eq 30
39
+ end
45
40
 
46
- it "cannot destroy a stock item" do
47
- api_delete :destroy, stock_location_id: stock_location.to_param, stock_item_id: stock_item.to_param
48
- response.status.should == 401
49
- end
41
+ it 'gets a stock item' do
42
+ api_get :show, stock_location_id: stock_location.to_param, id: stock_item.to_param
43
+ json_response.should have_attributes(attributes)
44
+ json_response['count_on_hand'].should eq stock_item.count_on_hand
50
45
  end
51
46
 
52
- context "as an admin" do
47
+ context 'as an admin' do
53
48
  sign_in_as_admin!
54
49
 
55
- it 'cannot list of stock items' do
56
- api_get :index, stock_location_id: stock_location.to_param
57
- json_response['stock_items'].first.should have_attributes(attributes)
58
- json_response['stock_items'].first['variant']['sku'].should eq 'ABC'
59
- end
60
-
61
- it 'requires a stock_location_id to be passed as a parameter' do
62
- api_get :index
63
- json_response['error'].should =~ /stock_location_id parameter must be provided/
64
- response.status.should == 422
65
- end
66
-
67
- it 'can control the page size through a parameter' do
68
- api_get :index, stock_location_id: stock_location.to_param, per_page: 1
69
- json_response['count'].should == 1
70
- json_response['current_page'].should == 1
71
- end
72
-
73
- it 'can query the results through a paramter' do
74
- stock_item.update_column(:count_on_hand, 30)
75
- api_get :index, stock_location_id: stock_location.to_param, q: { count_on_hand_eq: '30' }
76
- json_response['count'].should == 1
77
- json_response['stock_items'].first['count_on_hand'].should eq 30
78
- end
79
-
80
- it 'gets a stock item' do
81
- api_get :show, stock_location_id: stock_location.to_param, id: stock_item.to_param
82
- json_response.should have_attributes(attributes)
83
- json_response['count_on_hand'].should eq stock_item.count_on_hand
84
- end
85
-
86
50
  it 'can create a new stock item' do
87
51
  variant = create(:variant)
88
52
  # Creating a variant also creates stock items.
@@ -11,72 +11,45 @@ module Spree
11
11
  stub_authentication!
12
12
  end
13
13
 
14
- context "as a user" do
15
- it "cannot see stock locations" do
16
- api_get :index
17
- response.status.should == 401
18
- end
14
+ it "gets list of stock locations" do
15
+ api_get :index
16
+ json_response['stock_locations'].first.should have_attributes(attributes)
17
+ end
19
18
 
20
- it "cannot see a single stock location" do
21
- api_get :show, :id => stock_location.id
22
- response.status.should == 401
23
- end
19
+ it "includes the country" do
20
+ api_get :index
21
+ json_response['stock_locations'].first['country'].should_not be_nil
22
+ end
24
23
 
25
- it "cannot create a new stock location" do
26
- params = {
27
- stock_location: {
28
- name: "North Pole",
29
- active: true
30
- }
31
- }
24
+ it "includes the state" do
25
+ api_get :index
26
+ json_response['stock_locations'].first['state'].should_not be_nil
27
+ end
32
28
 
33
- api_post :create, params
34
- response.status.should == 401
35
- end
29
+ it 'can control the page size through a parameter' do
30
+ create(:stock_location)
31
+ api_get :index, per_page: 1
32
+ json_response['count'].should == 1
33
+ json_response['current_page'].should == 1
34
+ json_response['pages'].should == 2
35
+ end
36
36
 
37
- it "cannot update a stock location" do
38
- api_put :update, :stock_location => { :name => "South Pole" }, :id => stock_location.to_param
39
- response.status.should == 401
40
- end
37
+ it 'can query the results through a paramter' do
38
+ expected_result = create(:stock_location, name: 'South America')
39
+ api_get :index, q: { name_cont: 'south' }
40
+ json_response['count'].should == 1
41
+ json_response['stock_locations'].first['name'].should eq expected_result.name
42
+ end
41
43
 
42
- it "cannot delete a stock location" do
43
- api_put :destroy, :id => stock_location.to_param
44
- response.status.should == 401
45
- end
44
+ it "gets a stock location" do
45
+ api_get :show, id: stock_location.to_param
46
+ json_response.should have_attributes(attributes)
47
+ json_response['name'].should eq stock_location.name
46
48
  end
47
49
 
48
-
49
50
  context "as an admin" do
50
51
  sign_in_as_admin!
51
52
 
52
- it "gets list of stock locations" do
53
- api_get :index
54
- json_response['stock_locations'].first.should have_attributes(attributes)
55
- json_response['stock_locations'].first['country'].should_not be_nil
56
- json_response['stock_locations'].first['state'].should_not be_nil
57
- end
58
-
59
- it 'can control the page size through a parameter' do
60
- create(:stock_location)
61
- api_get :index, per_page: 1
62
- json_response['count'].should == 1
63
- json_response['current_page'].should == 1
64
- json_response['pages'].should == 2
65
- end
66
-
67
- it 'can query the results through a paramter' do
68
- expected_result = create(:stock_location, name: 'South America')
69
- api_get :index, q: { name_cont: 'south' }
70
- json_response['count'].should == 1
71
- json_response['stock_locations'].first['name'].should eq expected_result.name
72
- end
73
-
74
- it "gets a stock location" do
75
- api_get :show, id: stock_location.to_param
76
- json_response.should have_attributes(attributes)
77
- json_response['name'].should eq stock_location.name
78
- end
79
-
80
53
  it "can create a new stock location" do
81
54
  params = {
82
55
  stock_location: {
@@ -13,65 +13,41 @@ module Spree
13
13
  stub_authentication!
14
14
  end
15
15
 
16
- context 'as a user' do
17
- it 'cannot see a list of stock movements' do
18
- api_get :index, stock_location_id: stock_location.to_param
19
- response.status.should == 401
20
- end
16
+ it 'gets list of stock movements' do
17
+ api_get :index, stock_location_id: stock_location.to_param
18
+ json_response['stock_movements'].first.should have_attributes(attributes)
19
+ json_response['stock_movements'].first['stock_item']['count_on_hand'].should eq 11
20
+ end
21
21
 
22
- it 'cannot see a stock movement' do
23
- api_get :show, stock_location_id: stock_location.to_param, id: stock_movement.id
24
- response.status.should == 401
25
- end
22
+ it 'requires a stock_location_id to be passed as a parameter' do
23
+ api_get :index
24
+ json_response['error'].should =~ /stock_location_id parameter must be provided/
25
+ response.status.should == 422
26
+ end
26
27
 
27
- it 'cannot create a stock movement' do
28
- params = {
29
- stock_location_id: stock_location.to_param,
30
- stock_movement: {
31
- stock_item_id: stock_item.to_param
32
- }
33
- }
28
+ it 'can control the page size through a parameter' do
29
+ create(:stock_movement, stock_item: stock_item)
30
+ api_get :index, stock_location_id: stock_location.to_param, per_page: 1
31
+ json_response['count'].should == 1
32
+ json_response['current_page'].should == 1
33
+ json_response['pages'].should == 2
34
+ end
34
35
 
35
- api_post :create, params
36
- response.status.should == 401
37
- end
36
+ it 'can query the results through a paramter' do
37
+ expected_result = create(:stock_movement, :received, quantity: 10, stock_item: stock_item)
38
+ api_get :index, stock_location_id: stock_location.to_param, q: { quantity_eq: '10' }
39
+ json_response['count'].should == 1
40
+ end
41
+
42
+ it 'gets a stock movement' do
43
+ api_get :show, stock_location_id: stock_location.to_param, id: stock_movement.to_param
44
+ json_response.should have_attributes(attributes)
45
+ json_response['stock_item_id'].should eq stock_movement.stock_item_id
38
46
  end
39
47
 
40
48
  context 'as an admin' do
41
49
  sign_in_as_admin!
42
50
 
43
- it 'gets list of stock movements' do
44
- api_get :index, stock_location_id: stock_location.to_param
45
- json_response['stock_movements'].first.should have_attributes(attributes)
46
- json_response['stock_movements'].first['stock_item']['count_on_hand'].should eq 11
47
- end
48
-
49
- it 'requires a stock_location_id to be passed as a parameter' do
50
- api_get :index
51
- json_response['error'].should =~ /stock_location_id parameter must be provided/
52
- response.status.should == 422
53
- end
54
-
55
- it 'can control the page size through a parameter' do
56
- create(:stock_movement, stock_item: stock_item)
57
- api_get :index, stock_location_id: stock_location.to_param, per_page: 1
58
- json_response['count'].should == 1
59
- json_response['current_page'].should == 1
60
- json_response['pages'].should == 2
61
- end
62
-
63
- it 'can query the results through a paramter' do
64
- expected_result = create(:stock_movement, :received, quantity: 10, stock_item: stock_item)
65
- api_get :index, stock_location_id: stock_location.to_param, q: { quantity_eq: '10' }
66
- json_response['count'].should == 1
67
- end
68
-
69
- it 'gets a stock movement' do
70
- api_get :show, stock_location_id: stock_location.to_param, id: stock_movement.to_param
71
- json_response.should have_attributes(attributes)
72
- json_response['stock_item_id'].should eq stock_movement.stock_item_id
73
- end
74
-
75
51
  it 'can create a new stock movement' do
76
52
  params = {
77
53
  stock_location_id: stock_location.to_param,
@@ -7,7 +7,7 @@ module Spree
7
7
  let(:taxonomy) { create(:taxonomy) }
8
8
  let(:taxon) { create(:taxon, :name => "Ruby", :taxonomy => taxonomy) }
9
9
  let(:taxon2) { create(:taxon, :name => "Rails", :taxonomy => taxonomy) }
10
- let(:attributes) { ["id", "name", "pretty_name", "permalink", "parent_id", "taxonomy_id"] }
10
+ let(:attributes) { ["id", "name", "pretty_name", "permalink", "position", "parent_id", "taxonomy_id"] }
11
11
 
12
12
  before do
13
13
  stub_authentication!
@@ -27,14 +27,6 @@ module Spree
27
27
  children.first['taxons'].count.should eq 1
28
28
  end
29
29
 
30
- # Regression test for #4112
31
- it "does not include children when asked not to" do
32
- api_get :index, :taxonomy_id => taxonomy.id, :without_children => 1
33
-
34
- json_response['taxons'].first['name'].should eq(taxon.name)
35
- json_response['taxons'].first['taxons'].should be_nil
36
- end
37
-
38
30
  it "paginates through taxons" do
39
31
  new_taxon = create(:taxon, :name => "Go", :taxonomy => taxonomy)
40
32
  taxonomy.root.children << new_taxon
@@ -47,42 +39,21 @@ module Spree
47
39
  expect(json_response["pages"]).to eql(2)
48
40
  end
49
41
 
50
- describe 'searching' do
51
- context 'with a name' do
52
- before do
53
- api_get :index, :q => { :name_cont => name }
54
- end
55
-
56
- context 'with one result' do
57
- let(:name) { "Ruby" }
58
-
59
- it "returns an array including the matching taxon" do
60
- json_response['taxons'].count.should == 1
61
- json_response['taxons'].first['name'].should eq "Ruby"
62
- end
63
- end
64
-
65
- context 'with no results' do
66
- let(:name) { "Imaginary" }
67
-
68
- it 'returns an empty array of taxons' do
69
- json_response.keys.should include('taxons')
70
- json_response['taxons'].count.should == 0
71
- end
72
- end
73
- end
74
-
75
- context 'with no filters' do
76
- it "gets all taxons" do
77
- api_get :index
78
-
79
- json_response['taxons'].first['name'].should eq taxonomy.root.name
80
- children = json_response['taxons'].first['taxons']
81
- children.count.should eq 1
82
- children.first['name'].should eq taxon.name
83
- children.first['taxons'].count.should eq 1
84
- end
85
- end
42
+ it "gets all taxons" do
43
+ api_get :index
44
+
45
+ json_response['taxons'].first['name'].should eq taxonomy.root.name
46
+ children = json_response['taxons'].first['taxons']
47
+ children.count.should eq 1
48
+ children.first['name'].should eq taxon.name
49
+ children.first['taxons'].count.should eq 1
50
+ end
51
+
52
+ it "can search for a single taxon" do
53
+ api_get :index, :q => { :name_cont => "Ruby" }
54
+
55
+ json_response['taxons'].count.should == 1
56
+ json_response['taxons'].first['name'].should eq "Ruby"
86
57
  end
87
58
 
88
59
  it "gets a single taxon" do
@@ -134,10 +105,9 @@ module Spree
134
105
  response.status.should == 201
135
106
 
136
107
  taxonomy.reload.root.children.count.should eq 2
137
- taxon = Spree::Taxon.where(:name => 'Colors').first
138
108
 
139
- taxon.parent_id.should eq taxonomy.root.id
140
- taxon.taxonomy_id.should eq taxonomy.id
109
+ Spree::Taxon.last.parent_id.should eq taxonomy.root.id
110
+ Spree::Taxon.last.taxonomy_id.should eq taxonomy.id
141
111
  end
142
112
 
143
113
  it "cannot create a new taxon with invalid attributes" do
@@ -11,9 +11,7 @@ module Spree
11
11
  before { stub_authentication! }
12
12
 
13
13
  context "as a normal user" do
14
- before do
15
- controller.stub :current_api_user => user
16
- end
14
+ before { Spree::LegacyUser.stub :find_by_spree_api_key => user }
17
15
 
18
16
  it "can get own details" do
19
17
  api_get :show, :id => user.id
@@ -24,7 +22,7 @@ module Spree
24
22
  it "cannot get other users details" do
25
23
  api_get :show, :id => stranger.id
26
24
 
27
- assert_unauthorized!
25
+ assert_not_found!
28
26
  end
29
27
 
30
28
  it "can learn how to create a new user" do
@@ -52,7 +50,7 @@ module Spree
52
50
 
53
51
  it "cannot update other users details" do
54
52
  api_put :update, :id => stranger.id, :user => { :email => "mine@example.com" }
55
- assert_unauthorized!
53
+ assert_not_found!
56
54
  end
57
55
 
58
56
  it "can delete itself" do
@@ -62,7 +60,7 @@ module Spree
62
60
 
63
61
  it "cannot delete other user" do
64
62
  api_delete :destroy, :id => stranger.id
65
- assert_unauthorized!
63
+ assert_not_found!
66
64
  end
67
65
 
68
66
  it "should only get own details on index" do
@@ -4,7 +4,6 @@ module Spree
4
4
  describe Api::VariantsController do
5
5
  render_views
6
6
 
7
-
8
7
  let!(:product) { create(:product) }
9
8
  let!(:variant) do
10
9
  variant = product.master
@@ -13,7 +12,7 @@ module Spree
13
12
  end
14
13
  let!(:attributes) { [:id, :name, :sku, :price, :weight, :height,
15
14
  :width, :depth, :is_master, :cost_price,
16
- :permalink] }
15
+ :permalink, :description] }
17
16
 
18
17
  before do
19
18
  stub_authentication!
@@ -87,42 +86,27 @@ module Spree
87
86
  end
88
87
  end
89
88
 
90
- context "single variant" do
91
-
92
- it "can see a single variant" do
93
- api_get :show, :id => variant.to_param
94
- json_response.should have_attributes(attributes)
95
- option_values = json_response["option_values"]
96
- option_values.first.should have_attributes([:name,
97
- :presentation,
98
- :option_type_name,
99
- :option_type_id])
100
- end
101
-
102
- it "can see a single variant with images" do
103
- variant.images.create!(:attachment => image("thinking-cat.jpg"))
104
-
105
- api_get :show, :id => variant.to_param
106
-
107
- json_response.should have_attributes(attributes + [:images])
108
- option_values = json_response["option_values"]
109
- option_values.first.should have_attributes([:name,
110
- :presentation,
111
- :option_type_name,
112
- :option_type_id])
113
- end
114
-
115
- it 'shows variant image urls' do
116
- variant.images.create!(:attachment => image("thinking-cat.jpg"))
117
-
118
- api_get :show, :id => variant.to_param
89
+ it "can see a single variant" do
90
+ api_get :show, :id => variant.to_param
91
+ json_response.should have_attributes(attributes)
92
+ option_values = json_response["option_values"]
93
+ option_values.first.should have_attributes([:name,
94
+ :presentation,
95
+ :option_type_name,
96
+ :option_type_id])
97
+ end
119
98
 
120
- images = json_response["images"]
121
- image = images.first
99
+ it "can see a single variant with images" do
100
+ variant.images.create!(:attachment => image("thinking-cat.jpg"))
122
101
 
123
- expect(image).to have_attributes [:mini_url, :small_url, :product_url, :large_url]
124
- end
102
+ api_get :show, :id => variant.to_param
125
103
 
104
+ json_response.should have_attributes(attributes + [:images])
105
+ option_values = json_response["option_values"]
106
+ option_values.first.should have_attributes([:name,
107
+ :presentation,
108
+ :option_type_name,
109
+ :option_type_id])
126
110
  end
127
111
 
128
112
  it "can learn how to create a new variant" do
@@ -138,12 +122,12 @@ module Spree
138
122
 
139
123
  it "cannot update a variant" do
140
124
  api_put :update, :id => variant.to_param, :variant => { :sku => "12345" }
141
- assert_unauthorized!
125
+ assert_not_found!
142
126
  end
143
127
 
144
128
  it "cannot delete a variant" do
145
129
  api_delete :destroy, :id => variant.to_param
146
- assert_unauthorized!
130
+ assert_not_found!
147
131
  lambda { variant.reload }.should_not raise_error
148
132
  end
149
133
 
@@ -184,6 +168,5 @@ module Spree
184
168
  end
185
169
  end
186
170
 
187
-
188
171
  end
189
172
  end
@@ -48,13 +48,13 @@ module Spree
48
48
  end
49
49
 
50
50
  it "uses the specified template" do
51
- request.env['X-Spree-Template'] = 'show'
51
+ request.headers.env['X-Spree-Template'] = 'show'
52
52
  api_get :custom_show, :id => @zone.id
53
53
  response.should render_template('spree/api/zones/show')
54
54
  end
55
55
 
56
56
  it "falls back to the default template if the specified template does not exist" do
57
- request.env['X-Spree-Template'] = 'invoice'
57
+ request.headers.env['X-Spree-Template'] = 'invoice'
58
58
  api_get :show, :id => @zone.id
59
59
  response.should render_template('spree/api/zones/show')
60
60
  end