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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 000f3c59be99481b14b2742325d274f133cabc00
4
- data.tar.gz: 01625468afdfecc7484af058fc6e74bb23e3f0a9
3
+ metadata.gz: b712d43706678d3c8d2bdc20f8d43fff8c97bd2e
4
+ data.tar.gz: cd84829e4d96b32d0da411588a7531b6855668a4
5
5
  SHA512:
6
- metadata.gz: 3b8c446b4667837e62be864f8293a1fbd5c4a24d2c0fd467197b1c50c3c55f6065ac0fe192b72825c2eee20cdb232464c6e73bc45b354008153cfbdf43c06e52
7
- data.tar.gz: 779a8935320852f6b76df950fb1e444c79a2fff2f5ce9989408d909d30ab9e4f003c681d6b26c32b2327457d08cfac108158b5f287c80083b9d07daecd5d4435
6
+ metadata.gz: ba4fb81a81896f4851cc69fd23a3816b77ef4b8ec7f484cb08dcfbc78a39a9ce136d3b64bcce8610a97b34a497e259b8a2e8724af4fad664d73bbf426acb1218
7
+ data.tar.gz: 8be64b301511026a1b6c22f938a1dc7d42b8ea651c65c70ba180a07437ae7be511decfdac3c5327d1480b0e8fe14bb2e081162fc59e10d027c79defd19bc432c
@@ -142,11 +142,9 @@ module Spree
142
142
  end
143
143
 
144
144
  def find_product(id)
145
- begin
146
- product_scope.friendly.find(id.to_s)
147
- rescue ActiveRecord::RecordNotFound
148
- product_scope.find(id)
149
- end
145
+ product_scope.friendly.find(id.to_s)
146
+ rescue ActiveRecord::RecordNotFound
147
+ product_scope.find(id)
150
148
  end
151
149
 
152
150
  def product_scope
@@ -168,7 +166,7 @@ module Spree
168
166
  end
169
167
 
170
168
  def product_includes
171
- [ :option_types, variants: variants_associations, master: variants_associations ]
169
+ [ :option_types, :taxons, product_properties: :property, variants: variants_associations, master: variants_associations ]
172
170
  end
173
171
 
174
172
  def order_id
@@ -3,9 +3,9 @@ module Spree
3
3
  class OptionTypesController < Spree::Api::BaseController
4
4
  def index
5
5
  if params[:ids]
6
- @option_types = Spree::OptionType.accessible_by(current_ability, :read).where(:id => params[:ids].split(','))
6
+ @option_types = Spree::OptionType.includes(:option_values).accessible_by(current_ability, :read).where(id: params[:ids].split(','))
7
7
  else
8
- @option_types = Spree::OptionType.accessible_by(current_ability, :read).load.ransack(params[:q]).result
8
+ @option_types = Spree::OptionType.includes(:option_values).accessible_by(current_ability, :read).load.ransack(params[:q]).result
9
9
  end
10
10
  respond_with(@option_types)
11
11
  end
@@ -59,7 +59,15 @@ module Spree
59
59
  find_order(true)
60
60
  authorize! :update, @order, order_token
61
61
 
62
- if @order.contents.update_cart(order_params)
62
+ result = if request.patch?
63
+ # This will update the order without a checkout reset.
64
+ @order.update_attributes(order_params)
65
+ else
66
+ # This will reset checkout back to address and delete all shipments.
67
+ @order.contents.update_cart(order_params)
68
+ end
69
+
70
+ if result
63
71
  user_id = params[:order][:user_id]
64
72
  if current_api_user.has_spree_role?('admin') && user_id
65
73
  @order.associate_user!(Spree.user_class.find(user_id))
@@ -45,15 +45,6 @@ module Spree
45
45
  end
46
46
  end
47
47
 
48
- def receive
49
- @return_authorization = order.return_authorizations.accessible_by(current_ability, :update).find(params[:id])
50
- if @return_authorization.receive
51
- respond_with @return_authorization, default_template: :show
52
- else
53
- invalid_resource!(@return_authorization)
54
- end
55
- end
56
-
57
48
  def cancel
