Skip to content

Commit

Permalink
Fix Embeddable and super issues. Prep for release 1.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
samlown committed Jul 4, 2011
1 parent 8efa520 commit 9d724ae
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 11 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.1.0
1.1.1
2 changes: 1 addition & 1 deletion couchrest_model.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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<couchrest>, "1.1.0")
s.add_dependency(%q<couchrest>, "1.1.1")
s.add_dependency(%q<mime-types>, "~> 1.15")
s.add_dependency(%q<activemodel>, "~> 3.0")
s.add_dependency(%q<tzinfo>, "~> 0.3.22")
Expand Down
6 changes: 6 additions & 0 deletions history.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
21 changes: 12 additions & 9 deletions lib/couchrest/model/embeddable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -20,17 +22,18 @@ def base_doc?
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?
Expand Down
11 changes: 11 additions & 0 deletions spec/unit/embeddable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,17 @@ def set_name; self.name = "foobar"; end
@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
Expand Down

0 comments on commit 9d724ae

Please sign in to comment.