spree_api 2.3.7 → 2.3.8

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: c86642ea05d6a5350541464b82b8b774febe3532
4
- data.tar.gz: 91018c99f686869bda68dd2739a3b7c12bca104a
3
+ metadata.gz: a470389ba42cc2784f2674b4314aae172289e33a
4
+ data.tar.gz: 5337359568da0e0eea4f7bed4ee290fdfb3250f5
5
5
  SHA512:
6
- metadata.gz: 06c52b89378e523abd9afb3b70d062db5e5c470f7cf0f6b29bfe34183404ad5b6b110d6e4b89e54fc1885fddf7e93fc10c4290cfcc83958c9fd5b9dac35cf58b
7
- data.tar.gz: 293b54a13a576887073affb535b710c96f46101a38f5da1748733ec88a56d22041ad8c487bfc6fae48d0611fe0f7443ebc58b2986701382c6fa99534336a1985
6
+ metadata.gz: 647eccbe632e19c45bd23103cc8e0cf089cd037983b0b175acf7fd418820761f3858e52dfabb4a08cc3a0e3fbfbdb5f4a5d16c6d26463d6ba5af6912a4fa8971
7
+ data.tar.gz: 70c8168c225c5891b62bf63f7ea0fcfb4b9348f1638f4612e2f5ab8279e8097ea31669f4a7c3160f2f0ebd9e863392d04c99f9d95dea1856446ceb68fff07c7e
@@ -65,7 +65,7 @@ module Spree
65
65
  end
66
66
 
67
67
  def load_user
68
- @current_api_user = (try_spree_current_user || Spree.user_class.find_by(spree_api_key: api_key.to_s))
68
+ @current_api_user = Spree.user_class.find_by(spree_api_key: api_key.to_s)
69
69
  end
70
70
 
71
71
  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
@@ -8,17 +8,9 @@ describe Spree::Api::BaseController, :type => :controller 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
- user = double(:email => "spree@example.com")
14
- allow(user).to receive_message_chain :spree_roles, pluck: []
15
- allow(controller).to receive_messages :try_spree_current_user => user
16
- end
17
-
18
- it "can make a request" do
19
- api_get :index
20
- expect(json_response).to eq({ "products" => [] })
21
- expect(response.status).to eq(200)
11
+ before do
12
+ @routes = ActionDispatch::Routing::RouteSet.new.tap do |r|
13
+ r.draw { get 'index', to: 'spree/api/base#index' }
22
14
  end
23
15
  end
24
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
- allow(controller).to receive_messages :try_spree_current_user => current_api_user
15
18
  api_get :new
16
19
  expect(json_response["attributes"]).to eq(["quantity", "price", "variant_id"])
17
20
  required_attributes = json_response["required_attributes"]
@@ -37,7 +40,6 @@ module Spree
37
40
 
38
41
  context "as the order owner" do
39
42
  before do
40
- allow(controller).to receive_messages :try_spree_current_user => current_api_user
41
43
  allow_any_instance_of(Order).to receive_messages :user => current_api_user
42
44
  end
43
45
 
@@ -126,7 +128,6 @@ module Spree
126
128
  context "as just another user" do
127
129
  before do
128
130
  user = create(:user)
129
- allow(controller).to receive_messages :try_spree_current_user => user
130
131
  end
131
132
 
132
133
  it "cannot add a new line item to the order" do
@@ -172,7 +172,7 @@ module Spree
172
172
  allow(user).to receive_message_chain(:spree_roles, :pluck).and_return(["bar"])
173
173
  allow(user).to receive(:has_spree_role?).with('bar').and_return(true)
174
174
  allow(user).to receive(:has_spree_role?).with('admin').and_return(false)
175
- allow(controller).to receive_messages try_spree_current_user: user
175
+ allow(Spree.user_class).to receive_messages find_by: user
176
176
  api_get :show, :id => order.to_param
177
177
  expect(response.status).to eq(200)
178
178
  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.3.7
4
+ version: 2.3.8
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.3.7
19
+ version: 2.3.8
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.7
26
+ version: 2.3.8
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rabl
29
29
  requirement: !ruby/object:Gem::Requirement