58
49
  @return_authorization = order.return_authorizations.accessible_by(current_ability, :update).find(params[:id])
59
50
  if @return_authorization.cancel
@@ -6,9 +6,9 @@ module Spree
6
6
  @taxons = taxonomy.root.children
7
7
  else
8
8
  if params[:ids]
9
- @taxons = Spree::Taxon.accessible_by(current_ability, :read).where(id: params[:ids].split(','))
9
+ @taxons = Spree::Taxon.includes(:children).accessible_by(current_ability, :read).where(id: params[:ids].split(','))
10
10
  else
11
- @taxons = Spree::Taxon.accessible_by(current_ability, :read).order(:taxonomy_id, :lft).ransack(params[:q]).result
11
+ @taxons = Spree::Taxon.includes(:children).accessible_by(current_ability, :read).order(:taxonomy_id, :lft).ransack(params[:q]).result
12
12
  end
13
13
  end
14
14
 
@@ -65,7 +65,7 @@ module Spree
65
65
  # Products#index does not do the sorting.
66
66
  taxon = Spree::Taxon.find(params[:id])
67
67
  @products = taxon.products.ransack(params[:q]).result
68
- @products = @products.page(params[:page]).per(500 || params[:per_page])
68
+ @products = @products.page(params[:page]).per(params[:per_page] || 500)
69
69
  render "spree/api/products/index"
70
70
  end
71
71
 
@@ -15,8 +15,6 @@ module Spree
15
15
  :shipment_attributes,
16
16
  :taxonomy_attributes,
17
17
  :taxon_attributes,
18
- :inventory_unit_attributes,
19
- :return_authorization_attributes,
20
18
  :address_attributes,
21
19
  :country_attributes,
22
20
  :state_attributes,
@@ -46,3 +46,7 @@ end
46
46
  node :permissions do
47
47
  { can_update: current_ability.can?(:update, root_object) }
48
48
  end
49
+
50
+ child :valid_credit_cards => :credit_cards do
51
+ extends "spree/api/credit_cards/show"
52
+ end
@@ -21,3 +21,7 @@ end
21
21
  child :product_properties => :product_properties do
22
22
  attributes *product_property_attributes
23
23
  end
24
+
25
+ child :taxons => :taxons do
26
+ extends "spree/api/taxons/show"
27
+ end
@@ -31,3 +31,7 @@ child :manifest => :manifest do
31
31
  node(:quantity) { |m| m.quantity }
32
32
  node(:states) { |m| m.states }
33
33
  end
34
+
35
+ child :adjustments => :adjustments do
36
+ extends "spree/api/adjustments/show"
37
+ end
@@ -12,23 +12,23 @@ module Spree
12
12
  end
13
13
 
14
14
  def assert_not_found!
15
- json_response.should == { "error" => "The resource you were looking for could not be found." }
16
- response.status.should == 404
15
+ expect(json_response).to eq({ "error" => "The resource you were looking for could not be found." })
16
+ expect(response.status).to eq 404
17
17
  end
18
18
 
19
19
  def assert_unauthorized!
20
- json_response.should == { "error" => "You are not authorized to perform that action." }
21
- response.status.should == 401
20
+ expect(json_response).to eq({ "error" => "You are not authorized to perform that action." })
21
+ expect(response.status).to eq 401
22
22
  end
23
23
 
24
24
  def stub_authentication!
25
- Spree::LegacyUser.stub(:find_by).with(hash_including(:spree_api_key)) { current_api_user }
25
+ allow(Spree::LegacyUser).to receive(:find_by).with(hash_including(:spree_api_key)) { current_api_user }
26
26
  end
27
27
 
28
28
  # This method can be overriden (with a let block) inside a context
29
29
  # For instance, if you wanted to have an admin user instead.
30
30
  def current_api_user
31
- @current_api_user ||= stub_model(Spree::LegacyUser, :email => "spree@example.com")
31
+ @current_api_user ||= stub_model(Spree::LegacyUser, email: "spree@example.com")
32
32
  end
33
33
 
34
34
  def image(filename)
@@ -5,8 +5,8 @@ module Spree
5
5
  def sign_in_as_admin!
