spree_api 2.4.4 → 2.4.5

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: ca43b49ea66d204fdeefd36be3e54a9e5a6bee02
4
- data.tar.gz: 65645ed9ac2395b7fa3d971caaa314e5ee452690
3
+ metadata.gz: df85069fa27344d037168635f2c4ec87e02b9011
4
+ data.tar.gz: 8fbc76a068f2684e7bafd00bcf3e06ac8f5add06
5
5
  SHA512:
6
- metadata.gz: 5c2f8a7e39ada5e2fc32f2557f4ae89926bd6d1e5af6a28c537a868ccd0756fe9cd712c4ccd603f6515e44bca9b7e5ca8cd592c3fd92dd9d1bc239a734ad9164
7
- data.tar.gz: 8178a618dcbf35bd1759368ff8e218156287a76a2ee91692a611519d86fef823441dbb668e4ad8f4718fedf7c54539fd2d1e565f8a19129dfec2f1f45335f6a8
6
+ metadata.gz: 144367eaf50a16d2d40d1ed194265f471f2d8098b918306b9ba96cbd1e0822cb9cd4434c579026585a133621f79d32ee6c37b48166b24f9b285fcfd12d003d46
7
+ data.tar.gz: 2acc72fc6fad8788ef7b42b9a007ede5afb66cc6c7bb2794144fbe18ce3ef0d47509aa21e442b8dd1bf2710aa17ddb26b2043ee7f38aaafdd474e556a7584b6d
@@ -67,7 +67,7 @@ module Spree
67
67
  end
68
68
 
69
69
  def load_user
70
- @current_api_user = (try_spree_current_user || Spree.user_class.find_by(spree_api_key: api_key.to_s))
70
+ @current_api_user = Spree.user_class.find_by(spree_api_key: api_key.to_s)
71
71
  end
72
72
 
73
73
  def authenticate_user
@@ -22,7 +22,7 @@ module Spree
22
22
  end
23
23
 
24
24
  def stub_authentication!
25
- allow(Spree::LegacyUser).to receive(:find_by).with(hash_including(:spree_api_key)) { current_api_user }
25
+ allow(Spree.user_class).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
@@ -11,17 +11,9 @@ describe Spree::Api::BaseController, :type => :controller do
11
11
  end
12
12
  end
13
13
 
14
- context "signed in as a user using an authentication extension" do
15
- before do
16
- user = double(:email => "spree@example.com")
17
- allow(user).to receive_message_chain :spree_roles, pluck: []
18
- allow(controller).to receive_messages :try_spree_current_user => user
19
- end
20
-
21
- it "can make a request" do
22
- api_get :index
23
- expect(json_response).to eq({ "products" => [] })
24
- expect(response.status).to eq(200)
14
+ before do
15
+ @routes = ActionDispatch::Routing::RouteSet.new.tap do |r|
16
+ r.draw { get 'index', to: 'spree/api/base#index' }
25
17
  end
26
18
  end
27
19
 
@@ -117,13 +109,15 @@ describe Spree::Api::BaseController, :type => :controller do
117
109
  before do
118
110
  user = double(email: "spree@example.com")
119
111
  allow(user).to receive_message_chain :spree_roles, pluck: []
120
- allow(controller).to receive_messages try_spree_current_user: user
121
- routes.draw { get 'foo' => 'fakes#foo' }
112
+ allow(Spree.user_class).to receive_messages find_by: user
113
+ @routes = ActionDispatch::Routing::RouteSet.new.tap do |r|
114
+ r.draw { get 'foo' => 'fakes#foo' }
115
+ end
122
116
  end
123
117
 
124
118
  it 'should notify notify_error_during_processing' do
125
119
  expect(MockHoneybadger).to receive(:notify_or_ignore).once.with(kind_of(Exception), rack_env: kind_of(Hash))
126
- api_get :foo
120
+ api_get :foo, token: 123
127
121
  expect(response.status).to eq(422)
128
122
  end
129
123
  end
@@ -21,8 +21,11 @@ module Spree
21
21
  let(:attributes) { [:id, :quantity, :price, :variant, :total, :display_amount, :single_display_amount] }
22
22
  let(:resource_scoping) { { :order_id => order.to_param } }
