You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When an embedded model gets initialized the directly_set_attributes option doesn't get passed through to the initializer call. Therefore read-only properties of the embedded model do not get set.
Here is a simple test case:
# encoding: utf-8require"spec_helper"classEmbeddedWithReadOnlyincludeCouchRest::Model::Embeddableproperty:read_write,:read_only=>falseproperty:read_only,:read_only=>trueendclassBaseModel < CouchRest::Model::Baseproperty:embedded,:type=>EmbeddedWithReadOnlyenddescribe"initializing an embedded model"doit"should set a read-only property in an embedded model"dodoc=BaseModel.build_from_database({type: "BaseModel",embedded: {type: "EmbeddedWithReadOnly",read_only: "foo",read_write: "bar"}})doc.embedded.read_write.shouldeq"bar"doc.embedded.read_only.shouldeq"foo"endend
This test currently fails on master:
$ bundle exec rspec spec/functional/embeddable_with_read_only_spec.rb
F
Failures:
1) initializing an embedded model should set a read-only property in an embedded model
Failure/Error: doc.embedded.read_only.should eq "foo"
expected "foo"
got nil
(compared using ==)
# ./spec/functional/embeddable_with_read_only_spec.rb:18:in `block (2 levels) in <top (required)>'
Finished in 0.16174 seconds
1 example, 1 failure
Failed examples:
rspec ./spec/functional/embeddable_with_read_only_spec.rb:15 # initializing an embedded model should set a read-only property in an embedded model
One possible fix is to check whether a property's type includes the CouchRest::Model::Embeddable module before building the property value - if it does, the :directly_set_attributes option should be passed into it's initializer:
When an embedded model gets initialized the
directly_set_attributes
option doesn't get passed through to the initializer call. Therefore read-only properties of the embedded model do not get set.Here is a simple test case:
This test currently fails on master:
One possible fix is to check whether a property's type includes the
CouchRest::Model::Embeddable
module before building the property value - if it does, the:directly_set_attributes
option should be passed into it's initializer:I don't particularly like checking for the type of the property's class in this way so I hope there is a better way to fix this.
The text was updated successfully, but these errors were encountered: