spree_api 3.1.5 → 3.1.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/spree/api/v1/product_properties_controller.rb +7 -10
  3. data/app/views/spree/api/v1/countries/index.v1.rabl +1 -1
  4. data/app/views/spree/api/v1/credit_cards/index.v1.rabl +1 -1
  5. data/app/views/spree/api/v1/orders/index.v1.rabl +1 -1
  6. data/app/views/spree/api/v1/orders/mine.v1.rabl +1 -1
  7. data/app/views/spree/api/v1/payments/index.v1.rabl +1 -1
  8. data/app/views/spree/api/v1/product_properties/index.v1.rabl +1 -1
  9. data/app/views/spree/api/v1/products/index.v1.rabl +1 -1
  10. data/app/views/spree/api/v1/properties/index.v1.rabl +1 -1
  11. data/app/views/spree/api/v1/return_authorizations/index.v1.rabl +1 -1
  12. data/app/views/spree/api/v1/shipments/mine.v1.rabl +1 -1
  13. data/app/views/spree/api/v1/states/index.v1.rabl +1 -1
  14. data/app/views/spree/api/v1/stock_items/index.v1.rabl +1 -1
  15. data/app/views/spree/api/v1/stock_locations/index.v1.rabl +1 -1
  16. data/app/views/spree/api/v1/stock_movements/index.v1.rabl +1 -1
  17. data/app/views/spree/api/v1/taxonomies/index.v1.rabl +1 -1
  18. data/app/views/spree/api/v1/taxons/index.v1.rabl +1 -1
  19. data/app/views/spree/api/v1/users/index.v1.rabl +1 -1
  20. data/app/views/spree/api/v1/zones/index.v1.rabl +1 -1
  21. data/spree_api.gemspec +1 -2
  22. metadata +6 -88
  23. data/spec/controllers/spree/api/base_controller_spec.rb +0 -96
  24. data/spec/controllers/spree/api/v1/addresses_controller_spec.rb +0 -56
  25. data/spec/controllers/spree/api/v1/checkouts_controller_spec.rb +0 -363
  26. data/spec/controllers/spree/api/v1/classifications_controller_spec.rb +0 -48
  27. data/spec/controllers/spree/api/v1/countries_controller_spec.rb +0 -48
  28. data/spec/controllers/spree/api/v1/credit_cards_controller_spec.rb +0 -80
  29. data/spec/controllers/spree/api/v1/images_controller_spec.rb +0 -115
  30. data/spec/controllers/spree/api/v1/inventory_units_controller_spec.rb +0 -49
  31. data/spec/controllers/spree/api/v1/line_items_controller_spec.rb +0 -184
  32. data/spec/controllers/spree/api/v1/option_types_controller_spec.rb +0 -122
  33. data/spec/controllers/spree/api/v1/option_values_controller_spec.rb +0 -141
  34. data/spec/controllers/spree/api/v1/orders_controller_spec.rb +0 -735
  35. data/spec/controllers/spree/api/v1/payments_controller_spec.rb +0 -234
  36. data/spec/controllers/spree/api/v1/product_properties_controller_spec.rb +0 -116
  37. data/spec/controllers/spree/api/v1/products_controller_spec.rb +0 -409
  38. data/spec/controllers/spree/api/v1/promotion_application_spec.rb +0 -50
  39. data/spec/controllers/spree/api/v1/promotions_controller_spec.rb +0 -64
  40. data/spec/controllers/spree/api/v1/properties_controller_spec.rb +0 -102
  41. data/spec/controllers/spree/api/v1/return_authorizations_controller_spec.rb +0 -161
  42. data/spec/controllers/spree/api/v1/shipments_controller_spec.rb +0 -187
  43. data/spec/controllers/spree/api/v1/states_controller_spec.rb +0 -86
  44. data/spec/controllers/spree/api/v1/stock_items_controller_spec.rb +0 -143
  45. data/spec/controllers/spree/api/v1/stock_locations_controller_spec.rb +0 -113
  46. data/spec/controllers/spree/api/v1/stock_movements_controller_spec.rb +0 -84
  47. data/spec/controllers/spree/api/v1/stores_controller_spec.rb +0 -133
  48. data/spec/controllers/spree/api/v1/taxonomies_controller_spec.rb +0 -114
  49. data/spec/controllers/spree/api/v1/taxons_controller_spec.rb +0 -177
  50. data/spec/controllers/spree/api/v1/unauthenticated_products_controller_spec.rb +0 -26
  51. data/spec/controllers/spree/api/v1/users_controller_spec.rb +0 -153
  52. data/spec/controllers/spree/api/v1/variants_controller_spec.rb +0 -205
  53. data/spec/controllers/spree/api/v1/zones_controller_spec.rb +0 -91
  54. data/spec/fixtures/thinking-cat.jpg +0 -0
  55. data/spec/models/spree/legacy_user_spec.rb +0 -19
  56. data/spec/requests/rabl_cache_spec.rb +0 -32
  57. data/spec/requests/ransackable_attributes_spec.rb +0 -79
  58. data/spec/requests/version_spec.rb +0 -19
  59. data/spec/shared_examples/protect_product_actions.rb +0 -17
  60. data/spec/spec_helper.rb +0 -55
  61. data/spec/support/controller_hacks.rb +0 -33
  62. data/spec/support/database_cleaner.rb +0 -14
  63. data/spec/support/have_attributes_matcher.rb +0 -13
