cia 0.4.4 → 0.5.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/Gemfile +1 -1
- data/Gemfile.lock +2 -2
- data/gemfiles/rails2.gemfile +1 -1
- data/gemfiles/rails2.gemfile.lock +2 -2
- data/gemfiles/rails3.gemfile +1 -1
- data/gemfiles/rails3.gemfile.lock +2 -2
- data/lib/cia/event.rb +9 -1
- data/lib/cia/version.rb +1 -1
- data/spec/cia/event_spec.rb +18 -0
- metadata +5 -5
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
data/gemfiles/rails2.gemfile
CHANGED
data/gemfiles/rails3.gemfile
CHANGED
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 :
|
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
data/spec/cia/event_spec.rb
CHANGED
@@ -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
|
+
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-
|
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:
|
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:
|
65
|
+
hash: 1430160923032758122
|
66
66
|
requirements: []
|
67
67
|
rubyforge_project:
|
68
|
-
rubygems_version: 1.8.
|
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
|