spree_api 2.3.2 → 2.3.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1c3d7994fdc3ab159cb6c5c25c3df0328bdb7d09
4
- data.tar.gz: 8ed983dd2706eacfa4081f2cb2509685f1e4e565
3
+ metadata.gz: 5752a91942e0ac29588a3ebb480984ae1e8a4833
4
+ data.tar.gz: f7a88ac18005ccce8cb89b0e95201174e39404e0
5
5
  SHA512:
6
- metadata.gz: fd18911bd56574872239ba21ed83030ec250bfaf3d339b05be20d7195bf4a03f27f3fa915b947e09284d01514445e81ae07ef5ef765e5cce971ee8ac69452175
7
- data.tar.gz: b82a4694d499d371a463583ae30a7b414576cfca8b0430610b2c4191f42f823341c70cdf4f291a4fe856e46c18778d5a71ac69b7eff0058dd6247b4b9f0eaba8
6
+ metadata.gz: fe932da355fa5f4289aef12236e5054ea5489152e82d0e9bf1c22d8343c1d96891da9d132477fd6eece63df8f019f5656eeca7e49a825bb5046563a7fe85773a
7
+ data.tar.gz: 3e6d70b9faa3d422a88f7b30aadc53bffebfc9754121c39cab70ade338e6c81adb3641c00b4fb5fcea70e329db558f20c5e4f2a1f7a4d836648688ac4cdd0798
@@ -4,12 +4,14 @@ module Spree
4
4
  before_filter :find_order
5
5
 
6
6
  def show
7
- load_and_authorize_address(:read)
7
+ authorize! :read, @order, order_token
8
+ find_address
8
9
  respond_with(@address)
9
10
  end
10
11
 
11
12
  def update
12
- load_and_authorize_address(:update)
13
+ authorize! :update, @order, order_token
14
+ find_address
13
15
 
14
16
  if @address.update_attributes(address_params)
15
17
  respond_with(@address, :default_template => :show)
@@ -24,29 +26,16 @@ module Spree
24
26
  end
25
27
 
26
28
  def find_order
27
- @order = Spree::Order.find_by!(number: order_id) if order_id
29
+ @order = Spree::Order.find_by!(number: order_id)
28
30
  end
29
31
 
30
32
  def find_address
31
- if @order
32
- @address = if @order.bill_address_id == params[:id].to_i
33
- @order.bill_address
34
- elsif @order.ship_address_id == params[:id].to_i
35
- @order.ship_address
36
- else
37
- raise CanCan::AccessDenied
38
- end
33
+ @address = if @order.bill_address_id == params[:id].to_i
34
+ @order.bill_address
35
+ elsif @order.ship_address_id == params[:id].to_i
36
+ @order.ship_address
39
37
  else
40
- @address = Spree::Address.find(params[:id])
41
- end
42
- end
43
-
44
- def load_and_authorize_address(permission)
45
- find_address
46
- if @order
47
- authorize! permission, @order, order_token
48
- else
49
- authorize! permission, @address
38
+ raise CanCan::AccessDenied
50
39
  end
51
40
  end
52
41
  end
@@ -7,76 +7,50 @@ module Spree
7
7
  before do
8
8
  stub_authentication!
9
9
  @address = create(:address)
10
+ @order = create(:order, :bill_address => @address)
10
11
  end
11
-
12
- context "with order" do
12
+
13
+ context "with their own address" do
13
14
  before do
14
- @order = create(:order, :bill_address => @address)
15
+ Order.any_instance.stub :user => current_api_user
15
16
  end
16
-
17
- context "with their own address" do
18
- before do
19
- Order.any_instance.stub :user => current_api_user
20
- end
21
-
22
- it "gets an address" do
23
- api_get :show, :id => @address.id, :order_id => @order.number
24
- json_response['address1'].should eq @address.address1
25
- end
26
-
27
- it "updates an address" do
28
- api_put :update, :id => @address.id, :order_id => @order.number,
29
- :address => { :address1 => "123 Test Lane" }
30
- json_response['address1'].should eq '123 Test Lane'
31
- end
32
-
33
- it "receives the errors object if address is invalid" do
34
- api_put :update, :id => @address.id, :order_id => @order.number,
35
- :address => { :address1 => "" }
36
17
 
37
- json_response['error'].should_not be_nil
38
- json_response['errors'].should_not be_nil
39
- json_response['errors']['address1'].first.should eq "can't be blank"
40
- end
18
+ it "gets an address" do
19
+ api_get :show, :id => @address.id, :order_id => @order.number
20
+ json_response['address1'].should eq @address.address1
41
21
  end
42
22
 