@@ -1,48 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Spree
4
- describe Api::V1::CountriesController, :type => :controller do
5
- render_views
6
-
7
- before do
8
- stub_authentication!
9
- @state = create(:state)
10
- @country = @state.country
11
- end
12
-
13
- it "gets all countries" do
14
- api_get :index
15
- expect(json_response['countries'].first['iso3']).to eq @country.iso3
16
- end
17
-
18
- context "with two countries" do
19
- before { @zambia = create(:country, :name => "Zambia") }
20
-
21
- it "can view all countries" do
22
- api_get :index
23
- expect(json_response['count']).to eq(2)
24
- expect(json_response['current_page']).to eq(1)
25
- expect(json_response['pages']).to eq(1)
26
- end
27
-
28
- it 'can query the results through a paramter' do
29
- api_get :index, :q => { :name_cont => 'zam' }
30
- expect(json_response['count']).to eq(1)
31
- expect(json_response['countries'].first['name']).to eq @zambia.name
32
- end
33
-
34
- it 'can control the page size through a parameter' do
35
- api_get :index, :per_page => 1
36
- expect(json_response['count']).to eq(1)
37
- expect(json_response['current_page']).to eq(1)
38
- expect(json_response['pages']).to eq(2)
39
- end
40
- end
41
-
42
- it "includes states" do
43
- api_get :show, :id => @country.id
44
- states = json_response['states']
45
- expect(states.first['name']).to eq @state.name
46
- end
47
- end
48
- end
@@ -1,80 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Spree
4
- describe Api::V1::CreditCardsController, :type => :controller do
5
- render_views
6
-
7
- let!(:admin_user) do
8
- user = Spree.user_class.new(:email => "spree@example.com", :id => 1)
9
- user.generate_spree_api_key!
10
- allow(user).to receive(:has_spree_role?).with('admin').and_return(true)
11
- user
12
- end
13
-
14
- let!(:normal_user) do
15
- user = Spree.user_class.new(:email => "spree2@example.com", :id => 2)
16
- user.generate_spree_api_key!
17
- user
18
- end
19
-
20
- let!(:card) { create(:credit_card, :user_id => admin_user.id, gateway_customer_profile_id: "random") }
21
-
22
- before do
23
- stub_authentication!
24
- end
25
-
26
- it "the user id doesn't exist" do
27
- api_get :index, user_id: 1000
28
- expect(response.status).to eq(404)
29
- end
30
-
31
- context "calling user is in admin role" do
32
- let(:current_api_user) do
33
- user = admin_user
34
- user
35
- end
36
-
37
- it "no credit cards exist for user" do
38
- api_get :index, user_id: normal_user.id
39
-
40
- expect(response.status).to eq(200)
41
- expect(json_response["pages"]).to eq(0)
42
- end
43
-
44
- it "can view all credit cards for user" do
45
- api_get :index, user_id: current_api_user.id
46
-
47
- expect(response.status).to eq(200)
48
- expect(json_response["pages"]).to eq(1)
49
- expect(json_response["current_page"]).to eq(1)
50
- expect(json_response["credit_cards"].length).to eq(1)
51
- expect(json_response["credit_cards"].first["id"]).to eq(card.id)
52
- end
53
- end
54
-
55
- context "calling user is not in admin role" do
56
- let(:current_api_user) do
57
- user = normal_user
58
- user
59
- end
60
-
61
- let!(:card) { create(:credit_card, :user_id => normal_user.id, gateway_customer_profile_id: "random") }
62
-
63
- it "can not view user" do
64
- api_get :index, user_id: admin_user.id
65
-
66
- expect(response.status).to eq(404)
67
- end
68
-
69
- it "can view own credit cards" do
70
- api_get :index, user_id: normal_user.id
71
-
72
- expect(response.status).to eq(200)
73
- expect(json_response["pages"]).to eq(1)
74
- expect(json_response["current_page"]).to eq(1)
75
- expect(json_response["credit_cards"].length).to eq(1)
76
- expect(json_response["credit_cards"].first["id"]).to eq(card.id)
77
- end
78
- end
79
- end
80
- end
@@ -1,115 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Spree
4
- describe Api::V1::ImagesController, :type => :controller do
5
- render_views
6
-
7
- let!(:product) { create(:product) }
8
- let!(:attributes) { [:id, :position, :attachment_content_type,
9
- :attachment_file_name, :type, :attachment_updated_at, :attachment_width,
10
- :attachment_height, :alt] }
11
-
12
- before do
13
- stub_authentication!
14
- end
15
-
16
- context "as an admin" do
17
- sign_in_as_admin!
18
-
19
- it "can learn how to create a new image" do
20
- api_get :new, product_id: product.id
21
- expect(json_response["attributes"]).to eq(attributes.map(&:to_s))
22
- expect(json_response["required_attributes"]).to be_empty
23
- end
24
-
25
- it "can upload a new image for a variant" do
26
- expect do
27
- api_post :create,
28
- :image => { :attachment => upload_image('thinking-cat.jpg'),
29
- :viewable_type => 'Spree::Variant',
30
- :viewable_id => product.master.to_param },
31
- :product_id => product.id
32
- expect(response.status).to eq(201)
33
- expect(json_response).to have_attributes(attributes)
34
- end.to change(Image, :count).by(1)
35
- end
36
-
37
- it "can't upload a new image for a variant without attachment" do
38
- api_post :create,
39
- image: { viewable_type: 'Spree::Variant',
40
- viewable_id: product.master.to_param
41
- },
42
- product_id: product.id
43
- expect(response.status).to eq(422)
44
- end
45
-
46
- context "working with an existing image" do
47
- let!(:product_image) { product.master.images.create!(:attachment => image('thinking-cat.jpg')) }
48
-
49
- it "can get a single product image" do
50
- api_get :show, :id => product_image.id, :product_id => product.id
51
- expect(response.status).to eq(200)
52
- expect(json_response).to have_attributes(attributes)
53
- end
54
-
55
- it "can get a single variant image" do
56
- api_get :show, :id => product_image.id, :variant_id => product.master.id
57
- expect(response.status).to eq(200)
58
- expect(json_response).to have_attributes(attributes)
59
- end
60
-
61
- it "can get a list of product images" do
62
- api_get :index, :product_id => product.id
63
- expect(response.status).to eq(200)
64
- expect(json_response).to have_key("images")
65
- expect(json_response["images"].first).to have_attributes(attributes)
66
- end
67
-
68
- it "can get a list of variant images" do
69
- api_get :index, :variant_id => product.master.id
70
- expect(response.status).to eq(200)
71
- expect(json_response).to have_key("images")
72
- expect(json_response["images"].first).to have_attributes(attributes)
73
- end
74
-
75
- it "can update image data" do
76
- expect(product_image.position).to eq(1)
77
- api_post :update, :image => { :position => 2 }, :id => product_image.id, :product_id => product.id
78
- expect(response.status).to eq(200)
79
- expect(json_response).to have_attributes(attributes)
80
- expect(product_image.reload.position).to eq(2)
81
- end
82
-
83
- it "can't update a image without attachment" do
84
- api_post :update,
85
- image: { attachment: nil },
86
- id: product_image.id, product_id: product.id
87
- expect(response.status).to eq(422)
88
- end
89
-
90
- it "can delete an image" do
91
- api_delete :destroy, :id => product_image.id, :product_id => product.id
92
- expect(response.status).to eq(204)
93
- expect { product_image.reload }.to raise_error(ActiveRecord::RecordNotFound)
94
- end
95
- end
96
- end
97
-
98
- context "as a non-admin" do
99
- it "cannot create an image" do
100
- api_post :create, :product_id => product.id
101
- assert_unauthorized!
102
- end
103
-
104
- it "cannot update an image" do
105
- api_put :update, :id => 1, :product_id => product.id
106
- assert_not_found!
107
- end
108
-
109
- it "cannot delete an image" do
110
- api_delete :destroy, :id => 1, :product_id => product.id
111
- assert_not_found!
112
- end
113
- end
114
- end
115
- end
@@ -1,49 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Spree
4
- describe Api::V1::InventoryUnitsController, :type => :controller do
5
- render_views
6
-
7
- before do
8
- stub_authentication!
9
- @inventory_unit = create(:inventory_unit)
10
- end
11
-
12
- context "as an admin" do
13
- sign_in_as_admin!
14
-
15
- it "gets an inventory unit" do
16
- api_get :show, :id => @inventory_unit.id
17
- expect(json_response['state']).to eq @inventory_unit.state
18
- end
19
-
20
- it "updates an inventory unit (only shipment is accessable by default)" do
21
- api_put :update, :id => @inventory_unit.id,
22
- :inventory_unit => { :shipment => nil }
23
- expect(json_response['shipment_id']).to be_nil
24
- end
25
-
26
- context 'fires state event' do
27
- it 'if supplied with :fire param' do
28
- api_put :update, :id => @inventory_unit.id,
29
- :fire => 'ship',
30
- :inventory_unit => { :shipment => nil }
31
-
32
- expect(json_response['state']).to eq 'shipped'
33
- end
34
-
35
- it 'and returns exception if cannot fire' do
36
- api_put :update, :id => @inventory_unit.id,
37
- :fire => 'return'
38
- expect(json_response['exception']).to match /cannot transition to return/
39
- end
40
-
41
- it 'and returns exception bad state' do
42
- api_put :update, :id => @inventory_unit.id,
43
- :fire => 'bad'
44
- expect(json_response['exception']).to match /cannot transition to bad/
45
- end
46
- end
47
- end
48
- end
49
- end
@@ -1,184 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Spree
4
- PermittedAttributes.module_eval do
5
- mattr_writer :line_item_attributes
6
- end
7
-
8
- unless PermittedAttributes.line_item_attributes.include? :some_option
9
- PermittedAttributes.line_item_attributes += [:some_option]
10
- end
11
-
12
- # This should go in an initializer
13
- Spree::Api::V1::LineItemsController.line_item_options += [:some_option]
14
-
15
- describe Api::V1::LineItemsController, :type => :controller do
16
- render_views
17
-
18
- let!(:order) { create(:order_with_line_items, line_items_count: 1) }
19
-
20
- let(:product) { create(:product) }
21
- let(:attributes) { [:id, :quantity, :price, :variant, :total, :display_amount, :single_display_amount] }
22
- let(:resource_scoping) { { :order_id => order.to_param } }
23
-
24
- before do
25
- stub_authentication!
26
- end
27
-
28
- it "can learn how to create a new line item" do
29
- api_get :new
30
- expect(json_response["attributes"]).to eq(["quantity", "price", "variant_id"])
31
- required_attributes = json_response["required_attributes"]
32
- expect(required_attributes).to include("quantity", "variant_id")
33
- end
34
-
35
- context "authenticating with a token" do
36
- it "can add a new line item to an existing order" do
37
- api_post :create, :line_item => { :variant_id => product.master.to_param, :quantity => 1 }, :order_token => order.guest_token
38
- expect(response.status).to eq(201)
39
- expect(json_response).to have_attributes(attributes)
40
- expect(json_response["variant"]["name"]).not_to be_blank
41
- end
42
-
43
- it "can add a new line item to an existing order with token in header" do
44
- request.headers["X-Spree-Order-Token"] = order.guest_token
45
- api_post :create, :line_item => { :variant_id => product.master.to_param, :quantity => 1 }
46
- expect(response.status).to eq(201)
47
- expect(json_response).to have_attributes(attributes)
48
- expect(json_response["variant"]["name"]).not_to be_blank
49
- end
50
- end
51
-
52
- context "as the order owner" do
53
- before do
54
- allow_any_instance_of(Order).to receive_messages :user => current_api_user
55
- end
56
-
57
- it "can add a new line item to an existing order" do
58
- api_post :create, :line_item => { :variant_id => product.master.to_param, :quantity => 1 }
59
- expect(response.status).to eq(201)
60
- expect(json_response).to have_attributes(attributes)
61
- expect(json_response["variant"]["name"]).not_to be_blank
62
- end
63
-
64
- it "can add a new line item to an existing order with options" do
65
- expect_any_instance_of(LineItem).to receive(:some_option=).with(4)
66
- api_post :create,
67
- line_item: {
68
- variant_id: product.master.to_param,
69
- quantity: 1,
70
- options: { some_option: 4 }
71
- }
72
- expect(response.status).to eq(201)
73
- end
74
-
75
- it "default quantity to 1 if none is given" do
76
- api_post :create, :line_item => { :variant_id => product.master.to_param }
77
- expect(response.status).to eq(201)
78
- expect(json_response).to have_attributes(attributes)
79
- expect(json_response[:quantity]).to eq 1
80
- end
81
-
82
- it "increases a line item's quantity if it exists already" do
83
- order.line_items.create(:variant_id => product.master.id, :quantity => 10)
84
- api_post :create, :line_item => { :variant_id => product.master.to_param, :quantity => 1 }
85
- expect(response.status).to eq(201)
86
- order.reload
87
- expect(order.line_items.count).to eq(2) # 1 original due to factory, + 1 in this test
88
- expect(json_response).to have_attributes(attributes)
89
- expect(json_response["quantity"]).to eq(11)
90
- end
91
-
92
- it "can update a line item on the order" do
93
- line_item = order.line_items.first
94
- api_put :update, :id => line_item.id, :line_item => { :quantity => 101 }
95
- expect(response.status).to eq(200)
96
- order.reload
97
- expect(order.total).to eq(1010) # 10 original due to factory, + 1000 in this test
98
- expect(json_response).to have_attributes(attributes)
99
- expect(json_response["quantity"]).to eq(101)
100
- end
101
-
102
- it "can update a line item's options on the order" do
103
- expect_any_instance_of(LineItem).to receive(:some_option=).with(12)
104
- line_item = order.line_items.first
105
- api_put :update,
106
- id: line_item.id,
107
- line_item: { quantity: 1, options: { some_option: 12 } }
108
- expect(response.status).to eq(200)
109
- end
110
-
111
- it "can delete a line item on the order" do
112
- line_item = order.line_items.first
113
- api_delete :destroy, :id => line_item.id
114
- expect(response.status).to eq(204)
115
- order.reload
116
- expect(order.line_items.count).to eq(0) # 1 original due to factory, - 1 in this test
117
- expect { line_item.reload }.to raise_error(ActiveRecord::RecordNotFound)
118
- end
119
-
120
- context "order contents changed after shipments were created" do
121
- let!(:order) { Order.create }
122
- let!(:line_item) { order.contents.add(product.master) }
123
-
124
- before { order.create_proposed_shipments }
125
-
126
- it "clear out shipments on create" do
127
- expect(order.reload.shipments).not_to be_empty
128
- api_post :create, :line_item => { :variant_id => product.master.to_param, :quantity => 1 }
129
- expect(order.reload.shipments).to be_empty
130
- end
131
-
132
- it "clear out shipments on update" do
133
- expect(order.reload.shipments).not_to be_empty
134
- api_put :update, :id => line_item.id, :line_item => { :quantity => 1000 }
135
- expect(order.reload.shipments).to be_empty
136
- end
137
-
138
- it "clear out shipments on delete" do
139
- expect(order.reload.shipments).not_to be_empty
140
- api_delete :destroy, :id => line_item.id
141
- expect(order.reload.shipments).to be_empty
142
- end
143
-
144
- context "order is completed" do
145
- before do
146
- allow(order).to receive_messages completed?: true
147
- allow(Order).to receive_message_chain :includes, find_by!: order
148
- end
149
-
150
- it "doesn't destroy shipments or restart checkout flow" do
151
- expect(order.reload.shipments).not_to be_empty
152
- api_post :create, :line_item => { :variant_id => product.master.to_param, :quantity => 1 }
153
- expect(order.reload.shipments).not_to be_empty
154
- end
155
- end
156
- end
157
- end
158
-
159
- context "as just another user" do
160
- before do
161
- user = create(:user)
162
- end
163
-
164
- it "cannot add a new line item to the order" do
165
- api_post :create, :line_item => { :variant_id => product.master.to_param, :quantity => 1 }
166
- assert_unauthorized!
167
- end
168
-
169
- it "cannot update a line item on the order" do
170
- line_item = order.line_items.first
171
- api_put :update, :id => line_item.id, :line_item => { :quantity => 1000 }
172
- assert_unauthorized!
173
- expect(line_item.reload.quantity).not_to eq(1000)
174
- end
175
-
176
- it "cannot delete a line item on the order" do
177
- line_item = order.line_items.first
178
- api_delete :destroy, :id => line_item.id
179
- assert_unauthorized!
180
- expect { line_item.reload }.not_to raise_error
181
- end
182
- end
183
- end
184
- end