active_metadata 0.5.2 → 0.6.0

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.
Files changed (113) hide show
  1. data/README.md +4 -0
  2. data/Rakefile +31 -0
  3. data/app/assets/javascripts/active_metadata/application.js +15 -0
  4. data/app/assets/stylesheets/active_metadata/application.css +13 -0
  5. data/app/controllers/active_metadata/application_controller.rb +4 -0
  6. data/app/controllers/active_metadata/attachments_controller.rb +4 -6
  7. data/app/controllers/active_metadata/notes_controller.rb +7 -10
  8. data/app/controllers/active_metadata/stream_controller.rb +12 -0
  9. data/app/helpers/active_metadata/application_helper.rb +4 -0
  10. data/app/helpers/active_metadata/stream_helper.rb +14 -0
  11. data/app/models/active_metadata/attachment.rb +26 -0
  12. data/app/models/active_metadata/history.rb +4 -0
  13. data/app/models/active_metadata/note.rb +4 -0
  14. data/app/models/active_metadata/watcher.rb +6 -0
  15. data/app/views/active_metadata/attachments/_attachment.html.erb +7 -0
  16. data/app/views/active_metadata/attachments/index.html.erb +2 -10
  17. data/app/views/active_metadata/notes/_note.html.erb +7 -0
  18. data/app/views/active_metadata/notes/index.html.erb +1 -9
  19. data/app/views/active_metadata/stream/_element.html.erb +1 -0
  20. data/app/views/active_metadata/stream/index.html.erb +3 -0
  21. data/app/views/layouts/active_metadata/application.html.erb +11 -0
  22. data/config/active_metadata.yml +6 -0
  23. data/config/cucumber.yml +8 -0
  24. data/config/database.yml +4 -2
  25. data/config/routes.rb +25 -26
  26. data/db/migrate/02_active_metadata_migrations.rb +24 -24
  27. data/features/{watchlist/add_a_user_to_a_watcher.feature → add_a_user_to_a_watcher.feature} +0 -0
  28. data/features/support/env.rb +8 -0
  29. data/features/supports/file.txt +0 -1
  30. data/features/supports/updated_file.txt +0 -1
  31. data/features/{watchlist/trigger_alert_on_modify.feature → trigger_alert_on_modify.feature} +0 -0
  32. data/lib/active_metadata/base.rb +3 -1
  33. data/lib/active_metadata/engine.rb +11 -0
  34. data/lib/active_metadata/helpers.rb +15 -1
  35. data/lib/active_metadata/persistence/{active_record/attachment.rb → attachment.rb} +10 -10
  36. data/lib/active_metadata/persistence/{active_record/history.rb → history.rb} +4 -4
  37. data/lib/active_metadata/persistence/{active_record/note.rb → note.rb} +8 -8
  38. data/lib/active_metadata/persistence/persistence.rb +14 -4
  39. data/lib/active_metadata/persistence/{active_record/watcher.rb → watcher.rb} +5 -5
  40. data/lib/active_metadata/streamable.rb +25 -0
  41. data/lib/active_metadata/version.rb +1 -1
  42. data/lib/active_metadata.rb +3 -3
  43. data/lib/{rake/ci.rb → tasks/active_metadata_tasks.rake} +27 -6
  44. data/lib/tasks/cucumber.rake +65 -0
  45. data/spec/active_metadata_yml.rb +25 -0
  46. data/spec/controllers/active_metadata/attachments_controller_spec.rb +40 -0
  47. data/spec/controllers/active_metadata/notes_controller_spec.rb +41 -0
  48. data/spec/controllers/active_metadata/stream_controller_spec.rb +46 -0
  49. data/spec/dummy/README.rdoc +261 -0
  50. data/spec/dummy/Rakefile +7 -0
  51. data/spec/dummy/app/assets/javascripts/application.js +15 -0
  52. data/spec/dummy/app/assets/stylesheets/application.css +13 -0
  53. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  54. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  55. data/{config/application.rb → spec/dummy/app/mailers/.gitkeep} +0 -0
  56. data/spec/dummy/app/models/.gitkeep +0 -0
  57. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  58. data/spec/dummy/config/application.rb +56 -0
  59. data/spec/dummy/config/boot.rb +10 -0
  60. data/spec/dummy/config/database.yml +25 -0
  61. data/spec/dummy/config/environment.rb +5 -0
  62. data/spec/dummy/config/environments/development.rb +37 -0
  63. data/spec/dummy/config/environments/production.rb +67 -0
  64. data/spec/dummy/config/environments/test.rb +37 -0
  65. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  66. data/spec/dummy/config/initializers/inflections.rb +15 -0
  67. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  68. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  69. data/spec/dummy/config/initializers/session_store.rb +8 -0
  70. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  71. data/spec/dummy/config/locales/en.yml +5 -0
  72. data/spec/dummy/config/routes.rb +4 -0
  73. data/spec/dummy/config.ru +4 -0
  74. data/spec/dummy/db/development.sqlite3 +0 -0
  75. data/spec/dummy/db/schema.rb +106 -0
  76. data/spec/dummy/db/test.sqlite3 +0 -0
  77. data/spec/dummy/lib/assets/.gitkeep +0 -0
  78. data/spec/dummy/log/.gitkeep +0 -0
  79. data/spec/dummy/public/404.html +26 -0
  80. data/spec/dummy/public/422.html +26 -0
  81. data/spec/dummy/public/500.html +25 -0
  82. data/spec/dummy/public/favicon.ico +0 -0
  83. data/spec/dummy/script/rails +6 -0
  84. data/spec/helpers/active_metadata/stream_helpers_spec.rb +23 -0
  85. data/spec/routing/active_metadata/stream_controller_routing_spec.rb +17 -0
  86. data/spec/spec_helper.rb +18 -31
  87. data/spec/streamable_spec.rb +120 -0
  88. data/spec/support/document.rb +0 -1
  89. data/spec/support/pdf_test_1.pdf +0 -0
  90. data/spec/support/section.rb +0 -1
  91. data/spec/support/user.rb +0 -2
  92. data/spec/views/active_metadata/stream/index.html.erb_spec.rb +5 -0
  93. metadata +165 -73
  94. data/app/helpers/application_helper.rb +0 -2
  95. data/config/initializers/inflections.rb +0 -7
  96. data/config/mongoid.yml +0 -28
  97. data/db/test.sqlite3 +0 -0
  98. data/features/supports/initializer.rb +0 -1
  99. data/lib/active_metadata/persistence/active_record.rb +0 -26
  100. data/lib/application_controller.rb +0 -28
  101. data/lib/application_helper.rb +0 -7
  102. data/lib/engine.rb +0 -29
  103. data/lib/model/active_record/attachment.rb +0 -22
  104. data/lib/model/active_record/history.rb +0 -2
  105. data/lib/model/active_record/note.rb +0 -2
  106. data/lib/model/active_record/watcher.rb +0 -4
  107. data/lib/rails/railties/tasks.rake +0 -16
  108. data/lib/rake/active_record_tasks.rb +0 -77
  109. data/lib/templates/active_metadata.yml +0 -17
  110. data/lib/templates/active_metadata_migrations +0 -71
  111. data/lib/templates/mongoid.yml +0 -20
  112. data/spec/benchmark_spec.rb +0 -35
  113. data/spec/controllers/metadata_controller_spec.rb +0 -14
