spree_api 2.4.0.rc2 → 2.4.0.rc3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/spree/api/base_controller.rb +4 -6
  3. data/app/controllers/spree/api/option_types_controller.rb +2 -2
  4. data/app/controllers/spree/api/orders_controller.rb +9 -1
  5. data/app/controllers/spree/api/return_authorizations_controller.rb +0 -9
  6. data/app/controllers/spree/api/taxons_controller.rb +3 -3
  7. data/app/helpers/spree/api/api_helpers.rb +0 -2
  8. data/app/views/spree/api/orders/show.v1.rabl +4 -0
  9. data/app/views/spree/api/products/show.v1.rabl +4 -0
  10. data/app/views/spree/api/shipments/small.v1.rabl +4 -0
  11. data/lib/spree/api/testing_support/helpers.rb +6 -6
  12. data/lib/spree/api/testing_support/setup.rb +2 -2
  13. data/spec/controllers/spree/api/addresses_controller_spec.rb +8 -8
  14. data/spec/controllers/spree/api/base_controller_spec.rb +22 -22
  15. data/spec/controllers/spree/api/checkouts_controller_spec.rb +53 -53
  16. data/spec/controllers/spree/api/classifications_controller_spec.rb +5 -5
  17. data/spec/controllers/spree/api/config_controller_spec.rb +9 -9
  18. data/spec/controllers/spree/api/countries_controller_spec.rb +11 -11
  19. data/spec/controllers/spree/api/credit_cards_controller_spec.rb +16 -16
  20. data/spec/controllers/spree/api/images_controller_spec.rb +21 -21
  21. data/spec/controllers/spree/api/inventory_units_controller_spec.rb +6 -6
  22. data/spec/controllers/spree/api/line_items_controller_spec.rb +33 -33
  23. data/spec/controllers/spree/api/option_types_controller_spec.rb +19 -19
  24. data/spec/controllers/spree/api/option_values_controller_spec.rb +23 -23
  25. data/spec/controllers/spree/api/orders_controller_spec.rb +186 -143
  26. data/spec/controllers/spree/api/payments_controller_spec.rb +39 -39
  27. data/spec/controllers/spree/api/product_properties_controller_spec.rb +21 -21
  28. data/spec/controllers/spree/api/products_controller_spec.rb +71 -66
  29. data/spec/controllers/spree/api/promotion_application_spec.rb +13 -13
  30. data/spec/controllers/spree/api/promotions_controller_spec.rb +1 -1
  31. data/spec/controllers/spree/api/properties_controller_spec.rb +25 -25
  32. data/spec/controllers/spree/api/return_authorizations_controller_spec.rb +27 -36
  33. data/spec/controllers/spree/api/shipments_controller_spec.rb +22 -22
  34. data/spec/controllers/spree/api/states_controller_spec.rb +18 -18
  35. data/spec/controllers/spree/api/stock_items_controller_spec.rb +26 -26
  36. data/spec/controllers/spree/api/stock_locations_controller_spec.rb +22 -22
  37. data/spec/controllers/spree/api/stock_movements_controller_spec.rb +16 -16
  38. data/spec/controllers/spree/api/taxonomies_controller_spec.rb +24 -24
  39. data/spec/controllers/spree/api/taxons_controller_spec.rb +39 -39
  40. data/spec/controllers/spree/api/unauthenticated_products_controller_spec.rb +6 -6
  41. data/spec/controllers/spree/api/users_controller_spec.rb +25 -25
  42. data/spec/controllers/spree/api/variants_controller_spec.rb +36 -36
  43. data/spec/controllers/spree/api/zones_controller_spec.rb +20 -20
  44. data/spec/models/spree/legacy_user_spec.rb +5 -5
  45. data/spec/requests/rabl_cache_spec.rb +9 -9
  46. data/spec/spec_helper.rb +0 -1
  47. data/spec/support/controller_hacks.rb +4 -0
  48. metadata +4 -4
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  module Spree
4
- describe Api::ClassificationsController do
4
+ describe Api::ClassificationsController, :type => :controller do
5
5
  let(:taxon) do
6
6
  taxon = create(:taxon)
7
7
  3.times do
@@ -18,7 +18,7 @@ module Spree
18
18
  context "as a user" do
19
19
  it "cannot change the order of a product" do
20
20
  api_put :update, :taxon_id => taxon, :product_id => taxon.products.first, :position => 1
21
- response.status.should == 401
21
+ expect(response.status).to eq(401)
22
22
  end
23
23
  end
24
24
 
@@ -28,10 +28,10 @@ module Spree
28
28
  it "can change the order a product" do
