2010-03-23 11:28:17 -04:00
|
|
|
require 'active_support/test_case'
|
|
|
|
|
2010-01-23 21:38:52 -05:00
|
|
|
class ActiveSupport::TestCase
|
|
|
|
VALID_AUTHENTICATION_TOKEN = 'AbCdEfGhIjKlMnOpQrSt'.freeze
|
|
|
|
|
2010-02-05 19:33:32 -05:00
|
|
|
def setup_mailer
|
|
|
|
ActionMailer::Base.deliveries = []
|
|
|
|
end
|
|
|
|
|
|
|
|
def store_translations(locale, translations, &block)
|
|
|
|
begin
|
2010-02-16 08:31:49 -05:00
|
|
|
I18n.backend.store_translations(locale, translations)
|
2010-02-05 19:33:32 -05:00
|
|
|
yield
|
|
|
|
ensure
|
|
|
|
I18n.reload!
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def generate_unique_email
|
|
|
|
@@email_count ||= 0
|
|
|
|
@@email_count += 1
|
2011-04-17 21:14:56 -04:00
|
|
|
"test#{@@email_count}@example.com"
|
2010-02-05 19:33:32 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def valid_attributes(attributes={})
|
|
|
|
{ :username => "usertest",
|
|
|
|
:email => generate_unique_email,
|
|
|
|
:password => '123456',
|
|
|
|
:password_confirmation => '123456' }.update(attributes)
|
|
|
|
end
|
|
|
|
|
|
|
|
def new_user(attributes={})
|
|
|
|
User.new(valid_attributes(attributes))
|
|
|
|
end
|
|
|
|
|
|
|
|
def create_user(attributes={})
|
|
|
|
User.create!(valid_attributes(attributes))
|
|
|
|
end
|
2010-02-16 08:31:49 -05:00
|
|
|
|
2010-09-21 04:52:57 -04:00
|
|
|
def create_admin(attributes={})
|
|
|
|
valid_attributes = valid_attributes(attributes)
|
|
|
|
valid_attributes.delete(:username)
|
|
|
|
Admin.create!(valid_attributes)
|
|
|
|
end
|
|
|
|
|
2010-02-16 08:31:49 -05:00
|
|
|
# Execute the block setting the given values and restoring old values after
|
|
|
|
# the block is executed.
|
|
|
|
def swap(object, new_values)
|
|
|
|
old_values = {}
|
|
|
|
new_values.each do |key, value|
|
|
|
|
old_values[key] = object.send key
|
|
|
|
object.send :"#{key}=", value
|
|
|
|
end
|
|
|
|
yield
|
|
|
|
ensure
|
|
|
|
old_values.each do |key, value|
|
|
|
|
object.send :"#{key}=", value
|
|
|
|
end
|
|
|
|
end
|
2011-04-17 21:14:56 -04:00
|
|
|
end
|