active_metadata 0.8.1 → 0.8.2
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/lib/active_metadata/base.rb +3 -2
- data/lib/active_metadata/persistence/history.rb +1 -1
- data/lib/active_metadata/persistence/watcher.rb +1 -1
- data/lib/active_metadata/version.rb +1 -1
- data/spec/lib/history_spec.rb +54 -4
- data/spec/lib/watchers_spec.rb +5 -25
- data/spec/support/migrations.rb +6 -0
- data/spec/support/models.rb +34 -0
- data/spec/support/watcher_notifier.rb +1 -1
- metadata +6 -12
- data/spec/support/chapter.rb +0 -5
- data/spec/support/document.rb +0 -6
- data/spec/support/section.rb +0 -5
- data/spec/support/user.rb +0 -11
data/lib/active_metadata/base.rb
CHANGED
@@ -32,8 +32,9 @@ module ActiveMetadata
|
|
32
32
|
|
33
33
|
before_update :manage_concurrency
|
34
34
|
after_save :save_history
|
35
|
-
attr_accessor :conflicts
|
36
|
-
|
35
|
+
attr_accessor :conflicts, :active_metadata_timestamp, :skip_history_notification
|
36
|
+
|
37
|
+
alias_method :skip_history_notification?, :skip_history_notification
|
37
38
|
|
38
39
|
instance_variable_set("@active_metadata_options", options)
|
39
40
|
|
@@ -12,7 +12,7 @@ module ActiveMetadata::Persistence::History
|
|
12
12
|
next if ActiveMetadata::CONFIG['history_skip_fields'].include?(key)
|
13
13
|
ActiveMetadata::History.create! :value => value[1],:model_class => metadata_class, :model_id => metadata_id,:label => key.to_s, :created_by => current_user_id
|
14
14
|
invalidate_history_cache_for key.to_s
|
15
|
-
self.send(:send_notification, key, value[0], value[1], :history_message, current_user_id)
|
15
|
+
self.send(:send_notification, key, value[0], value[1], :history_message, current_user_id) unless skip_history_notification?
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
@@ -30,7 +30,7 @@ module ActiveMetadata::Persistence::Watcher
|
|
30
30
|
ActiveMetadata::Watcher.where(:model_class => metadata_class, :model_id => metadata_id, :label => field, :owner_id => owner.id).empty? ? false : true
|
31
31
|
end
|
32
32
|
|
33
|
-
def send_notification(field, old_value, new_value, type=:default_message, created_by=nil)
|
33
|
+
def send_notification(field, old_value, new_value, type=:default_message, created_by=nil)
|
34
34
|
watchers_for(field).each { |watch| notify_changes(field, old_value, new_value, self.class.to_s, self.id, watch.owner_id, type, created_by) }
|
35
35
|
end
|
36
36
|
|
data/spec/lib/history_spec.rb
CHANGED
@@ -3,13 +3,14 @@ require "time"
|
|
3
3
|
|
4
4
|
describe ActiveMetadata do
|
5
5
|
|
6
|
-
before(:each) do
|
7
|
-
@document = Document.create! { |d| d.name = "John" }
|
8
|
-
@document.reload
|
9
|
-
end
|
10
6
|
|
11
7
|
describe "history" do
|
12
8
|
|
9
|
+
before(:each) do
|
10
|
+
@document = Document.create! { |d| d.name = "John" }
|
11
|
+
@document.reload
|
12
|
+
end
|
13
|
+
|
13
14
|
it "should create history when a document is created" do
|
14
15
|
@document.history_for(:name).should have(1).record
|
15
16
|
end
|
@@ -78,4 +79,53 @@ describe ActiveMetadata do
|
|
78
79
|
|
79
80
|
end
|
80
81
|
|
82
|
+
describe "skip_history_notification" do
|
83
|
+
|
84
|
+
context "given an user that watch Document#name" do
|
85
|
+
|
86
|
+
before do
|
87
|
+
@user = User.create!(:email => "email@email.it", :firstname => 'John', :lastname => 'smith')
|
88
|
+
ActiveMetadata::Watcher.create! :model_class => "Document", :label => :name, :owner_id => @user.id
|
89
|
+
end
|
90
|
+
|
91
|
+
it "and skip_history_notification false creating a Document with name not null should save the history and generate a notification" do
|
92
|
+
@document = Document.create! name: "John"
|
93
|
+
@document.history_for(:name)[0].value.should eq(@document.name)
|
94
|
+
@document.notifier.should_not be_nil
|
95
|
+
end
|
96
|
+
|
97
|
+
it "when true creating a Document with name not null should save the history but do not generate any notification" do
|
98
|
+
@document = Document.create! name: "John", skip_history_notification: true
|
99
|
+
@document.history_for(:name)[0].value.should eq(@document.name)
|
100
|
+
@document.notifier.should be_nil
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
104
|
+
|
105
|
+
context "given an user that watch Author#name (does not persist ancestor)" do
|
106
|
+
|
107
|
+
before do
|
108
|
+
@user = User.create!(:email => "email@email.it", :firstname => 'John', :lastname => 'smith')
|
109
|
+
ActiveMetadata::Watcher.create! :model_class => "Author", :label => :name, :owner_id => @user.id
|
110
|
+
end
|
111
|
+
|
112
|
+
it "when a new record is craeted by the parent document instance should save history and generate a notification" do
|
113
|
+
@document = Document.create! name: "John"
|
114
|
+
@author = @document.create_author name: "my title"
|
115
|
+
@author.history_for(:name)[0].value.should eq(@author.name)
|
116
|
+
@author.notifier.should_not be_nil
|
117
|
+
end
|
118
|
+
|
119
|
+
it "when a new record is craeted by the parent document skipping notifications should save history and not generate any notification" do
|
120
|
+
@document = Document.create! name: "John"
|
121
|
+
@author = @document.create_author name: "my title", skip_history_notification: true
|
122
|
+
@author.history_for(:name)[0].value.should eq(@author.name)
|
123
|
+
@author.notifier.should be_nil
|
124
|
+
end
|
125
|
+
|
126
|
+
end
|
127
|
+
|
128
|
+
end
|
129
|
+
|
130
|
+
|
81
131
|
end
|
data/spec/lib/watchers_spec.rb
CHANGED
@@ -3,12 +3,13 @@ require "time"
|
|
3
3
|
|
4
4
|
describe ActiveMetadata do
|
5
5
|
|
6
|
-
before(:each) do
|
7
|
-
@document = Document.create! { |d| d.name = "John" }
|
8
|
-
end
|
9
6
|
|
10
7
|
describe "watchers" do
|
11
8
|
|
9
|
+
before(:each) do
|
10
|
+
@document = Document.create! { |d| d.name = "John" }
|
11
|
+
end
|
12
|
+
|
12
13
|
it "should create a watcher for a given field" do
|
13
14
|
user = User.create!(:email => "email@email.it", :firstname => 'John', :lastname => 'smith' )
|
14
15
|
@document.create_watcher_for(:name, user)
|
@@ -33,28 +34,6 @@ describe ActiveMetadata do
|
|
33
34
|
@document.is_watched_by(:name,another_user).should be_false
|
34
35
|
end
|
35
36
|
|
36
|
-
|
37
|
-
it "should create an unread message by default" do
|
38
|
-
pending "to be moved in virgilio project"
|
39
|
-
user = User.create!(:email => "email@email.it", :firstname => 'John', :lastname => 'smith' )
|
40
|
-
@document.create_watcher_for(:name, user)
|
41
|
-
@document.update_attribute(:name, 'new_value')
|
42
|
-
|
43
|
-
|
44
|
-
user.inbox.messages.should have(1).record
|
45
|
-
user.inbox.messages.first.read.should be_false
|
46
|
-
end
|
47
|
-
|
48
|
-
it "should read an unread message" do
|
49
|
-
pending "to be moved in virgilio project"
|
50
|
-
user = User.create!(:email => "email@email.it", :firstname => 'John', :lastname => 'smith' )
|
51
|
-
@document.create_watcher_for(:name, user)
|
52
|
-
@document.update_attribute(:name, 'new_value')
|
53
|
-
alert_message = user.inbox.messages.first
|
54
|
-
alert_message.mark_as_read
|
55
|
-
user.inbox.messages.first.read.should be_true
|
56
|
-
end
|
57
|
-
|
58
37
|
end
|
59
38
|
|
60
39
|
describe "#watchers_for" do
|
@@ -64,6 +43,7 @@ describe ActiveMetadata do
|
|
64
43
|
before do
|
65
44
|
@user = User.create!(:email => "email@email.it", :firstname => 'John', :lastname => 'smith' )
|
66
45
|
@another_user = User.create!(:email => "email2@email.it", :firstname => 'George', :lastname => 'Washington' )
|
46
|
+
@document = Document.create! { |d| d.name = "John" }
|
67
47
|
@document.create_watcher_for(:name, @user)
|
68
48
|
ActiveMetadata::Watcher.create! :model_class => "Document", :label => :name, :owner_id => @another_user.id
|
69
49
|
end
|
data/spec/support/migrations.rb
CHANGED
@@ -18,6 +18,12 @@ module TestDb
|
|
18
18
|
t.timestamps
|
19
19
|
end
|
20
20
|
|
21
|
+
ActiveRecord::Base.connection.create_table :authors, force: true do |t|
|
22
|
+
t.string :name
|
23
|
+
t.integer :document_id
|
24
|
+
t.timestamps
|
25
|
+
end
|
26
|
+
|
21
27
|
ActiveRecord::Base.connection.create_table :chapters, force: true do |t|
|
22
28
|
t.string :title
|
23
29
|
t.timestamps
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
class Document < ActiveRecord::Base
|
3
|
+
has_one :section
|
4
|
+
has_one :author
|
5
|
+
acts_as_metadata
|
6
|
+
end
|
7
|
+
|
8
|
+
# Persist ancestor
|
9
|
+
class Section < ActiveRecord::Base
|
10
|
+
belongs_to :document
|
11
|
+
acts_as_metadata :ancestors => [:document], :persists_ancestor => true
|
12
|
+
end
|
13
|
+
|
14
|
+
# Does not persist ancestor
|
15
|
+
class Author < ActiveRecord::Base
|
16
|
+
belongs_to :document
|
17
|
+
acts_as_metadata :ancestors => [:document]
|
18
|
+
end
|
19
|
+
|
20
|
+
class Chapter < ActiveRecord::Base
|
21
|
+
acts_as_metadata ancestors: [:sections, :document]
|
22
|
+
has_many :sections
|
23
|
+
end
|
24
|
+
|
25
|
+
class User < ActiveRecord::Base
|
26
|
+
has_one :inbox
|
27
|
+
|
28
|
+
@@current_user = User.create!
|
29
|
+
|
30
|
+
def self.current
|
31
|
+
@@current_user
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
@@ -5,7 +5,7 @@ class WatcherNotifier
|
|
5
5
|
puts "---------------------------------------->"
|
6
6
|
end
|
7
7
|
|
8
|
-
def notify(matched_label, old_value, new_value, model_class, model_id,owner_id,type, created_by)
|
8
|
+
def notify(matched_label, old_value, new_value, model_class, model_id,owner_id,type, created_by)
|
9
9
|
@matched_label= matched_label
|
10
10
|
@old_value = old_value
|
11
11
|
@new_value = new_value
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_metadata
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-09-
|
13
|
+
date: 2012-09-21 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rails
|
@@ -240,14 +240,11 @@ files:
|
|
240
240
|
- spec/models/history_spec.rb
|
241
241
|
- spec/routing/active_metadata/stream_controller_routing_spec.rb
|
242
242
|
- spec/spec_helper.rb
|
243
|
-
- spec/support/chapter.rb
|
244
|
-
- spec/support/document.rb
|
245
243
|
- spec/support/migrations.rb
|
244
|
+
- spec/support/models.rb
|
246
245
|
- spec/support/pdf_test.pdf
|
247
246
|
- spec/support/pdf_test_1.pdf
|
248
247
|
- spec/support/pdf_test_2.pdf
|
249
|
-
- spec/support/section.rb
|
250
|
-
- spec/support/user.rb
|
251
248
|
- spec/support/watcher_notifier.rb
|
252
249
|
- spec/views/active_metadata/stream/index.html.erb_spec.rb
|
253
250
|
homepage: ''
|
@@ -264,7 +261,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
264
261
|
version: '0'
|
265
262
|
segments:
|
266
263
|
- 0
|
267
|
-
hash:
|
264
|
+
hash: 2514822335632258370
|
268
265
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
269
266
|
none: false
|
270
267
|
requirements:
|
@@ -273,7 +270,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
273
270
|
version: '0'
|
274
271
|
segments:
|
275
272
|
- 0
|
276
|
-
hash:
|
273
|
+
hash: 2514822335632258370
|
277
274
|
requirements: []
|
278
275
|
rubyforge_project: active_metadata
|
279
276
|
rubygems_version: 1.8.19
|
@@ -337,13 +334,10 @@ test_files:
|
|
337
334
|
- spec/models/history_spec.rb
|
338
335
|
- spec/routing/active_metadata/stream_controller_routing_spec.rb
|
339
336
|
- spec/spec_helper.rb
|
340
|
-
- spec/support/chapter.rb
|
341
|
-
- spec/support/document.rb
|
342
337
|
- spec/support/migrations.rb
|
338
|
+
- spec/support/models.rb
|
343
339
|
- spec/support/pdf_test.pdf
|
344
340
|
- spec/support/pdf_test_1.pdf
|
345
341
|
- spec/support/pdf_test_2.pdf
|
346
|
-
- spec/support/section.rb
|
347
|
-
- spec/support/user.rb
|
348
342
|
- spec/support/watcher_notifier.rb
|
349
343
|
- spec/views/active_metadata/stream/index.html.erb_spec.rb
|
data/spec/support/chapter.rb
DELETED
data/spec/support/document.rb
DELETED
data/spec/support/section.rb
DELETED