Sha256: 0619079a936aa6da115515917454773e3d59f568364d09078ce4ba669fa4d00b
Contents?: true
Size: 1.11 KB
Versions: 1
Compression:
Stored size: 1.11 KB
Contents
require 'test_helper' require 'representable/json' class DeserializeTest < BaseTest class AlbumContract < Reform::Form include Reform::Form::ActiveModel::FormBuilderMethods # overrides #update!, too. self.representer_class.class_eval do include Representable::JSON end def deserialize_method :from_json end property :title validates :title, :presence => true, :length => {:minimum => 3} property :hit do property :title validates :title, :presence => true end property :band do # yepp, people do crazy stuff like that. validates :label, :presence => true property :label do property :name validates :name, :presence => true end end end let (:album) { Album.new(nil, Song.new, [Song.new, Song.new], Band.new(Label.new("Fat Wreck")) ) } subject { AlbumContract.new(album) } let (:json) { '{"hit":{"title":"Sacrifice"},"title":"Second Heat","songs":[{"title":"Heart Of A Lion"}],"band":{"label":{"name":"Fat Wreck"}}}' } it do subject.validate(json) subject.band.label.name.must_equal "Fat Wreck" end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
reform-1.1.1 | test/deserialize_test.rb |