Methods
T
Included Modules
Instance Public methods
test_acronym_override()
# File activesupport/test/inflector_test.rb, line 141
def test_acronym_override
  ActiveSupport::Inflector.inflections do |inflect|
    inflect.acronym("API")
    inflect.acronym("LegacyApi")
  end

  assert_equal("LegacyApi", ActiveSupport::Inflector.camelize("legacyapi"))
  assert_equal("LegacyAPI", ActiveSupport::Inflector.camelize("legacy_api"))
  assert_equal("SomeLegacyApi", ActiveSupport::Inflector.camelize("some_legacyapi"))
  assert_equal("Nonlegacyapi", ActiveSupport::Inflector.camelize("nonlegacyapi"))
end
test_acronyms()
# File activesupport/test/inflector_test.rb, line 96
def test_acronyms
  ActiveSupport::Inflector.inflections do |inflect|
    inflect.acronym("API")
    inflect.acronym("HTML")
    inflect.acronym("HTTP")
    inflect.acronym("RESTful")
    inflect.acronym("W3C")
    inflect.acronym("PhD")
    inflect.acronym("RoR")
    inflect.acronym("SSL")
  end

  #  camelize             underscore            humanize              titleize
  [
    ["API",               "api",                "API",                "API"],
    ["APIController",     "api_controller",     "API controller",     "API Controller"],
    ["Nokogiri::HTML",    "nokogiri/html",      "Nokogiri/HTML",      "Nokogiri/HTML"],
    ["HTTPAPI",           "http_api",           "HTTP API",           "HTTP API"],
    ["HTTP::Get",         "http/get",           "HTTP/get",           "HTTP/Get"],
    ["SSLError",          "ssl_error",          "SSL error",          "SSL Error"],
    ["RESTful",           "restful",            "RESTful",            "RESTful"],
    ["RESTfulController", "restful_controller", "RESTful controller", "RESTful Controller"],
    ["IHeartW3C",         "i_heart_w3c",        "I heart W3C",        "I Heart W3C"],
    ["PhDRequired",       "phd_required",       "PhD required",       "PhD Required"],
    ["IRoRU",             "i_ror_u",            "I RoR u",            "I RoR U"],
    ["RESTfulHTTPAPI",    "restful_http_api",   "RESTful HTTP API",   "RESTful HTTP API"],

    # misdirection
    ["Capistrano",        "capistrano",         "Capistrano",       "Capistrano"],
    ["CapiController",    "capi_controller",    "Capi controller",  "Capi Controller"],
    ["HttpsApis",         "https_apis",         "Https apis",       "Https Apis"],
    ["Html5",             "html5",              "Html5",            "Html5"],
    ["Restfully",         "restfully",          "Restfully",        "Restfully"],
    ["RoRails",           "ro_rails",           "Ro rails",         "Ro Rails"]
  ].each do |camel, under, human, title|
    assert_equal(camel, ActiveSupport::Inflector.camelize(under))
    assert_equal(camel, ActiveSupport::Inflector.camelize(camel))
    assert_equal(under, ActiveSupport::Inflector.underscore(under))
    assert_equal(under, ActiveSupport::Inflector.underscore(camel))
    assert_equal(title, ActiveSupport::Inflector.titleize(under))
    assert_equal(title, ActiveSupport::Inflector.titleize(camel))
    assert_equal(human, ActiveSupport::Inflector.humanize(under))
  end
end
test_acronyms_camelize_lower()
# File activesupport/test/inflector_test.rb, line 153
def test_acronyms_camelize_lower
  ActiveSupport::Inflector.inflections do |inflect|
    inflect.acronym("API")
    inflect.acronym("HTML")
  end

  assert_equal("htmlAPI", ActiveSupport::Inflector.camelize("html_api", false))
  assert_equal("htmlAPI", ActiveSupport::Inflector.camelize("htmlAPI", false))
  assert_equal("htmlAPI", ActiveSupport::Inflector.camelize("HTMLAPI", false))
end
test_camelize()
# File activesupport/test/inflector_test.rb, line 82
def test_camelize
  CamelToUnderscore.each do |camel, underscore|
    assert_equal(camel, ActiveSupport::Inflector.camelize(underscore))
  end
end
test_camelize_with_lower_downcases_the_first_letter()
# File activesupport/test/inflector_test.rb, line 88
def test_camelize_with_lower_downcases_the_first_letter
  assert_equal('capital', ActiveSupport::Inflector.camelize('Capital', false))