43
- context "on an address that does not belong to this order" do
44
- before do
45
- @order.bill_address_id = nil
46
- @order.ship_address = nil
47
- end
23
+ it "updates an address" do
24
+ api_put :update, :id => @address.id, :order_id => @order.number,
25
+ :address => { :address1 => "123 Test Lane" }
26
+ json_response['address1'].should eq '123 Test Lane'
27
+ end
48
28
 
49
- it "cannot retreive address information" do
50
- api_get :show, :id => @address.id, :order_id => @order.number
51
- assert_unauthorized!
52
- end
29
+ it "receives the errors object if address is invalid" do
30
+ api_put :update, :id => @address.id, :order_id => @order.number,
31
+ :address => { :address1 => "" }
53
32
 
54
- it "cannot update address information" do
55
- api_get :update, :id => @address.id, :order_id => @order.number
56
- assert_unauthorized!
57
- end
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"
58
36
  end
59
37
  end
60
-
61
- context "without order" do
62
- context "with their own address" do
63
- before do
64
- Address.any_instance.stub :user => current_api_user
65
- end
66
38
 
67
- it "gets an address" do
68
- api_get :show, :id => @address.id
69
- json_response['address1'].should eq @address.address1
70
- end
39
+ context "on an address that does not belong to this order" do
40
+ before do
41
+ @order.bill_address_id = nil
42
+ @order.ship_address = nil
43
+ end
44
+
45
+ it "cannot retreive address information" do
46
+ api_get :show, :id => @address.id, :order_id => @order.number
47
+ assert_unauthorized!
71
48
  end
72
49
 
73
- context "on an address that does not belong to this user" do
74
- it "cannot update address information" do
75
- api_put :update, :id => @address.id, :address => { :address1 => "123 Test Lane" }
76
- json_response['address1'].should be_nil
77
- assert_unauthorized!
78
- end
50
+ it "cannot update address information" do
51
+ api_get :update, :id => @address.id, :order_id => @order.number
52
+ assert_unauthorized!
79
53
  end
80
54
  end
81
55
  end
82
- end
56
+ end
@@ -81,8 +81,8 @@ describe Spree::Api::BaseController do
81
81
  'name' => 'test order' }
82
82
 
83
83
  mapped = subject.map_nested_attributes_keys(klass, attributes)
84
- mapped.has_key?('line_items_attributes').should be_true
85
- mapped.has_key?('name').should be_true
84
+ mapped.has_key?('line_items_attributes').should be true
85
+ mapped.has_key?('name').should be true
86
86
  end
87
87
 
88
88
  it "lets a subclass override the product associations that are eager-loaded" do
@@ -67,7 +67,7 @@ module Spree
67
67
  end
68
68
 
69
69
  it "will return an error if the order cannot transition" do
70
- pending "not sure if this test is valid"
70
+ skip "not sure if this test is valid"
71
71
  order.bill_address = nil
72
72
  order.save
73
73
  order.update_column(:state, "address")
@@ -135,7 +135,7 @@ module Spree
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
+ json_shipping_rate['selected'].should be true
139
139
  # Order should automatically transfer to payment because all criteria are met
140
140
  json_response['state'].should == 'payment'
141
141
  end
@@ -240,7 +240,7 @@ module Spree
240
240
  end
241
241
 
242
242
  it "can apply a coupon code to an order" do
243
- pending "ensure that the order totals are properly updated, see frontend orders_controller or checkout_controller as example"
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
246
  PromotionHandler::Coupon.should_receive(:new).with(order).and_call_original
@@ -460,10 +460,10 @@ module Spree
460
460
  end
461
461
 
462
462
  it "includes the ship_total in the response" do
463
- api_get :show, :id => order.to_param
463
+ api_get :show, id: order.to_param
464
464
 
465
- json_response['ship_total'].should == '0.0'
466
- json_response['display_ship_total'].should == '$0.00'
465
+ expect(json_response['ship_total']).to eq '10.0'
466
+ expect(json_response['display_ship_total']).to eq '$10.00'
467
467
  end
468
468
 
469
469
  it "returns available shipments for an order" do
@@ -486,7 +486,7 @@ module Spree
486
486
  shipping_rate = shipment["shipping_rates"][0]
487
487
  shipping_rate["name"].should == json_shipping_method["name"]
488
488
  shipping_rate["cost"].should == "10.0"
489
- shipping_rate["selected"].should be_true
489
+ shipping_rate["selected"].should be true
490
490
  shipping_rate["display_cost"].should == "$10.00"
491
491
 
492
492
  shipment["stock_location_name"].should_not be_blank
@@ -511,9 +511,9 @@ module Spree
511
511
 
512
512
  it "responds with orders updated_at with miliseconds precision" do
513
513
  if ActiveRecord::Base.connection.adapter_name == "Mysql2"
514
- pending "MySQL does not support millisecond timestamps."
514
+ skip "MySQL does not support millisecond timestamps."
515
515
  else
