summaryrefslogtreecommitdiff
path: root/users/test
diff options
context:
space:
mode:
Diffstat (limited to 'users/test')
-rw-r--r--users/test/factories.rb1
-rw-r--r--users/test/support/auth_test_helper.rb6
-rw-r--r--users/test/support/stub_record_helper.rb13
3 files changed, 13 insertions, 7 deletions
diff --git a/users/test/factories.rb b/users/test/factories.rb
index 6b094bd..4bf7e62 100644
--- a/users/test/factories.rb
+++ b/users/test/factories.rb
@@ -7,6 +7,7 @@ FactoryGirl.define do
factory :user_with_settings do
email_forward { Faker::Internet.email }
+ email { Faker::Internet.user_name + '@' + APP_CONFIG[:domain] }
email_aliases_attributes do
{:a => Faker::Internet.user_name + '@' + APP_CONFIG[:domain]}
end
diff --git a/users/test/support/auth_test_helper.rb b/users/test/support/auth_test_helper.rb
index c9f5612..c0fcf3a 100644
--- a/users/test/support/auth_test_helper.rb
+++ b/users/test/support/auth_test_helper.rb
@@ -10,10 +10,10 @@ module AuthTestHelper
end
def login(user_or_method_hash = {})
- @current_user = stub_record(User, user_or_method_hash)
- unless @current_user.respond_to? :is_admin?
- @current_user.stubs(:is_admin?).returns(false)
+ if user_or_method_hash.respond_to?(:reverse_merge)
+ user_or_method_hash.reverse_merge! :is_admin? => false
end
+ @current_user = stub_record(:user, user_or_method_hash, true)
request.env['warden'] = stub :user => @current_user
return @current_user
end
diff --git a/users/test/support/stub_record_helper.rb b/users/test/support/stub_record_helper.rb
index 18db5ae..168a827 100644
--- a/users/test/support/stub_record_helper.rb
+++ b/users/test/support/stub_record_helper.rb
@@ -4,10 +4,11 @@ module StubRecordHelper
# return the record given.
# If no record is given but a hash or nil will create a stub based on
# that instead and returns the stub.
- def find_record(factory)
- record = stub_record factory
+ def find_record(factory, attribs_hash = {})
+ attribs_hash.reverse_merge!(:id => Random.rand(10000).to_s)
+ record = stub_record factory, attribs_hash
klass = record.class
- finder = klass.respond_to?(:find_by_param) ? :find_by_param : :find_by_id
+ finder = klass.respond_to?(:find_by_param) ? :find_by_param : :find
klass.expects(finder).with(record.to_param.to_s).returns(record)
return record
end
@@ -18,11 +19,15 @@ module StubRecordHelper
# If the second parameter is a record we return the record itself.
# This way you can build functions that either take a record or a
# method hash to stub from. See find_record for an example.
- def stub_record(factory, record_or_method_hash = {})
+ def stub_record(factory, record_or_method_hash = {}, persisted=false)
if record_or_method_hash && !record_or_method_hash.is_a?(Hash)
return record_or_method_hash
end
FactoryGirl.build_stubbed(factory).tap do |record|
+ if persisted or record.persisted?
+ record_or_method_hash.reverse_merge! :created_at => Time.now,
+ :updated_at => Time.now, :id => Random.rand(100000).to_s
+ end
record.stubs(record_or_method_hash) if record_or_method_hash.present?
end
end