cia 0.4.4 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source :rubygems
1
+ source "https://rubygems.org"
2
2
  gemspec
3
3
 
4
4
  gem 'bump'
data/Gemfile.lock CHANGED
@@ -1,10 +1,10 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cia (0.4.4)
4
+ cia (0.5.0)
5
5
 
6
6
  GEM
7
- remote: http://rubygems.org/
7
+ remote: https://rubygems.org/
8
8
  specs:
9
9
  activemodel (3.2.11)
10
10
  activesupport (= 3.2.11)
@@ -1,6 +1,6 @@
1
1
  # This file was generated by Appraisal
2
2
 
3
- source :rubygems
3
+ source "https://rubygems.org"
4
4
 
5
5
  gem "bump"
6
6
  gem "rake"
@@ -1,10 +1,10 @@
1
1
  PATH
2
2
  remote: /Users/mgrosser/code/tools/cia
3
3
  specs:
4
- cia (0.4.3)
4
+ cia (0.4.4)
5
5
 
6
6
  GEM
7
- remote: http://rubygems.org/
7
+ remote: https://rubygems.org/
8
8
  specs:
9
9
  activerecord (2.3.14)
10
10
  activesupport (= 2.3.14)
@@ -1,6 +1,6 @@
1
1
  # This file was generated by Appraisal
2
2
 
3
- source :rubygems
3
+ source "https://rubygems.org"
4
4
 
5
5
  gem "bump"
6
6
  gem "rake"
@@ -1,10 +1,10 @@
1
1
  PATH
2
2
  remote: /Users/mgrosser/code/tools/cia
3
3
  specs:
4
- cia (0.4.3)
4
+ cia (0.4.4)
5
5
 
6
6
  GEM
7
- remote: http://rubygems.org/
7
+ remote: https://rubygems.org/
8
8
  specs:
9
9
  activemodel (3.2.3)
10
10
  activesupport (= 3.2.3)
data/lib/cia/event.rb CHANGED
@@ -6,7 +6,9 @@ module CIA
6
6
  belongs_to :source, :polymorphic => true
7
7
  has_many :attribute_changes, :foreign_key => :cia_event_id
8
8
 
9
- validates_presence_of :source, :action
9
+ validates_presence_of :action
10
+ validates_presence_of :source, :if => :source_must_be_exist?
11
+ validates_presence_of :source_id, :source_type, :unless => :source_must_be_exist?
10
12
 
11
13
  def self.previous
12
14
  scoped(:order => "created_at desc")
@@ -30,5 +32,11 @@ module CIA
30
32
  )
31
33
  end
32
34
  end
35
+
36
+ private
37
+
38
+ def source_must_be_exist?
39
+ new_record? and action != "destroy"
40
+ end
33
41
  end
34
42
  end
data/lib/cia/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module CIA
2
- VERSION = '0.4.4'
2
+ VERSION = '0.5.0'
3
3
  end
@@ -24,4 +24,22 @@ describe CIA::Event do
24
24
  CIA::Event.previous.map(&:id).should == events.reverse
25
25
  end
26
26
  end
27
+
28
+ context "validations" do
29
+ let(:source_attributes){ {:source => nil, :source_id => 99999, :source_type => "Car"} }
30
+
31
+ it "validates source" do
32
+ expect{
33
+ create_event(source_attributes)
34
+ }.to raise_error
35
+ end
36
+
37
+ it "does not validates source when action is destroy" do
38
+ create_event(source_attributes.merge(:action => "destroy"))
39
+ end
40
+
41
+ it "does not validates source when updating" do
42
+ create_event.update_attributes!(:source_id => 9999)
43
+ end
44
+ end
27
45
  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.4.4
4
+ version: 0.5.0
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: 2013-02-22 00:00:00.000000000 Z
12
+ date: 2013-03-19 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description:
15
15
  email: michael@grosser.it
@@ -53,7 +53,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
53
53
  version: '0'
54
54
  segments:
55
55
  - 0
56
- hash: 4468237118319359723
56
+ hash: 1430160923032758122
57
57
  required_rubygems_version: !ruby/object:Gem::Requirement
58
58
  none: false
59
59
  requirements:
@@ -62,10 +62,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
62
62
  version: '0'
63
63
  segments:
64
64
  - 0
65
- hash: 4468237118319359723
65
+ hash: 1430160923032758122
66
66
  requirements: []
67
67
  rubyforge_project:
68
- rubygems_version: 1.8.24
68
+ rubygems_version: 1.8.25
69
69
  signing_key:
70
70
  specification_version: 3
71
71
  summary: Audit model events like update/create/delete + attribute changes + group