@@ -1,4 +1,4 @@
1
- module ActiveMetadata::Persistence::ActiveRecord::Attachment
1
+ module ActiveMetadata::Persistence::Attachment
2
2
 
3
3
  def self.included(receiver)
4
4
  receiver.send :include, InstanceMethods
@@ -7,20 +7,20 @@ module ActiveMetadata::Persistence::ActiveRecord::Attachment
7
7
  module InstanceMethods
8
8
 
9
9
  def save_attachment_for(field, file, starred=false)
10
- attachment = Attachment.create! :document_class => metadata_class, :document_id => metadata_id, :label => field, :attach => file,
10
+ attachment = ActiveMetadata::Attachment.create! :document_class => metadata_class, :document_id => metadata_id, :label => field, :attach => file,
11
11
  :starred => starred, :created_by => current_user_id
12
12
  reload_attachments_cache_for field
13
13
  self.send(:send_notification, field, "", attachment.attach.original_filename, :attachment_message, current_user_id)
14
14
  end
15
15
 
16
- def attachments_for(field, order_by="attach_updated_at DESC")
16
+ def attachments_for(field, order_by="updated_at DESC")
17
17
  Rails.cache.fetch(attachments_cache_key(field), :expires_in => ActiveMetadata::CONFIG['cache_expires_in'].minutes) do
