|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +require "abstract_unit" |
| 4 | + |
| 5 | +class FormatsTest < ActiveSupport::TestCase |
| 6 | + def test_json_format_uses_camelcase |
| 7 | + assert_equal ActiveResource::Formats::JsonFormat, ActiveResource::Formats[:json] |
| 8 | + end |
| 9 | + |
| 10 | + def test_xml_format_uses_camelcase |
| 11 | + assert_equal ActiveResource::Formats::XmlFormat, ActiveResource::Formats[:xml] |
| 12 | + end |
| 13 | + |
| 14 | + def test_custom_format_uses_camelcase |
| 15 | + klass = Class.new |
| 16 | + ActiveResource::Formats.const_set(:MsgpackFormat, klass) |
| 17 | + |
| 18 | + assert_equal klass, ActiveResource::Formats[:msgpack] |
| 19 | + ensure |
| 20 | + ActiveResource::Formats.send(:remove_const, :MsgpackFormat) |
| 21 | + end |
| 22 | + |
| 23 | + def test_unknown_format_raises_not_found_error |
| 24 | + assert_raises NameError, match: "uninitialized constant ActiveResource::Formats::MsgpackFormat" do |
| 25 | + ActiveResource::Formats[:msgpack] |
| 26 | + end |
| 27 | + end |
| 28 | + |
| 29 | + def test_json_format_uses_acronym_inflections |
| 30 | + ActiveSupport::Inflector.inflections { |inflect| inflect.acronym "JSON" } |
| 31 | + |
| 32 | + assert_equal ActiveResource::Formats::JsonFormat, ActiveResource::Formats[:json] |
| 33 | + ensure |
| 34 | + ActiveSupport::Inflector.inflections.clear :acronyms |
| 35 | + end |
| 36 | + |
| 37 | + def test_xml_format_uses_acronym_inflections |
| 38 | + ActiveSupport::Inflector.inflections { |inflect| inflect.acronym "XML" } |
| 39 | + |
| 40 | + assert_equal ActiveResource::Formats::XmlFormat, ActiveResource::Formats[:xml] |
| 41 | + ensure |
| 42 | + ActiveSupport::Inflector.inflections.clear :acronyms |
| 43 | + end |
| 44 | +end |
0 commit comments