Methods
- T
-
- test_acronym_override,
- test_acronyms,
- test_acronyms_camelize_lower,
- test_camelize,
- test_camelize_with_lower_downcases_the_first_letter,
- test_camelize_with_module,
- test_camelize_with_underscores,
- test_classify,
- test_classify_with_leading_schema_name,
- test_classify_with_symbol,
- test_clear_all,
- test_clear_with_default,
- test_constantize,
- test_dasherize,
- test_deconstantize,
- test_demodulize,
- test_foreign_key,
- test_humanize,
- test_humanize_by_rule,
- test_humanize_by_string,
- test_humanize_without_capitalize,
- test_inflections_with_uncountable_words,
- test_inflector_locality,
- test_ordinal,
- test_ordinalize,
- test_overwrite_previous_inflectors,
- test_parameterize,
- test_parameterize_and_normalize,
- test_parameterize_with_custom_separator,
- test_parameterize_with_multi_character_separator,
- test_pluralize_empty_string,
- test_pluralize_plurals,
- test_safe_constantize,
- test_symbol_to_lower_camel,
- test_tableize,
- test_uncountable_word_is_not_greedy,
- test_underscore,
- test_underscore_acronym_sequence,
- test_underscore_as_reverse_of_dasherize,
- test_underscore_to_lower_camel,
- test_underscore_with_slashes
- W
Included Modules
Instance Public methods
test_acronym_override()
Link
# File activesupport/test/inflector_test.rb, line 150 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()
Link
# File activesupport/test/inflector_test.rb, line 101 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()
Link
# File activesupport/test/inflector_test.rb, line 162 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()
Link
test_camelize_with_lower_downcases_the_first_letter()
Link
test_camelize_with_module()
Link
test_camelize_with_underscores()
Link
test_classify()
Link
# File activesupport/test/inflector_test.rb, line 273 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()
Link
test_classify_with_symbol()
Link
test_clear_all()
Link
# File activesupport/test/inflector_test.rb, line 407 def test_clear_all with_dup do 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 end
test_clear_with_default()
Link
# File activesupport/test/inflector_test.rb, line 426 def test_clear_with_default with_dup do 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 end
test_constantize()
Link
test_dasherize()
Link
test_deconstantize()
Link
# File activesupport/test/inflector_test.rb, line 211 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()
Link
# File activesupport/test/inflector_test.rb, line 204 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()
Link
# File activesupport/test/inflector_test.rb, line 223 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()
Link
test_humanize_by_rule()
Link
# File activesupport/test/inflector_test.rb, line 302 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()
Link
# File activesupport/test/inflector_test.rb, line 311 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()
Link
test_inflections_with_uncountable_words()
Link
test_inflector_locality()
Link
# File activesupport/test/inflector_test.rb, line 378 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()
Link
test_ordinalize()
Link
test_overwrite_previous_inflectors()
Link
# File activesupport/test/inflector_test.rb, line 72 def test_overwrite_previous_inflectors with_dup do assert_equal("series", ActiveSupport::Inflector.singularize("series")) ActiveSupport::Inflector.inflections.singular "series", "serie" assert_equal("serie", ActiveSupport::Inflector.singularize("series")) end end
test_parameterize()
Link
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 245 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()
Link
# File activesupport/test/inflector_test.rb, line 252 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()
Link
# File activesupport/test/inflector_test.rb, line 259 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, '_')) end end
test_parameterize_with_multi_character_separator()
Link
# File activesupport/test/inflector_test.rb, line 266 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, '__sep__')) end end
test_pluralize_empty_string()
Link
test_pluralize_plurals()
Link
test_safe_constantize()
Link
test_symbol_to_lower_camel()
Link
test_tableize()
Link
test_uncountable_word_is_not_greedy()
Link
# File activesupport/test/inflector_test.rb, line 28 def test_uncountable_word_is_not_greedy with_dup do 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 end
test_underscore()
Link
# File activesupport/test/inflector_test.rb, line 183 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()
Link
# File activesupport/test/inflector_test.rb, line 173 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()
Link
test_underscore_to_lower_camel()
Link
test_underscore_with_slashes()
Link
with_dup()
Link
Dups the singleton and yields, restoring the original inflections later. Use this in tests what modify the state of the singleton.
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.
# File activesupport/test/inflector_test.rb, line 530 def with_dup original = ActiveSupport::Inflector::Inflections.instance_variable_get(:@__instance__)[:en] ActiveSupport::Inflector::Inflections.instance_variable_set(:@__instance__, en: original.dup) yield ensure ActiveSupport::Inflector::Inflections.instance_variable_set(:@__instance__, en: original) end