spree_api 2.2.9 → 2.2.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4054c45aa7f1dd4b9117a0c93e50dd091b9127c5
4
- data.tar.gz: 9cede9c151509a65bdec3a800ff420f203df7b48
3
+ metadata.gz: c1e4f94cd07462a030047555911538bcaf13cba8
4
+ data.tar.gz: f35bbca0a030a0627ee12d6e53689e52b83c3956
5
5
  SHA512:
6
- metadata.gz: bce419abf3f9a6073307b79a5630c1fcee32a794677824eaa9fa4a1f1f212ac18f5677e50fe9386a6b3aaec113983b176e66f13a86bc7d1a2637137859754daa
7
- data.tar.gz: 6a13db2891ded39d5051ea07d7fcc2c3d045f12c5a07aba191d84dabc23fce875fbcd1342bfb9f09de1fb4d5d9d97cfda8a8ed166c610a2e327ead4851a829d9
6
+ metadata.gz: fc7bb77eff861a8585824f001119058b5388be6cd27f09605785cae8b20e62e6d3c04eaadf836b4524c2b74d7cc1cd2bb56e2972f6a27879af24c5da558d0b0f
7
+ data.tar.gz: f0bf714d8696e7abb69a6f56d9626821216b4aab9005aec55d0fa8d890e062480db1006a1aadc485e18ee34a83a3d7da9df0e4c24adf66807e6610e5972da6cf
@@ -61,7 +61,7 @@ module Spree
61
61
  end
62
62
 
63
63
  def load_user
64
- @current_api_user = (try_spree_current_user || Spree.user_class.find_by(spree_api_key: api_key.to_s))
64
+ @current_api_user = Spree.user_class.find_by(spree_api_key: api_key.to_s)
65
65
  end
66
66
 
67
67
  def authenticate_user
@@ -17,7 +17,7 @@ module Spree
17
17
  end
18
18
 
19
19
  def stub_authentication!
20
- Spree::LegacyUser.stub(:find_by).with(hash_including(:spree_api_key)) { current_api_user }
20
+ allow(Spree.user_class).to receive(:find_by).with(hash_including(:spree_api_key)) { current_api_user }
21
21
  end
22
22
 
23
23
  # This method can be overriden (with a let block) inside a context
@@ -8,16 +8,9 @@ describe Spree::Api::BaseController do
8
8
  end
9
9
  end
10
10
 
11
- context "signed in as a user using an authentication extension" do
12
- before do
13
- controller.stub :try_spree_current_user => double(:email => "spree@example.com")
14
- Spree::Api::Config[:requires_authentication] = true
15
- end
16
-
17
- it "can make a request" do
18
- api_get :index
19
- json_response.should == { "products" => [] }
20
- response.status.should == 200
11
+ before do
12
+ @routes = ActionDispatch::Routing::RouteSet.new.tap do |r|
13
+ r.draw { get 'index', to: 'spree/api/base#index' }
21
14
  end
22
15
  end
23
16
 
@@ -10,8 +10,11 @@ module Spree
10
10
  let(:attributes) { [:id, :quantity, :price, :variant, :total, :display_amount, :single_display_amount] }
11
11
  let(:resource_scoping) { { :order_id => order.to_param } }
12
12
 
13
+ before do
14
+ stub_authentication!
15
+ end
16
+
13
17
  it "can learn how to create a new line item" do
14
- controller.stub :try_spree_current_user => current_api_user
15
18
  api_get :new
16
19
  json_response["attributes"].should == ["quantity", "price", "variant_id"]
17
20
  required_attributes = json_response["required_attributes"]
@@ -37,8 +40,7 @@ module Spree
37
40
 
38
41
  context "as the order owner" do
39
42
  before do
40
- controller.stub :try_spree_current_user => current_api_user
41
- Order.any_instance.stub :user => current_api_user
43
+ allow_any_instance_of(Order).to receive_messages :user => current_api_user
42
44
  end
43
45
 
44
46
  it "can add a new line item to an existing order" do
@@ -119,7 +121,8 @@ module Spree
119
121
  context "as just another user" do
120
122
  before do
121
123
  user = create(:user)
122
- controller.stub :try_spree_current_user => user
124
+ allow(Spree.user_class).to receive(:find_by).
125
+ and_return(user)
123
126
  end
124
127
 
125
128
  it "cannot add a new line item to the order" do
@@ -135,9 +135,10 @@ module Spree
135
135
 
136
136
  it "can view an order" do
137
137
  user = mock_model(Spree::LegacyUser)
138
- user.stub(:has_spree_role?).with('bar').and_return(true)
139
- user.stub(:has_spree_role?).with('admin').and_return(false)
140
- controller.stub try_spree_current_user: user
138
+ allow(user).to receive_message_chain(:spree_roles, :pluck).and_return(["bar"])
139
+ allow(user).to receive(:has_spree_role?).with('bar').and_return(true)
140
+ allow(user).to receive(:has_spree_role?).with('admin').and_return(false)
141
+ allow(Spree.user_class).to receive_messages find_by: user
141
142
  api_get :show, :id => order.to_param