6
6
  let!(:current_api_user) do
7
7
  user = stub_model(Spree::LegacyUser)
8
- user.stub_chain(:spree_roles, :pluck).and_return(["admin"])
9
- user.stub(:has_spree_role?).with("admin").and_return(true)
8
+ allow(user).to receive_message_chain(:spree_roles, :pluck).and_return(["admin"])
9
+ allow(user).to receive(:has_spree_role?).with("admin").and_return(true)
10
10
  user
11
11
  end
12
12
  end
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  module Spree
4
- describe Api::AddressesController do
4
+ describe Api::AddressesController, :type => :controller do
5
5
  render_views
6
6
 
7
7
  before do
@@ -12,27 +12,27 @@ module Spree
12
12
 
13
13
  context "with their own address" do
14
14
  before do
15
- Order.any_instance.stub :user => current_api_user
15
+ allow_any_instance_of(Order).to receive_messages :user => current_api_user
16
16
  end
17
17
 
18
18
  it "gets an address" do
19
19
  api_get :show, :id => @address.id, :order_id => @order.number
20
- json_response['address1'].should eq @address.address1
20
+ expect(json_response['address1']).to eq @address.address1
21
21
  end
22
22
 
23
23
  it "updates an address" do
24
24
  api_put :update, :id => @address.id, :order_id => @order.number,
25
25
  :address => { :address1 => "123 Test Lane" }
26
- json_response['address1'].should eq '123 Test Lane'
26
+ expect(json_response['address1']).to eq '123 Test Lane'
27
27
  end
28
28
 
29
29
  it "receives the errors object if address is invalid" do
30
30
  api_put :update, :id => @address.id, :order_id => @order.number,
31
31
  :address => { :address1 => "" }
32
32
 
33
- json_response['error'].should_not be_nil
34
- json_response['errors'].should_not be_nil
35
- json_response['errors']['address1'].first.should eq "can't be blank"
33
+ expect(json_response['error']).not_to be_nil
34
+ expect(json_response['errors']).not_to be_nil
35
+ expect(json_response['errors']['address1'].first).to eq "can't be blank"
36
36
  end
37
37
  end
38
38
 
@@ -42,7 +42,7 @@ module Spree
42
42
  @order.ship_address = nil
43
43
  end
44
44
 
45
- it "cannot retreive address information" do
45
+ it "cannot retrieve address information" do
46
46
  api_get :show, :id => @address.id, :order_id => @order.number
47
47
  assert_unauthorized!
48
48
  end
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  class FakesController < Spree::Api::BaseController
4
4
  end
5
5
 
6
- describe Spree::Api::BaseController do
6
+ describe Spree::Api::BaseController, :type => :controller do
7
7
  render_views
8
8
  controller(Spree::Api::BaseController) do
9
9
  def index
@@ -14,14 +14,14 @@ describe Spree::Api::BaseController do
14
14
  context "signed in as a user using an authentication extension" do
15
15
  before do
16
16
  user = double(:email => "spree@example.com")
17
- user.stub_chain :spree_roles, pluck: []
18
- controller.stub :try_spree_current_user => user
17
+ allow(user).to receive_message_chain :spree_roles, pluck: []
18
+ allow(controller).to receive_messages :try_spree_current_user => user
19
19
  end
20
20
 
21
21
  it "can make a request" do
22
22
  api_get :index
23
- json_response.should == { "products" => [] }
24
- response.status.should == 200
23
+ expect(json_response).to eq({ "products" => [] })
24
+ expect(response.status).to eq(200)
25
25
  end
26
26
  end
27
27
 
@@ -31,19 +31,19 @@ describe Spree::Api::BaseController do
31
31
  context "with a correct order token" do
32
32
  it "succeeds" do
33
33
  api_get :index, order_token: order.guest_token, order_id: order.number
34
- response.status.should == 200
34
+ expect(response.status).to eq(200)
35
35
  end
36
36
 
37
37
  it "succeeds with an order_number parameter" do
38
38
  api_get :index, order_token: order.guest_token, order_number: order.number
39
- response.status.should == 200
39
+ expect(response.status).to eq(200)
40
40
  end
