active_metadata 0.7.8 → 0.7.9
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.
|
@@ -34,17 +34,30 @@ module ActiveMetadata::Persistence::Attachment
|
|
|
34
34
|
self.send(:send_notification, a.label, filename, "", :delete_attachment_message, created_by)
|
|
35
35
|
end
|
|
36
36
|
|
|
37
|
-
|
|
37
|
+
# Update an attachment replacing the old file
|
|
38
|
+
# Fires a notification.
|
|
39
|
+
# When is used to star or unstar fires a notification of the correct type
|
|
40
|
+
# The cache is reloaded any time an operation is completed
|
|
41
|
+
def update_attachment(id, newfile, *args)
|
|
42
|
+
options = args.last.is_a?(Hash) ? args.last : {}
|
|
43
|
+
options[:message_type] ||= :update_attachment_message
|
|
44
|
+
|
|
38
45
|
a = ActiveMetadata::Attachment.find(id)
|
|
39
46
|
old_filename = a.attach.original_filename
|
|
40
47
|
a.attach = newfile
|
|
41
48
|
a.updated_by = current_user_id
|
|
42
|
-
|
|
49
|
+
|
|
50
|
+
#mass assign starred inly if provided
|
|
51
|
+
unless options[:starred].nil?
|
|
52
|
+
a[:starred] = options[:starred]
|
|
53
|
+
options[:message_type] = options[:starred] ? :star_attachment_message : :unstar_attachment_message
|
|
54
|
+
end
|
|
55
|
+
|
|
43
56
|
a.save!
|
|
44
57
|
new_filename = a.attach.original_filename
|
|
45
|
-
|
|
46
58
|
reload_attachments_cache_for a.label
|
|
47
|
-
|
|
59
|
+
|
|
60
|
+
self.send(:send_notification, a.label, old_filename, new_filename, options[:message_type], current_user_id)
|
|
48
61
|
end
|
|
49
62
|
|
|
50
63
|
def has_attachments_for field
|
|
@@ -71,12 +84,12 @@ module ActiveMetadata::Persistence::Attachment
|
|
|
71
84
|
|
|
72
85
|
def star_attachment(id)
|
|
73
86
|
n = ActiveMetadata::Attachment.find(id)
|
|
74
|
-
update_attachment id, n.attach, true
|
|
87
|
+
update_attachment id, n.attach, starred: true
|
|
75
88
|
end
|
|
76
89
|
|
|
77
90
|
def unstar_attachment(id)
|
|
78
91
|
n = ActiveMetadata::Attachment.find(id)
|
|
79
|
-
update_attachment id, n.attach, false
|
|
92
|
+
update_attachment id, n.attach, starred: false
|
|
80
93
|
end
|
|
81
94
|
|
|
82
95
|
private
|
|
@@ -20,17 +20,29 @@ module ActiveMetadata::Persistence::Note
|
|
|
20
20
|
self.send(:send_notification, field, "", note, :new_note_message, current_user_id)
|
|
21
21
|
end
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
#
|
|
24
|
+
# Update a note
|
|
25
|
+
# *update the record and recreate the cache
|
|
26
|
+
# *send and update_note_meesage notification
|
|
27
|
+
# *if update is starring or unstarring is sent a message of the correct type
|
|
28
|
+
def update_note(id, note, *args)
|
|
29
|
+
|
|
30
|
+
options = options = args.last.is_a?(Hash) ? args.last : {}
|
|
31
|
+
options[:message_type] ||= :update_note_message
|
|
32
|
+
|
|
24
33
|
n = ActiveMetadata::Note.find(id)
|
|
25
34
|
old_value = n.note
|
|
26
35
|
attributes = {:note => note, :updated_by => current_user_id, :updated_at => Time.now.utc}
|
|
36
|
+
|
|
27
37
|
#mass assign starred inly if provided
|
|
28
|
-
unless starred.nil?
|
|
29
|
-
attributes[:starred] = starred
|
|
38
|
+
unless options[:starred].nil?
|
|
39
|
+
attributes[:starred] = options[:starred]
|
|
40
|
+
options[:message_type] = options[:starred] ? :star_note_message : :unstar_note_message
|
|
30
41
|
end
|
|
42
|
+
|
|
31
43
|
n.update_attributes! attributes
|
|
32
44
|
reload_notes_cache_for n.label
|
|
33
|
-
self.send(:send_notification, n.label, old_value, note, :
|
|
45
|
+
self.send(:send_notification, n.label, old_value, note, options[:message_type], current_user_id)
|
|
34
46
|
end
|
|
35
47
|
|
|
36
48
|
def notes_for(field, order_by="updated_at DESC")
|
|
@@ -79,14 +91,14 @@ module ActiveMetadata::Persistence::Note
|
|
|
79
91
|
# reload the cache calling update
|
|
80
92
|
def star_note(id)
|
|
81
93
|
n = ActiveMetadata::Note.find(id)
|
|
82
|
-
update_note id, n.note, true
|
|
94
|
+
update_note id, n.note, starred: true
|
|
83
95
|
end
|
|
84
96
|
|
|
85
97
|
# unstar a note
|
|
86
98
|
# reload the cache calling update
|
|
87
99
|
def unstar_note(id)
|
|
88
100
|
n = ActiveMetadata::Note.find(id)
|
|
89
|
-
update_note id, n.note, false
|
|
101
|
+
update_note id, n.note, starred: false
|
|
90
102
|
end
|
|
91
103
|
|
|
92
104
|
private
|
|
@@ -142,7 +142,7 @@ describe ActiveMetadata do
|
|
|
142
142
|
it "should update an attachment as starred" do
|
|
143
143
|
@document.save_attachment_for(:name, @attachment)
|
|
144
144
|
attachment = @document.attachments_for(:name).first
|
|
145
|
-
@document.update_attachment(attachment.id, attachment.attach, true)
|
|
145
|
+
@document.update_attachment(attachment.id, attachment.attach, starred: true)
|
|
146
146
|
@document.attachments_for(:name).first.starred?.should be_true
|
|
147
147
|
end
|
|
148
148
|
|
|
@@ -174,6 +174,39 @@ describe ActiveMetadata do
|
|
|
174
174
|
att.starred?.should be_false
|
|
175
175
|
end
|
|
176
176
|
|
|
177
|
+
context "when starring" do
|
|
178
|
+
|
|
179
|
+
it "should send a notification of type star_attachment_message" do
|
|
180
|
+
#watch
|
|
181
|
+
user = User.create!(:email => "email@email.it", :firstname => 'John', :lastname => 'smith' )
|
|
182
|
+
@document.create_watcher_for(:name, user)
|
|
183
|
+
# create note and star it
|
|
184
|
+
@document.save_attachment_for(:name, @attachment, true)
|
|
185
|
+
att = @document.attachments_for(:name).first
|
|
186
|
+
|
|
187
|
+
@document.star_attachment(att.id)
|
|
188
|
+
@document.notifier.type.should eq :star_attachment_message
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
context "when unstarring" do
|
|
194
|
+
|
|
195
|
+
it "should send a notification of type unstar_attachment_message" do
|
|
196
|
+
#watch
|
|
197
|
+
user = User.create!(:email => "email@email.it", :firstname => 'John', :lastname => 'smith' )
|
|
198
|
+
@document.create_watcher_for(:name, user)
|
|
199
|
+
# create note and star it
|
|
200
|
+
@document.save_attachment_for(:name, @attachment, true)
|
|
201
|
+
att = @document.attachments_for(:name).first
|
|
202
|
+
|
|
203
|
+
@document.unstar_attachment(att.id)
|
|
204
|
+
@document.notifier.type.should eq :unstar_attachment_message
|
|
205
|
+
end
|
|
206
|
+
|
|
207
|
+
end
|
|
208
|
+
|
|
209
|
+
|
|
177
210
|
end
|
|
178
211
|
|
|
179
212
|
describe "#starred_attachments" do
|
data/spec/lib/notes_spec.rb
CHANGED
|
@@ -168,7 +168,7 @@ describe ActiveMetadata do
|
|
|
168
168
|
it "should update a note as starred" do
|
|
169
169
|
@document.create_note_for(:name, "nuova nota")
|
|
170
170
|
note = @document.notes_for(:name).first
|
|
171
|
-
@document.update_note(note.id, note.note, true)
|
|
171
|
+
@document.update_note(note.id, note.note, starred: true)
|
|
172
172
|
@document.notes_for(:name).first.starred?.should be_true
|
|
173
173
|
end
|
|
174
174
|
|
|
@@ -201,6 +201,36 @@ describe ActiveMetadata do
|
|
|
201
201
|
nota.starred?.should be_false
|
|
202
202
|
end
|
|
203
203
|
|
|
204
|
+
context "when starring a note" do
|
|
205
|
+
|
|
206
|
+
it "should send a notification of type star_note_message" do
|
|
207
|
+
#watch
|
|
208
|
+
user = User.create!(:email => "email@email.it", :firstname => 'John', :lastname => 'smith' )
|
|
209
|
+
@document.create_watcher_for(:name, user)
|
|
210
|
+
# create note and star it
|
|
211
|
+
@document.create_note_for(:name, "nota 1")
|
|
212
|
+
nota = @document.notes_for(:name).first
|
|
213
|
+
@document.star_note(nota.id)
|
|
214
|
+
@document.notifier.type.should eq :star_note_message
|
|
215
|
+
end
|
|
216
|
+
|
|
217
|
+
end
|
|
218
|
+
|
|
219
|
+
context "when unstarring a note" do
|
|
220
|
+
|
|
221
|
+
it "should send a notification of type unstar_note_message" do
|
|
222
|
+
#watch
|
|
223
|
+
user = User.create!(:email => "email@email.it", :firstname => 'John', :lastname => 'smith' )
|
|
224
|
+
@document.create_watcher_for(:name, user)
|
|
225
|
+
# create note and unstar it
|
|
226
|
+
@document.create_note_for(:name, "nota 1")
|
|
227
|
+
nota = @document.notes_for(:name).first
|
|
228
|
+
@document.unstar_note(nota.id)
|
|
229
|
+
@document.notifier.type.should eq :unstar_note_message
|
|
230
|
+
end
|
|
231
|
+
|
|
232
|
+
end
|
|
233
|
+
|
|
204
234
|
end
|
|
205
235
|
|
|
206
236
|
describe "#starred_notes" do
|
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.9
|
|
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-05 00:00:00.000000000 Z
|
|
14
14
|
dependencies:
|
|
15
15
|
- !ruby/object:Gem::Dependency
|
|
16
16
|
name: rails
|
|
@@ -261,7 +261,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
261
261
|
version: '0'
|
|
262
262
|
segments:
|
|
263
263
|
- 0
|
|
264
|
-
hash:
|
|
264
|
+
hash: 3903981385835603000
|
|
265
265
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
266
266
|
none: false
|
|
267
267
|
requirements:
|
|
@@ -270,7 +270,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
270
270
|
version: '0'
|
|
271
271
|
segments:
|
|
272
272
|
- 0
|
|
273
|
-
hash:
|
|
273
|
+
hash: 3903981385835603000
|
|
274
274
|
requirements: []
|
|
275
275
|
rubyforge_project: active_metadata
|
|
276
276
|
rubygems_version: 1.8.19
|