active_metadata 0.3.2 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -14,6 +14,7 @@ class ActiveMetadataMigrations < ActiveRecord::Migration
14
14
  add_index :notes, :document_id
15
15
  add_index :notes, :label
16
16
  add_index :notes, :updated_at
17
+ add_index :notes, :document_class
17
18
 
18
19
  create_table :histories do |t|
19
20
  t.text :value
@@ -27,6 +28,7 @@ class ActiveMetadataMigrations < ActiveRecord::Migration
27
28
  add_index :histories, :document_id
28
29
  add_index :histories, :label
29
30
  add_index :histories, :created_at
31
+ add_index :histories, :document_class
30
32
 
31
33
  create_table :attachments do |t|
32
34
  t.string :label
@@ -45,6 +47,7 @@ class ActiveMetadataMigrations < ActiveRecord::Migration
45
47
  add_index :attachments, :document_id
46
48
  add_index :attachments, :label
47
49
  add_index :attachments, :attach_updated_at
50
+ add_index :attachments, :document_class
48
51
 
49
52
  create_table :watchers do |t|
50
53
  t.integer :owner_id
data/db/test.sqlite3 CHANGED
Binary file
@@ -24,7 +24,7 @@ module ActiveMetadata
24
24
  attr_accessor :conflicts
25
25
  attr_accessor :active_metadata_timestamp
26
26
 
27
- class_variable_set("@@metadata_id_from", args.empty? ? nil : args[0][:metadata_id_from])
27
+ class_variable_set("@@active_metadata_ancestors", args.empty? ? nil : args[0][:active_metadata_ancestors])
28
28
 
29
29
  include ActiveMetadata::Base::InstanceMethods
30
30
  include ActiveMetadata::Persistence
@@ -58,6 +58,10 @@ module ActiveMetadata
58
58
  metadata_root.id
59
59
  end
60
60
 
61
+ def metadata_class
62
+ metadata_root.class.to_s
63
+ end
64
+
61
65
  # Normalize the active_metadata_timestamp into a float to be comparable with the history
62
66
  def am_timestamp
63
67
  ts = metadata_root.active_metadata_timestamp
@@ -74,10 +78,10 @@ module ActiveMetadata
74
78
  end
75
79
 
76
80
  def metadata_root
77
- metadata_id_from = self.class.class_variable_get("@@metadata_id_from")
78
- return self if metadata_id_from.nil?
81
+ active_metadata_ancestors = self.class.class_variable_get("@@active_metadata_ancestors")
82
+ return self if active_metadata_ancestors.nil?
79
83
  receiver = self
80
- metadata_id_from.each do |item|
84
+ active_metadata_ancestors.each do |item|
81
85
  receiver = receiver.send item
82
86
  end
83
87
  receiver
@@ -7,7 +7,7 @@ module ActiveMetadata::Persistence::ActiveRecord::Attachment
7
7
  module InstanceMethods
8
8
 
9
9
  def save_attachment_for(field, file)
10
- attachment = Attachment.create! :document_id => metadata_id, :label => field, :attach => file, :created_by => current_user_id
10
+ attachment = Attachment.create! :document_class => metadata_class, :document_id => metadata_id, :label => field, :attach => file, :created_by => current_user_id
11
11
  reload_attachments_cache_for field
12
12
  self.send(:send_notification, field, "", attachment.attach.original_filename, :attachment_message, current_user_id)
13
13
  end
@@ -49,7 +49,7 @@ module ActiveMetadata::Persistence::ActiveRecord::Attachment
49
49
  end
50
50
 
51
51
  def fetch_attachments_for field
52
- Attachment.all(:conditions => {:document_id => metadata_id,:label => field}, :order => "attach_updated_at DESC")
52
+ Attachment.all(:conditions => {:document_class => metadata_class, :document_id => metadata_id,:label => field}, :order => "attach_updated_at DESC")
53
53
  end
54
54
 
55
55
 
@@ -9,7 +9,7 @@ module ActiveMetadata::Persistence::ActiveRecord::History
9
9
  def save_history
10
10
  self.changes.each do |key, value|
11
11
  next if ActiveMetadata::CONFIG['history_skip_fields'].include?(key)
