property 0.8.1 → 0.8.2

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.
data/History.txt CHANGED
@@ -1,3 +1,10 @@
1
+ == 0.8.2 2010-02-16
2
+
3
+ * 2 minor enhancements
4
+ * fixed a bug where properties would be dumped even if none changed
5
+ * fixed a bug where properties would not be dumped soon enough to mark
6
+ storage object as dirty
7
+
1
8
  == 0.8.1 2010-02-14
2
9
 
3
10
  * 2 major enhancement
data/lib/property.rb CHANGED
@@ -9,7 +9,7 @@ require 'property/serialization/json'
9
9
  require 'property/core_ext/time'
10
10
 
11
11
  module Property
12
- VERSION = '0.8.1'
12
+ VERSION = '0.8.2'
13
13
 
14
14
  def self.included(base)
15
15
  base.class_eval do
@@ -23,7 +23,7 @@ module Property
23
23
 
24
24
  store_properties_in self
25
25
 
26
- before_save :dump_properties
26
+ after_validation :dump_properties
27
27
 
28
28
  alias_method_chain :attributes=, :properties
29
29
  end
@@ -48,14 +48,14 @@ module Property
48
48
  end
49
49
 
50
50
  def dump_properties
51
- if @properties
51
+ if @properties && @properties.changed?
52
52
  if !@properties.empty?
53
53
  #{accessor}write_attribute('properties', encode_properties(@properties))
54
54
  else
55
55
  #{accessor}write_attribute('properties', nil)
56
56
  end
57
+ @properties.clear_changes!
57
58
  end
58
- @properties.clear_changes!
59
59
  true
60
60
  end
61
61
  EOF
data/property.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{property}
8
- s.version = "0.8.1"
8
+ s.version = "0.8.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Renaud Kern", "Gaspard Bucher"]
12
- s.date = %q{2010-02-14}
12
+ s.date = %q{2010-02-16}
13
13
  s.description = %q{Wrap model properties into a single database column and declare properties from within the model.}
14
14
  s.email = %q{gaspard@teti.ch}
15
15
  s.extra_rdoc_files = [
@@ -226,6 +226,8 @@ class DeclarationTest < Test::Unit::TestCase
226
226
  end
227
227
 
228
228
  Contact = Class.new(ActiveRecord::Base) do
229
+ attr_accessor :assertion
230
+ before_save :before_save_assertion
229
231
  set_table_name :employees
230
232
  has_many :versions, :class_name => 'DeclarationTest::Version'
231
233
 
@@ -253,6 +255,13 @@ class DeclarationTest < Test::Unit::TestCase
253
255
  end
254
256
  end
255
257
  end
258
+
259
+ private
260
+ def before_save_assertion
261
+ return true unless @assertion
262
+ @assertion.call
263
+ true
264
+ end
256
265
  end
257
266
 
258
267
  setup do
@@ -274,6 +283,13 @@ class DeclarationTest < Test::Unit::TestCase
274
283
  assert_equal 'no', subject.famous
275
284
  assert_equal Hash["first_name"=>["Martin", "Hannah"]], subject.changes
276
285
  end
286
+
287
+ should 'dump properties before any before_save triggers' do
288
+ subject.assertion = Proc.new do
289
+ assert_match %r{Karl}, subject.version.properties
290
+ end
291
+ subject.update_attributes('first_name' => 'Karl')
292
+ end
277
293
  end
278
294
  end
279
295
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: property
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.1
4
+ version: 0.8.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Renaud Kern
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2010-02-14 00:00:00 +01:00
13
+ date: 2010-02-16 00:00:00 +01:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency