cadenero 0.0.2.b3 → 0.0.2.b4

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.
Files changed (31) hide show
  1. checksums.yaml +8 -8
  2. data/README.md +12 -9
  3. data/app/controllers/cadenero/v1/account/sessions_controller.rb +1 -1
  4. data/app/controllers/cadenero/v1/account/users_controller.rb +8 -9
  5. data/app/controllers/cadenero/v1/accounts_controller.rb +2 -9
  6. data/app/extenders/controllers/application_controller_decorator.rb +1 -1
  7. data/app/extenders/middleware/robustness.rb +0 -2
  8. data/app/models/cadenero/user.rb +2 -1
  9. data/app/models/cadenero/v1/account.rb +2 -0
  10. data/config/routes.rb +3 -2
  11. data/lib/cadenero/testing_support/authentication_helpers.rb +93 -0
  12. data/lib/cadenero/version.rb +1 -1
  13. data/spec/dummy/config/application.rb +8 -7
  14. data/spec/dummy/config/boot.rb +7 -3
  15. data/spec/dummy/config/environments/development.rb +9 -2
  16. data/spec/dummy/config/environments/production.rb +1 -2
  17. data/spec/dummy/config/environments/test.rb +7 -2
  18. data/spec/dummy/config/initializers/secret_token.rb +13 -2
  19. data/spec/dummy/config/initializers/wrap_parameters.rb +13 -0
  20. data/spec/dummy/log/development.log +5 -0
  21. data/spec/dummy/log/test.log +16262 -0
  22. data/spec/features/accounts/sign_up_spec.rb +10 -23
  23. data/spec/features/users/sign_in_spec.rb +16 -50
  24. data/spec/features/users/sign_up_spec.rb +22 -17
  25. data/spec/support/factories/user_factory.rb +0 -1
  26. metadata +18 -39
  27. data/config/initializers/strong_parameters.rb +0 -1
  28. data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -7
  29. data/spec/dummy/config/initializers/inflections.rb +0 -15
  30. data/spec/dummy/config/initializers/mime_types.rb +0 -5
  31. data/spec/dummy/config/initializers/session_store.rb +0 -8
@@ -1,34 +1,21 @@
1
1
  require 'spec_helper'
2
+ require 'cadenero/testing_support/authentication_helpers'
2
3
 
3
- def create_account
4
- @visitor ||= { name: "Testy", subdomain: "test", owner_attributes:
5
- {email: "testy@example.com", password: "changeme", password_confirmation: "changeme"} }
6
- end
7
-
8
- def find_account_by_name
9
- @account = Cadenero::V1::Account.where(name: @visitor[:name]).first
10
- end
4
+ feature 'Accounts' do
5
+ include Cadenero::TestingSupport::AuthenticationHelpers
11
6
 
12
- def sign_up
13
- create_account
14
- post "/v1/accounts", format: :json, account: @visitor
15
- find_account_by_name
16
- end
7
+ let(:errors_already_taken_subdomain) {{ errors: {subdomain:["has already been taken"]} }.to_json}
17
8
 
18
- feature 'Accounts' do
19
9
  scenario "creating an account" do
20
- sign_up
10
+ sign_up_account
21
11
  expect(last_response.status).to eq 201
22
- expect(JSON.parse(last_response.body)).to have_content "authentication_token"
23
- expect(JSON.parse(last_response.body)["account"]["authentication_token"]).not_to eq nil
12
+ expect(json_last_response_body).to have_content "authentication_token"
13
+ expect(json_last_response_body["account"]["authentication_token"]).not_to eq nil
24
14
  end
25
15
 
26
16
  scenario "cannot create an account with an already used subdomain" do
27
- create_account
28
- Cadenero::V1::Account.create!(@visitor)
29
- sign_up
30
- expect(last_response.status).to eq 422
31
- errors = { errors: {subdomain:["has already been taken"]} }
32
- expect(last_response.body).to eql(errors.to_json)
17
+ Cadenero::V1::Account.create!(create_account)
18
+ sign_up_account
19
+ expected_json_errors(errors_already_taken_subdomain)
33
20
  end
34
21
  end
@@ -1,26 +1,11 @@
1
1
  require 'spec_helper'
2
2
  require 'cadenero/testing_support/subdomain_helpers'
3
+ require 'cadenero/testing_support/authentication_helpers'
3
4
 
4
5
  feature 'User sign in' do
5
6
  extend Cadenero::TestingSupport::SubdomainHelpers
