historic 0.1.0 → 0.2.0

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/VERSION.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  ---
2
2
  :major: 0
3
- :minor: 1
3
+ :minor: 2
4
4
  :patch: 0
5
5
  :build:
@@ -39,6 +39,7 @@ module ActiveRecord
39
39
  @historic_record_class = (options.delete(:class_name) || "#{self.to_s}History").constantize
40
40
 
41
41
  options[:on_change_of] = [options[:on_change_of]] if options[:on_change_of] && !options[:on_change_of].is_a?(Array)
42
+ options[:version_column] ||= :version
42
43
  @historic_options = options
43
44
  end
44
45
 
@@ -54,6 +55,9 @@ module ActiveRecord
54
55
 
55
56
  if historic_should_move_to_history?(historic_options)
56
57
  historic_copy_to_history
58
+ if self.respond_to?(historic_options[:version_column])
59
+ self.increment(historic_options[:version_column])
60
+ end
57
61
  end
58
62
  end
59
63
 
@@ -30,6 +30,10 @@ class HistoricTest < Test::Unit::TestCase
30
30
  assert HistoricItemHistory.exists?({:field_1=>@old_item.field_1, :field_2=>@old_item.field_2, :field_3=>@old_item.field_3})
31
31
  end
32
32
 
33
+ should "increment @item's version by one" do
34
+ assert_equal @old_item.version + 1, @item.version
35
+ end
36
+
33
37
  context ", the HistoricItemHistory" do
34
38
  setup do
35
39
  @item_history = HistoricItemHistory.find_by_field_1_and_field_2_and_field_3(@old_item.field_1, @old_item.field_2, @old_item.field_3)
@@ -54,6 +58,10 @@ class HistoricTest < Test::Unit::TestCase
54
58
  should "set historic_item_id reference field" do
55
59
  assert_equal @item.id, @item_history.historic_item_id
56
60
  end
61
+
62
+ should "have a version equal to the old item's version" do
63
+ assert_equal @old_item.version, @item_history.version
64
+ end
57
65
  end #for the HistoricItemHistory
58
66
  end #when changing field_1 of HistoricIte
59
67
  end #when changing the value of :field_1 to @new_field_1
@@ -88,5 +96,6 @@ class HistoricTest < Test::Unit::TestCase
88
96
  # assert HistoricItemHistory.exists?({:field_1=>@item.field_1, :field_2=>@item.field_2, :field_3=>@item.field_3})
89
97
  end
90
98
  end #when destroyed
99
+
91
100
  end # An item guide
92
101
  end
data/test/test_helper.rb CHANGED
@@ -16,12 +16,14 @@ class Test::Unit::TestCase
16
16
  columns = [:field_1, :field_2, :field_3]
17
17
  create_table :historic_items do |t|
18
18
  t.string *columns
19
+ t.integer :version, :default => 0
19
20
  end
20
21
 
21
22
  create_table :historic_item_histories do |t|
22
23
  t.string *columns
23
24
  t.integer :position
24
25
  t.integer :historic_item_id
26
+ t.integer :version
25
27
  end
26
28
  end
27
29
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: historic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Greg Fitzgerald