516
- pending "Probable need to make it call as_json. See https://github.com/rails/rails/commit/0f33d70e89991711ff8b3dde134a61f4a5a0ec06"
516
+ skip "Probable need to make it call as_json. See https://github.com/rails/rails/commit/0f33d70e89991711ff8b3dde134a61f4a5a0ec06"
517
517
  end
518
518
 
519
519
  api_get :index
@@ -145,7 +145,7 @@ module Spree
145
145
  end
146
146
 
147
147
  it "does not raise a stack level error" do
148
- pending "Investigate why a payment.reload after the request raises 'stack level too deep'"
148
+ skip "Investigate why a payment.reload after the request raises 'stack level too deep'"
149
149
  payment.reload.state.should == "failed"
150
150
  end
151
151
  end
@@ -10,7 +10,7 @@ module Spree::Api
10
10
 
11
11
  context "with an available promotion" do
12
12
  let!(:order) { create(:order_with_line_items, :line_items_count => 1) }
13
- let!(:promotion) do
13
+ let!(:promotion) do
14
14
  promotion = Spree::Promotion.create(name: "10% off", code: "10off")
15
15
  calculator = Spree::Calculator::FlatPercentItemTotal.create(preferred_flat_percent: "10")
16
16
  action = Spree::Promotion::Actions::CreateItemAdjustments.create(calculator: calculator)
@@ -25,7 +25,7 @@ module Spree::Api
25
25
  order.reload.total.should == 109.00
26
26
  json_response["success"].should == "The coupon code was successfully applied to your order."
27
27
  json_response["error"].should be_blank
28
- json_response["successful"].should be_true
28
+ json_response["successful"].should be true
29
29
  end
30
30
 
31
31
  context "with an expired promotion" do
@@ -40,7 +40,7 @@ module Spree::Api
40
40
  response.status.should == 422
41
41
  json_response["success"].should be_blank
42
42
  json_response["error"].should == "The coupon code is expired"
43
- json_response["successful"].should be_false
43
+ json_response["successful"].should be false
44
44
  end
45
45
  end
46
46
  end
@@ -47,7 +47,7 @@ module Spree
47
47
  children = json_response['root']['taxons']
48
48
  children.count.should eq 1
49
49
  children.first['name'].should eq taxon.name
50
- children.first.key?('taxons').should be_false
50
+ children.first.key?('taxons').should be false
51
51
  end
52
52
 
53
53
  it "gets a single taxonomy with set=nested" do
@@ -56,7 +56,7 @@ module Spree
56
56
  json_response['name'].should eq taxonomy.name
57
57
 
58
58
  children = json_response['root']['taxons']
59
- children.first.key?('taxons').should be_true
59
+ children.first.key?('taxons').should be true
60
60
  end
61
61
 
62
62
  it "gets the jstree-friendly version of a taxonomy" do
@@ -18,13 +18,13 @@ describe "Rabl Cache", :caching => true do
18
18
  !v['is_master']
19
19
  end.first
20
20
 
21
- variant_a['is_master'].should be_false
21
+ variant_a['is_master'].should be false
22
22
  variant_a['stock_items'].should_not be_nil
23
23
 
24
24
  get "/api/products/#{Spree::Product.first.id}", :token => user.spree_api_key
25
25
  response.status.should == 200
26
26
  variant_b = JSON.parse(response.body)['variants'].last
27
- variant_b['is_master'].should be_false
27
+ variant_b['is_master'].should be false
28
28
 
29
29
  variant_a['id'].should == variant_b['id']
30
30
  variant_b['stock_items'].should be_nil
data/spec/spec_helper.rb CHANGED
@@ -39,6 +39,7 @@ require 'spree/api/testing_support/setup'
39
39
  RSpec.configure do |config|
40
40
  config.backtrace_exclusion_patterns = [/gems\/activesupport/, /gems\/actionpack/, /gems\/rspec/]
41
41
  config.color = true
42
+ config.infer_spec_type_from_file_location!
42
43
 
43
44
  config.include FactoryGirl::Syntax::Methods
44
45
  config.include Spree::Api::TestingSupport::Helpers, :type => :controller
@@ -23,5 +23,5 @@ module ControllerHacks
23
23
  end
24
24
 
25
25
  RSpec.configure do |config|
26
- config.include ControllerHacks, :type => :controller
26
+ config.include ControllerHacks, type: :controller
27
27
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spree_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.2
4
+ version: 2.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Bigg
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-29 00:00:00.000000000 Z
11
+ date: 2014-09-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: spree_core
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 2.3.2
19
+ version: 2.3.3
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 2.3.2
26
+ version: 2.3.3
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rabl
29
29
  requirement: !ruby/object:Gem::Requirement