cia 0.5.2 → 0.5.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.
- data/Gemfile.lock +1 -1
- data/gemfiles/rails2.gemfile.lock +1 -1
- data/gemfiles/rails3.gemfile.lock +1 -1
- data/lib/cia.rb +1 -0
- data/lib/cia/attribute_change.rb +8 -1
- data/lib/cia/event.rb +2 -5
- data/lib/cia/source_validation.rb +8 -0
- data/lib/cia/version.rb +1 -1
- data/spec/cia/attribute_change_spec.rb +20 -0
- data/spec/cia_spec.rb +1 -1
- data/spec/spec_helper.rb +0 -1
- metadata +5 -4
data/Gemfile.lock
CHANGED
data/lib/cia.rb
CHANGED
data/lib/cia/attribute_change.rb
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
module CIA
|
2
2
|
class AttributeChange < ActiveRecord::Base
|
3
|
+
include SourceValidation
|
3
4
|
self.table_name = "cia_attribute_changes"
|
4
5
|
|
5
6
|
belongs_to :event, :foreign_key => "cia_event_id"
|
6
7
|
belongs_to :source, :polymorphic => true
|
7
8
|
|
8
|
-
validates_presence_of :event, :attribute_name
|
9
|
+
validates_presence_of :event, :attribute_name
|
9
10
|
|
10
11
|
if ActiveRecord::VERSION::MAJOR > 2
|
11
12
|
scope :previous, :order => "id desc"
|
@@ -18,5 +19,11 @@ module CIA
|
|
18
19
|
def self.on_attribute(attribute)
|
19
20
|
scoped(:conditions => {:attribute_name => attribute})
|
20
21
|
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def source_must_be_present?
|
26
|
+
event.present? && event.source_must_be_present?
|
27
|
+
end
|
21
28
|
end
|
22
29
|
end
|
data/lib/cia/event.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
module CIA
|
2
2
|
class Event < ActiveRecord::Base
|
3
|
+
include SourceValidation
|
3
4
|
self.table_name = "cia_events"
|
4
5
|
|
5
6
|
belongs_to :actor, :polymorphic => true
|
@@ -7,8 +8,6 @@ module CIA
|
|
7
8
|
has_many :attribute_changes, :foreign_key => :cia_event_id
|
8
9
|
|
9
10
|
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?
|
12
11
|
|
13
12
|
def self.previous
|
14
13
|
scoped(:order => "created_at desc")
|
@@ -33,9 +32,7 @@ module CIA
|
|
33
32
|
end
|
34
33
|
end
|
35
34
|
|
36
|
-
|
37
|
-
|
38
|
-
def source_must_be_exist?
|
35
|
+
def source_must_be_present?
|
39
36
|
new_record? and action != "destroy" and (!attributes.key?("source_display_name") or source_display_name.blank?)
|
40
37
|
end
|
41
38
|
end
|
data/lib/cia/version.rb
CHANGED
@@ -42,4 +42,24 @@ describe CIA::AttributeChange do
|
|
42
42
|
CIA::AttributeChange.on_attribute(:xxx).all.should == [a]
|
43
43
|
end
|
44
44
|
end
|
45
|
+
|
46
|
+
describe "enforcing presence of source" do
|
47
|
+
it "requires a source when associated event requires a source" do
|
48
|
+
event = CIA::Event.new { |event| event.id = 1 }
|
49
|
+
event.stub(:source_must_be_present? => true)
|
50
|
+
change = CIA::AttributeChange.new(:event => event, :attribute_name => 'awesomeness')
|
51
|
+
|
52
|
+
change.valid?.should be_false
|
53
|
+
change.errors.full_messages.should =~ ["Source can't be blank"]
|
54
|
+
end
|
55
|
+
|
56
|
+
it "does not require a source when associated event does not" do
|
57
|
+
event = CIA::Event.new { |event| event.id = 1 }
|
58
|
+
event.stub(:source_must_be_present? => false)
|
59
|
+
change = CIA::AttributeChange.new(:event => event, :attribute_name => 'awesomeness',
|
60
|
+
:source_type => 'ObscureType', :source_id => 101)
|
61
|
+
|
62
|
+
change.valid?.should be_true
|
63
|
+
end
|
64
|
+
end
|
45
65
|
end
|
data/spec/cia_spec.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
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.5.
|
4
|
+
version: 0.5.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: 2013-
|
12
|
+
date: 2013-05-23 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description:
|
15
15
|
email: michael@grosser.it
|
@@ -33,6 +33,7 @@ files:
|
|
33
33
|
- lib/cia/attribute_change.rb
|
34
34
|
- lib/cia/auditable.rb
|
35
35
|
- lib/cia/event.rb
|
36
|
+
- lib/cia/source_validation.rb
|
36
37
|
- lib/cia/version.rb
|
37
38
|
- spec/cia/attribute_change_spec.rb
|
38
39
|
- spec/cia/event_spec.rb
|
@@ -53,7 +54,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
53
54
|
version: '0'
|
54
55
|
segments:
|
55
56
|
- 0
|
56
|
-
hash:
|
57
|
+
hash: 2131541393242182873
|
57
58
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
59
|
none: false
|
59
60
|
requirements:
|
@@ -62,7 +63,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
62
63
|
version: '0'
|
63
64
|
segments:
|
64
65
|
- 0
|
65
|
-
hash:
|
66
|
+
hash: 2131541393242182873
|
66
67
|
requirements: []
|
67
68
|
rubyforge_project:
|
68
69
|
rubygems_version: 1.8.25
|