6
-
7
- def create_account_user
8
- @user ||= { email: "user@example.com", password: "password" }
9
- end
10
-
11
- def account_user(user)
12
- @user = { email: user.email, password: "password" }
13
- end
14
-
15
- def find_account_by_email
16
- create_account_user
17
- @account = Cadenero::V1::Account.where(name: @user[:email]).first
18
- end
19
-
20
- def sign_in_user(url, user)
21
- post "#{url}", format: :json, user: user
22
- find_account_by_email
23
- end
7
+ include Cadenero::TestingSupport::AuthenticationHelpers
8
+
24
9
 
25
10
  let(:account) { FactoryGirl.create(:account_with_schema) }
26
11
  let(:errors_redirect_ro_sign_in) {{errors: %Q{Please sign in. posting the user json credentials as: {"user": {"email": "testy2@example.com", "password": "changeme"}} to /v1/sessions}, links: "/v1/sessions"}.to_json}
@@ -32,64 +17,45 @@ feature 'User sign in' do
32
17
 
33
18
  within_account_subdomain do
34
19
  scenario "signs in as an account owner successfully" do
35
- get cadenero.v1_root_url(:subdomain => account.subdomain)
36
- expect(last_response.body).to eql(errors_redirect_ro_sign_in)
37
- expect(last_response.status).to eq 422
38
- sign_in_user sessions_url, account_user(account.owner)
39
- expect(last_response.status).to eq 201
40
- expect(JSON.parse(last_response.body)["user"]["account_ids"]).to eq [account.id]
41
- user_email = JSON.parse(last_response.body)["user"]["email"]
42
- expect(JSON.parse(last_response.body)).to have_content "auth_token"
43
- access_token = JSON.parse(last_response.body)["user"]["auth_token"]
44
- expect(JSON.parse(last_response.body)["user"]["auth_token"]).to eq account.authentication_token
20
+ check_error_for_not_signed_in_yet
21
+ user_email = successful_sign_in_owner(account)
45
22
  get root_url
46
23
  expect(last_response.status).to eq 200
47
- expect(JSON.parse(last_response.body)["message"]).to have_content user_email
24
+ expect(json_last_response_body["message"]).to have_content user_email
48
25
  end
49
26
 
50
27
  scenario "signout as an account owner successfully" do
51
- sign_in_user sessions_url, account_user(account.owner)
52
- expect(last_response.status).to eq 201
53
- expect(JSON.parse(last_response.body)["user"]["account_ids"]).to eq [account.id]
54
- user_email = JSON.parse(last_response.body)["user"]["email"]
28
+ user_email = successful_sign_in_owner(account)
55
29
  delete sessions_url, id: account.owner.id
56
30
  expect(last_response.status).to eq 200
57
- expect(JSON.parse(last_response.body)["message"]).to have_content "Successful logout"
58
- get cadenero.v1_root_url(:subdomain => account.subdomain)
59
- expect(last_response.status).to eq 422
60
- expect(last_response.body).to eql(errors_redirect_ro_sign_in)
31
+ expect(json_last_response_body["message"]).to have_content "Successful logout"
32
+ check_error_for_not_signed_in_yet
61
33
  end
62
34
 
63
35
  end
64
36
 
65
37
  it "attempts sign in with an invalid password and fails" do
66
- get cadenero.v1_root_url(:subdomain => account.subdomain)
67
- expect(last_response.body).to eql(errors_redirect_ro_sign_in)
38
+ check_error_for_not_signed_in_yet
68
39
  sign_in_user sessions_url, { email: "user@example.com", password: "" }
69
- expect(last_response.status).to eq 422
70
- expect(last_response.body).to eql(errors_invalid_email_or_password)
40
+ expected_json_errors(errors_invalid_email_or_password)
71
41
  end
72
42
 
73
43
  it "attempts sign in with an invalid email address and fails" do
74
- get cadenero.v1_root_url(:subdomain => account.subdomain)
75
- expect(last_response.body).to eql(errors_redirect_ro_sign_in)
44
+ check_error_for_not_signed_in_yet
76
45
  sign_in_user sessions_url, { email: "foo@example.com", password: "password"}
77
- expect(last_response.status).to eq 422
78
- expect(last_response.body).to eql(errors_invalid_email_or_password)
46
+ expected_json_errors(errors_invalid_email_or_password)
79
47
  end
80
48
 
81
- it "cannot sign in if not a part of an existing subdomain" do
49
+ it "cannot sign in if not a member of an existing subdomain" do
82
50
  other_account = FactoryGirl.create(:account)
83
51
  get cadenero.v1_root_url(:subdomain => account.subdomain)
84
52
  expect(last_response.body).to eql(errors_redirect_ro_sign_in)
85
53
  sign_in_user sessions_url, { email: other_account.owner.email, password: "" }
86
- expect(last_response.status).to eq 422
87
- expect(last_response.body).to eql(errors_invalid_email_or_password)
54
+ expected_json_errors(errors_invalid_email_or_password)
88
55
  end
