spree_api 3.0.0.rc3 → 3.0.0.rc4

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: ce116e8fb4a30f1ccbe401442ea8f6d467b664ad
4
- data.tar.gz: f3eb5f31fafbc8481803e6054228fda895d9d747
3
+ metadata.gz: 289fb29c93471320f7597347942a3e5977c44376
4
+ data.tar.gz: f7286dcb7c91f8a12a0ea037629c87ed10acc163
5
5
  SHA512:
6
- metadata.gz: 235a1081a4cb779a5e78879937479474f14630355b3c080b404a79ea0958e3f137d02a7f9cfee2aa6e8b6863e76f0beaf3727d41b150967e637e227bbdcebef0
7
- data.tar.gz: 537fe799160cebcd7bb91609e57f7e547bcc19b2be169264156247b2b5e0f8d62318bf6f4a9a5c6064d29d5c40aa6cc0f1f88c790f9797d24eda3ba544edac16
6
+ metadata.gz: f51b957333c99f66c04f1552caaae42ab3c07dd130c915e592fec07b758f60a47d52eb033898dfb8812b2de6ec3ed92be28987b76f5f489da7bb0105b4d1038a
7
+ data.tar.gz: e86dd63722a692e1271acb5bd198ec1b694e792811d3abb13d7786358dbd01724b7cc2e1d8ea03e162ea9779cc834a59e36f08932bb35bc3162fea8737f61ec3
data/CHANGELOG.md CHANGED
@@ -1 +1,3 @@
1
- ## Spree 2.4.0 (unreleased) ##
1
+ ## Spree 3.0.0 (unreleased) ##
2
+
3
+ * Deprecate the Spree::Api::ConfigController
@@ -64,7 +64,7 @@ module Spree
64
64
  end
65
65
 
66
66
  def load_user
67
- @current_api_user = (try_spree_current_user || Spree.user_class.find_by(spree_api_key: api_key.to_s))
67
+ @current_api_user = Spree.user_class.find_by(spree_api_key: api_key.to_s)
68
68
  end
69
69
 
70
70
  def authenticate_user
@@ -4,6 +4,7 @@ attributes *variant_attributes
4
4
 
5
5
  node(:display_price) { |p| p.display_price.to_s }
6
6
  node(:options_text) { |v| v.options_text }
7
+ node(:track_inventory) { |v| v.should_track_inventory? }
7
8
  node(:in_stock) { |v| v.in_stock? }
8
9
  node(:is_backorderable) { |v| v.is_backorderable? }
9
10
  node(:total_on_hand) { |v| v.total_on_hand }
data/config/routes.rb CHANGED
@@ -118,9 +118,6 @@ Spree::Core::Engine.add_routes do
118
118
  resources :stock_items, only: [:index, :update, :destroy]
119
119
  resources :stores
120
120
 
121
- get '/config/money', to: 'config#money'
122
- get '/config', to: 'config#show'
123
-
124
121
  put '/classifications', to: 'classifications#update', as: :classifications
125
122
  get '/taxons/products', to: 'taxons#products', as: :taxon_products
126
123
  end
@@ -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
@@ -17,20 +17,6 @@ describe Spree::Api::BaseController, :type => :controller do
17
17
  end
18
18
  end
19
19
 
20
- context "signed in as a user using an authentication extension" do
21
- before do
22
- user = double(:email => "spree@example.com")
23
- allow(user).to receive_message_chain :spree_roles, pluck: []
24
- allow(controller).to receive_messages :try_spree_current_user => user
25
- end
26
-
27
- it "can make a request" do
28
- api_get :index
29
- expect(json_response).to eq({ "products" => [] })
30
- expect(response.status).to eq(200)
31
- end
32
- end
33
-
34
20
  context "when validating based on an order token" do
35
21
  let!(:order) { create :order }
36
22
 
@@ -123,7 +109,7 @@ describe Spree::Api::BaseController, :type => :controller do
123
109
  before do
124
110
  user = double(email: "spree@example.com")
125
111
  allow(user).to receive_message_chain :spree_roles, pluck: []