29
29
  last_product = taxon.products.last
30
30
  classification = taxon.classifications.find_by(:product_id => last_product.id)
31
- classification.position.should == 3
31
+ expect(classification.position).to eq(3)
32
32
  api_put :update, :taxon_id => taxon, :product_id => last_product, :position => 0
33
- response.status.should == 200
34
- classification.reload.position.should == 1
33
+ expect(response.status).to eq(200)
34
+ expect(classification.reload.position).to eq(1)
35
35
  end
36
36
  end
37
37
  end
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  module Spree
4
- describe Api::ConfigController do
4
+ describe Api::ConfigController, :type => :controller do
5
5
  render_views
6
6
 
7
7
  before do
@@ -10,18 +10,18 @@ module Spree
10
10
 
11
11
  it "returns Spree::Money settings" do
12
12
  api_get :money
13
- response.should be_success
14
- json_response["symbol"].should == "$"
15
- json_response["symbol_position"].should == "before"
16
- json_response["no_cents"].should == false
17
- json_response["decimal_mark"].should == "."
18
- json_response["thousands_separator"].should == ","
13
+ expect(response).to be_success
14
+ expect(json_response["symbol"]).to eq("$")
15
+ expect(json_response["symbol_position"]).to eq("before")
16
+ expect(json_response["no_cents"]).to eq(false)
17
+ expect(json_response["decimal_mark"]).to eq(".")
18
+ expect(json_response["thousands_separator"]).to eq(",")
19
19
  end
20
20
 
21
21
  it "returns some configuration settings" do
22
22
  api_get :show
23
- response.should be_success
24
- json_response["default_country_id"].should == Spree::Config[:default_country_id]
23
+ expect(response).to be_success
24
+ expect(json_response["default_country_id"]).to eq(Spree::Config[:default_country_id])
25
25
  end
26
26
  end
27
27
  end
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  module Spree
4
- describe Api::CountriesController do
4
+ describe Api::CountriesController, :type => :controller do
5
5
  render_views
6
6
 
7
7
  before do
@@ -12,7 +12,7 @@ module Spree
12
12
 
13
13
  it "gets all countries" do
14
14
  api_get :index
15
- json_response['countries'].first['iso3'].should eq @country.iso3
15
+ expect(json_response['countries'].first['iso3']).to eq @country.iso3
16
16
  end
17
17
 
18
18
  context "with two countries" do
@@ -20,29 +20,29 @@ module Spree
20
20
 
21
21
  it "can view all countries" do
22
22
  api_get :index
23
- json_response['count'].should == 2
24
- json_response['current_page'].should == 1
25
- json_response['pages'].should == 1
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
26
  end
27
27
 
28
28
  it 'can query the results through a paramter' do
29
29
  api_get :index, :q => { :name_cont => 'zam' }
30
- json_response['count'].should == 1
31
- json_response['countries'].first['name'].should eq @zambia.name
30
+ expect(json_response['count']).to eq(1)
31
+ expect(json_response['countries'].first['name']).to eq @zambia.name
32
32
  end
33
33
 
34
34
  it 'can control the page size through a parameter' do
35
35
  api_get :index, :per_page => 1
36
- json_response['count'].should == 1
37
- json_response['current_page'].should == 1
38
- json_response['pages'].should == 2
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
39
  end
40
40
  end
41
41
 
42
42
  it "includes states" do
43
43
  api_get :show, :id => @country.id
44
44
  states = json_response['states']
45
- states.first['name'].should eq @state.name
45
+ expect(states.first['name']).to eq @state.name
46
46
  end
47
47
  end
48
48
  end
@@ -1,13 +1,13 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  module Spree
4
- describe Api::CreditCardsController do
4
+ describe Api::CreditCardsController, :type => :controller do
5
5
  render_views
6
6
 
7
7
  let!(:admin_user) do
8
8
  user = Spree.user_class.new(:email => "spree@example.com", :id => 1)
9
9
  user.generate_spree_api_key!
10
- user.stub(:has_spree_role?).with('admin').and_return(true)
10
+ allow(user).to receive(:has_spree_role?).with('admin').and_return(true)
11
11
  user
12
12
  end
13
13
 
@@ -25,7 +25,7 @@ module Spree
25
25
 
26
26
  it "the user id doesn't exist" do
27
27
  api_get :index, user_id: 1000
28
- response.status.should == 404
28
+ expect(response.status).to eq(404)
29
29
  end
30
30
 
31
31
  context "calling user is in admin role" do
@@ -37,18 +37,18 @@ module Spree
37
37
  it "no credit cards exist for user" do
