Sha256: d61bf10d4cdd666445e148f0cb0d7f332b2a34d8eb1e3b54baa52e3366722be1

Contents?: true

Size: 1.39 KB

Versions: 19

Compression:

Stored size: 1.39 KB

Contents

require 'active_support/test_case'

class ActiveSupport::TestCase
  VALID_AUTHENTICATION_TOKEN = 'AbCdEfGhIjKlMnOpQrSt'.freeze

  def setup_mailer
    ActionMailer::Base.deliveries = []
  end

  def store_translations(locale, translations, &block)
    begin
      I18n.backend.store_translations(locale, translations)
      yield
    ensure
      I18n.reload!
    end
  end

  def generate_unique_email
    @@email_count ||= 0
    @@email_count += 1
    "test#{@@email_count}@email.com"
  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

  def create_admin(attributes={})
    valid_attributes = valid_attributes(attributes)
    valid_attributes.delete(:username)
    Admin.create!(valid_attributes)
  end

  # 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
end

Version data entries

19 entries across 19 versions & 6 rubygems

Version Path
devise_sociable-0.1.0 vendor/bundle/gems/devise-1.2.1/test/support/helpers.rb
devise-1.3.0 test/support/helpers.rb
devise-1.2.1 test/support/helpers.rb
devise-1.2.0 test/support/helpers.rb
devise-1.1.9 test/support/helpers.rb
devise-jdguyot-1.2.rc3 test/support/helpers.rb
devise-1.1.8 test/support/helpers.rb
devise-1.2.rc2 test/support/helpers.rb
devise-jdguyot-1.2.rc2 test/support/helpers.rb
devise-1.1.7 test/support/helpers.rb
devise-1.1.6 test/support/helpers.rb
devise-jdguyot-1.2.rc test/support/helpers.rb
devise-1.1.5 test/support/helpers.rb
devise-1.1.4 test/support/helpers.rb
devise-1.2.rc test/support/helpers.rb
aihs_devise-1.2.rc test/support/helpers.rb
gonow-devise-1.2.rc test/support/helpers.rb
devise-edge-1.2.rc test/support/helpers.rb
devise-1.1.3 test/support/helpers.rb