41
41
  end
42
42
 
43
43
  context "with an incorrect order token" do
44
44
  it "returns unauthorized" do
45
45
  api_get :index, order_token: "NOT_A_TOKEN", order_id: order.number
46
- response.status.should == 401
46
+ expect(response.status).to eq(401)
47
47
  end
48
48
  end
49
49
  end
@@ -51,29 +51,29 @@ describe Spree::Api::BaseController do
51
51
  context "cannot make a request to the API" do
52
52
  it "without an API key" do
53
53
  api_get :index
54
- json_response.should == { "error" => "You must specify an API key." }
55
- response.status.should == 401
54
+ expect(json_response).to eq({ "error" => "You must specify an API key." })
55
+ expect(response.status).to eq(401)
56
56
  end
57
57
 
58
58
  it "with an invalid API key" do
59
59
  request.headers["X-Spree-Token"] = "fake_key"
60
60
  get :index, {}
61
- json_response.should == { "error" => "Invalid API key (fake_key) specified." }
62
- response.status.should == 401
61
+ expect(json_response).to eq({ "error" => "Invalid API key (fake_key) specified." })
62
+ expect(response.status).to eq(401)
63
63
  end
64
64
 
65
65
  it "using an invalid token param" do
66
66
  get :index, :token => "fake_key"
67
- json_response.should == { "error" => "Invalid API key (fake_key) specified." }
67
+ expect(json_response).to eq({ "error" => "Invalid API key (fake_key) specified." })
68
68
  end
69
69
  end
70
70
 
71
71
  it 'handles exceptions' do
72
- subject.should_receive(:authenticate_user).and_return(true)
73
- subject.should_receive(:load_user_roles).and_return(true)
74
- subject.should_receive(:index).and_raise(Exception.new("no joy"))
72
+ expect(subject).to receive(:authenticate_user).and_return(true)
73
+ expect(subject).to receive(:load_user_roles).and_return(true)
74
+ expect(subject).to receive(:index).and_raise(Exception.new("no joy"))
75
75
  get :index, :token => "fake_key"
76
- json_response.should == { "exception" => "no joy" }
76
+ expect(json_response).to eq({ "exception" => "no joy" })
77
77
  end
78
78
 
79
79
  it "maps semantic keys to nested_attributes keys" do
@@ -84,12 +84,12 @@ describe Spree::Api::BaseController do
84
84
  'name' => 'test order' }
85
85
 
86
86
  mapped = subject.map_nested_attributes_keys(klass, attributes)
87
- mapped.has_key?('line_items_attributes').should be true
88
- mapped.has_key?('name').should be true
87
+ expect(mapped.has_key?('line_items_attributes')).to be true
88
+ expect(mapped.has_key?('name')).to be true
89
89
  end
90
90
 
91
91
  it "lets a subclass override the product associations that are eager-loaded" do
92
- controller.respond_to?(:product_includes, true).should be
92
+ expect(controller.respond_to?(:product_includes, true)).to be
93
93
  end
94
94
 
95
95
  describe '#error_during_processing' do
@@ -116,8 +116,8 @@ describe Spree::Api::BaseController do
116
116
 
117
117
  before do
118
118
  user = double(email: "spree@example.com")
119
- user.stub_chain :spree_roles, pluck: []
120
- controller.stub try_spree_current_user: user
119
+ allow(user).to receive_message_chain :spree_roles, pluck: []
120
+ allow(controller).to receive_messages try_spree_current_user: user
121
121
  routes.draw { get 'foo' => 'fakes#foo' }
122
122
  end
123
123
 
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  module Spree
4
- describe Api::CheckoutsController do
4
+ describe Api::CheckoutsController, :type => :controller do
5
5
  render_views
6
6
 
7
7
  before(:each) do
@@ -31,39 +31,39 @@ module Spree
31
31
  end
32
32
 
33
33
  before(:each) do
34
- Order.any_instance.stub(:confirmation_required? => true)
35
- Order.any_instance.stub(:payment_required? => true)
34
+ allow_any_instance_of(Order).to receive_messages(:confirmation_required? => true)
35
+ allow_any_instance_of(Order).to receive_messages(:payment_required? => true)
36
36
  end