38
38
  api_get :index, user_id: normal_user.id
39
39
 
40
- response.status.should == 200
41
- json_response["pages"].should == 0
40
+ expect(response.status).to eq(200)
41
+ expect(json_response["pages"]).to eq(0)
42
42
  end
43
43
 
44
44
  it "can view all credit cards for user" do
45
45
  api_get :index, user_id: current_api_user.id
46
46
 
47
- response.status.should == 200
48
- json_response["pages"].should == 1
49
- json_response["current_page"].should == 1
50
- json_response["credit_cards"].length.should == 1
51
- json_response["credit_cards"].first["id"].should == card.id
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
52
  end
53
53
  end
54
54
 
@@ -63,17 +63,17 @@ module Spree
63
63
  it "can not view user" do
64
64
  api_get :index, user_id: admin_user.id
65
65
 
66
- response.status.should == 404
66
+ expect(response.status).to eq(404)
67
67
  end
68
68
 
69
69
  it "can view own credit cards" do
70
70
  api_get :index, user_id: normal_user.id
71
71
 
72
- response.status.should == 200
73
- json_response["pages"].should == 1
74
- json_response["current_page"].should == 1
75
- json_response["credit_cards"].length.should == 1
76
- json_response["credit_cards"].first["id"].should == card.id
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
77
  end
78
78
  end
79
79
  end
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  module Spree
4
- describe Spree::Api::ImagesController do
4
+ describe Spree::Api::ImagesController, :type => :controller do
5
5
  render_views
6
6
 
7
7
  let!(:product) { create(:product) }
@@ -17,15 +17,15 @@ module Spree
17
17
  sign_in_as_admin!
18
18
 
19
19
  it "can upload a new image for a variant" do
20
- lambda do
20
+ expect do
21
21
  api_post :create,
22
22
  :image => { :attachment => upload_image('thinking-cat.jpg'),
23
23
  :viewable_type => 'Spree::Variant',
24
24
  :viewable_id => product.master.to_param },
25
25
  :product_id => product.id
26
- response.status.should == 201
27
- json_response.should have_attributes(attributes)
28
- end.should change(Image, :count).by(1)
26
+ expect(response.status).to eq(201)
27
+ expect(json_response).to have_attributes(attributes)
28
+ end.to change(Image, :count).by(1)
29
29
  end
30
30
 
31
31
  context "working with an existing image" do
@@ -33,42 +33,42 @@ module Spree
33
33
 
34
34
  it "can get a single product image" do
35
35
  api_get :show, :id => product_image.id, :product_id => product.id
36
- response.status.should == 200
37
- json_response.should have_attributes(attributes)
36
+ expect(response.status).to eq(200)
37
+ expect(json_response).to have_attributes(attributes)
38
38
  end
39
39
 
40
40
  it "can get a single variant image" do
41
41
  api_get :show, :id => product_image.id, :variant_id => product.master.id
42
- response.status.should == 200
43
- json_response.should have_attributes(attributes)
42
+ expect(response.status).to eq(200)
43
+ expect(json_response).to have_attributes(attributes)
44
44
  end
45
45
 
46
46
  it "can get a list of product images" do
47
47
  api_get :index, :product_id => product.id
48
- response.status.should == 200
49
- json_response.should have_key("images")
50
- json_response["images"].first.should have_attributes(attributes)
48
+ expect(response.status).to eq(200)
49
+ expect(json_response).to have_key("images")
50
+ expect(json_response["images"].first).to have_attributes(attributes)
51
51
  end
52
52
 
53
53
  it "can get a list of variant images" do
54
54
  api_get :index, :variant_id => product.master.id
55
- response.status.should == 200
56
- json_response.should have_key("images")
57
- json_response["images"].first.should have_attributes(attributes)
55
+ expect(response.status).to eq(200)
56
+ expect(json_response).to have_key("images")
57
+ expect(json_response["images"].first).to have_attributes(attributes)
58
58
  end
59
59
 
60
60
  it "can update image data" do
61
- product_image.position.should == 1
61
+ expect(product_image.position).to eq(1)
62
62
  api_post :update, :image => { :position => 2 }, :id => product_image.id, :product_id => product.id
63
- response.status.should == 200
64
- json_response.should have_attributes(attributes)
65
- product_image.reload.position.should == 2
63
+ expect(response.status).to eq(200)
64
+ expect(json_response).to have_attributes(attributes)
65
+ expect(product_image.reload.position).to eq(2)
66
66
  end
67
67
 
68
68
  it "can delete an image" do
69
69
  api_delete :destroy, :id => product_image.id, :product_id => product.id