12
- History.create! :value => value[1],:document_id => metadata_id,:label => key.to_s, :created_by => current_user_id
12
+ History.create! :value => value[1],:document_class => metadata_class, :document_id => metadata_id,:label => key.to_s, :created_by => current_user_id
13
13
  invalidate_history_cache_for key.to_s
14
14
  self.send(:send_notification, key, value[0], value[1], :history_message,current_user_id)
15
15
  end
@@ -28,7 +28,7 @@ module ActiveMetadata::Persistence::ActiveRecord::History
28
28
  end
29
29
 
30
30
  def fetch_histories_for field, order
31
- History.all(:conditions => {:document_id => metadata_id,:label => field}, :order => order)
31
+ History.all(:conditions => {:document_class => metadata_class, :document_id => metadata_id,:label => field}, :order => order)
32
32
  end
33
33
 
34
34
 
@@ -7,7 +7,7 @@ module ActiveMetadata::Persistence::ActiveRecord::Note
7
7
  module InstanceMethods
8
8
 
9
9
  def create_note_for(field, note)
10
- Note.create! :document_id => metadata_id,:label => field.to_s,:note => note, :created_by => current_user_id
10
+ Note.create! :document_id => metadata_id, :document_class => metadata_class, :label => field.to_s,:note => note, :created_by => current_user_id
11
11
  reload_notes_cache_for field
12
12
  self.send(:send_notification, field, "", note, :note_message, current_user_id)
13
13
  end
@@ -53,7 +53,7 @@ module ActiveMetadata::Persistence::ActiveRecord::Note
53
53
  end
54
54
 
55
55
  def fetch_notes_for field
56
- Note.all(:conditions => {:label => field, :document_id => metadata_id}, :order => "updated_at DESC" )
56
+ Note.all(:conditions => {:label => field, :document_class => metadata_class, :document_id => metadata_id}, :order => "updated_at DESC" )
57
57
  end
58
58
 
59
59
  end
@@ -7,11 +7,11 @@ module ActiveMetadata::Persistence::ActiveRecord::Watcher
7
7
  module InstanceMethods
8
8
  def create_watcher_for(field, owner)
9
9
  raise RuntimeError, "The object id MUST be valued" unless self.id
10
- Watcher.create! :document_id => metadata_id, :label => field, :owner_id => owner.id
10
+ Watcher.create! :document_class => metadata_class, :document_id => metadata_id, :label => field, :owner_id => owner.id
11
11
  end
12
12
 
13
13
  def watchers_for(field)
14
- Watcher.all(:conditions => {:label => field, :document_id => metadata_id})
14
+ Watcher.all(:conditions => {:document_class => metadata_class, :label => field, :document_id => metadata_id})
15
15
  end
16
16
 
17
17
  def delete_watcher_for(field, owner)
@@ -21,7 +21,7 @@ module ActiveMetadata::Persistence::ActiveRecord::Watcher
21
21
  end
22
22
 
23
23
  def is_watched_by(field,owner)
24
- Watcher.where(:document_id => metadata_id, :label => field, :owner_id => owner.id).empty? ? false : true
24
+ Watcher.where(:document_class => metadata_class, :document_id => metadata_id, :label => field, :owner_id => owner.id).empty? ? false : true
25
25
  end
26
26
 
27
27
  def send_notification(field, old_value, new_value, type=:default_message, created_by=nil)
@@ -1,3 +1,3 @@
1
1
  module ActiveMetadata
2
- VERSION = "0.3.2"
2
+ VERSION = "0.4.1"
3
3
  end
@@ -8,7 +8,7 @@ namespace :active_metadata do
8
8
 
9
9
  puts "Copying migrations"
10
10
  ts = Time.now.utc.strftime('%Y%m%d%H%M%S')
11
- FileUtils.cp File.expand_path('../../templates/active_metadata_migrations',__FILE__), File.expand_path("db/migrate/#{ts}_active_metadata_migrations.rb")
11
+ FileUtils.cp File.expand_path('../../../db/migrate/02_active_metadata_migrations.rb',__FILE__), File.expand_path("db/migrate/#{ts}_active_metadata_migrations.rb")
12
12
  puts "run rake db:migrate to complete the gem installation"
13
13
 
14
14
  end
@@ -4,6 +4,7 @@ class ActiveMetadataMigrations < ActiveRecord::Migration
4
4
  create_table :notes do |t|