37
37
 
38
38
  it "should transition a recently created order from cart to address" do
39
- order.state.should eq "cart"
40
- order.email.should_not be_nil
39
+ expect(order.state).to eq "cart"
40
+ expect(order.email).not_to be_nil
41
41
  api_put :update, :id => order.to_param, :order_token => order.guest_token
42
- order.reload.state.should eq "address"
42
+ expect(order.reload.state).to eq "address"
43
43
  end
44
44
 
45
45
  it "should transition a recently created order from cart to address with order token in header" do
46
- order.state.should eq "cart"
47
- order.email.should_not be_nil
46
+ expect(order.state).to eq "cart"
47
+ expect(order.email).not_to be_nil
48
48
  request.headers["X-Spree-Order-Token"] = order.guest_token
49
49
  api_put :update, :id => order.to_param
50
- order.reload.state.should eq "address"
50
+ expect(order.reload.state).to eq "address"
51
51
  end
52
52
 
53
53
  it "can take line_items_attributes as a parameter" do
54
54
  line_item = order.line_items.first
55
55
  api_put :update, :id => order.to_param, :order_token => order.guest_token,
56
56
  :order => { :line_items_attributes => { 0 => { :id => line_item.id, :quantity => 1 } } }
57
- response.status.should == 200
58
- order.reload.state.should eq "address"
57
+ expect(response.status).to eq(200)
58
+ expect(order.reload.state).to eq "address"
59
59
  end
60
60
 
61
61
  it "can take line_items as a parameter" do
62
62
  line_item = order.line_items.first
63
63
  api_put :update, :id => order.to_param, :order_token => order.guest_token,
64
64
  :order => { :line_items => { 0 => { :id => line_item.id, :quantity => 1 } } }
65
- response.status.should == 200
66
- order.reload.state.should eq "address"
65
+ expect(response.status).to eq(200)
66
+ expect(order.reload.state).to eq "address"
67
67
  end
68
68
 
69
69
  it "will return an error if the order cannot transition" do
@@ -73,7 +73,7 @@ module Spree
73
73
  order.update_column(:state, "address")
74
74
  api_put :update, :id => order.to_param, :order_token => order.guest_token
75
75
  # Order has not transitioned
76
- response.status.should == 422
76
+ expect(response.status).to eq(422)
77
77
  end
78
78
 
79
79
  context "transitioning to delivery" do
@@ -101,10 +101,10 @@ module Spree
101
101
  :bill_address_attributes => address,
102
102
  :ship_address_attributes => address
103
103
  }
104
- json_response['state'].should == 'delivery'
105
- json_response['bill_address']['firstname'].should == 'John'
106
- json_response['ship_address']['firstname'].should == 'John'
107
- response.status.should == 200
104
+ expect(json_response['state']).to eq('delivery')
105
+ expect(json_response['bill_address']['firstname']).to eq('John')
106
+ expect(json_response['ship_address']['firstname']).to eq('John')
107
+ expect(response.status).to eq(200)
108
108
  end
109
109
 
110
110
  # Regression test for #4498
@@ -129,25 +129,25 @@ module Spree
129
129
  shipping_rate = shipment.shipping_rates.where(:selected => false).first
130
130
  api_put :update, :id => order.to_param, :order_token => order.guest_token,
131
131
  :order => { :shipments_attributes => { "0" => { :selected_shipping_rate_id => shipping_rate.id, :id => shipment.id } } }
132
- response.status.should == 200
132
+ expect(response.status).to eq(200)
133
133
  # Find the correct shipment...
134
134
  json_shipment = json_response['shipments'].detect { |s| s["id"] == shipment.id }
135
135
  # Find the correct shipping rate for that shipment...
136
136
  json_shipping_rate = json_shipment['shipping_rates'].detect { |sr| sr["id"] == shipping_rate.id }
137
137
  # ... And finally ensure that it's selected
138
- json_shipping_rate['selected'].should be true
138
+ expect(json_shipping_rate['selected']).to be true
139
139
  # Order should automatically transfer to payment because all criteria are met