18
18
  fetch_attachments_for field, nil, order_by
19
19
  end
20
20
  end
21
21
 
22
22
  def delete_attachment(id)
23
- a = Attachment.find(id)
23
+ a = ActiveMetadata::Attachment.find(id)
24
24
  filename = a.attach.original_filename
25
25
  a.destroy
26
26
  reload_attachments_cache_for a.label
@@ -28,7 +28,7 @@ module ActiveMetadata::Persistence::ActiveRecord::Attachment
28
28
  end
29
29
 
30
30
  def update_attachment(id, newfile, starred=nil)
31
- a = Attachment.find(id)
31
+ a = ActiveMetadata::Attachment.find(id)
32
32
  old_filename = a.attach.original_filename
33
33
  a.attach = newfile
34
34
  a.updated_by = current_user_id
@@ -45,7 +45,7 @@ module ActiveMetadata::Persistence::ActiveRecord::Attachment
45
45
  end
46
46
 
47
47
  def find_attachment_by_id(id)
48
- Attachment.find(id)
48
+ ActiveMetadata::Attachment.find(id)
49
49
  end
50
50
 
51
51
  # not cached
@@ -54,12 +54,12 @@ module ActiveMetadata::Persistence::ActiveRecord::Attachment
54
54
  end
55
55
 
56
56
  def star_attachment(id)
57
- n = Attachment.find(id)
57
+ n = ActiveMetadata::Attachment.find(id)
58
58
  update_attachment id,n.attach,true
59
59
  end
60
60
 
61
61
  def unstar_attachment(id)
62
- n = Attachment.find(id)
62
+ n = ActiveMetadata::Attachment.find(id)
63
63
  update_attachment id,n.attach,false
64
64
  end
65
65
 
@@ -69,10 +69,10 @@ module ActiveMetadata::Persistence::ActiveRecord::Attachment
69
69
  Rails.cache.write(attachments_cache_key(field),fetch_attachments_for(field), :expires_in => ActiveMetadata::CONFIG['cache_expires_in'].minutes )
70
70
  end
71
71
 
72
- def fetch_attachments_for(field, starred=nil, order_by="attach_updated_at DESC")
72
+ def fetch_attachments_for(field, starred=nil, order_by="updated_at DESC")
73
73
  conditions = {:document_class => metadata_class, :document_id => metadata_id,:label => field}
74
74
  conditions[:starred] = starred if !starred.nil?
75
- Attachment.all(:conditions => conditions , :order => order_by)
75
+ ActiveMetadata::Attachment.all(:conditions => conditions , :order => order_by)
76
76
  end
77
77
 
78
78
  end
@@ -1,4 +1,4 @@
1
- module ActiveMetadata::Persistence::ActiveRecord::History
1
+ module ActiveMetadata::Persistence::History
2
2
 
3
3
  def self.included(receiver)
4
4
  receiver.send :include, InstanceMethods
@@ -8,8 +8,8 @@ module ActiveMetadata::Persistence::ActiveRecord::History
8
8
 
9
9
  def save_history
10
10
  self.changes.each do |key, value|
11
- next if ActiveMetadata::CONFIG['history_skip_fields'].include?(key)
12
- History.create! :value => value[1],:document_class => metadata_class, :document_id => metadata_id,:label => key.to_s, :created_by => current_user_id
11
+ next if ActiveMetadata::CONFIG['history_skip_fields'].include?(key)
12
+ ActiveMetadata::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_class => metadata_class, :document_id => metadata_id,:label => field}, :order => order)
31
+ ActiveMetadata::History.all(:conditions => {:document_class => metadata_class, :document_id => metadata_id,:label => field}, :order => order)
32
32
  end
33
33
 
34
34
 
