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.
- data/README.md +4 -0
- data/Rakefile +31 -0
- data/app/assets/javascripts/active_metadata/application.js +15 -0
- data/app/assets/stylesheets/active_metadata/application.css +13 -0
- data/app/controllers/active_metadata/application_controller.rb +4 -0
- data/app/controllers/active_metadata/attachments_controller.rb +4 -6
- data/app/controllers/active_metadata/notes_controller.rb +7 -10
- data/app/controllers/active_metadata/stream_controller.rb +12 -0
- data/app/helpers/active_metadata/application_helper.rb +4 -0
- data/app/helpers/active_metadata/stream_helper.rb +14 -0
- data/app/models/active_metadata/attachment.rb +26 -0
- data/app/models/active_metadata/history.rb +4 -0
- data/app/models/active_metadata/note.rb +4 -0
- data/app/models/active_metadata/watcher.rb +6 -0
- data/app/views/active_metadata/attachments/_attachment.html.erb +7 -0
- data/app/views/active_metadata/attachments/index.html.erb +2 -10
- data/app/views/active_metadata/notes/_note.html.erb +7 -0
- data/app/views/active_metadata/notes/index.html.erb +1 -9
- data/app/views/active_metadata/stream/_element.html.erb +1 -0
- data/app/views/active_metadata/stream/index.html.erb +3 -0
- data/app/views/layouts/active_metadata/application.html.erb +11 -0
- data/config/active_metadata.yml +6 -0
- data/config/cucumber.yml +8 -0
- data/config/database.yml +4 -2
- data/config/routes.rb +25 -26
- data/db/migrate/02_active_metadata_migrations.rb +24 -24
- data/features/{watchlist/add_a_user_to_a_watcher.feature → add_a_user_to_a_watcher.feature} +0 -0
- data/features/support/env.rb +8 -0
- data/features/supports/file.txt +0 -1
- data/features/supports/updated_file.txt +0 -1
- data/features/{watchlist/trigger_alert_on_modify.feature → trigger_alert_on_modify.feature} +0 -0
- data/lib/active_metadata/base.rb +3 -1
- data/lib/active_metadata/engine.rb +11 -0
- data/lib/active_metadata/helpers.rb +15 -1
- data/lib/active_metadata/persistence/{active_record/attachment.rb → attachment.rb} +10 -10
- data/lib/active_metadata/persistence/{active_record/history.rb → history.rb} +4 -4
- data/lib/active_metadata/persistence/{active_record/note.rb → note.rb} +8 -8
- data/lib/active_metadata/persistence/persistence.rb +14 -4
- data/lib/active_metadata/persistence/{active_record/watcher.rb → watcher.rb} +5 -5
- data/lib/active_metadata/streamable.rb +25 -0
- data/lib/active_metadata/version.rb +1 -1
- data/lib/active_metadata.rb +3 -3
- data/lib/{rake/ci.rb → tasks/active_metadata_tasks.rake} +27 -6
- data/lib/tasks/cucumber.rake +65 -0
- data/spec/active_metadata_yml.rb +25 -0
- data/spec/controllers/active_metadata/attachments_controller_spec.rb +40 -0
- data/spec/controllers/active_metadata/notes_controller_spec.rb +41 -0
- data/spec/controllers/active_metadata/stream_controller_spec.rb +46 -0
- data/spec/dummy/README.rdoc +261 -0
- data/spec/dummy/Rakefile +7 -0
- data/spec/dummy/app/assets/javascripts/application.js +15 -0
- data/spec/dummy/app/assets/stylesheets/application.css +13 -0
- data/spec/dummy/app/controllers/application_controller.rb +3 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/{config/application.rb → spec/dummy/app/mailers/.gitkeep} +0 -0
- data/spec/dummy/app/models/.gitkeep +0 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/config/application.rb +56 -0
- data/spec/dummy/config/boot.rb +10 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +37 -0
- data/spec/dummy/config/environments/production.rb +67 -0
- data/spec/dummy/config/environments/test.rb +37 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/inflections.rb +15 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +7 -0
- data/spec/dummy/config/initializers/session_store.rb +8 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/routes.rb +4 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/schema.rb +106 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/lib/assets/.gitkeep +0 -0
- data/spec/dummy/log/.gitkeep +0 -0
- data/spec/dummy/public/404.html +26 -0
- data/spec/dummy/public/422.html +26 -0
- data/spec/dummy/public/500.html +25 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/helpers/active_metadata/stream_helpers_spec.rb +23 -0
- data/spec/routing/active_metadata/stream_controller_routing_spec.rb +17 -0
- data/spec/spec_helper.rb +18 -31
- data/spec/streamable_spec.rb +120 -0
- data/spec/support/document.rb +0 -1
- data/spec/support/pdf_test_1.pdf +0 -0
- data/spec/support/section.rb +0 -1
- data/spec/support/user.rb +0 -2
- data/spec/views/active_metadata/stream/index.html.erb_spec.rb +5 -0
- metadata +165 -73
- data/app/helpers/application_helper.rb +0 -2
- data/config/initializers/inflections.rb +0 -7
- data/config/mongoid.yml +0 -28
- data/db/test.sqlite3 +0 -0
- data/features/supports/initializer.rb +0 -1
- data/lib/active_metadata/persistence/active_record.rb +0 -26
- data/lib/application_controller.rb +0 -28
- data/lib/application_helper.rb +0 -7
- data/lib/engine.rb +0 -29
- data/lib/model/active_record/attachment.rb +0 -22
- data/lib/model/active_record/history.rb +0 -2
- data/lib/model/active_record/note.rb +0 -2
- data/lib/model/active_record/watcher.rb +0 -4
- data/lib/rails/railties/tasks.rake +0 -16
- data/lib/rake/active_record_tasks.rb +0 -77
- data/lib/templates/active_metadata.yml +0 -17
- data/lib/templates/active_metadata_migrations +0 -71
- data/lib/templates/mongoid.yml +0 -20
- data/spec/benchmark_spec.rb +0 -35
- data/spec/controllers/metadata_controller_spec.rb +0 -14
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
# encoding: UTF-8
|
|
2
|
+
# This file is auto-generated from the current state of the database. Instead
|
|
3
|
+
# of editing this file, please use the migrations feature of Active Record to
|
|
4
|
+
# incrementally modify your database, and then regenerate this schema definition.
|
|
5
|
+
#
|
|
6
|
+
# Note that this schema.rb definition is the authoritative source for your
|
|
7
|
+
# database schema. If you need to create the application database on another
|
|
8
|
+
# system, you should be using db:schema:load, not running all the migrations
|
|
9
|
+
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
|
|
10
|
+
# you'll amass, the slower it'll run and the greater likelihood for issues).
|
|
11
|
+
#
|
|
12
|
+
# It's strongly recommended to check this file into your version control system.
|
|
13
|
+
|
|
14
|
+
ActiveRecord::Schema.define(:version => 2) do
|
|
15
|
+
|
|
16
|
+
create_table "attachments", :force => true do |t|
|
|
17
|
+
t.string "label"
|
|
18
|
+
t.integer "document_id"
|
|
19
|
+
t.string "document_class"
|
|
20
|
+
t.integer "created_by"
|
|
21
|
+
t.integer "updated_by"
|
|
22
|
+
t.integer "counter"
|
|
23
|
+
t.string "attach_file_name"
|
|
24
|
+
t.string "attach_content_type"
|
|
25
|
+
t.integer "attach_file_size"
|
|
26
|
+
t.datetime "attach_updated_at"
|
|
27
|
+
t.boolean "starred"
|
|
28
|
+
t.datetime "created_at", :null => false
|
|
29
|
+
t.datetime "updated_at", :null => false
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
add_index "attachments", ["attach_updated_at"], :name => "index_attachments_on_attach_updated_at"
|
|
33
|
+
add_index "attachments", ["document_class"], :name => "index_attachments_on_document_class"
|
|
34
|
+
add_index "attachments", ["document_id"], :name => "index_attachments_on_document_id"
|
|
35
|
+
add_index "attachments", ["label"], :name => "index_attachments_on_label"
|
|
36
|
+
|
|
37
|
+
create_table "documents", :force => true do |t|
|
|
38
|
+
t.string "name"
|
|
39
|
+
t.string "surname"
|
|
40
|
+
t.boolean "keep_alive"
|
|
41
|
+
t.datetime "created_at", :null => false
|
|
42
|
+
t.datetime "updated_at", :null => false
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
create_table "histories", :force => true do |t|
|
|
46
|
+
t.text "value"
|
|
47
|
+
t.string "label"
|
|
48
|
+
t.string "document_class"
|
|
49
|
+
t.integer "document_id"
|
|
50
|
+
t.integer "created_by"
|
|
51
|
+
t.datetime "created_at", :null => false
|
|
52
|
+
t.datetime "updated_at", :null => false
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
add_index "histories", ["created_at"], :name => "index_histories_on_created_at"
|
|
56
|
+
add_index "histories", ["document_class"], :name => "index_histories_on_document_class"
|
|
57
|
+
add_index "histories", ["document_id"], :name => "index_histories_on_document_id"
|
|
58
|
+
add_index "histories", ["label"], :name => "index_histories_on_label"
|
|
59
|
+
|
|
60
|
+
create_table "notes", :force => true do |t|
|
|
61
|
+
t.text "note"
|
|
62
|
+
t.string "label"
|
|
63
|
+
t.string "document_class"
|
|
64
|
+
t.integer "document_id"
|
|
65
|
+
t.integer "created_by"
|
|
66
|
+
t.integer "updated_by"
|
|
67
|
+
t.boolean "starred"
|
|
68
|
+
t.datetime "created_at", :null => false
|
|
69
|
+
t.datetime "updated_at", :null => false
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
add_index "notes", ["document_class"], :name => "index_notes_on_document_class"
|
|
73
|
+
add_index "notes", ["document_id"], :name => "index_notes_on_document_id"
|
|
74
|
+
add_index "notes", ["label"], :name => "index_notes_on_label"
|
|
75
|
+
add_index "notes", ["updated_at"], :name => "index_notes_on_updated_at"
|
|
76
|
+
|
|
77
|
+
create_table "sections", :force => true do |t|
|
|
78
|
+
t.string "title"
|
|
79
|
+
t.integer "document_id"
|
|
80
|
+
t.datetime "created_at", :null => false
|
|
81
|
+
t.datetime "updated_at", :null => false
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
create_table "users", :force => true do |t|
|
|
85
|
+
t.string "email"
|
|
86
|
+
t.string "firstname"
|
|
87
|
+
t.string "lastname"
|
|
88
|
+
t.datetime "created_at", :null => false
|
|
89
|
+
t.datetime "updated_at", :null => false
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
create_table "watchers", :force => true do |t|
|
|
93
|
+
t.integer "owner_id"
|
|
94
|
+
t.string "label"
|
|
95
|
+
t.string "document_class"
|
|
96
|
+
t.integer "document_id"
|
|
97
|
+
t.datetime "created_at", :null => false
|
|
98
|
+
t.datetime "updated_at", :null => false
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
add_index "watchers", ["created_at"], :name => "index_watchers_on_created_at"
|
|
102
|
+
add_index "watchers", ["document_id"], :name => "index_watchers_on_document_id"
|
|
103
|
+
add_index "watchers", ["label"], :name => "index_watchers_on_label"
|
|
104
|
+
add_index "watchers", ["owner_id"], :name => "index_watchers_on_owner_id"
|
|
105
|
+
|
|
106
|
+
end
|
|
Binary file
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<title>The page you were looking for doesn't exist (404)</title>
|
|
5
|
+
<style type="text/css">
|
|
6
|
+
body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
|
|
7
|
+
div.dialog {
|
|
8
|
+
width: 25em;
|
|
9
|
+
padding: 0 4em;
|
|
10
|
+
margin: 4em auto 0 auto;
|
|
11
|
+
border: 1px solid #ccc;
|
|
12
|
+
border-right-color: #999;
|
|
13
|
+
border-bottom-color: #999;
|
|
14
|
+
}
|
|
15
|
+
h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
|
|
16
|
+
</style>
|
|
17
|
+
</head>
|
|
18
|
+
|
|
19
|
+
<body>
|
|
20
|
+
<!-- This file lives in public/404.html -->
|
|
21
|
+
<div class="dialog">
|
|
22
|
+
<h1>The page you were looking for doesn't exist.</h1>
|
|
23
|
+
<p>You may have mistyped the address or the page may have moved.</p>
|
|
24
|
+
</div>
|
|
25
|
+
</body>
|
|
26
|
+
</html>
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<title>The change you wanted was rejected (422)</title>
|
|
5
|
+
<style type="text/css">
|
|
6
|
+
body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
|
|
7
|
+
div.dialog {
|
|
8
|
+
width: 25em;
|
|
9
|
+
padding: 0 4em;
|
|
10
|
+
margin: 4em auto 0 auto;
|
|
11
|
+
border: 1px solid #ccc;
|
|
12
|
+
border-right-color: #999;
|
|
13
|
+
border-bottom-color: #999;
|
|
14
|
+
}
|
|
15
|
+
h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
|
|
16
|
+
</style>
|
|
17
|
+
</head>
|
|
18
|
+
|
|
19
|
+
<body>
|
|
20
|
+
<!-- This file lives in public/422.html -->
|
|
21
|
+
<div class="dialog">
|
|
22
|
+
<h1>The change you wanted was rejected.</h1>
|
|
23
|
+
<p>Maybe you tried to change something you didn't have access to.</p>
|
|
24
|
+
</div>
|
|
25
|
+
</body>
|
|
26
|
+
</html>
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<title>We're sorry, but something went wrong (500)</title>
|
|
5
|
+
<style type="text/css">
|
|
6
|
+
body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
|
|
7
|
+
div.dialog {
|
|
8
|
+
width: 25em;
|
|
9
|
+
padding: 0 4em;
|
|
10
|
+
margin: 4em auto 0 auto;
|
|
11
|
+
border: 1px solid #ccc;
|
|
12
|
+
border-right-color: #999;
|
|
13
|
+
border-bottom-color: #999;
|
|
14
|
+
}
|
|
15
|
+
h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
|
|
16
|
+
</style>
|
|
17
|
+
</head>
|
|
18
|
+
|
|
19
|
+
<body>
|
|
20
|
+
<!-- This file lives in public/500.html -->
|
|
21
|
+
<div class="dialog">
|
|
22
|
+
<h1>We're sorry, but something went wrong.</h1>
|
|
23
|
+
</div>
|
|
24
|
+
</body>
|
|
25
|
+
</html>
|
|
File without changes
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
|
|
3
|
+
|
|
4
|
+
APP_PATH = File.expand_path('../../config/application', __FILE__)
|
|
5
|
+
require File.expand_path('../../config/boot', __FILE__)
|
|
6
|
+
require 'rails/commands'
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
require "spec_helper"
|
|
2
|
+
|
|
3
|
+
describe ActiveMetadata::StreamHelper do
|
|
4
|
+
|
|
5
|
+
include ActiveMetadata::StreamHelper
|
|
6
|
+
|
|
7
|
+
describe "stream_partial_name" do
|
|
8
|
+
|
|
9
|
+
it "should return the partial name to render notes" do
|
|
10
|
+
stream_partial_path(ActiveMetadata::Note.new).should eq 'active_metadata/notes/note'
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
describe "clean_class_name" do
|
|
16
|
+
|
|
17
|
+
it "should remove the module from a class name" do
|
|
18
|
+
clean_class_name('ActiveMetadata::Note').should eq 'Note'
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
require "spec_helper"
|
|
2
|
+
|
|
3
|
+
describe ActiveMetadata::StreamController do
|
|
4
|
+
|
|
5
|
+
describe "routing" do
|
|
6
|
+
|
|
7
|
+
before(:each) { @routes = ActiveMetadata::Engine.routes }
|
|
8
|
+
|
|
9
|
+
it "recognizes and generate :model_name/:model_id/:field_name/stream" do
|
|
10
|
+
{ :get => "/model/12/field/stream" }.should route_to(:controller => 'active_metadata/stream', :action => 'index', :model_name => 'model', :model_id => '12',
|
|
11
|
+
:field_name =>'field')
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
end
|
data/spec/spec_helper.rb
CHANGED
|
@@ -1,36 +1,18 @@
|
|
|
1
1
|
# encoding: utf-8
|
|
2
2
|
require 'rubygems'
|
|
3
|
-
require "rails/all"
|
|
4
|
-
require "logger"
|
|
5
|
-
require 'rspec/core'
|
|
6
|
-
require "sqlite3"
|
|
7
|
-
require "rack/test/uploaded_file"
|
|
8
|
-
require 'active_support/cache'
|
|
9
3
|
|
|
10
|
-
|
|
11
|
-
gemfile = File.expand_path('../Gemfile', __FILE__)
|
|
4
|
+
ENV["RAILS_ENV"] ||= 'test'
|
|
12
5
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
rescue Bundler::GemNotFound => e
|
|
18
|
-
STDERR.puts e.message
|
|
19
|
-
STDERR.puts "Try running `bundle install`."
|
|
20
|
-
exit!
|
|
21
|
-
end if File.exist?(gemfile)
|
|
6
|
+
require 'rails/all'
|
|
7
|
+
require 'active_metadata'
|
|
8
|
+
require 'rack/test/uploaded_file'
|
|
9
|
+
require File.expand_path("../dummy/config/environment.rb", __FILE__)
|
|
22
10
|
|
|
23
|
-
|
|
24
|
-
|
|
11
|
+
ENGINE_RAILS_ROOT=File.join(File.dirname(__FILE__), '../')
|
|
12
|
+
Dir[File.join(ENGINE_RAILS_ROOT, "spec/support/**/*.rb")].each {|f| require f }
|
|
13
|
+
|
|
14
|
+
require 'rspec/rails'
|
|
25
15
|
|
|
26
|
-
ActiveRecord::Base.establish_connection YAML.load_file("config/database.yml")[ENV["RAILS_ENV"]]
|
|
27
|
-
ActiveRecord::Base.logger = Logger.new "log/test.log"
|
|
28
|
-
Rails.logger = ActiveRecord::Base.logger
|
|
29
|
-
RAILS_CACHE = ActiveSupport::Cache::MemoryStore.new
|
|
30
|
-
|
|
31
|
-
# loading ruby files
|
|
32
|
-
require "#{File.dirname(__FILE__)}/../lib/engine.rb"
|
|
33
|
-
Dir["spec/support/*.rb"].each {|f| require "support/#{(File.basename(f, File.extname(f)) )}"}
|
|
34
16
|
|
|
35
17
|
RSpec.configure do |config|
|
|
36
18
|
# == Mock Framework
|
|
@@ -53,14 +35,19 @@ RSpec.configure do |config|
|
|
|
53
35
|
|
|
54
36
|
config.before(:each) do
|
|
55
37
|
Document.delete_all
|
|
56
|
-
Note.delete_all
|
|
57
|
-
Watcher.delete_all
|
|
58
|
-
Attachment.delete_all
|
|
59
|
-
History.delete_all
|
|
38
|
+
ActiveMetadata::Note.delete_all
|
|
39
|
+
ActiveMetadata::Watcher.delete_all
|
|
40
|
+
ActiveMetadata::Attachment.delete_all
|
|
41
|
+
ActiveMetadata::History.delete_all
|
|
60
42
|
FileUtils.remove_dir File.expand_path('public/system/') if Dir.exist?(File.expand_path('public/system/'))
|
|
61
43
|
end
|
|
62
44
|
|
|
63
45
|
config.after(:suite) do
|
|
64
46
|
# seems that closing the established connection isn't really necessary
|
|
65
47
|
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def test_pdf name='pdf_test'
|
|
51
|
+
doc = File.expand_path("../support/#{name}.pdf", __FILE__)
|
|
52
|
+
Rack::Test::UploadedFile.new(doc, "application/pdf")
|
|
66
53
|
end
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
require "spec_helper"
|
|
2
|
+
|
|
3
|
+
describe ActiveMetadata::Streamable do
|
|
4
|
+
|
|
5
|
+
describe "module" do
|
|
6
|
+
|
|
7
|
+
it "should respond to stream_for" do
|
|
8
|
+
ActiveMetadata::Streamable.instance_eval do
|
|
9
|
+
self.instance_methods.grep(/stream_for/).size.should == 1
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
describe "stream_for" do
|
|
16
|
+
|
|
17
|
+
context "given 2 notes and 2 attachments" do
|
|
18
|
+
|
|
19
|
+
before(:each) do
|
|
20
|
+
@document = Document.create! { |d| d.name = "John" }
|
|
21
|
+
@document.reload
|
|
22
|
+
|
|
23
|
+
(1..2).each do |i|
|
|
24
|
+
@document.save_attachment_for(:name,test_pdf("pdf_test_#{i}"))
|
|
25
|
+
@document.create_note_for(:name, "note_#{i}")
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
describe "stream_collect_method" do
|
|
30
|
+
|
|
31
|
+
it "should return notes_for for Note class" do
|
|
32
|
+
@document.send(:stream_collect_method, :note).should eq 'notes_for'
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
it "should return attachments_for for attachment class" do
|
|
36
|
+
@document.send(:stream_collect_method, :attachment).should eq 'attachments_for'
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
describe "collect_data" do
|
|
42
|
+
|
|
43
|
+
it "should exists as private method" do
|
|
44
|
+
ActiveMetadata::Streamable.instance_eval do
|
|
45
|
+
self.private_instance_methods.grep(/collect_stream_data/).size.should == 1
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
it "should return an array" do
|
|
50
|
+
res = @document.send(:collect_stream_data, :name)
|
|
51
|
+
res.should be_kind_of Array
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
it "should return an array containing notes and attachments" do
|
|
55
|
+
res = @document.send(:collect_stream_data,:name)
|
|
56
|
+
res.size.should == 4
|
|
57
|
+
all_items_returened(res).should be_true
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
it "should return only the items referring to the request field" do
|
|
61
|
+
@document.save_attachment_for(:surname,test_pdf("pdf_test_1"))
|
|
62
|
+
@document.create_note_for(:surname, "surname note")
|
|
63
|
+
res = @document.send(:collect_stream_data, :name)
|
|
64
|
+
res.size.should == 4
|
|
65
|
+
all_items_returened(res).should be_true
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
describe "sort_stream" do
|
|
71
|
+
|
|
72
|
+
it "should exists as private method" do
|
|
73
|
+
ActiveMetadata::Streamable.instance_eval do
|
|
74
|
+
self.private_instance_methods.grep(/sort_stream/).size.should == 1
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
it "should sort the stream data by updated_at DESC by default" do
|
|
80
|
+
@document.save_attachment_for(:surname,test_pdf("pdf_test_1"))
|
|
81
|
+
sleep 2.seconds
|
|
82
|
+
@document.create_note_for(:surname, "surname note")
|
|
83
|
+
sleep 2.seconds
|
|
84
|
+
@document.save_attachment_for(:surname,test_pdf("pdf_test_2"))
|
|
85
|
+
|
|
86
|
+
stream = @document.send(:collect_stream_data, :surname)
|
|
87
|
+
res = @document.send(:sort_stream, stream)
|
|
88
|
+
|
|
89
|
+
res[0].attach_file_name.should eq 'pdf_test_2.pdf'
|
|
90
|
+
res[1].note.should eq 'surname note'
|
|
91
|
+
res[2].attach_file_name.should eq 'pdf_test_1.pdf'
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
describe "stream_for" do
|
|
97
|
+
|
|
98
|
+
it "should stream" do
|
|
99
|
+
res = @document.stream_for :name
|
|
100
|
+
res.size.should == 4
|
|
101
|
+
all_items_returened(res).should be_true
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
# test that the res array contains the 4 elements created in this context
|
|
107
|
+
def all_items_returened res
|
|
108
|
+
return false unless res.dup.keep_if{|item| item.respond_to?(:note) && item.note == 'note_1'}.count == 1
|
|
109
|
+
return false unless res.dup.keep_if{|item| item.respond_to?(:note) && item.note == 'note_2'}.count == 1
|
|
110
|
+
return false unless res.dup.keep_if{|item| item.respond_to?(:attach_file_name) && item.attach_file_name == 'pdf_test_1.pdf'}.count == 1
|
|
111
|
+
return false unless res.dup.keep_if{|item| item.respond_to?(:attach_file_name) && item.attach_file_name == 'pdf_test_2.pdf'}.count == 1
|
|
112
|
+
true
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
end
|
data/spec/support/document.rb
CHANGED
|
Binary file
|
data/spec/support/section.rb
CHANGED
data/spec/support/user.rb
CHANGED