end
test_camelize_with_module()
# File activesupport/test/inflector_test.rb, line 183
def test_camelize_with_module
  CamelWithModuleToUnderscoreWithSlash.each do |camel, underscore|
    assert_equal(camel, ActiveSupport::Inflector.camelize(underscore))
  end
end
test_camelize_with_underscores()
# File activesupport/test/inflector_test.rb, line 92
def test_camelize_with_underscores
  assert_equal("CamelCase", ActiveSupport::Inflector.camelize('Camel_Case'))
end
test_classify()
# File activesupport/test/inflector_test.rb, line 253
def test_classify
  ClassNameToTableName.each do |class_name, table_name|
    assert_equal(class_name, ActiveSupport::Inflector.classify(table_name))
    assert_equal(class_name, ActiveSupport::Inflector.classify("table_prefix." + table_name))
  end
end
test_classify_with_leading_schema_name()
# File activesupport/test/inflector_test.rb, line 266
def test_classify_with_leading_schema_name
  assert_equal 'FooBar', ActiveSupport::Inflector.classify('schema.foo_bar')
end
test_classify_with_symbol()
# File activesupport/test/inflector_test.rb, line 260
def test_classify_with_symbol
  assert_nothing_raised do
    assert_equal 'FooBar', ActiveSupport::Inflector.classify(:foo_bars)
  end
end
test_clear_all()
# File activesupport/test/inflector_test.rb, line 346
def test_clear_all
  cached_values = ActiveSupport::Inflector.inflections.plurals.dup, ActiveSupport::Inflector.inflections.singulars.dup, ActiveSupport::Inflector.inflections.uncountables.dup, ActiveSupport::Inflector.inflections.humans.dup
  ActiveSupport::Inflector.inflections do |inflect|
    # ensure any data is present
    inflect.plural(/(quiz)$/i, '\1zes')
    inflect.singular(/(database)s$/i, '\1')
    inflect.uncountable('series')
    inflect.human("col_rpted_bugs", "Reported bugs")

    inflect.clear :all

    assert inflect.plurals.empty?
    assert inflect.singulars.empty?
    assert inflect.uncountables.empty?
    assert inflect.humans.empty?
  end
  ActiveSupport::Inflector.inflections.instance_variable_set :@plurals, cached_values[0]
  ActiveSupport::Inflector.inflections.instance_variable_set :@singulars, cached_values[1]
  ActiveSupport::Inflector.inflections.instance_variable_set :@uncountables, cached_values[2]
  ActiveSupport::Inflector.inflections.instance_variable_set :@humans, cached_values[3]
end
test_clear_with_default()
# File activesupport/test/inflector_test.rb, line 368
def test_clear_with_default
  cached_values = ActiveSupport::Inflector.inflections.plurals.dup, ActiveSupport::Inflector.inflections.singulars.dup, ActiveSupport::Inflector.inflections.uncountables.dup, ActiveSupport::Inflector.inflections.humans.dup
  ActiveSupport::Inflector.inflections do |inflect|
    # ensure any data is present
    inflect.plural(/(quiz)$/i, '\1zes')
    inflect.singular(/(database)s$/i, '\1')
    inflect.uncountable('series')
    inflect.human("col_rpted_bugs", "Reported bugs")

    inflect.clear

    assert inflect.plurals.empty?
    assert inflect.singulars.empty?
    assert inflect.uncountables.empty?
    assert inflect.humans.empty?
  end
  ActiveSupport::Inflector.inflections.instance_variable_set :@plurals, cached_values[0]
  ActiveSupport::Inflector.inflections.instance_variable_set :@singulars, cached_values[1]
  ActiveSupport::Inflector.inflections.instance_variable_set :@uncountables, cached_values[2]
  ActiveSupport::Inflector.inflections.instance_variable_set :@humans, cached_values[3]
end
test_constantize()
# File activesupport/test/inflector_test.rb, line 293
def test_constantize
  run_constantize_tests_on do |string|
    ActiveSupport::Inflector.constantize(string)
  end
end
test_dasherize()
# File activesupport/test/inflector_test.rb, line 311
def test_dasherize
  UnderscoresToDashes.each do |underscored, dasherized|
    assert_equal(dasherized, ActiveSupport::Inflector.dasherize(underscored))
  end
