active_metadata 0.7.2 → 0.7.3
Sign up to get free protection for your applications and to get access to all the features.
@@ -10,8 +10,14 @@ module ActiveMetadata::Persistence::Watcher
|
|
10
10
|
ActiveMetadata::Watcher.create! :document_class => metadata_class, :document_id => metadata_id, :label => field, :owner_id => owner.id
|
11
11
|
end
|
12
12
|
|
13
|
+
# return all the watches related to a passed field.
|
14
|
+
# query always match for the current model
|
15
|
+
# matches are returned grouped by owner and contains records that define or not a particular model instance watching
|
13
16
|
def watchers_for(field)
|
14
|
-
ActiveMetadata::Watcher.
|
17
|
+
ActiveMetadata::Watcher.where(
|
18
|
+
"document_class = :document_class AND label = :label AND (document_id = :document_id OR document_id IS NULL)",
|
19
|
+
{ :document_class => metadata_class, :label => field, :document_id => metadata_id }
|
20
|
+
).group("owner_id").all
|
15
21
|
end
|
16
22
|
|
17
23
|
def delete_watcher_for(field, owner)
|
data/spec/dummy/db/test.sqlite3
CHANGED
Binary file
|
data/spec/lib/watchers_spec.rb
CHANGED
@@ -57,4 +57,32 @@ describe ActiveMetadata do
|
|
57
57
|
|
58
58
|
end
|
59
59
|
|
60
|
+
describe "#watchers_for" do
|
61
|
+
|
62
|
+
context "when some record does not relate to a specific model instance" do
|
63
|
+
|
64
|
+
before do
|
65
|
+
@user = User.create!(:email => "email@email.it", :firstname => 'John', :lastname => 'smith' )
|
66
|
+
@another_user = User.create!(:email => "email2@email.it", :firstname => 'George', :lastname => 'Washington' )
|
67
|
+
@document.create_watcher_for(:name, @user)
|
68
|
+
ActiveMetadata::Watcher.create! :document_class => "Document", :label => :name, :owner_id => @another_user.id
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should return all the records that match model/field" do
|
72
|
+
docs = @document.watchers_for(:name)
|
73
|
+
docs.count.should eq 2
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should group result by owner" do
|
77
|
+
@document.create_watcher_for(:name, @another_user)
|
78
|
+
ActiveMetadata::Watcher.create! :document_class => "Document", :label => :name, :owner_id => @user.id
|
79
|
+
docs = @document.watchers_for(:name)
|
80
|
+
docs.count.should eq 2
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
|
86
|
+
end
|
87
|
+
|
60
88
|
end
|
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.7.
|
4
|
+
version: 0.7.3
|
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-05-
|
13
|
+
date: 2012-05-14 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rails
|
@@ -165,7 +165,6 @@ files:
|
|
165
165
|
- config/cucumber.yml
|
166
166
|
- config/database.yml
|
167
167
|
- config/routes.rb
|
168
|
-
- db/development.sqlite3
|
169
168
|
- db/migrate/01_create_test_resources.rb
|
170
169
|
- db/migrate/02_active_metadata_migrations.rb
|
171
170
|
- lib/active_metadata/base.rb
|
@@ -263,7 +262,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
263
262
|
version: '0'
|
264
263
|
segments:
|
265
264
|
- 0
|
266
|
-
hash:
|
265
|
+
hash: -4307170871527026867
|
267
266
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
268
267
|
none: false
|
269
268
|
requirements:
|
@@ -272,10 +271,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
272
271
|
version: '0'
|
273
272
|
segments:
|
274
273
|
- 0
|
275
|
-
hash:
|
274
|
+
hash: -4307170871527026867
|
276
275
|
requirements: []
|
277
276
|
rubyforge_project: active_metadata
|
278
|
-
rubygems_version: 1.8.
|
277
|
+
rubygems_version: 1.8.19
|
279
278
|
signing_key:
|
280
279
|
specification_version: 3
|
281
280
|
summary: Add metadata to fields in an active record model
|
data/db/development.sqlite3
DELETED
Binary file
|