Sha256: 61a522161dbc8f789e9c245a9fa71b733eae748e408b52adfebf9454da123d55
Contents?: true
Size: 1.52 KB
Versions: 9
Compression:
Stored size: 1.52 KB
Contents
require 'test_helper' class ContractTest < BaseTest class AlbumContract < Reform::Contract property :title validates :title, :presence => true, :length => {:minimum => 3} property :hit do property :title validates :title, :presence => true end collection :songs do property :title validates :title, :presence => true end validates :songs, :length => {:minimum => 4} property :band do # yepp, people do crazy stuff like that. validates :label, :presence => true property :label do property :name validates :name, :presence => true end # TODO: make band a required object. end end let (:album) { Album.new(nil, Song.new, [Song.new, Song.new], Band.new() ) } subject { AlbumContract.new(album) } describe "invalid" do before { res = subject.validate res.must_equal false } it { subject.errors.messages.must_equal({:"hit.title"=>["can't be blank"], :"songs.title"=>["can't be blank"], :"band.label"=>["can't be blank"], :songs=>["is too short (minimum is 4 characters)"], :title=>["can't be blank", "is too short (minimum is 3 characters)"]}) } end describe "valid" do let (:album) { Album.new( "Keeper Of The Seven Keys", nil, [Song.new("Initiation"), Song.new("I'm Alive"), Song.new("A Little Time"), Song.new("Future World"),], Band.new(Label.new("Noise")) ) } before { subject.validate.must_equal true } it { subject.errors.messages.must_equal({}) } end end
Version data entries
9 entries across 9 versions & 1 rubygems