126
- allow(controller).to receive_messages try_spree_current_user: user
112
+ allow(Spree.user_class).to receive_messages find_by: user
127
113
  @routes = ActionDispatch::Routing::RouteSet.new.tap do |r|
128
114
  r.draw { get 'foo' => 'fakes#foo' }
129
115
  end
@@ -131,7 +117,7 @@ describe Spree::Api::BaseController, :type => :controller do
131
117
 
132
118
  it 'should notify notify_error_during_processing' do
133
119
  expect(MockHoneybadger).to receive(:notify_or_ignore).once.with(kind_of(Exception), rack_env: kind_of(Hash))
134
- api_get :foo
120
+ api_get :foo, token: 123
135
121
  expect(response.status).to eq(422)
136
122
  end
137
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
@@ -215,7 +215,7 @@ module Spree
215
215
  allow(user).to receive_message_chain(:spree_roles, :pluck).and_return(["bar"])
216
216
  allow(user).to receive(:has_spree_role?).with('bar').and_return(true)
217
217
  allow(user).to receive(:has_spree_role?).with('admin').and_return(false)
218
- allow(controller).to receive_messages try_spree_current_user: user
218
+ allow(Spree.user_class).to receive_messages find_by: user
219
219
  api_get :show, :id => order.to_param
220
220
  expect(response.status).to eq(200)
221
221
  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: 3.0.0.rc3
4
+ version: 3.0.0.rc4
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: 3.0.0.rc3
19
+ version: 3.0.0.rc4
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: 3.0.0.rc3
26
+ version: 3.0.0.rc4
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rabl
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -68,7 +68,6 @@ files:
68
68
  - app/controllers/spree/api/base_controller.rb
69
69
  - app/controllers/spree/api/checkouts_controller.rb
70
70
  - app/controllers/spree/api/classifications_controller.rb
71
- - app/controllers/spree/api/config_controller.rb
72
71
  - app/controllers/spree/api/countries_controller.rb
73
72
  - app/controllers/spree/api/credit_cards_controller.rb
74
73
  - app/controllers/spree/api/images_controller.rb
@@ -210,7 +209,6 @@ files:
210
209
  - spec/controllers/spree/api/base_controller_spec.rb
211
210
  - spec/controllers/spree/api/checkouts_controller_spec.rb
212
211
  - spec/controllers/spree/api/classifications_controller_spec.rb
213
- - spec/controllers/spree/api/config_controller_spec.rb
214
212
  - spec/controllers/spree/api/countries_controller_spec.rb
215
213
  - spec/controllers/spree/api/credit_cards_controller_spec.rb
216
214
  - spec/controllers/spree/api/images_controller_spec.rb
@@ -276,7 +274,6 @@ test_files:
276
274
  - spec/controllers/spree/api/base_controller_spec.rb
277
275
  - spec/controllers/spree/api/checkouts_controller_spec.rb
278
276
  - spec/controllers/spree/api/classifications_controller_spec.rb
279
- - spec/controllers/spree/api/config_controller_spec.rb
280
277
  - spec/controllers/spree/api/countries_controller_spec.rb
281
278
  - spec/controllers/spree/api/credit_cards_controller_spec.rb
282
279
  - spec/controllers/spree/api/images_controller_spec.rb
@@ -1,6 +0,0 @@
1
- module Spree
2
- module Api
3
- class ConfigController < Spree::Api::BaseController
4
- end
5
- end
6
- end
@@ -1,23 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Spree
4
- describe Api::ConfigController, :type => :controller do
5
- render_views
6
-
7
- before do
8
- stub_authentication!
9
- end
10
-
11
- it "returns Spree::Money settings" do
12
- api_get :money
13
- expect(response).to be_success
14
- expect(json_response["symbol"]).to eq("$")
15
- end
16
-
17
- it "returns some configuration settings" do
18
- api_get :show
19
- expect(response).to be_success
20
- expect(json_response["default_country_id"]).to eq(Spree::Config[:default_country_id])
21
- end
22
- end
23
- end