require File.dirname(__FILE__) + '/table_less' class OnlyFooSpecialContextModel < Tableless to_json_options :special, :only=>:foo column :foo, :string column :bar, :string end class OnlyFooModel < Tableless to_json_options :only=>:foo column :foo, :string column :bar, :string end class ExceptFooModel < Tableless to_json_options :except=>:foo column :foo, :string column :bar, :string end class OnlyFooAndExtendedFooModel < OnlyFooModel to_json_options :only=>:extended_foo column :extended_foo, :string end class ToJsonOptionsTest < Test::Unit::TestCase def test_only_foo m=OnlyFooModel.new m.foo="fooValue" m.bar="barValue" assert_equal m.to_json,'{"foo": "fooValue"}' end def test_except_foo m=ExceptFooModel.new m.foo="fooValue" m.bar="barValue" assert_equal m.to_json,'{"bar": "barValue"}' end def test_only_foo_and_extended_foo m=OnlyFooAndExtendedFooModel.new m.foo="fooValue" m.bar="barValue" m.extended_foo="extenedFooValue" assert_equal m.to_json,'{"extended_foo": "extenedFooValue", "foo": "fooValue"}' end def test_context m=OnlyFooSpecialContextModel.new m.foo="fooValue" m.bar="barValue" assert_equal m.to_json(:context=>:any_unknown),'{"foo": "fooValue", "bar": "barValue"}' assert_equal m.to_json(:context=>:special), '{"foo": "fooValue"}' end end