70
- response.status.should == 204
71
- lambda { product_image.reload }.should raise_error(ActiveRecord::RecordNotFound)
70
+ expect(response.status).to eq(204)
71
+ expect { product_image.reload }.to raise_error(ActiveRecord::RecordNotFound)
72
72
  end
73
73
  end
74
74
  end
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  module Spree
4
- describe Api::InventoryUnitsController do
4
+ describe Api::InventoryUnitsController, :type => :controller do
5
5
  render_views
6
6
 
7
7
  before do
@@ -14,13 +14,13 @@ module Spree
14
14
 
15
15
  it "gets an inventory unit" do
16
16
  api_get :show, :id => @inventory_unit.id
17
- json_response['state'].should eq @inventory_unit.state
17
+ expect(json_response['state']).to eq @inventory_unit.state
18
18
  end
19
19
 
20
20
  it "updates an inventory unit (only shipment is accessable by default)" do
21
21
  api_put :update, :id => @inventory_unit.id,
22
22
  :inventory_unit => { :shipment => nil }
23
- json_response['shipment_id'].should be_nil
23
+ expect(json_response['shipment_id']).to be_nil
24
24
  end
25
25
 
26
26
  context 'fires state event' do
@@ -29,19 +29,19 @@ module Spree
29
29
  :fire => 'ship',
30
30
  :inventory_unit => { :shipment => nil }
31
31
 
32
- json_response['state'].should eq 'shipped'
32
+ expect(json_response['state']).to eq 'shipped'
33
33
  end
34
34
 
35
35
  it 'and returns exception if cannot fire' do
36
36
  api_put :update, :id => @inventory_unit.id,
37
37
  :fire => 'return'
38
- json_response['exception'].should match /cannot transition to return/
38
+ expect(json_response['exception']).to match /cannot transition to return/
39
39
  end
40
40
 
41
41
  it 'and returns exception bad state' do
42
42
  api_put :update, :id => @inventory_unit.id,
43
43
  :fire => 'bad'
44
- json_response['exception'].should match /cannot transition to bad/
44
+ expect(json_response['exception']).to match /cannot transition to bad/
45
45
  end
46
46
  end
47
47
  end
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  module Spree
4
- describe Api::LineItemsController do
4
+ describe Api::LineItemsController, :type => :controller do
5
5
  render_views
6
6
 
7
7
  let!(:order) { create(:order_with_line_items, line_items_count: 1) }
@@ -11,77 +11,77 @@ module Spree
11
11
  let(:resource_scoping) { { :order_id => order.to_param } }
12
12
 
13
13
  it "can learn how to create a new line item" do
14
- controller.stub :try_spree_current_user => current_api_user
14
+ allow(controller).to receive_messages :try_spree_current_user => current_api_user
15
15
  api_get :new
16
- json_response["attributes"].should == ["quantity", "price", "variant_id"]
16
+ expect(json_response["attributes"]).to eq(["quantity", "price", "variant_id"])
17
17
  required_attributes = json_response["required_attributes"]
18
- required_attributes.should include("quantity", "variant_id")
18
+ expect(required_attributes).to include("quantity", "variant_id")
19
19
  end
20
20
 
21
21
  context "authenticating with a token" do
22
22
  it "can add a new line item to an existing order" do
23
23
  api_post :create, :line_item => { :variant_id => product.master.to_param, :quantity => 1 }, :order_token => order.guest_token
24
- response.status.should == 201
25
- json_response.should have_attributes(attributes)
26
- json_response["variant"]["name"].should_not be_blank
24
+ expect(response.status).to eq(201)
25
+ expect(json_response).to have_attributes(attributes)
26
+ expect(json_response["variant"]["name"]).not_to be_blank
27
27
  end
28
28
 
29
29
  it "can add a new line item to an existing order with token in header" do
30
30
  request.headers["X-Spree-Order-Token"] = order.guest_token
31
31
  api_post :create, :line_item => { :variant_id => product.master.to_param, :quantity => 1 }
32
- response.status.should == 201
33
- json_response.should have_attributes(attributes)
34
- json_response["variant"]["name"].should_not be_blank
32
+ expect(response.status).to eq(201)
33
+ expect(json_response).to have_attributes(attributes)
34
+ expect(json_response["variant"]["name"]).not_to be_blank
35
35
  end
36
36
  end
37
37
 
38
38
  context "as the order owner" do
39
39
  before do
40
- controller.stub :try_spree_current_user => current_api_user
41
- Order.any_instance.stub :user => current_api_user
40
+ allow(controller).to receive_messages :try_spree_current_user => current_api_user
41
+ allow_any_instance_of(Order).to receive_messages :user => current_api_user
42
42
  end