140
- json_response['state'].should == 'payment'
140
+ expect(json_response['state']).to eq('payment')
141
141
  end
142
142
 
143
143
  it "can update payment method and transition from payment to confirm" do
144
144
  order.update_column(:state, "payment")
145
145
  api_put :update, :id => order.to_param, :order_token => order.guest_token,
146
146
  :order => { :payments_attributes => [{ :payment_method_id => @payment_method.id }] }
147
- json_response['state'].should == 'confirm'
148
- json_response['payments'][0]['payment_method']['name'].should == @payment_method.name
149
- json_response['payments'][0]['amount'].should == order.total.to_s
150
- response.status.should == 200
147
+ expect(json_response['state']).to eq('confirm')
148
+ expect(json_response['payments'][0]['payment_method']['name']).to eq(@payment_method.name)
149
+ expect(json_response['payments'][0]['amount']).to eq(order.total.to_s)
150
+ expect(response.status).to eq(200)
151
151
  end
152
152
 
153
153
  it "can update payment method with source and transition from payment to confirm" do
@@ -163,9 +163,9 @@ module Spree
163
163
  api_put :update, :id => order.to_param, :order_token => order.guest_token,
164
164
  :order => { :payments_attributes => [{ :payment_method_id => @payment_method.id.to_s }],
165
165
  :payment_source => { @payment_method.id.to_s => source_attributes } }
166
- json_response['payments'][0]['payment_method']['name'].should == @payment_method.name
167
- json_response['payments'][0]['amount'].should == order.total.to_s
168
- response.status.should == 200
166
+ expect(json_response['payments'][0]['payment_method']['name']).to eq(@payment_method.name)
167
+ expect(json_response['payments'][0]['amount']).to eq(order.total.to_s)
168
+ expect(response.status).to eq(200)
169
169
  end
170
170
 
171
171
  it "returns errors when source is missing attributes" do
@@ -178,12 +178,12 @@ module Spree
178
178
  @payment_method.id.to_s => { name: "Spree" }
179
179
  }
180
180
 
181
- response.status.should == 422
181
+ expect(response.status).to eq(422)
182
182
  cc_errors = json_response['errors']['payments.Credit Card']
183
- cc_errors.should include("Number can't be blank")
184
- cc_errors.should include("Month is not a number")
185
- cc_errors.should include("Year is not a number")
186
- cc_errors.should include("Verification Value can't be blank")
183
+ expect(cc_errors).to include("Number can't be blank")
184
+ expect(cc_errors).to include("Month is not a number")
185
+ expect(cc_errors).to include("Year is not a number")
186
+ expect(cc_errors).to include("Verification Value can't be blank")
187
187
  end
188
188
 
189
189
  it "allow users to reuse a credit card" do
@@ -199,17 +199,17 @@ module Spree
199
199
 
200
200
  it "can transition from confirm to complete" do
201
201
  order.update_column(:state, "confirm")
202
- Spree::Order.any_instance.stub(:payment_required? => false)
202
+ allow_any_instance_of(Spree::Order).to receive_messages(:payment_required? => false)
203
203
  api_put :update, :id => order.to_param, :order_token => order.guest_token
204
- json_response['state'].should == 'complete'
205
- response.status.should == 200
204
+ expect(json_response['state']).to eq('complete')
205
+ expect(response.status).to eq(200)
206
206
  end
207
207
 
208
208
  it "returns the order if the order is already complete" do
209
209
  order.update_column(:state, "complete")
210
210
  api_put :update, :id => order.to_param, :order_token => order.guest_token
211
- json_response['number'].should == order.number
212
- response.status.should == 200
211
+ expect(json_response['number']).to eq(order.number)
212
+ expect(response.status).to eq(200)
213
213
  end
214
214
 
215
215
  # Regression test for #3784
@@ -227,24 +227,24 @@ module Spree
227
227
  # Need to pass email as well so that validations succeed
228
228
  api_put :update, :id => order.to_param, :order_token => order.guest_token,
229
229
  :order => { :user_id => user.id, :email => "guest@spreecommerce.com" }
