From 9d724aee47e532c263c818b1dce839377bd8abab Mon Sep 17 00:00:00 2001 From: Sam Lown Date: Mon, 4 Jul 2011 18:53:25 +0200 Subject: [PATCH] Fix Embeddable and super issues. Prep for release 1.1.1 --- VERSION | 2 +- couchrest_model.gemspec | 2 +- history.md | 6 ++++++ lib/couchrest/model/embeddable.rb | 21 ++++++++++++--------- spec/unit/embeddable_spec.rb | 11 +++++++++++ 5 files changed, 31 insertions(+), 11 deletions(-) diff --git a/VERSION b/VERSION index 9084fa2..524cb55 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.1.0 +1.1.1 diff --git a/couchrest_model.gemspec b/couchrest_model.gemspec index 9138525..8e7e315 100644 --- a/couchrest_model.gemspec +++ b/couchrest_model.gemspec @@ -23,7 +23,7 @@ Gem::Specification.new do |s| s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } s.require_paths = ["lib"] - s.add_dependency(%q, "1.1.0") + s.add_dependency(%q, "1.1.1") s.add_dependency(%q, "~> 1.15") s.add_dependency(%q, "~> 3.0") s.add_dependency(%q, "~> 0.3.22") diff --git a/history.md b/history.md index f7fd395..e1c8329 100644 --- a/history.md +++ b/history.md @@ -1,5 +1,11 @@ # CouchRest Model Change History +## 1.1.1 - 2011-07-04 + +* Minor fix + * Bumping CouchRest version dependency for important initialize method fix. + * Ensuring super on Embeddable#initialize can be called. + ## 1.1.0 - 2011-06-25 * Major Alterations diff --git a/lib/couchrest/model/embeddable.rb b/lib/couchrest/model/embeddable.rb index 2da140c..05970a2 100644 --- a/lib/couchrest/model/embeddable.rb +++ b/lib/couchrest/model/embeddable.rb @@ -2,8 +2,10 @@ module CouchRest::Model module Embeddable extend ActiveSupport::Concern + # Include Attributes early to ensure super() will work + include CouchRest::Attributes + included do - include CouchRest::Attributes include CouchRest::Model::Configuration include CouchRest::Model::Properties include CouchRest::Model::PropertyProtection @@ -20,17 +22,18 @@ module CouchRest::Model false # Can never be base doc! end - # Initialize a new Casted Model. Accepts the same - # options as CouchRest::Model::Base for preparing and initializing - # attributes. - def initialize(keys = {}, options = {}) - super() - prepare_all_attributes(keys, options) - run_callbacks(:initialize) { self } - end end end + # Initialize a new Casted Model. Accepts the same + # options as CouchRest::Model::Base for preparing and initializing + # attributes. + def initialize(keys = {}, options = {}) + super() + prepare_all_attributes(keys, options) + run_callbacks(:initialize) { self } + end + # False if the casted model has already # been saved in the containing document def new? diff --git a/spec/unit/embeddable_spec.rb b/spec/unit/embeddable_spec.rb index c56f304..9b5b52e 100644 --- a/spec/unit/embeddable_spec.rb +++ b/spec/unit/embeddable_spec.rb @@ -79,6 +79,17 @@ describe CouchRest::Model::Embeddable do @obj = klass.new @obj.name.should eql("foobar") end + it "should allow override of initialize with super" do + klass = Class.new do + include CouchRest::Model::Embeddable + after_initialize :set_name + property :name + def set_name; self.name = "foobar"; end + def initialize(attrs = {}); super(); end + end + @obj = klass.new + @obj.name.should eql("foobar") + end end describe "casted as an attribute, but without a value" do