142
143
  response.status.should == 200
143
144
  end
@@ -4,70 +4,68 @@ module Spree
4
4
  describe Api::UsersController do
5
5
  render_views
6
6
 
7
- let(:user) { create(:user) }
7
+ let(:user) { create(:user, spree_api_key: rand) }
8
8
  let(:stranger) { create(:user, :email => 'stranger@example.com') }
9
9
  let(:attributes) { [:id, :email, :created_at, :updated_at] }
10
10
 
11
- before { stub_authentication! }
12
-
13
11
  context "as a normal user" do
14
- before do
15
- controller.stub :try_spree_current_user => user
16
- end
17
-
18
12
  it "can get own details" do
19
- api_get :show, :id => user.id
13
+ api_get :show, id: user.id, token: user.spree_api_key
20
14
 
21
15
  json_response['email'].should eq user.email
22
16
  end
23
17
 
24
18
  it "cannot get other users details" do
25
- api_get :show, :id => stranger.id
19
+ api_get :show, id: stranger.id, token: user.spree_api_key
26
20
 
27
21
  assert_not_found!
28
22
  end
29
23
 
30
24
  it "can learn how to create a new user" do
31
- api_get :new
32
- json_response["attributes"].should == attributes.map(&:to_s)
25
+ api_get :new, token: user.spree_api_key
26
+ expect(json_response["attributes"]).to eq(attributes.map(&:to_s))
33
27
  end
34
28
 
35
29
  it "can create a new user" do
36
- api_post :create, :user => { :email => 'new@example.com', :password => 'spree123', :password_confirmation => 'spree123' }
37
- json_response['email'].should eq 'new@example.com'
30
+ user_params = {
31
+ :email => 'new@example.com', :password => 'spree123', :password_confirmation => 'spree123'
32
+ }
33
+
34
+ api_post :create, :user => user_params, token: user.spree_api_key
35
+ expect(json_response['email']).to eq 'new@example.com'
38
36
  end
39
37
 
40
38
  # there's no validations on LegacyUser?
41
39
  xit "cannot create a new user with invalid attributes" do
42
- api_post :create, :user => {}
43
- response.status.should == 422
44
- json_response["error"].should == "Invalid resource. Please fix errors and try again."
40
+ api_post :create, :user => {}, token: user.spree_api_key
41
+ expect(response.status).to eq(422)
42
+ expect(json_response["error"]).to eq("Invalid resource. Please fix errors and try again.")
45
43
  errors = json_response["errors"]
46
44
  end
47
45
 
48
46
  it "can update own details" do
49
- api_put :update, :id => user.id, :user => { :email => "mine@example.com" }
47
+ api_put :update, id: user.id, token: user.spree_api_key, user: { email: "mine@example.com" }
50
48
  json_response['email'].should eq 'mine@example.com'
51
49
  end
52
50
 
53
51
  it "cannot update other users details" do
54
- api_put :update, :id => stranger.id, :user => { :email => "mine@example.com" }
52
+ api_put :update, id: stranger.id, token: user.spree_api_key, user: { :email => "mine@example.com" }
55
53
  assert_not_found!
56
54
  end
57
55
 
58
56
  it "can delete itself" do
59
- api_delete :destroy, :id => user.id
60
- response.status.should == 204
57
+ api_delete :destroy, id: user.id, token: user.spree_api_key
58
+ expect(response.status).to eq(204)
61
59
  end
62
60
 
63
61
  it "cannot delete other user" do
64
- api_delete :destroy, :id => stranger.id
62
+ api_delete :destroy, id: stranger.id, token: user.spree_api_key
65
63
  assert_not_found!
66
64
  end
67
65
 
68
66
  it "should only get own details on index" do
69
67
  2.times { create(:user) }
70
- api_get :index
68
+ api_get :index, token: user.spree_api_key
71
69
 
72
70
  Spree.user_class.count.should eq 3
73
71
  json_response['count'].should eq 1
@@ -76,6 +74,8 @@ module Spree
76
74
  end
77
75
 
78
76
  context "as an admin" do
77
+ before { stub_authentication! }
78
+
79
79
  sign_in_as_admin!
80
80
 
81
81
  it "gets all users" do
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.2.9
4
+ version: 2.2.10
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-12-23 00:00:00.000000000 Z
11
+ date: 2015-03-03 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.2.9
19
+ version: 2.2.10
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.2.9
26
+ version: 2.2.10
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rabl
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -254,7 +254,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
254
254
  version: '0'
255
255
  requirements: []
256
256
  rubyforge_project:
257
- rubygems_version: 2.2.2
257
+ rubygems_version: 2.4.5
258
258
  signing_key:
259
259
  specification_version: 4
260
260
  summary: Spree's API