couchrest 1.1.0 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,8 @@
1
+ == 1.1.1 - 2011-07-04
2
+
3
+ * Urgent change
4
+ * Ensuring attributes hash initalized on use to avoid issues when initializer is overwritten.
5
+
1
6
  == 1.1.0 - 2011-06-25
2
7
 
3
8
  * Minor changes
@@ -20,26 +20,25 @@ module CouchRest
20
20
  # that the attributes hash has been initialized before
21
21
  # you attempt to use it.
22
22
  def initialize(attrs = nil)
23
- @_attributes = {}
24
23
  attrs.each{|k,v| self[k] = v} unless attrs.nil?
25
24
  end
26
25
 
27
26
  # Hash equivilent methods to access the attributes
28
- def_delegators :@_attributes, :to_a, :==, :eql?, :keys, :values, :each,
27
+ def_delegators :_attributes, :to_a, :==, :eql?, :keys, :values, :each,
29
28
  :reject, :reject!, :empty?, :clear, :merge, :merge!,
30
29
  :encode_json, :as_json, :to_json, :frozen?
31
30
 
32
31
  def []=(key, value)
33
- @_attributes[key.to_s] = value
32
+ _attributes[key.to_s] = value
34
33
  end
35
34
  def [](key)
36
- @_attributes[key.to_s]
35
+ _attributes[key.to_s]
37
36
  end
38
37
  def has_key?(key)
39
- @_attributes.has_key?(key.to_s)
38
+ _attributes.has_key?(key.to_s)
40
39
  end
41
40
  def delete(key)
42
- @_attributes.delete(key.to_s)
41
+ _attributes.delete(key.to_s)
43
42
  end
44
43
  def dup
45
44
  new = super
@@ -52,14 +51,14 @@ module CouchRest
52
51
  new
53
52
  end
54
53
  def to_hash
55
- @_attributes
54
+ _attributes
56
55
  end
57
56
 
58
57
  # Freeze the object's attributes instead of the actual document.
59
58
  # This prevents further modifications to stored data, but does allow access
60
59
  # to local variables useful for callbacks or cached data.
61
60
  def freeze
62
- @_attributes.freeze; self
61
+ _attributes.freeze; self
63
62
  end
64
63
 
65
64
  # Provide details of the current keys in the reponse. Based on ActiveRecord::Base.
@@ -70,6 +69,14 @@ module CouchRest
70
69
  "#<#{self.class} #{attributes_as_nice_string}>"
71
70
  end
72
71
 
72
+ protected
73
+
74
+ # Define accessor for _attributes hash that will instantiate the
75
+ # model if this has not already been done.
76
+ def _attributes
77
+ @_attributes ||= {}
78
+ end
79
+
73
80
  end
74
81
 
75
82
  end
@@ -1,3 +1,3 @@
1
1
  module CouchRest
2
- VERSION = '1.1.0'
2
+ VERSION = '1.1.1'
3
3
  end
@@ -27,8 +27,22 @@ describe CouchRest::Document do
27
27
  @doc['_id'].should eql('sample')
28
28
  @doc['foo'].should eql('bar')
29
29
  end
30
+
31
+ context "replacing initalize" do
32
+ it "should not raise error" do
33
+ klass = Class.new(CouchRest::Document)
34
+ klass.class_eval do
35
+ def initialize; end # don't do anything, just overwrite
36
+ end
37
+ expect {
38
+ @doc = klass.new
39
+ @doc['test'] = 'sample'
40
+ }.to_not raise_error
41
+ end
42
+ end
30
43
  end
31
44
 
45
+
32
46
  describe "hash methods" do
33
47
  it "should respond to forwarded hash methods" do
34
48
  @doc = CouchRest::Document.new(:foo => 'bar')
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: couchrest
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.1.0
5
+ version: 1.1.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - J. Chris Anderson