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_ordinal,
- 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
Included Modules
Instance Public methods
test_acronym_override()
Link
# 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()
Link
# 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()
Link
# 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()
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 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()
Link
test_classify_with_symbol()
Link
test_clear_all()
Link
# 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()
Link
# 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()
Link
test_dasherize()
Link
test_deconstantize()
Link
# 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()
Link
# 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()
Link
# 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()
Link
test_humanize_by_rule()
Link
# 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()
Link
# 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()
Link
test_overwrite_previous_inflectors()
Link
# 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()
Link
test_parameterize_and_normalize()
Link
test_parameterize_with_custom_separator()
Link
# 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()
Link
# 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()
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 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()
Link
# 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()
Link
# 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()
Link
test_underscore_to_lower_camel()
Link