Skip to content

Commit

Permalink
Merge pull request #101 from amco/property_inheretance
Browse files Browse the repository at this point in the history
Inheretance persist properties into parent object
  • Loading branch information
javierg committed Dec 11, 2015
2 parents dbfc327 + 9c7b0c3 commit 14fbdbe
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/dolly/document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ def rows= col
raise Dolly::ResourceNotFound if col.empty?
col.each{ |r| @doc = r['doc'] }
_properties.each do |p|
#TODO: Refactor properties so it is not required
#to be a class property. But something that doesn't
#persist all the inheretence chain
next unless self.respond_to? :"#{p.name}="
self.send "#{p.name}=", doc[p.name]
end
@rows = col
Expand Down
9 changes: 9 additions & 0 deletions test/document_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ class DocWithSameDefaults < Dolly::Document
property :foo, :bar, class_name: Array, default: []
end

class Bar < FooBar
property :a, :b
end

class DocumentTest < ActiveSupport::TestCase
DB_BASE_PATH = "http://localhost:5984/test".freeze

Expand Down Expand Up @@ -467,6 +471,11 @@ def setup
assert_equal Base64.encode64(data), doc.doc['_attachments']['test.txt']['data']
end

test "new object from inhereted document" do
assert bar = Bar.new(a: 1)
assert_equal 1, bar.a
end

private
def generic_response rows, count = 1
{total_rows: count, offset:0, rows: rows}
Expand Down

0 comments on commit 14fbdbe

Please sign in to comment.