@@ -1,4 +1,4 @@
1
- module ActiveMetadata::Persistence::ActiveRecord::Note
1
+ module ActiveMetadata::Persistence::Note
2
2
 
3
3
  def self.included(receiver)
4
4
  receiver.send :include, InstanceMethods
@@ -7,13 +7,13 @@ module ActiveMetadata::Persistence::ActiveRecord::Note
7
7
  module InstanceMethods
8
8
 
9
9
  def create_note_for(field, note, starred=false)
10
- Note.create! :document_id => metadata_id, :document_class => metadata_class, :label => field.to_s,:note => note, :created_by => current_user_id, :starred => starred
10
+ ActiveMetadata::Note.create! :document_id => metadata_id, :document_class => metadata_class, :label => field.to_s,:note => note, :created_by => current_user_id, :starred => starred
11
11
  reload_notes_cache_for field
12
12
  self.send(:send_notification, field, "", note, :note_message, current_user_id)
13
13
  end
14
14
 
15
15
  def update_note(id, note, starred=nil)
16
- n = Note.find(id)
16
+ n = ActiveMetadata::Note.find(id)
17
17
  old_value = n.note
18
18
  attributes = {:note => note, :updated_by => current_user_id, :updated_at => Time.now.utc}
19
19
  #mass assign starred inly if provided
@@ -32,7 +32,7 @@ module ActiveMetadata::Persistence::ActiveRecord::Note
32
32
  end
33
33
 
34
34
  def find_note_by_id(id)
35
- Note.find(id)
35
+ ActiveMetadata::Note.find(id)
36
36
  end
37
37
 
38
38
  def create_notes_for(field,notes)
@@ -40,7 +40,7 @@ module ActiveMetadata::Persistence::ActiveRecord::Note
40
40
  end
41
41
 
42
42
  def delete_note(id)
43
- n = Note.find(id)
43
+ n = ActiveMetadata::Note.find(id)
44
44
  old_value = n.note
45
45
  n.destroy
46
46
  reload_notes_cache_for n.label
@@ -57,12 +57,12 @@ module ActiveMetadata::Persistence::ActiveRecord::Note
57
57
  end
58
58
 
59
59
  def star_note(id)
60
- n = Note.find(id)
60
+ n = ActiveMetadata::Note.find(id)
61
61
  update_note id,n.note,true
62
62
  end
63
63
 
64
64
  def unstar_note(id)
65
- n = Note.find(id)
65
+ n = ActiveMetadata::Note.find(id)
66
66
  update_note id,n.note,false
67
67
  end
68
68
 
@@ -77,7 +77,7 @@ module ActiveMetadata::Persistence::ActiveRecord::Note
77
77
  unless starred.nil?
78
78
  conditions[:starred] = starred
79
79
  end
80
- Note.all(:conditions => conditions, :order => order_by)
80
+ ActiveMetadata::Note.all(:conditions => conditions, :order => order_by)
81
81
  end
82
82
 
83
83
  end
@@ -1,9 +1,19 @@
1
1
  module ActiveMetadata::Persistence
2
-
3
- require "active_metadata/persistence/active_record"
4
-
2
+
3
+ require "active_metadata/persistence/note"
4
+ require "active_metadata/persistence/history"
5
+ require "active_metadata/persistence/watcher"
6
+ require "active_metadata/persistence/attachment"
7
+
5
8
  def self.included(receiver)
6
- receiver.send :include, ActiveMetadata::Persistence::ActiveRecord
9
+ receiver.send :include, InstanceMethods
10
+ end
11
+
12
+ module InstanceMethods
13
+ include ActiveMetadata::Persistence::Note
14
+ include ActiveMetadata::Persistence::History
15
+ include ActiveMetadata::Persistence::Watcher
16
+ include ActiveMetadata::Persistence::Attachment
7
17
  end
8
18
 
9
19
  end
@@ -1,4 +1,4 @@
1
- module ActiveMetadata::Persistence::ActiveRecord::Watcher
1
+ module ActiveMetadata::Persistence::Watcher
2
2
 
3
3
  def self.included(receiver)
4
4
  receiver.send :include, InstanceMethods