43
43
 
44
44
  it "can add a new line item to an existing order" do
45
45
  api_post :create, :line_item => { :variant_id => product.master.to_param, :quantity => 1 }
46
- response.status.should == 201
47
- json_response.should have_attributes(attributes)
48
- json_response["variant"]["name"].should_not be_blank
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
49
  end
50
50
 
51
51
  it "default quantity to 1 if none is given" do
52
52
  api_post :create, :line_item => { :variant_id => product.master.to_param }
53
- response.status.should == 201
54
- json_response.should have_attributes(attributes)
53
+ expect(response.status).to eq(201)
54
+ expect(json_response).to have_attributes(attributes)
55
55
  expect(json_response[:quantity]).to eq 1
56
56
  end
57
57
 
58
58
  it "increases a line item's quantity if it exists already" do
59
59
  order.line_items.create(:variant_id => product.master.id, :quantity => 10)
60
60
  api_post :create, :line_item => { :variant_id => product.master.to_param, :quantity => 1 }
61
- response.status.should == 201
61
+ expect(response.status).to eq(201)
62
62
  order.reload
63
- order.line_items.count.should == 2 # 1 original due to factory, + 1 in this test
64
- json_response.should have_attributes(attributes)
65
- json_response["quantity"].should == 11
63
+ expect(order.line_items.count).to eq(2) # 1 original due to factory, + 1 in this test
64
+ expect(json_response).to have_attributes(attributes)
65
+ expect(json_response["quantity"]).to eq(11)
66
66
  end
67
67
 
68
68
  it "can update a line item on the order" do
69
69
  line_item = order.line_items.first
70
70
  api_put :update, :id => line_item.id, :line_item => { :quantity => 101 }
71
- response.status.should == 200
71
+ expect(response.status).to eq(200)
72
72
  order.reload
73
- order.total.should == 1010 # 10 original due to factory, + 1000 in this test
74
- json_response.should have_attributes(attributes)
75
- json_response["quantity"].should == 101
73
+ expect(order.total).to eq(1010) # 10 original due to factory, + 1000 in this test
74
+ expect(json_response).to have_attributes(attributes)
75
+ expect(json_response["quantity"]).to eq(101)
76
76
  end
77
77
 
78
78
  it "can delete a line item on the order" do
79
79
  line_item = order.line_items.first
80
80
  api_delete :destroy, :id => line_item.id
81
- response.status.should == 204
81
+ expect(response.status).to eq(204)
82
82
  order.reload
83
- order.line_items.count.should == 0 # 1 original due to factory, - 1 in this test
84
- lambda { line_item.reload }.should raise_error(ActiveRecord::RecordNotFound)
83
+ expect(order.line_items.count).to eq(0) # 1 original due to factory, - 1 in this test
84
+ expect { line_item.reload }.to raise_error(ActiveRecord::RecordNotFound)
85
85
  end
86
86
 
87
87
  context "order contents changed after shipments were created" do
@@ -110,8 +110,8 @@ module Spree
110
110
 
111
111
  context "order is completed" do
112
112
  before do
113
- order.stub completed?: true
114
- Order.stub_chain :includes, find_by!: order
113
+ allow(order).to receive_messages completed?: true
114
+ allow(Order).to receive_message_chain :includes, find_by!: order
115
115
  end
116
116
 
117
117
  it "doesn't destroy shipments or restart checkout flow" do
@@ -126,7 +126,7 @@ module Spree
126
126
  context "as just another user" do
127
127
  before do
128
128
  user = create(:user)
129
- controller.stub :try_spree_current_user => user
129
+ allow(controller).to receive_messages :try_spree_current_user => user
130
130
  end
131
131
 
132
132
  it "cannot add a new line item to the order" do
@@ -138,14 +138,14 @@ module Spree
138
138
  line_item = order.line_items.first
139
139
  api_put :update, :id => line_item.id, :line_item => { :quantity => 1000 }
140
140
  assert_unauthorized!
141
- line_item.reload.quantity.should_not == 1000
141
+ expect(line_item.reload.quantity).not_to eq(1000)
142
142
  end
143
143
 
144
144
  it "cannot delete a line item on the order" do
145
145
  line_item = order.line_items.first
146
146
  api_delete :destroy, :id => line_item.id
147
147
  assert_unauthorized!
148
- lambda { line_item.reload }.should_not raise_error
148
+ expect { line_item.reload }.not_to raise_error
149
149
  end
150
150
  end
151
151
  end