spree_api 3.3.0.rc1 → 3.3.0.rc2

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 (49) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/spree/api/v1/users_controller.rb +9 -1
  3. data/config/routes.rb +7 -1
  4. data/spree_api.gemspec +1 -2
  5. metadata +6 -94
  6. data/spec/controllers/spree/api/base_controller_spec.rb +0 -84
  7. data/spec/controllers/spree/api/v1/addresses_controller_spec.rb +0 -56
  8. data/spec/controllers/spree/api/v1/checkouts_controller_spec.rb +0 -361
  9. data/spec/controllers/spree/api/v1/classifications_controller_spec.rb +0 -48
  10. data/spec/controllers/spree/api/v1/countries_controller_spec.rb +0 -48
  11. data/spec/controllers/spree/api/v1/credit_cards_controller_spec.rb +0 -80
  12. data/spec/controllers/spree/api/v1/customer_returns_controller_spec.rb +0 -27
  13. data/spec/controllers/spree/api/v1/images_controller_spec.rb +0 -114
  14. data/spec/controllers/spree/api/v1/inventory_units_controller_spec.rb +0 -48
  15. data/spec/controllers/spree/api/v1/line_items_controller_spec.rb +0 -210
  16. data/spec/controllers/spree/api/v1/option_types_controller_spec.rb +0 -122
  17. data/spec/controllers/spree/api/v1/option_values_controller_spec.rb +0 -141
  18. data/spec/controllers/spree/api/v1/orders_controller_spec.rb +0 -735
  19. data/spec/controllers/spree/api/v1/payments_controller_spec.rb +0 -234
  20. data/spec/controllers/spree/api/v1/product_properties_controller_spec.rb +0 -156
  21. data/spec/controllers/spree/api/v1/products_controller_spec.rb +0 -409
  22. data/spec/controllers/spree/api/v1/promotion_application_spec.rb +0 -50
  23. data/spec/controllers/spree/api/v1/promotions_controller_spec.rb +0 -64
  24. data/spec/controllers/spree/api/v1/properties_controller_spec.rb +0 -102
  25. data/spec/controllers/spree/api/v1/reimbursements_controller_spec.rb +0 -24
  26. data/spec/controllers/spree/api/v1/return_authorizations_controller_spec.rb +0 -161
  27. data/spec/controllers/spree/api/v1/shipments_controller_spec.rb +0 -187
  28. data/spec/controllers/spree/api/v1/states_controller_spec.rb +0 -86
  29. data/spec/controllers/spree/api/v1/stock_items_controller_spec.rb +0 -151
  30. data/spec/controllers/spree/api/v1/stock_locations_controller_spec.rb +0 -113
  31. data/spec/controllers/spree/api/v1/stock_movements_controller_spec.rb +0 -84
  32. data/spec/controllers/spree/api/v1/stores_controller_spec.rb +0 -133
  33. data/spec/controllers/spree/api/v1/tags_controller_spec.rb +0 -102
  34. data/spec/controllers/spree/api/v1/taxonomies_controller_spec.rb +0 -114
  35. data/spec/controllers/spree/api/v1/taxons_controller_spec.rb +0 -177
  36. data/spec/controllers/spree/api/v1/unauthenticated_products_controller_spec.rb +0 -26
  37. data/spec/controllers/spree/api/v1/users_controller_spec.rb +0 -153
  38. data/spec/controllers/spree/api/v1/variants_controller_spec.rb +0 -205
  39. data/spec/controllers/spree/api/v1/zones_controller_spec.rb +0 -91
  40. data/spec/fixtures/thinking-cat.jpg +0 -0
  41. data/spec/models/spree/legacy_user_spec.rb +0 -19
  42. data/spec/requests/rabl_cache_spec.rb +0 -32
  43. data/spec/requests/ransackable_attributes_spec.rb +0 -79
  44. data/spec/requests/version_spec.rb +0 -19
  45. data/spec/shared_examples/protect_product_actions.rb +0 -17
  46. data/spec/spec_helper.rb +0 -63
  47. data/spec/support/controller_hacks.rb +0 -40
  48. data/spec/support/database_cleaner.rb +0 -14
  49. 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::ClassificationsController, type: :controller do