23
23
 
24
+ before do
25
+ stub_authentication!
26
+ end
27
+
24
28
  it "can learn how to create a new line item" do
25
- allow(controller).to receive_messages :try_spree_current_user => current_api_user
26
29
  api_get :new
27
30
  expect(json_response["attributes"]).to eq(["quantity", "price", "variant_id"])
28
31
  required_attributes = json_response["required_attributes"]
@@ -48,7 +51,6 @@ module Spree
48
51
 
49
52
  context "as the order owner" do
50
53
  before do
51
- allow(controller).to receive_messages :try_spree_current_user => current_api_user
52
54
  allow_any_instance_of(Order).to receive_messages :user => current_api_user
53
55
  end
54
56
 
@@ -157,7 +159,6 @@ module Spree
157
159
  context "as just another user" do
158
160
  before do
159
161
  user = create(:user)
160
- allow(controller).to receive_messages :try_spree_current_user => user
161
162
  end
162
163
 
163
164
  it "cannot add a new line item to the order" do
@@ -238,7 +238,7 @@ module Spree
238
238
  allow(user).to receive_message_chain(:spree_roles, :pluck).and_return(["bar"])
239
239
  allow(user).to receive(:has_spree_role?).with('bar').and_return(true)
240
240
  allow(user).to receive(:has_spree_role?).with('admin').and_return(false)
241
- allow(controller).to receive_messages try_spree_current_user: user
241
+ allow(Spree.user_class).to receive_messages find_by: user
242
242
  api_get :show, :id => order.to_param
243
243
  expect(response.status).to eq(200)
244
244
  end
@@ -4,42 +4,40 @@ module Spree
4
4
  describe Api::UsersController, :type => :controller 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
- allow(controller).to receive_messages :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
  expect(json_response['email']).to 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
25
+ api_get :new, token: user.spree_api_key
32
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' }
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
37
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 => {}
40
+ api_post :create, :user => {}, token: user.spree_api_key
43
41
  expect(response.status).to eq(422)
44
42
  expect(json_response["error"]).to eq("Invalid resource. Please fix errors and try again.")
45
43
  errors = json_response["errors"]
@@ -47,7 +45,7 @@ module Spree
47
45
 
48
46
  it "can update own details" do
49
47
  country = create(:country)
50
- api_put :update, id: user.id, user: {
48
+ api_put :update, id: user.id, token: user.spree_api_key, user: {
51
49
  email: "mine@example.com",
52
50
  bill_address_attributes: {
53
51
  first_name: 'First',
@@ -76,23 +74,23 @@ module Spree
76
74
  end
77
75
 
78
76
  it "cannot update other users details" do
79
- api_put :update, :id => stranger.id, :user => { :email => "mine@example.com" }
77
+ api_put :update, id: stranger.id, token: user.spree_api_key, user: { :email => "mine@example.com" }
80
78
  assert_not_found!
81
79
  end
82
80
 
83
81
  it "can delete itself" do
84
- api_delete :destroy, :id => user.id
82
+ api_delete :destroy, id: user.id, token: user.spree_api_key
85
83
  expect(response.status).to eq(204)
86
84
  end
87
85
 
88
86
  it "cannot delete other user" do
89
- api_delete :destroy, :id => stranger.id
87
+ api_delete :destroy, id: stranger.id, token: user.spree_api_key
90
88
  assert_not_found!
91
89
  end
92
90
 
93
91
  it "should only get own details on index" do
94
92
  2.times { create(:user) }
95
- api_get :index
93
+ api_get :index, token: user.spree_api_key
96
94
 
97
95
  expect(Spree.user_class.count).to eq 3
98
96
  expect(json_response['count']).to eq 1
@@ -101,6 +99,8 @@ module Spree
101
99
  end
102
100
 
103
101
  context "as an admin" do
102
+ before { stub_authentication! }
103
+
104
104
  sign_in_as_admin!
105
105
 
106
106
  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.4.4
4
+ version: 2.4.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Bigg
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-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.4.4
19
+ version: 2.4.5
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.4.4
26
+ version: 2.4.5
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rabl
29
29
  requirement: !ruby/object:Gem::Requirement