fixed some serious issues but left some for tomorrow (validations aren't working right)
This commit is contained in:
parent
bc47e72ae0
commit
e448112ff6
8 changed files with 89 additions and 48 deletions
|
@ -1,19 +1,21 @@
|
|||
require File.join(File.dirname(__FILE__), '..', '..', 'spec_helper')
|
||||
require File.join(FIXTURE_PATH, 'more', 'card')
|
||||
|
||||
class WithCastedModelMixin < Hash
|
||||
include CouchRest::CastedModel
|
||||
property :name
|
||||
end
|
||||
|
||||
class DummyModel < CouchRest::ExtendedDocument
|
||||
use_database TEST_SERVER.default_database
|
||||
raise "Default DB not set" if TEST_SERVER.default_database.nil?
|
||||
property :casted_attribute, :cast_as => 'WithCastedModelMixin'
|
||||
end
|
||||
|
||||
|
||||
describe CouchRest::CastedModel do
|
||||
|
||||
class WithCastedModelMixin < Hash
|
||||
include CouchRest::CastedModel
|
||||
property :name
|
||||
end
|
||||
|
||||
class DummyModel < CouchRest::ExtendedDocument
|
||||
property :casted_attribute, :cast_as => 'WithCastedModelMixin'
|
||||
end
|
||||
|
||||
describe "A non hash class including CastedModel" do
|
||||
|
||||
it "should fail raising and include error" do
|
||||
lambda do
|
||||
class NotAHashButWithCastedModelMixin
|
||||
|
@ -23,7 +25,6 @@ describe CouchRest::CastedModel do
|
|||
|
||||
end.should raise_error
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "isolated" do
|
||||
|
@ -37,7 +38,6 @@ describe CouchRest::CastedModel do
|
|||
end
|
||||
|
||||
describe "casted as attribute" do
|
||||
|
||||
before(:each) do
|
||||
@obj = DummyModel.new(:casted_attribute => {:name => 'whatever'})
|
||||
@casted_obj = @obj.casted_attribute
|
||||
|
@ -54,6 +54,30 @@ describe CouchRest::CastedModel do
|
|||
it "should know who casted it" do
|
||||
@casted_obj.casted_by.should == @obj
|
||||
end
|
||||
end
|
||||
|
||||
describe "saved document with casted models" do
|
||||
before(:each) do
|
||||
@obj = DummyModel.new(:casted_attribute => {:name => 'whatever'})
|
||||
@obj.save
|
||||
end
|
||||
|
||||
it "should be able to load with the casted models" do
|
||||
casted_obj = @obj.casted_attribute
|
||||
casted_obj.should_not be_nil
|
||||
casted_obj.should be_an_instance_of(WithCastedModelMixin)
|
||||
end
|
||||
|
||||
it "should have defined getters for the casted model" do
|
||||
casted_obj = @obj.casted_attribute
|
||||
casted_obj.name.should == "whatever"
|
||||
end
|
||||
|
||||
it "should have defined setters for the casted model" do
|
||||
casted_obj = @obj.casted_attribute
|
||||
casted_obj.name = "test"
|
||||
casted_obj.name.should == "test"
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue