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 +4 -4
- data/app/controllers/spree/api/base_controller.rb +1 -1
- data/lib/spree/api/testing_support/helpers.rb +1 -1
- data/spec/controllers/spree/api/base_controller_spec.rb +3 -10
- data/spec/controllers/spree/api/line_items_controller_spec.rb +7 -4
- data/spec/controllers/spree/api/orders_controller_spec.rb +4 -3
- data/spec/controllers/spree/api/users_controller_spec.rb +22 -22
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c1e4f94cd07462a030047555911538bcaf13cba8
|
4
|
+
data.tar.gz: f35bbca0a030a0627ee12d6e53689e52b83c3956
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fc7bb77eff861a8585824f001119058b5388be6cd27f09605785cae8b20e62e6d3c04eaadf836b4524c2b74d7cc1cd2bb56e2972f6a27879af24c5da558d0b0f
|
7
|
+
data.tar.gz: f0bf714d8696e7abb69a6f56d9626821216b4aab9005aec55d0fa8d890e062480db1006a1aadc485e18ee34a83a3d7da9df0e4c24adf66807e6610e5972da6cf
|
@@ -17,7 +17,7 @@ module Spree
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def stub_authentication!
|
20
|
-
Spree
|
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
|
-
|
12
|
-
|
13
|
-
|
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
|
-
|
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
|
-
|
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.
|
139
|
-
user.
|
140
|
-
|
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
|
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
|
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"].
|
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
|
-
|
37
|
-
|
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.
|
44
|
-
json_response["error"].
|
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, :
|
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, :
|
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
|
60
|
-
response.status.
|
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
|
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.
|
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:
|
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.
|
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.
|
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.
|
257
|
+
rubygems_version: 2.4.5
|
258
258
|
signing_key:
|
259
259
|
specification_version: 4
|
260
260
|
summary: Spree's API
|