loose_change 0.3.3 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.3
1
+ 0.3.4
@@ -54,7 +54,7 @@ module LooseChange
54
54
  result = JSON.parse(RestClient.put("#{ uri }/#{ name }#{ '?rev=' + @_rev if @_rev }", attachments[name][:file], {:content_type => attachments[name][:content_type], :accept => 'text/json'}))
55
55
  @_rev = result['rev']
56
56
  end
57
-
57
+
58
58
  end
59
59
 
60
60
  end
@@ -60,7 +60,6 @@ module LooseChange
60
60
  @errors = ActiveModel::Errors.new(self)
61
61
  @database = self.database
62
62
  @new_record = true unless args['_id']
63
- @_attachments = {}
64
63
  args.each {|property, value| self.send("#{property}=".to_sym, value)}
65
64
  apply_defaults
66
65
  self
@@ -42,9 +42,8 @@ module LooseChange
42
42
  # Build a Loose Change record from a hash of attributes +hash+ as
43
43
  # returned by CouchDB.
44
44
  def instantiate_from_hash(hash)
45
- model = new(hash.reject {|k, _| 'model_name' == k || '_attachments' == k})
45
+ model = new(hash.reject {|k, _| 'model_name' == k})
46
46
  model.id = hash['_id']
47
- model._attachments = hash['_attachments']
48
47
  model.new_record = false
49
48
  if hash['_attachments']
50
49
  attachment_names = hash['_attachments'].map {|name, _| name}
@@ -124,7 +123,11 @@ module LooseChange
124
123
  end
125
124
 
126
125
  def put_record
127
- result = JSON.parse(RestClient.put(uri, self.to_json(:methods => [:model_name, :_rev, :_id, :_attachments], :except => [:id]), default_headers))
126
+ if self._attachments
127
+ result = JSON.parse(RestClient.put(uri, self.to_json(:methods => [:model_name, :_rev, :_id, :_attachments], :except => [:id]), default_headers))
128
+ else
129
+ result = JSON.parse(RestClient.put(uri, self.to_json(:methods => [:model_name, :_rev, :_id], :except => [:id]), default_headers))
130
+ end
128
131
  @_rev = result['rev']
129
132
  result
130
133
  end
data/loose_change.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{loose_change}
8
- s.version = "0.3.3"
8
+ s.version = "0.3.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Joshua Miller"]
@@ -122,5 +122,14 @@ class PersistenceTest < ActiveSupport::TestCase
122
122
  assert_times_close time, new_model.created_at
123
123
  Timecop.return
124
124
  end
125
+
126
+ should "handle multiple saves and changes" do
127
+ @model.save
128
+ @model = TestModel.find(@model.id)
129
+ @model.age = "S,M,L,XL,2X".split ','
130
+ @model.name = 10
131
+ @model.save
132
+ end
133
+
125
134
 
126
135
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 3
8
- - 3
9
- version: 0.3.3
8
+ - 4
9
+ version: 0.3.4
10
10
  platform: ruby
11
11
  authors:
12
12
  - Joshua Miller
@@ -131,7 +131,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
131
131
  requirements:
132
132
  - - ">="
133
133
  - !ruby/object:Gem::Version
134
- hash: 3336428029023757776
134
+ hash: 1769435733236060489
135
135
  segments:
136
136
  - 0
137
137
  version: "0"