cia 0.2.2 → 0.2.3

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,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cia (0.2.2)
4
+ cia (0.2.3)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: /Users/mgrosser/code/tools/cia
3
3
  specs:
4
- cia (0.2.1)
4
+ cia (0.2.2)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: /Users/mgrosser/code/tools/cia
3
3
  specs:
4
- cia (0.2.1)
4
+ cia (0.2.2)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
@@ -9,6 +9,16 @@ module CIA
9
9
 
10
10
  validates_presence_of :transaction, :source, :type
11
11
 
12
+ def self.previous
13
+ scoped(:order => "id desc")
14
+ end
15
+
16
+ def attribute_change_hash
17
+ attribute_changes.inject({}) do |h, a|
18
+ h[a.attribute_name] = [a.old_value, a.new_value]; h
19
+ end
20
+ end
21
+
12
22
  # tested via transaction_test.rb
13
23
  def record_attribute_changes!(changes)
14
24
  changes.each do |attribute_name, (old_value, new_value)|
@@ -1,3 +1,3 @@
1
1
  module CIA
2
- VERSION = '0.2.2'
2
+ VERSION = '0.2.3'
3
3
  end
@@ -5,4 +5,23 @@ describe CIA::Event do
5
5
  change = create_change
6
6
  change.event.attribute_changes.should == [change]
7
7
  end
8
+
9
+ context "attribute_change_hash" do
10
+ it "is empty for empty changes" do
11
+ create_event.attribute_change_hash.should == {}
12
+ end
13
+
14
+ it "contains all changes" do
15
+ change = create_change(:old_value => "a", :new_value => "b")
16
+ change = create_change(:attribute_name => "foo", :old_value => "b", :new_value => nil, :event => change.event)
17
+ change.event.attribute_change_hash.should == {"bar" => ["a", "b"], "foo" => ["b", nil]}
18
+ end
19
+ end
20
+
21
+ context ".previous" do
22
+ it "is sorted id desc" do
23
+ events = [create_event, create_event, create_event].map(&:id)
24
+ CIA::Event.previous.map(&:id).should == events.reverse
25
+ end
26
+ end
8
27
  end
@@ -1,6 +1,14 @@
1
1
  $LOAD_PATH.unshift 'lib'
2
2
  require 'cia'
3
3
 
4
+ RSpec.configure do |config|
5
+ config.before do
6
+ CIA::Transaction.delete_all
7
+ CIA::Event.delete_all
8
+ CIA::AttributeChange.delete_all
9
+ end
10
+ end
11
+
4
12
  ActiveRecord::Base.establish_connection(
5
13
  :adapter => "sqlite3",
6
14
  :database => ":memory:"
@@ -56,6 +64,6 @@ def create_event
56
64
  end
57
65
 
58
66
  def create_change(options={})
59
- event = create_event
67
+ event = options.delete(:event) || create_event
60
68
  CIA::AttributeChange.create!({:event => event, :source => event.source, :attribute_name => "bar"}.merge(options))
61
69
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cia
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-14 00:00:00.000000000 Z
12
+ date: 2012-06-22 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description:
15
15
  email: michael@grosser.it
@@ -59,7 +59,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
59
59
  version: '0'
60
60
  segments:
61
61
  - 0
62
- hash: -3438842526212601421
62
+ hash: -3661699799177729927
63
63
  required_rubygems_version: !ruby/object:Gem::Requirement
64
64
  none: false
65
65
  requirements:
@@ -68,7 +68,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
68
68
  version: '0'
69
69
  segments:
70
70
  - 0
71
- hash: -3438842526212601421
71
+ hash: -3661699799177729927
72
72
  requirements: []
73
73
  rubyforge_project:
74
74
  rubygems_version: 1.8.24