Methods
S
T
Included Modules
Instance Public methods
setup()
# File activesupport/test/inflector_test.rb, line 11
def setup
  # Dups the singleton before each test, restoring the original inflections later.
  #
  # This helper is implemented by setting @__instance__ because in some tests
  # there are module functions that access ActiveSupport::Inflector.inflections,
  # so we need to replace the singleton itself.
  @original_inflections = ActiveSupport::Inflector::Inflections.instance_variable_get(:@__instance__)[:en]
  ActiveSupport::Inflector::Inflections.instance_variable_set(:@__instance__, en: @original_inflections.dup)
end
teardown()
# File activesupport/test/inflector_test.rb, line 21
def teardown
  ActiveSupport::Inflector::Inflections.instance_variable_set(:@__instance__, en: @original_inflections)
end
test_acronym_override()
# File activesupport/test/inflector_test.rb, line 160
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 111
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"],
    ["Nested::RESTful",   "nested/restful",     "Nested/RESTful",     "Nested/RESTful"],
    ["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"],
    ["HTTP::RESTful",     "http/restful",       "HTTP/RESTful",       "HTTP/RESTful"],
    ["HTTP::RESTfulAPI",  "http/restful_api",   "HTTP/RESTful API",   "HTTP/RESTful API"],
    ["APIRESTful",        "api_restful",        "API RESTful",        "API RESTful"],

    # 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 172
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 97
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 103
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 202
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 107
def test_camelize_with_underscores
  assert_equal("CamelCase", ActiveSupport::Inflector.camelize('Camel_Case'))
end
test_classify()
# File activesupport/test/inflector_test.rb, line 301
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 314
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 308
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 433
def test_clear_all
  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
end
test_clear_with_default()
# File activesupport/test/inflector_test.rb, line 450
def test_clear_with_default
  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
end
test_constantize()
# File activesupport/test/inflector_test.rb, line 347
def test_constantize
  run_constantize_tests_on do |string|
    ActiveSupport::Inflector.constantize(string)
  end
end
test_dasherize()
# File activesupport/test/inflector_test.rb, line 371
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 221
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 214
def test_demodulize
  assert_equal "Account", ActiveSupport::Inflector.demodulize("MyApplication::Billing::Account")
  assert_equal "Account", ActiveSupport::Inflector.demodulize("Account")
  assert_equal "Account", ActiveSupport::Inflector.demodulize("::Account")
  assert_equal "", ActiveSupport::Inflector.demodulize("")
end
test_foreign_key()
# File activesupport/test/inflector_test.rb, line 233
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 318
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 330
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 339
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_humanize_without_capitalize()
# File activesupport/test/inflector_test.rb, line 324
def test_humanize_without_capitalize
  UnderscoreToHumanWithoutCapitalize.each do |underscore, human|
    assert_equal(human, ActiveSupport::Inflector.humanize(underscore, capitalize: false))
  end
end
test_inflections_with_uncountable_words()
# File activesupport/test/inflector_test.rb, line 530
def test_inflections_with_uncountable_words
  ActiveSupport::Inflector.inflections do |inflect|
    inflect.uncountable "HTTP"
  end

  assert_equal "HTTP", ActiveSupport::Inflector.pluralize("HTTP")
end
test_inflector_locality()
# File activesupport/test/inflector_test.rb, line 404
def test_inflector_locality
  ActiveSupport::Inflector.inflections(:es) do |inflect|
    inflect.plural(/$/, 's')
    inflect.plural(/z$/i, 'ces')

    inflect.singular(/s$/, '')
    inflect.singular(/es$/, '')

    inflect.irregular('el', 'los')
  end

  assert_equal('hijos', 'hijo'.pluralize(:es))
  assert_equal('luces', 'luz'.pluralize(:es))
  assert_equal('luzs', 'luz'.pluralize)

  assert_equal('sociedad', 'sociedades'.singularize(:es))
  assert_equal('sociedade', 'sociedades'.singularize)

  assert_equal('los', 'el'.pluralize(:es))
  assert_equal('els', 'el'.pluralize)

  ActiveSupport::Inflector.inflections(:es) { |inflect| inflect.clear }

  assert ActiveSupport::Inflector.inflections(:es).plurals.empty?
  assert ActiveSupport::Inflector.inflections(:es).singulars.empty?
  assert !ActiveSupport::Inflector.inflections.plurals.empty?
  assert !ActiveSupport::Inflector.inflections.singulars.empty?