@@ -7,21 +7,21 @@ 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_class => metadata_class, :document_id => metadata_id, :label => field, :owner_id => owner.id
10
+ ActiveMetadata::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 => {:document_class => metadata_class, :label => field, :document_id => metadata_id})
14
+ ActiveMetadata::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)
18
- Watcher.where(:document_id => metadata_id, :label => field, :owner_id => owner.id).each do |watcher|
18
+ ActiveMetadata::Watcher.where(:document_id => metadata_id, :label => field, :owner_id => owner.id).each do |watcher|
19
19
  watcher.destroy
20
20
  end
21
21
  end
22
22
 
23
23
  def is_watched_by(field,owner)
24
- Watcher.where(:document_class => metadata_class, :document_id => metadata_id, :label => field, :owner_id => owner.id).empty? ? false : true
24
+ ActiveMetadata::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)
@@ -0,0 +1,25 @@
1
+ module ActiveMetadata::Streamable
2
+
3
+ def stream_for field
4
+ sort_stream(collect_stream_data(field))
5
+ end
6
+
7
+ private
8
+ def sort_stream stream
9
+ stream.sort{|a,b| b.updated_at <=> a.updated_at}
10
+ end
11
+
12
+ def collect_stream_data field
13
+ res = []
14
+ ActiveMetadata::CONFIG['streamables'].each do |model|
15
+ res.concat self.send(stream_collect_method(model.to_s),field).collect { |el| el }
16
+ end
17
+ res
18
+ end
19
+
20
+ def stream_collect_method model
21
+ model.to_s == 'note' ? 'notes_for' : 'attachments_for'
22
+ end
23
+
24
+
25
+ end
@@ -1,3 +1,3 @@
1
1
  module ActiveMetadata
2
- VERSION = "0.5.2"
2
+ VERSION = "0.6.0"
3
3
  end
@@ -1,7 +1,7 @@
1
+ require "active_metadata/engine"
2
+
1
3
  module ActiveMetadata
2
- require 'engine' if defined?(Rails) && Rails::VERSION::MAJOR == 3
3
4
  require 'active_metadata/base'
4
- require 'application_controller'
5
5
  require "active_metadata/version"
6
6
  require "active_metadata/form_helper"
7
- end
7
+ end
@@ -1,15 +1,18 @@
1
+ require 'rspec/core/rake_task'
2
+ require 'cucumber/rake/task'
3
+
1
4
  begin
2
5
  require 'ci/reporter/rake/rspec'
3
6
  require 'ci/reporter/rake/cucumber'
4
7
 
5
- namespace :ci do
8
+ namespace :ci do :environment
6
9
 
7
- ENV["DATABASE_ENV"] = 'test'
10
+ ENV["RAILS_ENV"] ||= 'test'
8
11
 
9
12
  namespace :setup do
10
-
13
+
11
14
  @reports_dir = ENV['CI_REPORTS'] || 'features/reports'
12
-
15
+
13
16
  task :cucumber_report_cleanup do
14
17
  rm_rf @reports_dir
15
18
  end
@@ -20,10 +23,10 @@ begin
20
23
  end
21
24
 
22
25
  end
23
-
26
+
24
27
  task "spec" => ["rspec_run"]
25
28
  task "cucumber" => ["cucumber_run"]
26
-
29
+
27
30
  end
28
31
 
29
32
  task "ci" => ["db:migrate", "ci:spec", "ci:cucumber"]
@@ -36,3 +39,21 @@ RSpec::Core::RakeTask.new(:rspec_run => ["ci:setup:rspec"]) do |t|
36
39
  end
37
40
 
38
41
  Cucumber::Rake::Task.new(:cucumber_run => ["ci:setup:cucumber"])
