class ActiveSupport::TestCase

Constants

VALID_AUTHENTICATION_TOKEN

Public Instance Methods

assert_blank(assertion) click to toggle source
# File test/support/assertions.rb, line 8
def assert_blank(assertion)
  assert assertion.blank?
end
assert_email_not_sent(&block) click to toggle source
# File test/support/assertions.rb, line 23
def assert_email_not_sent(&block)
  assert_no_difference('ActionMailer::Base.deliveries.size', &block)
end
assert_email_sent(address = nil, &block) click to toggle source
# File test/support/assertions.rb, line 16
def assert_email_sent(address = nil, &block)
  assert_difference('ActionMailer::Base.deliveries.size', &block)
  if address.present?
    assert_equal address, ActionMailer::Base.deliveries.last['to'].to_s
  end
end
assert_not(assertion) click to toggle source
# File test/support/assertions.rb, line 4
def assert_not(assertion)
  assert !assertion
end
assert_present(assertion) click to toggle source
# File test/support/assertions.rb, line 12
def assert_present(assertion)
  assert assertion.present?
end
assert_raise_with_message(exception_klass, message, &block) click to toggle source
# File test/support/assertions.rb, line 34
def assert_raise_with_message(exception_klass, message, &block)
  exception = assert_raise exception_klass, &block
  assert_equal exception.message, message,
    "The expected message was #{message} but your exception throwed #{exception.message}"
end
assert_same_content(result, expected) click to toggle source
# File test/support/assertions.rb, line 27
def assert_same_content(result, expected)
  assert expected.size == result.size, "the arrays doesn't have the same size"
  expected.each do |element|
    assert result.include?(element), "The array doesn't include '#{element}'."
  end
end
clear_cached_variables(options) click to toggle source
# File test/support/helpers.rb, line 70
def clear_cached_variables(options)
  if options.key?(:case_insensitive_keys) || options.key?(:strip_whitespace_keys)
    Devise.mappings.each do |_, mapping|
      mapping.to.instance_variable_set(:@devise_parameter_filter, nil)
    end
  end
end
create_admin(attributes={}) click to toggle source
# File test/support/helpers.rb, line 43
def create_admin(attributes={})
  valid_attributes = valid_attributes(attributes)
  valid_attributes.delete(:username)
  Admin.create!(valid_attributes)
end
create_user(attributes={}) click to toggle source
# File test/support/helpers.rb, line 39
def create_user(attributes={})
  User.create!(valid_attributes(attributes))
end
create_user_without_email(attributes={}) click to toggle source
# File test/support/helpers.rb, line 49
def create_user_without_email(attributes={})
  UserWithoutEmail.create!(valid_attributes(attributes))
end
generate_unique_email() click to toggle source
# File test/support/helpers.rb, line 22
def generate_unique_email
  @@email_count ||= 0
  @@email_count += 1
  "test#{@@email_count}@example.com"
end
new_user(attributes={}) click to toggle source
# File test/support/helpers.rb, line 35
def new_user(attributes={})
  User.new(valid_attributes(attributes))
end
setup_mailer() click to toggle source
# File test/support/helpers.rb, line 6
def setup_mailer
  ActionMailer::Base.deliveries = []
end
store_translations(locale, translations) { || ... } click to toggle source
# File test/support/helpers.rb, line 10
def store_translations(locale, translations, &block)
  # Calling 'available_locales' before storing the translations to ensure
  # that the I18n backend will be initialized before we store our custom
  # translations, so they will always override the translations for the
  # YML file.
  I18n.available_locales
  I18n.backend.store_translations(locale, translations)
  yield
ensure
  I18n.reload!
end
swap(object, new_values) { || ... } click to toggle source

Execute the block setting the given values and restoring old values after the block is executed.

# File test/support/helpers.rb, line 55
def swap(object, new_values)
  old_values = {}
  new_values.each do |key, value|
    old_values[key] = object.send key
    object.send :"#{key}=", value
  end
  clear_cached_variables(new_values)
  yield
ensure
  clear_cached_variables(new_values)
  old_values.each do |key, value|
    object.send :"#{key}=", value
  end
end
valid_attributes(attributes={}) click to toggle source
# File test/support/helpers.rb, line 28
def valid_attributes(attributes={})
  { username: "usertest",
    email: generate_unique_email,
    password: '12345678',
    password_confirmation: '12345678' }.update(attributes)
end