challah 0.5.2 → 0.5.3
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +9 -2
- data/README.md +18 -18
- data/lib/challah/test.rb +22 -5
- data/lib/challah/version.rb +1 -1
- data/test/audit_test.rb +32 -32
- data/test/controller_test.rb +9 -9
- data/test/cookie_store_test.rb +25 -25
- data/test/factories.rb +7 -7
- data/test/helper.rb +14 -12
- data/test/permission_test.rb +14 -14
- data/test/restrictions_controller_test.rb +29 -30
- data/test/role_test.rb +26 -26
- data/test/session_test.rb +65 -65
- data/test/sessions_controller_test.rb +13 -13
- data/test/simple_cookie_store_test.rb +25 -25
- data/test/user_test.rb +79 -79
- data/vendor/bundle/cache/factory_girl-3.0.0.gem +0 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/Appraisals +11 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/CONTRIBUTION_GUIDELINES.md +10 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/Changelog +168 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/GETTING_STARTED.md +735 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/Gemfile +5 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/Gemfile.lock +95 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/LICENSE +19 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/README.md +70 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/Rakefile +38 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/cucumber.yml +1 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/factory_girl.gemspec +38 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/features/factory_girl_steps.feature +237 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/features/find_definitions.feature +75 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/features/step_definitions/database_steps.rb +42 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/features/step_definitions/factory_girl_steps.rb +43 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/features/support/env.rb +11 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/features/support/factories.rb +119 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/gemfiles/2.3.gemfile +7 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/gemfiles/3.0.gemfile +7 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/gemfiles/3.0.gemfile.lock +86 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/gemfiles/3.1.gemfile +7 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/gemfiles/3.1.gemfile.lock +95 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/gemfiles/3.2.gemfile +7 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/gemfiles/3.2.gemfile.lock +93 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl.rb +69 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/aliases.rb +19 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/attribute.rb +40 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/attribute/association.rb +23 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/attribute/dynamic.rb +20 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/attribute/sequence.rb +17 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/attribute/static.rb +15 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/attribute_assigner.rb +73 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/attribute_list.rb +54 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/callback.rb +33 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/declaration.rb +22 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/declaration/association.rb +25 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/declaration/dynamic.rb +25 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/declaration/implicit.rb +32 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/declaration/static.rb +25 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/declaration_list.rb +48 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/definition.rb +76 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/definition_proxy.rb +159 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/errors.rb +19 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/evaluator.rb +76 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/evaluator_class_definer.rb +34 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/factory.rb +145 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/factory_runner.rb +24 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/find_definitions.rb +25 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/null_factory.rb +15 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/null_object.rb +7 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/registry.rb +46 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/reload.rb +8 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/sequence.rb +24 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/step_definitions.rb +130 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/strategy.rb +32 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/strategy/attributes_for.rb +12 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/strategy/build.rb +15 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/strategy/create.rb +17 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/strategy/stub.rb +61 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/strategy_calculator.rb +29 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/syntax.rb +16 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/syntax/blueprint.rb +42 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/syntax/default.rb +56 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/syntax/generate.rb +70 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/syntax/make.rb +45 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/syntax/methods.rb +136 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/syntax/sham.rb +45 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/syntax/vintage.rb +130 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/trait.rb +29 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/version.rb +4 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/aliases_spec.rb +19 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/attribute_aliases_spec.rb +45 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/attribute_existing_on_object_spec.rb +68 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/attributes_for_spec.rb +89 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/attributes_from_instance_spec.rb +53 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/attributes_ordered_spec.rb +51 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/build_list_spec.rb +41 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/build_spec.rb +89 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/build_stubbed_spec.rb +104 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/callbacks_spec.rb +47 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/create_list_spec.rb +82 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/create_spec.rb +117 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/define_child_before_parent_spec.rb +21 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/definition_spec.rb +26 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/definition_without_block_spec.rb +15 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/initialize_with_spec.rb +147 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/modify_factories_spec.rb +184 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/modify_inherited_spec.rb +52 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/nested_attributes_spec.rb +32 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/overrides_spec.rb +61 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/parent_spec.rb +90 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/sequence_spec.rb +33 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/stub_spec.rb +62 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/syntax/blueprint_spec.rb +34 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/syntax/generate_spec.rb +59 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/syntax/make_spec.rb +52 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/syntax/sham_spec.rb +43 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/syntax/vintage_spec.rb +217 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/traits_spec.rb +421 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/transient_attributes_spec.rb +124 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/aliases_spec.rb +31 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/attribute/association_spec.rb +28 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/attribute/dynamic_spec.rb +52 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/attribute/sequence_spec.rb +16 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/attribute/static_spec.rb +19 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/attribute_list_spec.rb +78 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/attribute_spec.rb +16 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/callback_spec.rb +41 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/declaration/implicit_spec.rb +25 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/declaration_list_spec.rb +71 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/definition_proxy_spec.rb +197 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/definition_spec.rb +104 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/evaluator_class_definer_spec.rb +54 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/factory_spec.rb +279 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/find_definitions_spec.rb +110 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/null_factory_spec.rb +13 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/null_object_spec.rb +8 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/registry_spec.rb +81 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/sequence_spec.rb +47 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/strategy/attributes_for_spec.rb +18 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/strategy/build_spec.rb +7 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/strategy/create_spec.rb +13 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/strategy/stub_spec.rb +40 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/strategy_calculator_spec.rb +33 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/strategy_spec.rb +21 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl_spec.rb +22 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/spec_helper.rb +26 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/support/macros/define_constant.rb +86 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/support/matchers/callback.rb +9 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/support/matchers/declaration.rb +71 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/support/matchers/delegate.rb +44 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/support/matchers/trait.rb +9 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/support/shared_examples/strategy.rb +104 -0
- data/vendor/bundle/specifications/factory_girl-3.0.0.gemspec +62 -0
- metadata +147 -12
@@ -2,39 +2,39 @@ require 'helper'
|
|
2
2
|
|
3
3
|
class SessionsControllerTest < ActionController::TestCase
|
4
4
|
tests SessionsController
|
5
|
-
|
5
|
+
|
6
6
|
context "The sessions controller" do
|
7
7
|
setup do
|
8
|
-
@user =
|
8
|
+
@user = create(:user, :username => 'sessions-user-test')
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
11
|
should "have a login page" do
|
12
12
|
get :new
|
13
13
|
assert_response :success
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
should "be able to login" do
|
17
17
|
Challah::Session.any_instance.stubs(:save).returns(true)
|
18
|
-
|
18
|
+
|
19
19
|
post :create, :username => 'sessions-user-test', :password => 'abc123'
|
20
20
|
assert_redirected_to '/'
|
21
|
-
|
21
|
+
|
22
22
|
Challah::Session.any_instance.unstub(:save)
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
25
|
should "send you back to the sign in page if you can't sign in" do
|
26
26
|
Challah::Session.any_instance.stubs(:save).returns(false)
|
27
|
-
|
27
|
+
|
28
28
|
post :create, :username => 'sessions-user-test', :password => 'abc123'
|
29
29
|
assert_redirected_to '/login'
|
30
|
-
|
30
|
+
|
31
31
|
Challah::Session.any_instance.unstub(:save)
|
32
|
-
end
|
33
|
-
|
32
|
+
end
|
33
|
+
|
34
34
|
should "be able to sign out" do
|
35
35
|
get :destroy
|
36
|
-
|
36
|
+
|
37
37
|
assert_redirected_to '/login'
|
38
|
-
end
|
38
|
+
end
|
39
39
|
end
|
40
40
|
end
|
@@ -2,93 +2,93 @@ require 'helper'
|
|
2
2
|
|
3
3
|
class SimpleCookieStoreTest < ActiveSupport::TestCase
|
4
4
|
include Challah
|
5
|
-
|
5
|
+
|
6
6
|
context "The SimpleCookieStore class" do
|
7
7
|
setup do
|
8
|
-
@user =
|
8
|
+
@user = create(:user)
|
9
9
|
@request = MockRequest.new
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
12
|
should "save session in a request cookie store" do
|
13
13
|
assert_equal [], @request.cookies.keys
|
14
|
-
|
14
|
+
|
15
15
|
session = Session.new(@request)
|
16
16
|
session.store = SimpleCookieStore.new(session)
|
17
17
|
session.persist = true
|
18
18
|
session.user = @user
|
19
19
|
session.save
|
20
|
-
|
20
|
+
|
21
21
|
assert_equal %w( challah-s challah-v ), @request.cookies.keys.sort
|
22
22
|
assert_equal "#{@user.persistence_token}@#{@user.id}", @request.cookies['challah-s'][:value]
|
23
23
|
assert_equal "test.dev", @request.cookies['challah-s'][:domain]
|
24
|
-
|
24
|
+
|
25
25
|
assert_equal Encrypter.md5("#{@user.persistence_token}@#{@user.id}"), @request.cookies['challah-v'][:value]
|
26
26
|
assert_equal "test.dev", @request.cookies['challah-v'][:domain]
|
27
27
|
end
|
28
|
-
|
28
|
+
|
29
29
|
should "be able to inspect the store" do
|
30
30
|
session = Session.new(@request)
|
31
31
|
session.store = SimpleCookieStore.new(session)
|
32
32
|
session.persist = true
|
33
33
|
session.user = @user
|
34
34
|
session.save
|
35
|
-
|
35
|
+
|
36
36
|
assert session.store.inspect =~ /<SimpleCookieStore:(.*?)>/, 'Does not match'
|
37
|
-
end
|
38
|
-
|
37
|
+
end
|
38
|
+
|
39
39
|
should "read cookies and detect tampered verification cookies" do
|
40
40
|
assert_equal [], @request.cookies.keys
|
41
|
-
|
41
|
+
|
42
42
|
session = Session.new(@request)
|
43
43
|
session.store = SimpleCookieStore.new(session)
|
44
44
|
session.persist = true
|
45
45
|
session.user = @user
|
46
46
|
session.save
|
47
|
-
|
47
|
+
|
48
48
|
validation_cookie_val = Encrypter.md5("#{@user.persistence_token}@#{@user.id}")
|
49
49
|
session_cookie_val = "#{@user.persistence_token}@#{@user.id}"
|
50
|
-
|
50
|
+
|
51
51
|
assert_equal session_cookie_val, @request.cookies['challah-s'][:value]
|
52
52
|
assert_equal session_cookie_val, session.store.send(:session_cookie)[:value]
|
53
53
|
assert_equal validation_cookie_val, @request.cookies['challah-v'][:value]
|
54
54
|
assert_equal validation_cookie_val, session.store.send(:validation_cookie)[:value]
|
55
|
-
|
55
|
+
|
56
56
|
session.store.stubs(:validation_cookie).returns(validation_cookie_val)
|
57
57
|
session.store.stubs(:session_cookie).returns(session_cookie_val)
|
58
|
-
|
58
|
+
|
59
59
|
session2 = Session.new(@request)
|
60
60
|
session2.persist = true
|
61
|
-
session2.store = session.store
|
61
|
+
session2.store = session.store
|
62
62
|
session2.read
|
63
|
-
|
63
|
+
|
64
64
|
assert_equal true, session2.store.send(:existing?)
|
65
65
|
assert_equal true, session2.valid?
|
66
66
|
assert_equal @user.id, session2.user_id
|
67
|
-
|
67
|
+
|
68
68
|
session.store.stubs(:validation_cookie).returns('bad-value')
|
69
|
-
|
69
|
+
|
70
70
|
session3 = Session.new(@request)
|
71
71
|
session3.store = session.store
|
72
72
|
session3.read
|
73
|
-
|
73
|
+
|
74
74
|
assert_equal false, session3.store.send(:existing?)
|
75
75
|
assert_equal false, session3.valid?
|
76
76
|
end
|
77
|
-
|
77
|
+
|
78
78
|
should "delete sessions from cookies" do
|
79
79
|
session = Session.new(@request)
|
80
80
|
session.store = SimpleCookieStore.new(session)
|
81
81
|
session.user = @user
|
82
82
|
session.persist = true
|
83
|
-
|
83
|
+
|
84
84
|
session.save
|
85
|
-
|
85
|
+
|
86
86
|
assert_equal true, session.valid?
|
87
87
|
assert_equal @user, session.user
|
88
88
|
assert_equal %w( challah-s challah-v ), @request.cookies.keys.sort
|
89
|
-
|
89
|
+
|
90
90
|
session.destroy
|
91
|
-
|
91
|
+
|
92
92
|
assert_equal false, session.valid?
|
93
93
|
assert_equal nil, session.user
|
94
94
|
assert_equal [], @request.cookies.keys.sort
|
data/test/user_test.rb
CHANGED
@@ -6,224 +6,224 @@ class UserTest < ActiveSupport::TestCase
|
|
6
6
|
should validate_presence_of :last_name
|
7
7
|
should validate_presence_of :role_id
|
8
8
|
should validate_presence_of :username
|
9
|
-
|
9
|
+
|
10
10
|
should belong_to :role
|
11
11
|
should have_many :permission_users
|
12
12
|
should have_many :permissions
|
13
|
-
|
13
|
+
|
14
14
|
context "With an existing user" do
|
15
15
|
setup do
|
16
|
-
|
16
|
+
create(:normal_user)
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
should validate_uniqueness_of :email
|
20
20
|
should validate_uniqueness_of :username
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
context "A User class" do
|
24
24
|
should "find a user by username or email" do
|
25
|
-
user_one =
|
26
|
-
user_two =
|
27
|
-
|
25
|
+
user_one = create(:normal_user, :username => 'test-user', :email => 'tester@example.com')
|
26
|
+
user_two = create(:normal_user, :username => 'test-user-2', :email => 'tester2@example.com')
|
27
|
+
|
28
28
|
assert_equal user_one, User.find_for_session('test-user')
|
29
29
|
assert_equal user_one, User.find_for_session('tester@example.com')
|
30
|
-
|
30
|
+
|
31
31
|
assert_equal user_two, User.find_for_session('test-user-2')
|
32
32
|
assert_equal user_two, User.find_for_session('tester2@example.com')
|
33
|
-
|
33
|
+
|
34
34
|
assert_equal nil, User.find_for_session(' ')
|
35
35
|
assert_equal nil, User.find_for_session('not-existing')
|
36
36
|
end
|
37
|
-
|
37
|
+
|
38
38
|
should "have protected attributes" do
|
39
39
|
assert Array === User.protected_attributes
|
40
|
-
|
40
|
+
|
41
41
|
assert_difference 'User.protected_attributes.size', 1 do
|
42
42
|
User.protect_attributes :blah
|
43
43
|
end
|
44
|
-
end
|
44
|
+
end
|
45
45
|
end
|
46
|
-
|
46
|
+
|
47
47
|
context "A user instance" do
|
48
48
|
should "have a name attribute that returns the full name" do
|
49
49
|
user = User.new
|
50
|
-
|
50
|
+
|
51
51
|
user.stubs(:first_name).returns('Cal')
|
52
52
|
user.stubs(:last_name).returns('Ripken')
|
53
53
|
|
54
54
|
assert_equal "Cal Ripken", user.name
|
55
55
|
assert_equal "Cal R.", user.small_name
|
56
56
|
end
|
57
|
-
|
57
|
+
|
58
58
|
should "have a default_path where this user will be sent upon login" do
|
59
|
-
role = Role.new
|
59
|
+
role = Role.new
|
60
60
|
role.stubs(:default_path).returns('/role-path')
|
61
|
-
|
61
|
+
|
62
62
|
user = User.new
|
63
|
-
|
63
|
+
|
64
64
|
user.stubs(:role).returns(role)
|
65
65
|
assert_equal '/role-path', user.default_path
|
66
|
-
|
66
|
+
|
67
67
|
user.stubs(:role).returns(nil)
|
68
68
|
assert_equal '/', user.default_path
|
69
69
|
end
|
70
|
-
|
70
|
+
|
71
71
|
should "have an active? user flag" do
|
72
72
|
user = User.new
|
73
|
-
|
74
|
-
user.active = true
|
73
|
+
|
74
|
+
user.active = true
|
75
75
|
assert_equal true, user.active
|
76
76
|
assert_equal true, user.active?
|
77
77
|
assert_equal true, user.valid_session?
|
78
|
-
|
78
|
+
|
79
79
|
user.active = false
|
80
80
|
assert_equal false, user.active
|
81
81
|
assert_equal false, user.active?
|
82
82
|
assert_equal false, user.valid_session?
|
83
83
|
end
|
84
|
-
|
84
|
+
|
85
85
|
should "not allow updating of certain protected attributes" do
|
86
|
-
user =
|
87
|
-
|
86
|
+
user = create(:user, :first_name => 'Old', :last_name => 'Nombre')
|
87
|
+
|
88
88
|
assert_equal false, user.new_record?
|
89
|
-
|
89
|
+
|
90
90
|
assert_equal 0, user.created_by
|
91
91
|
assert_equal 1, user.role_id
|
92
92
|
assert_equal 'Old Nombre', user.name
|
93
|
-
|
93
|
+
|
94
94
|
user.update_account_attributes({
|
95
95
|
:created_by => 1,
|
96
96
|
:first_name => 'New',
|
97
97
|
:last_name => 'Name',
|
98
98
|
:role_id => 5
|
99
99
|
})
|
100
|
-
|
100
|
+
|
101
101
|
assert_equal 0, user.created_by
|
102
102
|
assert_equal 1, user.role_id
|
103
103
|
assert_equal 'New Name', user.name
|
104
|
-
end
|
105
|
-
|
104
|
+
end
|
105
|
+
|
106
106
|
should "create a user with password and authenticate them" do
|
107
|
-
user =
|
108
|
-
|
107
|
+
user = build(:user)
|
108
|
+
|
109
109
|
user.password = 'abc123'
|
110
|
-
user.password_confirmation = 'abc123'
|
110
|
+
user.password_confirmation = 'abc123'
|
111
111
|
assert_equal 'abc123', user.password
|
112
|
-
|
112
|
+
|
113
113
|
assert user.save
|
114
|
-
|
114
|
+
|
115
115
|
assert_equal true, user.authenticate('abc123')
|
116
116
|
assert_equal true, user.authenticate(:password, 'abc123')
|
117
117
|
assert_equal false, user.authenticate('test123')
|
118
|
-
end
|
119
|
-
|
118
|
+
end
|
119
|
+
|
120
120
|
should "be able to update a user without changing their password" do
|
121
|
-
user =
|
122
|
-
|
121
|
+
user = create(:user)
|
122
|
+
|
123
123
|
assert_equal true, user.authenticate('abc123')
|
124
|
-
|
124
|
+
|
125
125
|
assert user.update_attributes(:first_name => 'New', :password => '', :password_confirmation => '')
|
126
|
-
|
126
|
+
|
127
127
|
assert_equal 'New', user.first_name
|
128
128
|
assert_equal true, user.authenticate('abc123')
|
129
129
|
end
|
130
|
-
|
130
|
+
|
131
131
|
should "validate a password" do
|
132
|
-
user =
|
132
|
+
user = build(:user)
|
133
133
|
assert_equal true, user.valid?
|
134
|
-
|
134
|
+
|
135
135
|
user.password = ''
|
136
|
-
user.password_confirmation = ''
|
136
|
+
user.password_confirmation = ''
|
137
137
|
assert_equal false, user.valid?
|
138
138
|
assert user.errors.full_messages.include?("Password can't be blank")
|
139
|
-
|
139
|
+
|
140
140
|
user.password = 'abc'
|
141
141
|
user.password_confirmation = 'abc'
|
142
142
|
assert_equal false, user.valid?
|
143
143
|
assert user.errors.full_messages.include?("Password is not a valid password. Please enter at least 4 letters or numbers.")
|
144
|
-
|
144
|
+
|
145
145
|
user.password = 'abc456'
|
146
146
|
user.password_confirmation = 'abc123'
|
147
147
|
assert_equal false, user.valid?
|
148
148
|
assert user.errors.full_messages.include?("Password does not match the confirmation password.")
|
149
149
|
end
|
150
|
-
|
150
|
+
|
151
151
|
should "get and set permission keys" do
|
152
|
-
%w( run pass throw block ).each { |p|
|
153
|
-
|
154
|
-
user =
|
155
|
-
|
152
|
+
%w( run pass throw block ).each { |p| create(:permission, :key => p) }
|
153
|
+
|
154
|
+
user = build(:user)
|
155
|
+
|
156
156
|
user.stubs(:role).returns(Role.new)
|
157
157
|
user.role.stubs(:permission_keys).returns([])
|
158
|
-
|
158
|
+
|
159
159
|
user.save
|
160
|
-
|
160
|
+
|
161
161
|
assert_equal [], user.permission_keys
|
162
|
-
|
163
|
-
user.permission_keys = %w( pass throw run )
|
164
|
-
|
162
|
+
|
163
|
+
user.permission_keys = %w( pass throw run )
|
164
|
+
|
165
165
|
assert_difference 'PermissionUser.count', 3 do
|
166
166
|
user.save
|
167
167
|
end
|
168
|
-
|
168
|
+
|
169
169
|
assert_equal true, user.pass?
|
170
170
|
assert_equal true, user.has(:pass)
|
171
171
|
assert_equal true, user.permission?(:pass)
|
172
|
-
|
172
|
+
|
173
173
|
assert_equal true, user.run?
|
174
174
|
assert_equal true, user.has(:run)
|
175
175
|
assert_equal true, user.permission?(:run)
|
176
|
-
|
176
|
+
|
177
177
|
assert_equal false, user.fake?
|
178
178
|
assert_equal false, user.has(:fake)
|
179
179
|
assert_equal false, user.permission?(:fake)
|
180
|
-
|
180
|
+
|
181
181
|
assert_raises NoMethodError do
|
182
182
|
user.does_not_exist
|
183
183
|
end
|
184
|
-
end
|
185
|
-
|
184
|
+
end
|
185
|
+
|
186
186
|
should "authenticate through various means by default" do
|
187
|
-
user =
|
188
|
-
|
187
|
+
user = create(:user)
|
188
|
+
|
189
189
|
# By password
|
190
190
|
assert_equal false, user.authenticate_with_password('test123')
|
191
191
|
assert_equal false, user.authenticate(:password, 'test123')
|
192
192
|
assert_equal false, user.authenticate('test123')
|
193
|
-
|
193
|
+
|
194
194
|
assert_equal true, user.authenticate_with_password('abc123')
|
195
195
|
assert_equal true, user.authenticate(:password, 'abc123')
|
196
196
|
assert_equal true, user.authenticate('abc123')
|
197
|
-
|
197
|
+
|
198
198
|
# By api key
|
199
199
|
user.stubs(:api_key).returns('this-is-my-api-key')
|
200
|
-
|
200
|
+
|
201
201
|
assert_equal true, user.authenticate_with_api_key('this-is-my-api-key')
|
202
202
|
assert_equal true, user.authenticate_with_api_key('this-is-my-api-key')
|
203
|
-
|
203
|
+
|
204
204
|
assert_equal false, user.authenticate_with_api_key('this-is-not-my-api-key')
|
205
205
|
assert_equal false, user.authenticate_with_api_key('this-is-not-my-api-key')
|
206
|
-
|
206
|
+
|
207
207
|
# With an unknown authentication method
|
208
208
|
assert_equal false, user.authenticate(:blah, 'sdsd', 'sdlsk')
|
209
209
|
end
|
210
|
-
|
210
|
+
|
211
211
|
should "have successful and failed authentication methods" do
|
212
|
-
user =
|
213
|
-
|
212
|
+
user = create(:user)
|
213
|
+
|
214
214
|
assert_nil user.last_session_ip
|
215
215
|
assert_nil user.last_session_at
|
216
|
-
|
216
|
+
|
217
217
|
assert_difference 'user.session_count', 1 do
|
218
218
|
user.successful_authentication!('192.168.0.1')
|
219
219
|
end
|
220
|
-
|
220
|
+
|
221
221
|
assert_not_nil user.last_session_ip
|
222
222
|
assert_not_nil user.last_session_at
|
223
|
-
|
223
|
+
|
224
224
|
assert_difference 'user.failed_auth_count', 1 do
|
225
225
|
user.failed_authentication!
|
226
226
|
end
|
227
|
-
end
|
227
|
+
end
|
228
228
|
end
|
229
229
|
end
|