5
- let(:taxon) do
6
- taxon = create(:taxon)
7
-
8
- 3.times do
9
- product = create(:product)
10
- product.taxons << taxon
11
- end
12
- taxon
13
- end
14
-
15
- before do
16
- stub_authentication!
17
- end
18
-
19
- context "as a user" do
20
- it "cannot change the order of a product" do
21
- api_put :update, taxon_id: taxon, product_id: taxon.products.first, position: 1
22
- expect(response.status).to eq(401)
23
- end
24
- end
25
-
26
- context "as an admin" do
27
- sign_in_as_admin!
28
-
29
- let(:last_product) { taxon.products.last }
30
-
31
- it "can change the order a product" do
32
- classification = taxon.classifications.find_by(product_id: last_product.id)
33
- expect(classification.position).to eq(3)
34
- api_put :update, taxon_id: taxon.id, product_id: last_product.id, position: 0
35
- expect(response.status).to eq(200)
36
- expect(classification.reload.position).to eq(1)
37
- end
38
-
39
- it "should touch the taxon" do
40
- taxon.update_attributes(updated_at: Time.current - 10.seconds)
41
- taxon_last_updated_at = taxon.updated_at
42
- api_put :update, taxon_id: taxon.id, product_id: last_product.id, position: 0
43
- taxon.reload
44
- expect(taxon_last_updated_at.to_i).to_not eq(taxon.updated_at.to_i)
45
- end
46
- end
47
- end
48
- end
@@ -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,27 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Spree
4
- describe Api::V1::CustomerReturnsController, type: :controller do
5
- render_views
6
-
7
- before do
8
- stub_authentication!
9
- @customer_return = create(:customer_return)
10
- end
11
-
12
- describe '#index' do
13
- let(:order) { customer_return.order }
14
- let(:customer_return) { create(:customer_return) }
15
-
16
- before do
17
- api_get :index
18
- end
19
-
20
- it 'loads customer returns' do
21
- expect(response.status).to eq(200)
22
- expect(json_response['count']).to eq(1)
23
- end
24
- end
25
- end
26
- end
27
-
@@ -1,114 +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 an image without attachment" do
84
- api_post :update,
85
- id: product_image.id, product_id: product.id
86
- expect(response.status).to eq(422)
87
- end
88
-
89
- it "can delete an image" do
90
- api_delete :destroy, id: product_image.id, product_id: product.id
91
- expect(response.status).to eq(204)
92
- expect { product_image.reload }.to raise_error(ActiveRecord::RecordNotFound)
93
- end
94
- end
95
- end
96
-
97
- context "as a non-admin" do
98
- it "cannot create an image" do
99
- api_post :create, product_id: product.id
100
- assert_unauthorized!
101
- end
102
-
103
- it "cannot update an image" do
104
- api_put :update, id: 1, product_id: product.id
105
- assert_not_found!
106
- end
107
-
108
- it "cannot delete an image" do
109
- api_delete :destroy, id: 1, product_id: product.id
110
- assert_not_found!
111
- end
112
- end
113
- end
114
- end
@@ -1,48 +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" do
21
- api_put :update, id: @inventory_unit.id,
22
- inventory_unit: { shipment_id: 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: { tracking: 'foobar' } }
31
- expect(json_response['state']).to eq 'shipped'
32
- end
33
-
34
- it 'and returns exception if cannot fire' do
35
- api_put :update, id: @inventory_unit.id,
36
- fire: 'return'
37
- expect(json_response['exception']).to match /cannot transition to return/
38
- end
39
-
40
- it 'and returns exception bad state' do
41
- api_put :update, id: @inventory_unit.id,
42
- fire: 'bad'
43
- expect(json_response['exception']).to match /cannot transition to bad/
44
- end
45
- end
46
- end
47
- end
48
- end
@@ -1,210 +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("foo")
66
- api_post :create,
67
- line_item: {
68
- variant_id: product.master.to_param,
69
- quantity: 1,
70
- options: { some_option: "foo" }
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("foo")
104
- line_item = order.line_items.first
105
- api_put :update,
106
- id: line_item.id,
107
- line_item: { quantity: 1, options: { some_option: "foo" } }
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
- order.reload
147
- allow(order).to receive_messages completed?: true
148
- allow(Order).to receive_message_chain :includes, find_by!: order
149
- end
150
-
151
- it "doesn't destroy shipments or restart checkout flow" do
152
- expect(order.reload.shipments).not_to be_empty
153
- api_post :create, line_item: { variant_id: product.master.to_param, quantity: 1 }
154
- expect(order.reload.shipments).not_to be_empty
155
- end
156
-
157
- context 'deleting line items' do
158
- let(:shipments) { order.shipments.load }
159
-
160
- before(:each) do
161
- allow(order).to receive(:shipments).and_return(shipments)
162
- end
163
-
164
- it 'restocks product after line item removal' do
165
- line_item = order.line_items.first
166
- variant = line_item.variant
167
- expect do
168
- api_delete :destroy, id: line_item.id
169
- end.to change { variant.total_on_hand }.by(line_item.quantity)
170
-
171
- expect(response.status).to eq(204)
172
- order.reload
173
- expect(order.line_items.count).to eq(0)
174
- end
175
-
176
- it 'calls `restock` on proper stock location' do
177
- expect(shipments.first.stock_location).to receive(:restock)
178
- api_delete :destroy, id: line_item.id
179
- end
180
- end
181
- end
182
- end
183
- end
184
-
185
- context "as just another user" do
186
- before do
187
- user = create(:user)
188
- end
189
-
190
- it "cannot add a new line item to the order" do
191
- api_post :create, line_item: { variant_id: product.master.to_param, quantity: 1 }
192
- assert_unauthorized!
193
- end
194
-
195
- it "cannot update a line item on the order" do
196
- line_item = order.line_items.first
197
- api_put :update, id: line_item.id, line_item: { quantity: 1000 }
198
- assert_unauthorized!
199
- expect(line_item.reload.quantity).not_to eq(1000)
200
- end
201
-
202
- it "cannot delete a line item on the order" do
203
- line_item = order.line_items.first
204
- api_delete :destroy, id: line_item.id
205
- assert_unauthorized!
206
- expect { line_item.reload }.not_to raise_error
207
- end
208
- end
209
- end
210
- end