42
+
43
+
44
+ namespace :active_metadata do
45
+
46
+ desc "Install the active_metadata gem requirements file ***TASK IS ON ALPHA STAGE***"
47
+ task :install do
48
+
49
+ FileUtils.cp File.expand_path('../../../config/active_metadata.yml',__FILE__), File.expand_path('config/')
50
+ puts "Installed active_metadata.yml"
51
+
52
+ puts "Copying migrations"
53
+ ts = Time.now.utc.strftime('%Y%m%d%H%M%S')
54
+ FileUtils.cp File.expand_path('../../../db/migrate/02_active_metadata_migrations.rb',__FILE__), File.expand_path("db/migrate/#{ts}_active_metadata_migrations.rb")
55
+ puts "run rake db:migrate to complete the gem installation"
56
+
57
+ end
58
+
59
+ end
@@ -0,0 +1,65 @@
1
+ # IMPORTANT: This file is generated by cucumber-rails - edit at your own peril.
2
+ # It is recommended to regenerate this file in the future when you upgrade to a
3
+ # newer version of cucumber-rails. Consider adding your own code to a new file
4
+ # instead of editing this one. Cucumber will automatically load all features/**/*.rb
5
+ # files.
6
+
7
+
8
+ unless ARGV.any? {|a| a =~ /^gems/} # Don't load anything when running the gems:* tasks
9
+
10
+ vendored_cucumber_bin = Dir["#{Rails.root}/vendor/{gems,plugins}/cucumber*/bin/cucumber"].first
11
+ $LOAD_PATH.unshift(File.dirname(vendored_cucumber_bin) + '/../lib') unless vendored_cucumber_bin.nil?
12
+
13
+ begin
14
+ require 'cucumber/rake/task'
15
+
16
+ namespace :cucumber do
17
+ Cucumber::Rake::Task.new({:ok => 'db:test:prepare'}, 'Run features that should pass') do |t|
18
+ t.binary = vendored_cucumber_bin # If nil, the gem's binary is used.
19
+ t.fork = true # You may get faster startup if you set this to false
20
+ t.profile = 'default'
21
+ end
22
+
23
+ Cucumber::Rake::Task.new({:wip => 'db:test:prepare'}, 'Run features that are being worked on') do |t|
24
+ t.binary = vendored_cucumber_bin
25
+ t.fork = true # You may get faster startup if you set this to false
26
+ t.profile = 'wip'
27
+ end
28
+
29
+ Cucumber::Rake::Task.new({:rerun => 'db:test:prepare'}, 'Record failing features and run only them if any exist') do |t|
30
+ t.binary = vendored_cucumber_bin
31
+ t.fork = true # You may get faster startup if you set this to false
32
+ t.profile = 'rerun'
33
+ end
34
+
35
+ desc 'Run all features'
36
+ task :all => [:ok, :wip]
37
+
38
+ task :statsetup do
39
+ require 'rails/code_statistics'
40
+ ::STATS_DIRECTORIES << %w(Cucumber\ features features) if File.exist?('features')
41
+ ::CodeStatistics::TEST_TYPES << "Cucumber features" if File.exist?('features')
42
+ end
43
+ end
44
+ desc 'Alias for cucumber:ok'
45
+ task :cucumber => 'cucumber:ok'
46
+
47
+ task :default => :cucumber
48
+
49
+ task :features => :cucumber do
50
+ STDERR.puts "*** The 'features' task is deprecated. See rake -T cucumber ***"
51
+ end
52
+
53
+ # In case we don't have ActiveRecord, append a no-op task that we can depend upon.
54
+ task 'db:test:prepare' do
55
+ end
56
+
57
+ task :stats => 'cucumber:statsetup'
58
+ rescue LoadError
59
+ desc 'cucumber rake task not available (cucumber not installed)'
60
+ task :cucumber do
61
+ abort 'Cucumber rake task is not available. Be sure to install cucumber as a gem or plugin'
62
+ end
63
+ end
64
+
65
+ end
@@ -0,0 +1,25 @@
1
+ require "spec_helper"
2
+
3
+ describe "active_metadata.yml" do
4
+
5
+ context "given the active_metadata.yml parsed" do
6
+
7
+ before do
8
+ @envs = ['test','development']
9
+ @config = YAML.load(File.read("config/active_metadata.yml"))
10
+ end
11
+
12
+ it "should have a streamables config" do
13
+ test_envs{|env| @config[env]['streamables'].should_not be_nil}
14
+ end
15
+
16
+
17
+ end
18
+
19
+ def test_envs &block
20
+ @envs.each do |env|
21
+ yield env
22
+ end
23
+ end
24
+
25
+ end
@@ -0,0 +1,40 @@
1
+ require 'spec_helper'
2
+
3
+ describe ActiveMetadata::AttachmentsController do
4
+
5
+ context "given 2 attachments for @document#name" do
6
+
7
+ render_views
8
+
9
+ before(:each) do
10
+ @document = Document.create! { |d| d.name = "John" }
11
+ (1..2).each do |i|
12
+ @document.save_attachment_for(:name,test_pdf("pdf_test_#{i}"))
13
+ end
14
+ end
15
+
16
+ describe "GET 'index'" do
17
+
18
+ it "should success" do
19
+ get 'index', :model_name => 'document', :model_id => @document.id, :field_name => 'name'
20
+ response.should be_success
21
+ end
22
+
23
+ it "should assign attachments" do
24
+ get 'index', :model_name => 'document', :model_id => @document.id, :field_name => 'name'
25
+ assigns(:attachments).should_not be_nil
26
+ assigns(:attachments).size.should eq 2
27
+ end
28
+
29
+ it "should display 3 notes" do
30
+ get 'index', :model_name => 'document', :model_id => @document.id, :field_name => 'name'
31
+ response.body.should match(/pdf_test_1.pdf/)
32
+ response.body.should match(/pdf_test_2.pdf/)
33
+ end
34
+
35
+ end
36
+
37
+ end
38
+
39
+
40
+ end
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+
3
+ describe ActiveMetadata::NotesController do
4
+
5
+ context "given 3 notes @document#name" do
6
+
7
+ render_views
8
+
9
+ before(:each) do
10
+ @document = Document.create! { |d| d.name = "John" }
11
+ (1..3).each do |i|
12
+ @document.create_note_for(:name, "note#{i}")
13
+ end
14
+ end
15
+
16
+ describe "GET 'index'" do
17
+
18
+ it "should success" do
19
+ get 'index', :model_name => 'document', :model_id => @document.id, :field_name => 'name'
20
+ response.should be_success
21
+ end
22
+
23
+ it "should assign notes" do
24
+ get 'index', :model_name => 'document', :model_id => @document.id, :field_name => 'name'
25
+ assigns(:notes).should_not be_nil
26
+ assigns(:notes).size.should eq 3
27
+ end
28
+
29
+ it "should display 3 notes" do
30
+ get 'index', :model_name => 'document', :model_id => @document.id, :field_name => 'name'
31
+ response.body.should match(/note1/)
32
+ response.body.should match(/note2/)
33
+ response.body.should match(/note3/)
34
+ end
35
+
36
+ end
37
+
38
+ end
39
+
40
+
41
+ end
@@ -0,0 +1,46 @@
1
+ require 'spec_helper'
2
+
3
+ describe ActiveMetadata::StreamController do
4
+
5
+ context "given 1 note and 1 attachment for @document#name" do
6
+
7
+ render_views
8
+
9
+ before(:each) do
10
+ @document = Document.create! { |d| d.name = "John" }
11
+ @document.save_attachment_for(:name,test_pdf("pdf_test"))
12
+ @document.create_note_for(:name, "nota per name john")
13
+ end
14
+
15
+ describe "GET 'index'" do
16
+
17
+ it "should success" do
18
+ get 'index', :model_name => 'document', :model_id => @document.id, :field_name => 'name'
19
+ response.should be_success
20
+ end
21
+
22
+ it "should assign document" do
23
+ get 'index', :model_name => 'document', :model_id => @document.id, :field_name => 'name'
24
+ assigns(:document).should_not be_nil
25
+ assigns(:document).id.should eq @document.id
26
+ end
27
+
28
+ it "should assign stream" do
29
+ get 'index', :model_name => 'document', :model_id => @document.id, :field_name => 'name'
30
+ assigns(:stream).should_not be_nil
31
+ assigns(:stream).size.should eq 2
32
+ end
33
+
34
+ it "should render both note and the attachment" do
35
+ get 'index', :model_name => 'document', :model_id => @document.id, :field_name => 'name'
36
+ response.body.should match(/pdf_test.pdf/)
37
+ response.body.should match(/nota per name john/)
38
+ end
39
+
40
+ end
41
+
42
+ end
43
+
44
+
45
+
46
+ end