89
56
 
90
57
  it "cannot sign in if the subdomain does not exist" do
91
58
  sign_in_user error_url, account_user(account.owner)
92
- expect(last_response.status).to eq 422
93
- expect(last_response.body).to eql(errors_invalid_subdomain)
59
+ expected_json_errors(errors_invalid_subdomain)
94
60
  end
95
61
  end
@@ -1,27 +1,32 @@
1
1
  require 'spec_helper'
2
-
3
- def create_account_user
4
- @user ||= { email: "user@example.com", password: "password", password_confirmation: "password" }
5
- end
6
-
7
- def find_account_by_email
8
- @account = Cadenero::V1::Account.where(name: @user[:email]).first
9
- end
10
-
11
- def sign_up_user(url)
12
- create_account_user
13
- post "#{url}/v1/users", format: :json, user: @user
14
- find_account_by_email
15
- end
2
+ require 'cadenero/testing_support/authentication_helpers'
16
3
 
17
4
  feature "User signup" do
18
- let(:account) { FactoryGirl.create(:account_with_schema) }
5
+ include Cadenero::TestingSupport::AuthenticationHelpers
6
+
7
+ let!(:account) { FactoryGirl.create(:account_with_schema) }
19
8
  let(:root_url) { "http://#{account.subdomain}.example.com/" }
20
9
  scenario "under an account" do
21
10
  sign_up_user root_url
22
11
  expect(last_response.status).to eq 201
23
- puts "last_response.body: #{last_response.body}"
24
- expect(JSON.parse(last_response.body)["user"]["membership_ids"]).to eq [account.id]
12
+ expect(json_last_response_body["user"]["membership_ids"]).to eq [account.id]
25
13
  expect(last_request.url).to eq "#{root_url}v1/users"
14
+ get "#{root_url}v1/users/#{json_last_response_body['user']['id']}"
15
+ expect(json_last_response_body["user"]["membership_ids"]).to eq [account.id]
26
16
  end
17
+
18
+ scenario "under two accounts" do
19
+ sign_up_user root_url
20
+ user_id = json_last_response_body['user']['id']
21
+ get "#{root_url}v1/users/#{user_id}"
22
+ expect(json_last_response_body["user"]["membership_ids"]).to eq [account.id]
23
+ second_account = FactoryGirl.create(:account_with_schema, owner: Cadenero::User.where(id: user_id).first)
24
+ sign_up_user "http://#{second_account.subdomain}.example.com/"
25
+ expect(json_last_response_body["user"]["membership_ids"]).to eq [second_account.id]
26
+ get "#{root_url}v1/users/#{user_id}"
27
+ expect(json_last_response_body["user"]["membership_ids"]).to eq [account.id, second_account.id]
28
+ get "#{root_url}v1/users"
29
+ expect(json_last_response_body["users"].length).to eq 2
30
+ end
31
+
27
32
  end
@@ -2,6 +2,5 @@ FactoryGirl.define do
2
2
  factory :user, :class => Cadenero::User do
3
3
  sequence(:email) { |n| "user#{n}@example.com" }
4
4
  password "password"
5
- password_confirmation "password"
6
5
  end
7
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cadenero
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2.b3
4
+ version: 0.0.2.b4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Manuel Vidaurre
@@ -10,20 +10,6 @@ bindir: bin
10
10
  cert_chain: []
11
11
  date: 2013-07-12 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: actionpack
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ~>
18
- - !ruby/object:Gem::Version
19
- version: 4.0.0
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ~>
25
- - !ruby/object:Gem::Version
26
- version: 4.0.0
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: rails-api
29
15
  requirement: !ruby/object:Gem::Requirement
@@ -80,6 +66,20 @@ dependencies:
80
66
  - - ~>
81
67
  - !ruby/object:Gem::Version
82
68
  version: '0.22'
69
+ - !ruby/object:Gem::Dependency
70
+ name: strong_parameters
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: 0.2.1
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: 0.2.1
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: active_model_serializers
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -192,20 +192,6 @@ dependencies:
192
192
  - - ~>
193
193
  - !ruby/object:Gem::Version
194
194
  version: 1.0.1
195
- - !ruby/object:Gem::Dependency
196
- name: yard
197
- requirement: !ruby/object:Gem::Requirement
198
- requirements:
199
- - - ! '>='
200
- - !ruby/object:Gem::Version
201
- version: '0'
202
- type: :development
203
- prerelease: false
204
- version_requirements: !ruby/object:Gem::Requirement
205
- requirements:
206
- - - ! '>='
207
- - !ruby/object:Gem::Version
208
- version: '0'
209
195
  description: A Rails.API Engine that use Warden for authenticate users using a RESTful
