cadenero 0.0.2.b4 → 0.0.2.b5
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 +8 -8
- data/README.md +19 -4
- data/app/controllers/cadenero/v1/account/users_controller.rb +4 -3
- data/app/controllers/cadenero/v1/accounts_controller.rb +3 -5
- data/app/extenders/controllers/application_controller_decorator.rb +4 -5
- data/app/models/cadenero/member.rb +43 -1
- data/app/models/cadenero/user.rb +5 -5
- data/app/models/cadenero/v1/account.rb +17 -10
- data/config/initializers/apartment.rb +0 -1
- data/config/initializers/warden/strategies/password.rb +1 -1
- data/db/migrate/20130612061604_create_cadenero_v1_accounts.rb +1 -1
- data/db/migrate/20130715174857_add_auth_token_to_cadenero_members.rb +6 -0
- data/db/seeds.rb +3 -3
- data/lib/cadenero.rb +6 -6
- data/lib/cadenero/engine.rb +1 -1
- data/lib/cadenero/testing_support/authentication_helpers.rb +55 -18
- data/lib/cadenero/testing_support/subdomain_helpers.rb +1 -1
- data/lib/cadenero/version.rb +1 -1
- data/lib/generators/cadenero/install_generator.rb +4 -9
- data/spec/controllers/cadenero/v1/accounts_controller_spec.rb +3 -5
- data/spec/controllers/cadenero/v1/users_controller_spec.rb +53 -0
- data/spec/dummy/config/initializers/cadenero.rb +13 -0
- data/spec/dummy/db/schema.rb +3 -1
- data/spec/dummy/log/development.log +8 -0
- data/spec/dummy/log/test.log +39150 -0
- data/spec/features/accounts/sign_up_spec.rb +1 -1
- data/spec/features/users/sign_in_spec.rb +49 -24
- data/spec/features/users/sign_up_spec.rb +8 -15
- data/spec/generators/install_generator_spec.rb +41 -6
- data/spec/models/cadenero/member_spec.rb +11 -1
- metadata +5 -2
@@ -14,7 +14,7 @@ feature 'Accounts' do
|
|
14
14
|
end
|
15
15
|
|
16
16
|
scenario "cannot create an account with an already used subdomain" do
|
17
|
-
Cadenero::V1::Account.create!(
|
17
|
+
Cadenero::V1::Account.create!(create_account_params_json)
|
18
18
|
sign_up_account
|
19
19
|
expected_json_errors(errors_already_taken_subdomain)
|
20
20
|
end
|
@@ -5,7 +5,6 @@ require 'cadenero/testing_support/authentication_helpers'
|
|
5
5
|
feature 'User sign in' do
|
6
6
|
extend Cadenero::TestingSupport::SubdomainHelpers
|
7
7
|
include Cadenero::TestingSupport::AuthenticationHelpers
|
8
|
-
|
9
8
|
|
10
9
|
let(:account) { FactoryGirl.create(:account_with_schema) }
|
11
10
|
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}
|
@@ -18,44 +17,70 @@ feature 'User sign in' do
|
|
18
17
|
within_account_subdomain do
|
19
18
|
scenario "signs in as an account owner successfully" do
|
20
19
|
check_error_for_not_signed_in_yet
|
21
|
-
user_email = successful_sign_in_owner
|
20
|
+
user_email = successful_sign_in_owner account
|
22
21
|
get root_url
|
23
22
|
expect(last_response.status).to eq 200
|
24
23
|
expect(json_last_response_body["message"]).to have_content user_email
|
25
24
|
end
|
26
25
|
|
26
|
+
scenario "signs in as a user successfully" do
|
27
|
+
check_error_for_not_signed_in_yet
|
28
|
+
second_user_email = successful_sign_up_user_in_existing_account account, "_second"
|
29
|
+
second_user = Cadenero::User.where(email: second_user_email).first
|
30
|
+
successful_sign_in_user(account, account_user_params_json(second_user))
|
31
|
+
get root_url
|
32
|
+
expect(last_response.status).to eq 200
|
33
|
+
expect(json_last_response_body["message"]).to have_content second_user_email
|
34
|
+
end
|
35
|
+
|
27
36
|
scenario "signout as an account owner successfully" do
|
28
|
-
user_email = successful_sign_in_owner
|
37
|
+
user_email = successful_sign_in_owner account
|
29
38
|
delete sessions_url, id: account.owner.id
|
30
39
|
expect(last_response.status).to eq 200
|
31
40
|
expect(json_last_response_body["message"]).to have_content "Successful logout"
|
32
41
|
check_error_for_not_signed_in_yet
|
33
42
|
end
|
34
43
|
|
35
|
-
|
44
|
+
scenario "two users of the same account should have different auth_tokens" do
|
45
|
+
user_email = successful_sign_in_owner account
|
46
|
+
user_auth_token = json_last_response_body["user"]["auth_token"]
|
47
|
+
user = Cadenero::User.where(email: user_email).first
|
48
|
+
delete sessions_url, id: user.id
|
49
|
+
check_error_for_not_signed_in_yet
|
50
|
+
second_user_email = successful_sign_up_user_in_existing_account account, "_second"
|
51
|
+
second_user = Cadenero::User.where(email: second_user_email).first
|
52
|
+
successful_sign_in_user(account, account_user_params_json(second_user))
|
53
|
+
second_user_auth_token = json_last_response_body["user"]["auth_token"]
|
54
|
+
expect(second_user_auth_token).not_to eq([])
|
55
|
+
expect(user).not_to eq(second_user)
|
56
|
+
expect(user_auth_token).not_to eq(second_user_auth_token)
|
57
|
+
end
|
36
58
|
|
37
|
-
it "attempts sign in with an invalid password and fails" do
|
38
|
-
check_error_for_not_signed_in_yet
|
39
|
-
sign_in_user sessions_url, { email: "user@example.com", password: "" }
|
40
|
-
expected_json_errors(errors_invalid_email_or_password)
|
41
59
|
end
|
42
60
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
61
|
+
context "without sign in" do
|
62
|
+
scenario "attempts sign in with an invalid password and fails" do
|
63
|
+
check_error_for_not_signed_in_yet
|
64
|
+
sign_in_user sessions_url, { email: "user@example.com", password: "" }
|
65
|
+
expected_json_errors(errors_invalid_email_or_password)
|
66
|
+
end
|
48
67
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
expected_json_errors(errors_invalid_email_or_password)
|
55
|
-
end
|
68
|
+
scenario "attempts sign in with an invalid email address and fails" do
|
69
|
+
check_error_for_not_signed_in_yet
|
70
|
+
sign_in_user sessions_url, { email: "foo@example.com", password: "password"}
|
71
|
+
expected_json_errors(errors_invalid_email_or_password)
|
72
|
+
end
|
56
73
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
74
|
+
scenario "cannot sign in if not a member of an existing subdomain" do
|
75
|
+
other_account = FactoryGirl.create(:account)
|
76
|
+
check_error_for_not_signed_in_yet
|
77
|
+
sign_in_user sessions_url, { email: other_account.owner.email, password: "password" }
|
78
|
+
expected_json_errors(errors_invalid_email_or_password)
|
79
|
+
end
|
80
|
+
|
81
|
+
scenario "cannot sign in if the subdomain does not exist" do
|
82
|
+
sign_in_user error_url, account_user_params_json(account.owner)
|
83
|
+
expected_json_errors(errors_invalid_subdomain)
|
84
|
+
end
|
85
|
+
end
|
61
86
|
end
|
@@ -7,24 +7,17 @@ feature "User signup" do
|
|
7
7
|
let!(:account) { FactoryGirl.create(:account_with_schema) }
|
8
8
|
let(:root_url) { "http://#{account.subdomain}.example.com/" }
|
9
9
|
scenario "under an account" do
|
10
|
-
|
11
|
-
expect(
|
12
|
-
expect(json_last_response_body["user"]["membership_ids"]).to eq [account.id]
|
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]
|
10
|
+
user_email = successful_sign_up_user_in_existing_account account
|
11
|
+
expect(user_email).to eq("user@example.com")
|
16
12
|
end
|
17
13
|
|
18
14
|
scenario "under two accounts" do
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
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]
|
15
|
+
account_user_email = successful_sign_up_user_in_existing_account account
|
16
|
+
owner = Cadenero::User.where(email: account_user_email).first
|
17
|
+
second_account = FactoryGirl.create(:account_with_schema, owner: owner)
|
18
|
+
second_account_user_email = successful_sign_up_user_in_existing_account second_account
|
19
|
+
get "#{root_url}v1/users/#{owner.id}"
|
20
|
+
expect_subject_ids_to_have("user", "membership_ids", [second_account.id, account.id], 200)
|
28
21
|
get "#{root_url}v1/users"
|
29
22
|
expect(json_last_response_body["users"].length).to eq 2
|
30
23
|
end
|
@@ -8,15 +8,18 @@ describe Cadenero::Generators::InstallGenerator do
|
|
8
8
|
# So we can know whether to backup or restore in cleanup!
|
9
9
|
# Wish RSpec had a setting for this already
|
10
10
|
before { flag_example! }
|
11
|
+
|
12
|
+
# For the example flag its run metadata to true
|
11
13
|
def flag_example!
|
12
14
|
example.metadata[:run] = true
|
13
15
|
end
|
14
16
|
|
17
|
+
# Sort the migrations
|
15
18
|
def migrations
|
16
19
|
Dir["#{Rails.root}/db/migrate/*.rb"].sort
|
17
20
|
end
|
18
21
|
|
19
|
-
it "
|
22
|
+
it "runs the installer correctly" do
|
20
23
|
migrations.should be_empty
|
21
24
|
capture(:stdout) do
|
22
25
|
described_class.start(["--user-class=User", "--no-migrate", "--current-user-helper=current_user",
|
@@ -40,16 +43,48 @@ describe Cadenero::Generators::InstallGenerator do
|
|
40
43
|
helper_method :cadenero_user
|
41
44
|
|
42
45
|
}
|
43
|
-
application_controller.
|
44
|
-
Cadenero::V1::Account.count.
|
45
|
-
Cadenero::User.count.
|
46
|
+
expect(application_controller).to include(expected_cadenero_user_method)
|
47
|
+
expect(Cadenero::V1::Account.count).to eq 0
|
48
|
+
expect(Cadenero::User.count).to eq 0
|
46
49
|
|
47
50
|
FactoryGirl.create(:account)
|
48
51
|
FactoryGirl.create(:user)
|
49
52
|
Cadenero::Engine.load_seed
|
50
53
|
|
51
|
-
Cadenero::V1::Account.count.
|
52
|
-
Cadenero::User.count.
|
54
|
+
expect(Cadenero::V1::Account.count).to eq 2
|
55
|
+
expect(Cadenero::User.count).to eq 3
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should add /config/initializers/cadenero.rb with Template if doesn't exist" do
|
59
|
+
FileUtils.rm("#{Rails.root}/config/initializers/cadenero.rb")
|
60
|
+
subject.add_cadenero_initializer
|
61
|
+
expect(File.exist?("#{Rails.root}/config/initializers/cadenero.rb")).to be_true
|
62
|
+
cadenero_initializer = File.read("#{Rails.root}/config/initializers/cadenero.rb")
|
63
|
+
expect(cadenero_initializer).to include("Cadenero.user_class =")
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should run the Cadenero migrations" do
|
67
|
+
subject.run_migrations
|
68
|
+
expect(Cadenero::User.columns.map{|column| {name: column.name}}).to eq [{:name=>"id"},
|
69
|
+
{:name=>"email"},
|
70
|
+
{:name=>"password_digest"},
|
71
|
+
{:name=>"created_at"},
|
72
|
+
{:name=>"updated_at"}]
|
73
|
+
end
|
74
|
+
|
75
|
+
context "no-migrate" do
|
76
|
+
before { subject.stub :options => {"no-migrate" => true}}
|
77
|
+
it "should not load the seeds" do
|
78
|
+
subject.seed_database
|
79
|
+
expect(Cadenero::V1::Account.count).to eq 0
|
80
|
+
expect(Cadenero::User.count).to eq 0
|
81
|
+
end
|
82
|
+
it "should not output as a finished message that the migrations were run" do
|
83
|
+
output = capture(:stdout) do
|
84
|
+
subject.finished
|
85
|
+
end
|
86
|
+
expect(output).not_to include("rake db:migrate")
|
87
|
+
end
|
53
88
|
end
|
54
89
|
|
55
90
|
end
|
@@ -2,6 +2,16 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
module Cadenero
|
4
4
|
describe Member do
|
5
|
-
|
5
|
+
let!(:user) { stub_model(Cadenero::User, id: 101, email: "testy@example.com", password: "12345678")}
|
6
|
+
let!(:account) { stub_model(Cadenero::V1::Account, id: 1001, authentication_token: "dsdaefer412add",
|
7
|
+
owner: user) }
|
8
|
+
|
9
|
+
it "should have the auth_token" do
|
10
|
+
member = Member.new
|
11
|
+
member.account = account
|
12
|
+
member.user = user
|
13
|
+
member.save!
|
14
|
+
expect(member.auth_token).not_to eq(nil)
|
15
|
+
end
|
6
16
|
end
|
7
17
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cadenero
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.2.
|
4
|
+
version: 0.0.2.b5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Manuel Vidaurre
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-07-
|
11
|
+
date: 2013-07-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails-api
|
@@ -225,6 +225,7 @@ files:
|
|
225
225
|
- db/migrate/20130612061604_create_cadenero_v1_accounts.rb
|
226
226
|
- db/migrate/20130612064652_create_cadenero_v1_users.rb
|
227
227
|
- db/migrate/20130612073709_create_cadenero_v1_members.rb
|
228
|
+
- db/migrate/20130715174857_add_auth_token_to_cadenero_members.rb
|
228
229
|
- db/seeds.rb
|
229
230
|
- lib/cadenero/active_record_extensions.rb
|
230
231
|
- lib/cadenero/constraints/subdomain_required.rb
|
@@ -240,6 +241,7 @@ files:
|
|
240
241
|
- Rakefile
|
241
242
|
- README.md
|
242
243
|
- spec/controllers/cadenero/v1/accounts_controller_spec.rb
|
244
|
+
- spec/controllers/cadenero/v1/users_controller_spec.rb
|
243
245
|
- spec/dummy/app/controllers/application_controller.rb
|
244
246
|
- spec/dummy/config/application.rb
|
245
247
|
- spec/dummy/config/boot.rb
|
@@ -311,6 +313,7 @@ specification_version: 4
|
|
311
313
|
summary: Rails.API Engine for manage multitenant authentication
|
312
314
|
test_files:
|
313
315
|
- spec/controllers/cadenero/v1/accounts_controller_spec.rb
|
316
|
+
- spec/controllers/cadenero/v1/users_controller_spec.rb
|
314
317
|
- spec/dummy/app/controllers/application_controller.rb
|
315
318
|
- spec/dummy/config/application.rb
|
316
319
|
- spec/dummy/config/boot.rb
|