5
5
  t.text :note
6
6
  t.string :label
7
+ t.string :document_class
7
8
  t.integer :document_id
8
9
  t.integer :created_by
9
10
  t.integer :updated_by
@@ -17,6 +18,7 @@ class ActiveMetadataMigrations < ActiveRecord::Migration
17
18
  create_table :histories do |t|
18
19
  t.text :value
19
20
  t.string :label
21
+ t.string :document_class
20
22
  t.integer :document_id
21
23
  t.integer :created_by
22
24
  t.timestamps
@@ -29,6 +31,7 @@ class ActiveMetadataMigrations < ActiveRecord::Migration
29
31
  create_table :attachments do |t|
30
32
  t.string :label
31
33
  t.integer :document_id
34
+ t.string :document_class
32
35
  t.integer :created_by
33
36
  t.integer :updated_by
34
37
  t.integer :counter
@@ -46,6 +49,7 @@ class ActiveMetadataMigrations < ActiveRecord::Migration
46
49
  create_table :watchers do |t|
47
50
  t.integer :owner_id
48
51
  t.string :label
52
+ t.string :document_class
49
53
  t.integer :document_id
50
54
  t.timestamps
51
55
  end
@@ -10,18 +10,20 @@ describe ActiveMetadata do
10
10
  Document.respond_to?(:acts_as_metadata).should be_true
11
11
  end
12
12
 
13
- it "should find the metadata id if no metadata_id_from params has been provided" do
13
+ it "should find the active_metadata_ancestors if no active_metadata_ancestors params has been provided" do
14
14
  @document = Document.create! { |d| d.name = "John" }
15
15
  @document.reload
16
16
  @document.metadata_id.should eq @document.id
17
+ @document.metadata_class.should eq @document.class.to_s
17
18
  end
18
19
 
19
- it "should find the metadata id if a metadata_id_from params has been specified" do
20
+ it "should find the metadata_root.id if an active_metadata_ancestors params has been specified" do
20
21
  @document = Document.create! { |d| d.name = "John" }
21
22
  @document.reload
22
23
  @section = @document.create_section :title => "new section"
23
24
  @section.reload
24
25
  @section.metadata_id.should eq @document.id
26
+ @section.metadata_class.should eq @document.class.to_s
25
27
  end
26
28
 
27
29
  end
@@ -38,11 +40,17 @@ describe ActiveMetadata do
38
40
  @document.notes_for(:name).should have(1).record
39
41
  end
40
42
 
43
+
41
44
  it "should verify the content of a note created" do
42
45
  @document.create_note_for(:name, "Very important note!")
43
46
  @document.notes_for(:name).last.note.should eq "Very important note!"
44
47
  end
45
48
 
49
+ it "should verify that notes are created for the correct model" do
50
+ @document.create_note_for(:name, "Very important note!")
51
+ @document.notes_for(:name).last.document_class.should eq(@document.class.to_s)
52
+ end
53
+
46
54
  it "should verify the created_by of a note created" do
47
55
  @document.create_note_for(:name, "Very important note!")
48
56
  @document.notes_for(:name).last.created_by.should eq User.current.id
@@ -189,6 +197,10 @@ describe ActiveMetadata do
189
197
  @document.history_for(:name)[0].value.should eq(@document.name)
190
198
  end
191
199
 
200
+ it "should verify that histories are created for the correct model" do
201
+ @document.history_for(:name)[0].document_class.should eq(@document.class.to_s)
202
+ end
203
+
192
204
  it "should save the craeted_at datetime anytime an history entry is created" do
193
205
  @document.history_for(:name)[0].created_at.should be_a_kind_of Time
194
206
  end
@@ -3,6 +3,6 @@ class Section < ActiveRecord::Base
3
3
  set_table_name :sections
4
4
  belongs_to :document
5
5
 
6
- acts_as_metadata :metadata_id_from => [:document]
6
+ acts_as_metadata :active_metadata_ancestors => [:document]
7
7
 
8
8
  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.3.2
4
+ version: 0.4.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2011-10-21 00:00:00.000000000Z
13
+ date: 2011-11-02 00:00:00.000000000Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rspec-rails
17
- requirement: &2168900840 !ruby/object:Gem::Requirement
17
+ requirement: &2154399200 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: '0'
23
23
  type: :development