end
test_ordinal()
# File activesupport/test/inflector_test.rb, line 359
def test_ordinal
  OrdinalNumbers.each do |number, ordinalized|
    assert_equal(ordinalized, number + ActiveSupport::Inflector.ordinal(number))
  end
end
test_ordinalize()
# File activesupport/test/inflector_test.rb, line 365
def test_ordinalize
  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 84
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"))
end
test_parameterize()

FIXME: get following tests to pass on jruby, currently skipped

Currently this fails because ActiveSupport::Multibyte::Unicode#tidy_bytes required a specific Encoding::Converter(UTF-8 to UTF8-MAC) which unavailable on JRuby causing our tests to error out. related bug jira.codehaus.org/browse/JRUBY-7194

# File activesupport/test/inflector_test.rb, line 255
def test_parameterize
  jruby_skip "UTF-8 to UTF8-MAC Converter is unavailable"
  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 262
def test_parameterize_and_normalize
  jruby_skip "UTF-8 to UTF8-MAC Converter is unavailable"
  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 269
def test_parameterize_with_custom_separator
  jruby_skip "UTF-8 to UTF8-MAC Converter is unavailable"
  StringToParameterizeWithUnderscore.each do |some_string, parameterized_string|
    assert_equal(parameterized_string, ActiveSupport::Inflector.parameterize(some_string, separator: '_'))
  end
end
test_parameterize_with_custom_separator_deprecated()
# File activesupport/test/inflector_test.rb, line 276
def test_parameterize_with_custom_separator_deprecated
  jruby_skip "UTF-8 to UTF8-MAC Converter is unavailable"
  StringToParameterizeWithUnderscore.each do |some_string, parameterized_string|
    assert_deprecated(/Passing the separator argument as a positional parameter is deprecated and will soon be removed. Use `separator: '_'` instead./i) do
      assert_equal(parameterized_string, ActiveSupport::Inflector.parameterize(some_string, '_'))
    end
  end
end
test_parameterize_with_multi_character_separator()
# File activesupport/test/inflector_test.rb, line 285
def test_parameterize_with_multi_character_separator
  jruby_skip "UTF-8 to UTF8-MAC Converter is unavailable"
  StringToParameterized.each do |some_string, parameterized_string|
    assert_equal(parameterized_string.gsub('-', '__sep__'), ActiveSupport::Inflector.parameterize(some_string, separator: '__sep__'))
  end
end
test_parameterize_with_multi_character_separator_deprecated()
# File activesupport/test/inflector_test.rb, line 292
def test_parameterize_with_multi_character_separator_deprecated
  jruby_skip "UTF-8 to UTF8-MAC Converter is unavailable"
  StringToParameterized.each do |some_string, parameterized_string|
    assert_deprecated(/Passing the separator argument as a positional parameter is deprecated and will soon be removed. Use `separator: '__sep__'` instead./i) do
      assert_equal(parameterized_string.gsub('-', '__sep__'), ActiveSupport::Inflector.parameterize(some_string, '__sep__'))
    end
  end
end
test_pluralize_empty_string()
# File activesupport/test/inflector_test.rb, line 30
def test_pluralize_empty_string
  assert_equal "", ActiveSupport::Inflector.pluralize("")
end
test_pluralize_plurals()
# File activesupport/test/inflector_test.rb, line 25
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 353
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 389
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 243
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 42
def test_uncountable_word_is_not_greedy
  uncountable_word = "ors"
  countable_word = "sponsor"

  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))
end
test_underscore()
# File activesupport/test/inflector_test.rb, line 193
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 183
def test_underscore_acronym_sequence
  ActiveSupport::Inflector.inflections do |inflect|
    inflect.acronym("API")
    inflect.acronym("JSON")
    inflect.acronym("HTML")
  end

  assert_equal("json_html_api", ActiveSupport::Inflector.underscore("JSONHTMLAPI"))
end
test_underscore_as_reverse_of_dasherize()
# File activesupport/test/inflector_test.rb, line 377
def test_underscore_as_reverse_of_dasherize
  UnderscoresToDashes.each_key do |underscored|
    assert_equal(underscored, ActiveSupport::Inflector.underscore(ActiveSupport::Inflector.dasherize(underscored)))
  end
end
test_underscore_to_lower_camel()
# File activesupport/test/inflector_test.rb, line 383
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 208
def test_underscore_with_slashes
  CamelWithModuleToUnderscoreWithSlash.each do |camel, underscore|
    assert_equal(underscore, ActiveSupport::Inflector.underscore(camel))
  end
end