230
- response.status.should == 200
231
- json_response['user_id'].should == user.id
230
+ expect(response.status).to eq(200)
231
+ expect(json_response['user_id']).to eq(user.id)
232
232
  end
233
233
  end
234
234
 
235
235
  it "can assign an email to the order" do
236
236
  api_put :update, :id => order.to_param, :order_token => order.guest_token,
237
237
  :order => { :email => "guest@spreecommerce.com" }
238
- json_response['email'].should == "guest@spreecommerce.com"
239
- response.status.should == 200
238
+ expect(json_response['email']).to eq("guest@spreecommerce.com")
239
+ expect(response.status).to eq(200)
240
240
  end
241
241
 
242
242
  it "can apply a coupon code to an order" do
243
243
  skip "ensure that the order totals are properly updated, see frontend orders_controller or checkout_controller as example"
244
244
 
245
245
  order.update_column(:state, "payment")
246
- PromotionHandler::Coupon.should_receive(:new).with(order).and_call_original
247
- PromotionHandler::Coupon.any_instance.should_receive(:apply).and_return({:coupon_applied? => true})
246
+ expect(PromotionHandler::Coupon).to receive(:new).with(order).and_call_original
247
+ expect_any_instance_of(PromotionHandler::Coupon).to receive(:apply).and_return({:coupon_applied? => true})
248
248
  api_put :update, :id => order.to_param, :order_token => order.guest_token, :order => { :coupon_code => "foobar" }
249
249
  end
250
250
  end
@@ -255,16 +255,16 @@ module Spree
255
255
  order.line_items.delete_all
256
256
  order.update_column(:email, "spree@example.com")
257
257
  api_put :next, :id => order.to_param, :order_token => order.guest_token
258
- response.status.should == 422
259
- json_response["errors"]["base"].should include(Spree.t(:there_are_no_items_for_this_order))
258
+ expect(response.status).to eq(422)
259
+ expect(json_response["errors"]["base"]).to include(Spree.t(:there_are_no_items_for_this_order))
260
260
  end
261
261
 
262
262
  it "can transition an order to the next state" do
263
263
  order.update_column(:email, "spree@example.com")
264
264
 
265
265
  api_put :next, :id => order.to_param, :order_token => order.guest_token
266
- response.status.should == 200
267
- json_response['state'].should == 'address'
266
+ expect(response.status).to eq(200)
267
+ expect(json_response['state']).to eq('address')
268
268
  end
269
269
 
270
270
  it "cannot transition if order email is blank" do
@@ -274,14 +274,14 @@ module Spree
274
274
  )
275
275
 
276
276
  api_put :next, :id => order.to_param, :order_token => order.guest_token
277
- response.status.should == 422
278
- json_response['error'].should =~ /could not be transitioned/
277
+ expect(response.status).to eq(422)
278
+ expect(json_response['error']).to match(/could not be transitioned/)
279
279
  end
280
280
 
281
281
  it "doesnt advance payment state if order has no payment" do
282
282
  order.update_column(:state, "payment")
283
283
  api_put :next, :id => order.to_param, :order_token => order.guest_token, :order => {}
284
- json_response["errors"]["base"].should include(Spree.t(:no_payment_found))
284
+ expect(json_response["errors"]["base"]).to include(Spree.t(:no_payment_found))
285
285
  end
286
286
  end
287
287
 
@@ -289,13 +289,13 @@ module Spree
289
289
  let!(:order) { create(:order_with_line_items) }
290
290
 
291
291
  it 'continues to advance advances an order while it can move forward' do
292
- Spree::Order.any_instance.should_receive(:next).exactly(3).times.and_return(true, true, false)
292
+ expect_any_instance_of(Spree::Order).to receive(:next).exactly(3).times.and_return(true, true, false)
293
293
  api_put :advance, :id => order.to_param, :order_token => order.guest_token
294
294
  end
295
295
 
296
296
  it 'returns the order' do
297
297
  api_put :advance, :id => order.to_param, :order_token => order.guest_token
298
- json_response['id'].should == order.id
298
+ expect(json_response['id']).to eq(order.id)
299
299
  end
300
300
  end
301
301
  end