24
24
  prerelease: false
25
- version_requirements: *2168900840
25
+ version_requirements: *2154399200
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: sqlite3
28
- requirement: &2168900260 !ruby/object:Gem::Requirement
28
+ requirement: &2154398660 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ! '>='
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
- version_requirements: *2168900260
36
+ version_requirements: *2154398660
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: sqlite3-ruby
39
- requirement: &2168899660 !ruby/object:Gem::Requirement
39
+ requirement: &2154397860 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ! '>='
@@ -44,10 +44,10 @@ dependencies:
44
44
  version: '0'
45
45
  type: :development
46
46
  prerelease: false
47
- version_requirements: *2168899660
47
+ version_requirements: *2154397860
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: cucumber
50
- requirement: &2168898680 !ruby/object:Gem::Requirement
50
+ requirement: &2154397280 !ruby/object:Gem::Requirement
51
51
  none: false
52
52
  requirements:
53
53
  - - ! '>='
@@ -55,10 +55,10 @@ dependencies:
55
55
  version: '0'
56
56
  type: :development
57
57
  prerelease: false
58
- version_requirements: *2168898680
58
+ version_requirements: *2154397280
59
59
  - !ruby/object:Gem::Dependency
60
60
  name: ci_reporter
61
- requirement: &2168897840 !ruby/object:Gem::Requirement
61
+ requirement: &2154396700 !ruby/object:Gem::Requirement
62
62
  none: false
63
63
  requirements:
64
64
  - - ! '>='
@@ -66,10 +66,10 @@ dependencies:
66
66
  version: '0'
67
67
  type: :development
68
68
  prerelease: false
69
- version_requirements: *2168897840
69
+ version_requirements: *2154396700
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: rails
72
- requirement: &2168896740 !ruby/object:Gem::Requirement
72
+ requirement: &2154395740 !ruby/object:Gem::Requirement
73
73
  none: false
74
74
  requirements:
75
75
  - - =
@@ -77,10 +77,10 @@ dependencies:
77
77
  version: 3.0.1
78
78
  type: :runtime
79
79
  prerelease: false
80
- version_requirements: *2168896740
80
+ version_requirements: *2154395740
81
81
  - !ruby/object:Gem::Dependency
82
82
  name: activerecord
83
- requirement: &2168895600 !ruby/object:Gem::Requirement
83
+ requirement: &2154395100 !ruby/object:Gem::Requirement
84
84
  none: false
85
85
  requirements:
86
86
  - - =
@@ -88,10 +88,10 @@ dependencies:
88
88
  version: 3.0.1
89
89
  type: :runtime
90
90
  prerelease: false
91
- version_requirements: *2168895600
91
+ version_requirements: *2154395100
92
92
  - !ruby/object:Gem::Dependency
93
93
  name: paperclip
94
- requirement: &2168894400 !ruby/object:Gem::Requirement
94
+ requirement: &2154394040 !ruby/object:Gem::Requirement
95
95
  none: false
96
96
  requirements:
97
97
  - - ! '>='
@@ -99,10 +99,10 @@ dependencies:
99
99
  version: '0'
100
100
  type: :runtime
101
101
  prerelease: false
102
- version_requirements: *2168894400
102
+ version_requirements: *2154394040
103
103
  - !ruby/object:Gem::Dependency
104
104
  name: to_xls
105
- requirement: &2168893600 !ruby/object:Gem::Requirement
105
+ requirement: &2154392820 !ruby/object:Gem::Requirement
106
106
  none: false
107
107
  requirements:
108
108
  - - ! '>='
@@ -110,7 +110,7 @@ dependencies:
110
110
  version: '0'
111
111
  type: :runtime
112
112
  prerelease: false
113
- version_requirements: *2168893600
113
+ version_requirements: *2154392820
114
114
  description: First implementation will write metadata on mongodb
115
115
  email:
116
116
  - acampolonghi@gmail.com
@@ -164,7 +164,6 @@ files:
164
164
  - config/initializers/inflections.rb
165
165
  - config/mongoid.yml
166
166
  - config/routes.rb
167
- - db/development.sqlite3
168
167
  - db/migrate/01_create_test_resources.rb
169
168
  - db/migrate/02_active_metadata_migrations.rb
170
169
  - db/test.sqlite3
Binary file