summaryrefslogtreecommitdiff
path: root/users/test/support/auth_test_helper.rb
diff options
context:
space:
mode:
authorAzul <azul@leap.se>2012-12-01 19:22:12 +0100
committerAzul <azul@leap.se>2012-12-01 19:22:12 +0100
commit01b37eb1115fcc5df97479f16ed3c1d9ee4415a0 (patch)
tree39b556c131d74ffa76080a3ce997bd23a7b59772 /users/test/support/auth_test_helper.rb
parent0a49faf417a993e838d1c37361d573bb86223f75 (diff)
parent277b9f98bfbe2ef0217dfd17c8d9d6597369b903 (diff)
Merge branch 'develop' into help_develop
Diffstat (limited to 'users/test/support/auth_test_helper.rb')
-rw-r--r--users/test/support/auth_test_helper.rb19
1 files changed, 17 insertions, 2 deletions
diff --git a/users/test/support/auth_test_helper.rb b/users/test/support/auth_test_helper.rb
index ca166bf..99dc141 100644
--- a/users/test/support/auth_test_helper.rb
+++ b/users/test/support/auth_test_helper.rb
@@ -1,4 +1,5 @@
module AuthTestHelper
+ include StubRecordHelper
extend ActiveSupport::Concern
# Controller will fetch current user from warden.
@@ -9,8 +10,8 @@ module AuthTestHelper
end
end
- def login(user = nil)
- @current_user = user || stub
+ def login(user_or_method_hash = nil)
+ @current_user = stub_user(user_or_method_hash)
unless @current_user.respond_to? :is_admin?
@current_user.stubs(:is_admin?).returns(false)
end
@@ -28,6 +29,20 @@ module AuthTestHelper
assert flash[:alert].blank?
end
end
+
+ protected
+
+ # Will create a stub user for logging in from either
+ # * a hash of methods to stub
+ # * a user record
+ # * nil -> create a user record stub
+ def stub_user(user_or_method_hash)
+ if user_or_method_hash.is_a?(Hash)
+ stub_record User, user_or_method_hash
+ else
+ user_or_method_hash || stub_record(User)
+ end
+ end
end
class ActionController::TestCase