Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Property type conflict - potential fix for issue 167 #168

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/couchrest/model/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def self.inherited(subklass)
def self.inherited(subklass)
super
subklass.properties = self.properties.dup
subklass.properties_by_name = self.properties_by_name.dup
# This is nasty:
subklass._validators = self._validators.dup
end
Expand Down
15 changes: 15 additions & 0 deletions spec/unit/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -564,4 +564,19 @@ def set_name; self.name = "foobar"; end
end
end

describe "model inheritance" do
context "multiple models with same base class" do
it "should not overwrite property definitions of the same name in different models" do
class MyBase < CouchRest::Model::Base; end
class MyModelA < MyBase
property :prop, Time
end
class MyModelB < MyBase
property :prop, Integer
end
MyModelA.new(:prop => Time.now).prop.class.should eq Time
end
end
end

end