end
test_deconstantize()
# File activesupport/test/inflector_test.rb, line 201
def test_deconstantize
  assert_equal "MyApplication::Billing", ActiveSupport::Inflector.deconstantize("MyApplication::Billing::Account")
  assert_equal "::MyApplication::Billing", ActiveSupport::Inflector.deconstantize("::MyApplication::Billing::Account")

  assert_equal "MyApplication", ActiveSupport::Inflector.deconstantize("MyApplication::Billing")
  assert_equal "::MyApplication", ActiveSupport::Inflector.deconstantize("::MyApplication::Billing")

  assert_equal "", ActiveSupport::Inflector.deconstantize("Account")
  assert_equal "", ActiveSupport::Inflector.deconstantize("::Account")
  assert_equal "", ActiveSupport::Inflector.deconstantize("")
end
test_demodulize()
# File activesupport/test/inflector_test.rb, line 195
def test_demodulize
  assert_equal "Account", ActiveSupport::Inflector.demodulize("MyApplication::Billing::Account")
  assert_equal "Account", ActiveSupport::Inflector.demodulize("Account")
  assert_equal "", ActiveSupport::Inflector.demodulize("")
end
test_foreign_key()
# File activesupport/test/inflector_test.rb, line 213
def test_foreign_key
  ClassNameToForeignKeyWithUnderscore.each do |klass, foreign_key|
    assert_equal(foreign_key, ActiveSupport::Inflector.foreign_key(klass))
  end

  ClassNameToForeignKeyWithoutUnderscore.each do |klass, foreign_key|
    assert_equal(foreign_key, ActiveSupport::Inflector.foreign_key(klass, false))
  end
end
test_humanize()
# File activesupport/test/inflector_test.rb, line 270
def test_humanize
  UnderscoreToHuman.each do |underscore, human|
    assert_equal(human, ActiveSupport::Inflector.humanize(underscore))
  end
end
test_humanize_by_rule()
# File activesupport/test/inflector_test.rb, line 276
def test_humanize_by_rule
  ActiveSupport::Inflector.inflections do |inflect|
    inflect.human(/_cnt$/i, '\1_count')
    inflect.human(/^prefx_/i, '\1')
  end
  assert_equal("Jargon count", ActiveSupport::Inflector.humanize("jargon_cnt"))
  assert_equal("Request", ActiveSupport::Inflector.humanize("prefx_request"))
end
test_humanize_by_string()
# File activesupport/test/inflector_test.rb, line 285
def test_humanize_by_string
  ActiveSupport::Inflector.inflections do |inflect|
    inflect.human("col_rpted_bugs", "Reported bugs")
  end
  assert_equal("Reported bugs", ActiveSupport::Inflector.humanize("col_rpted_bugs"))
  assert_equal("Col rpted bugs", ActiveSupport::Inflector.humanize("COL_rpted_bugs"))
end
test_ordinal()
# File activesupport/test/inflector_test.rb, line 305
def test_ordinal
  OrdinalNumbers.each do |number, ordinalized|
    assert_equal(ordinalized, ActiveSupport::Inflector.ordinalize(number))
  end
end
test_overwrite_previous_inflectors()
# File activesupport/test/inflector_test.rb, line 69
def test_overwrite_previous_inflectors
  assert_equal("series", ActiveSupport::Inflector.singularize("series"))
  ActiveSupport::Inflector.inflections.singular "series", "serie"
  assert_equal("serie", ActiveSupport::Inflector.singularize("series"))
  ActiveSupport::Inflector.inflections.uncountable "series" # Return to normal
end
test_parameterize()
# File activesupport/test/inflector_test.rb, line 229
def test_parameterize
  StringToParameterized.each do |some_string, parameterized_string|
    assert_equal(parameterized_string, ActiveSupport::Inflector.parameterize(some_string))
  end
end
test_parameterize_and_normalize()
# File activesupport/test/inflector_test.rb, line 235
def test_parameterize_and_normalize
  StringToParameterizedAndNormalized.each do |some_string, parameterized_string|
    assert_equal(parameterized_string, ActiveSupport::Inflector.parameterize(some_string))
  end
end
test_parameterize_with_custom_separator()
# File activesupport/test/inflector_test.rb, line 241
def test_parameterize_with_custom_separator
  StringToParameterizeWithUnderscore.each do |some_string, parameterized_string|
    assert_equal(parameterized_string, ActiveSupport::Inflector.parameterize(some_string, '_'))
  end