210
196
  API in a multitenant way
211
197
  email:
@@ -233,7 +219,6 @@ files:
233
219
  - app/serializers/cadenero/account_serializer.rb
234
220
  - app/serializers/cadenero/user_serializer.rb
235
221
  - config/initializers/apartment.rb
236
- - config/initializers/strong_parameters.rb
237
222
  - config/initializers/warden/strategies/password.rb
238
223
  - config/initializers/warden.rb
239
224
  - config/routes.rb
@@ -244,6 +229,7 @@ files:
244
229
  - lib/cadenero/active_record_extensions.rb
245
230
  - lib/cadenero/constraints/subdomain_required.rb
246
231
  - lib/cadenero/engine.rb
232
+ - lib/cadenero/testing_support/authentication_helpers.rb
247
233
  - lib/cadenero/testing_support/subdomain_helpers.rb
248
234
  - lib/cadenero/version.rb
249
235
  - lib/cadenero.rb
@@ -262,12 +248,9 @@ files:
262
248
  - spec/dummy/config/environments/development.rb
263
249
  - spec/dummy/config/environments/production.rb
264
250
  - spec/dummy/config/environments/test.rb
265
- - spec/dummy/config/initializers/backtrace_silencers.rb
266
251
  - spec/dummy/config/initializers/cadenero.rb
267
- - spec/dummy/config/initializers/inflections.rb
268
- - spec/dummy/config/initializers/mime_types.rb
269
252
  - spec/dummy/config/initializers/secret_token.rb
270
- - spec/dummy/config/initializers/session_store.rb
253
+ - spec/dummy/config/initializers/wrap_parameters.rb
271
254
  - spec/dummy/config/locales/en.yml
272
255
  - spec/dummy/config/routes.rb
273
256
  - spec/dummy/config.ru
@@ -336,12 +319,9 @@ test_files:
336
319
  - spec/dummy/config/environments/development.rb
337
320
  - spec/dummy/config/environments/production.rb
338
321
  - spec/dummy/config/environments/test.rb
339
- - spec/dummy/config/initializers/backtrace_silencers.rb
340
322
  - spec/dummy/config/initializers/cadenero.rb
341
- - spec/dummy/config/initializers/inflections.rb
342
- - spec/dummy/config/initializers/mime_types.rb
343
323
  - spec/dummy/config/initializers/secret_token.rb
344
- - spec/dummy/config/initializers/session_store.rb
324
+ - spec/dummy/config/initializers/wrap_parameters.rb
345
325
  - spec/dummy/config/locales/en.yml
346
326
  - spec/dummy/config/routes.rb
347
327
  - spec/dummy/config.ru
@@ -376,4 +356,3 @@ test_files:
376
356
  - spec/support/factories/account_factory.rb
377
357
  - spec/support/factories/user_factory.rb
378
358
  - spec/support/generator_macros.rb
379
- has_rdoc:
@@ -1 +0,0 @@
1
- ActionController::API.send :include, ActionController::StrongParameters
@@ -1,7 +0,0 @@
1
- # Be sure to restart your server when you modify this file.
2
-
3
- # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
4
- # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
5
-
6
- # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
7
- # Rails.backtrace_cleaner.remove_silencers!
@@ -1,15 +0,0 @@
1
- # Be sure to restart your server when you modify this file.
2
-
3
- # Add new inflection rules using the following format
4
- # (all these examples are active by default):
5
- # ActiveSupport::Inflector.inflections do |inflect|
6
- # inflect.plural /^(ox)$/i, '\1en'
7
- # inflect.singular /^(ox)en/i, '\1'
8
- # inflect.irregular 'person', 'people'
9
- # inflect.uncountable %w( fish sheep )
10
- # end
11
- #
12
- # These inflection rules are supported but not enabled by default:
13
- # ActiveSupport::Inflector.inflections do |inflect|
14
- # inflect.acronym 'RESTful'
15
- # end
@@ -1,5 +0,0 @@
1
- # Be sure to restart your server when you modify this file.
2
-
3
- # Add new mime types for use in respond_to blocks:
4
- # Mime::Type.register "text/richtext", :rtf
5
- # Mime::Type.register_alias "text/html", :iphone
@@ -1,8 +0,0 @@
1
- # Be sure to restart your server when you modify this file.
2
-
3
- Dummy::Application.config.session_store :cookie_store, key: '_dummy_session'
4
-
5
- # Use the database for sessions instead of the cookie-based default,
6
- # which shouldn't be used to store highly confidential information
7
- # (create the session table with "rails generate session_migration")
8
- # Dummy::Application.config.session_store :active_record_store