Should be able to assign a casted hash to a hash property

Fixes https://github.com/couchrest/couchrest_model/issues/68

Signed-off-by: Marcos Tapajós <tapajos@gmail.com>
This commit is contained in:
Kostiantyn Kahanskyi 2011-06-06 18:07:33 +02:00 committed by Marcos Tapajós
parent a55cf56213
commit d50d47c32a
3 changed files with 17 additions and 1 deletions

View file

@ -39,7 +39,7 @@ module CouchRest::Model
arr = value.collect { |data| cast_value(parent, data) }
# allow casted_by calls to be passed up chain by wrapping in CastedArray
CastedArray.new(arr, self, parent)
elsif (type == Object || type == Hash) && (value.class == Hash)
elsif (type == Object || type == Hash) && (value.kind_of?(Hash))
# allow casted_by calls to be passed up chain by wrapping in CastedHash
CastedHash[value, self, parent]
elsif !value.nil?

View file

@ -9,6 +9,7 @@ require File.join(FIXTURE_PATH, 'more', 'service')
require File.join(FIXTURE_PATH, 'more', 'event')
require File.join(FIXTURE_PATH, 'more', 'user')
require File.join(FIXTURE_PATH, 'more', 'course')
require File.join(FIXTURE_PATH, "more", "key_chain")
describe "Model properties" do
@ -239,6 +240,16 @@ describe "Model properties" do
end
describe "properties of hash of casted models" do
it "should be able to assign a casted hash to a hash property" do
chain = KeyChain.new
keys = {"House" => "8==$", "Office" => "<>==U"}
chain.keys = keys
chain.keys = chain.keys
chain.keys.should == keys
end
end
describe "properties of array of casted models" do
before(:each) do

5
spec/fixtures/more/key_chain.rb vendored Normal file
View file

@ -0,0 +1,5 @@
class KeyChain < CouchRest::Model::Base
use_database(DB)
property(:keys, Hash)
end