end
test_parameterize_with_multi_character_separator()
# File activesupport/test/inflector_test.rb, line 247
def test_parameterize_with_multi_character_separator
  StringToParameterized.each do |some_string, parameterized_string|
    assert_equal(parameterized_string.gsub('-', '__sep__'), ActiveSupport::Inflector.parameterize(some_string, '__sep__'))
  end
end
test_pluralize_empty_string()
# File activesupport/test/inflector_test.rb, line 16
def test_pluralize_empty_string
  assert_equal "", ActiveSupport::Inflector.pluralize("")
end
test_pluralize_plurals()
# File activesupport/test/inflector_test.rb, line 11
def test_pluralize_plurals
  assert_equal "plurals", ActiveSupport::Inflector.pluralize("plurals")
  assert_equal "Plurals", ActiveSupport::Inflector.pluralize("Plurals")
end
test_safe_constantize()
# File activesupport/test/inflector_test.rb, line 299
def test_safe_constantize
  run_safe_constantize_tests_on do |string|
    ActiveSupport::Inflector.safe_constantize(string)
  end
end
test_symbol_to_lower_camel()
# File activesupport/test/inflector_test.rb, line 329
def test_symbol_to_lower_camel
  SymbolToLowerCamel.each do |symbol, lower_camel|
    assert_equal(lower_camel, ActiveSupport::Inflector.camelize(symbol, false))
  end
end
test_tableize()
# File activesupport/test/inflector_test.rb, line 223
def test_tableize
  ClassNameToTableName.each do |class_name, table_name|
    assert_equal(table_name, ActiveSupport::Inflector.tableize(class_name))
  end
end
test_uncountable_word_is_not_greedy()
# File activesupport/test/inflector_test.rb, line 28
def test_uncountable_word_is_not_greedy
  uncountable_word = "ors"
  countable_word = "sponsor"

  cached_uncountables = ActiveSupport::Inflector.inflections.uncountables

  ActiveSupport::Inflector.inflections.uncountable << uncountable_word

  assert_equal uncountable_word, ActiveSupport::Inflector.singularize(uncountable_word)
  assert_equal uncountable_word, ActiveSupport::Inflector.pluralize(uncountable_word)
  assert_equal ActiveSupport::Inflector.pluralize(uncountable_word), ActiveSupport::Inflector.singularize(uncountable_word)

  assert_equal "sponsor", ActiveSupport::Inflector.singularize(countable_word)
  assert_equal "sponsors", ActiveSupport::Inflector.pluralize(countable_word)
  assert_equal "sponsor", ActiveSupport::Inflector.singularize(ActiveSupport::Inflector.pluralize(countable_word))

ensure
  ActiveSupport::Inflector.inflections.instance_variable_set :@uncountables, cached_uncountables
end
test_underscore()
# File activesupport/test/inflector_test.rb, line 174
def test_underscore
  CamelToUnderscore.each do |camel, underscore|
    assert_equal(underscore, ActiveSupport::Inflector.underscore(camel))
  end
  CamelToUnderscoreWithoutReverse.each do |camel, underscore|
    assert_equal(underscore, ActiveSupport::Inflector.underscore(camel))
  end
end
test_underscore_acronym_sequence()
# File activesupport/test/inflector_test.rb, line 164
def test_underscore_acronym_sequence
  ActiveSupport::Inflector.inflections do |inflect|
    inflect.acronym("API")
    inflect.acronym("HTML5")
    inflect.acronym("HTML")
  end

  assert_equal("html5_html_api", ActiveSupport::Inflector.underscore("HTML5HTMLAPI"))
end
test_underscore_as_reverse_of_dasherize()
# File activesupport/test/inflector_test.rb, line 317
def test_underscore_as_reverse_of_dasherize
  UnderscoresToDashes.each do |underscored, dasherized|
    assert_equal(underscored, ActiveSupport::Inflector.underscore(ActiveSupport::Inflector.dasherize(underscored)))
  end
end
test_underscore_to_lower_camel()
# File activesupport/test/inflector_test.rb, line 323
def test_underscore_to_lower_camel
  UnderscoreToLowerCamel.each do |underscored, lower_camel|
    assert_equal(lower_camel, ActiveSupport::Inflector.camelize(underscored, false))
  end
end
test_underscore_with_slashes()
# File activesupport/test/inflector_test.rb, line 189
def test_underscore_with_slashes
  CamelWithModuleToUnderscoreWithSlash.each do |camel, underscore|
    assert_equal(underscore, ActiveSupport::Inflector.underscore(camel))
  end
end