added spec to show problem with validation of array of casted models

This commit is contained in:
Nathan 2009-05-11 17:17:53 -05:00 committed by Matt Aimonetti
parent 1b6ed9ce93
commit 0c0b6ecff2
2 changed files with 39 additions and 1 deletions

View file

@ -1,5 +1,6 @@
require File.join(File.dirname(__FILE__), '..', '..', 'spec_helper')
require File.join(FIXTURE_PATH, 'more', 'card')
require File.join(FIXTURE_PATH, 'more', 'cat')
class WithCastedModelMixin < Hash
include CouchRest::CastedModel
@ -67,7 +68,7 @@ describe CouchRest::CastedModel do
describe "casted as an array of a different type" do
before(:each) do
@obj = DummyModel.new(:keywords => ['couch', 'sofa', 'relax', 'canapé'])
@obj = DummyModel.new(:keywords => ['couch', 'sofa', 'relax', 'canape'])
end
it "should cast the array propery" do
@ -103,5 +104,24 @@ describe CouchRest::CastedModel do
end
end
describe "saving document with array of casted models and validation" do
before :each do
@cat = Cat.new
@cat.save
end
it "should save" do
toy = CatToy.new :name => "Mouse"
@cat.toys.push(toy)
@cat.save.should be_true
end
it "should fail because name is not present" do
toy = CatToy.new
@cat.toys.push(toy)
@cat.save.should be_false
end
end
end

18
spec/fixtures/more/cat.rb vendored Normal file
View file

@ -0,0 +1,18 @@
class Cat < CouchRest::ExtendedDocument
include ::CouchRest::Validation
# Set the default database to use
use_database TEST_SERVER.default_database
property :name
property :toys, :cast_as => ['CatToy'], :default => []
end
class CatToy < Hash
include ::CouchRest::CastedModel
include ::CouchRest::Validation
property :name
validates_present :name
end