active_metadata 0.0.2 → 0.1.9
Sign up to get free protection for your applications and to get access to all the features.
- data/app/controllers/active_metadata/attachments_controller.rb +47 -0
- data/app/controllers/active_metadata/histories_controller.rb +16 -0
- data/app/controllers/active_metadata/notes_controller.rb +61 -0
- data/app/controllers/active_metadata/watchers_controller.rb +34 -0
- data/app/helpers/application_helper.rb +2 -0
- data/app/views/active_metadata/attachments/index.html.erb +11 -0
- data/app/views/active_metadata/histories/index.html.erb +5 -0
- data/app/views/active_metadata/notes/_form.html.erb +23 -0
- data/app/views/active_metadata/notes/edit.html.erb +8 -0
- data/app/views/active_metadata/notes/index.html.erb +11 -0
- data/app/views/active_metadata/notes/index.js.erb +1 -0
- data/app/views/active_metadata/notes/show.html.erb +9 -0
- data/app/views/active_metadata/watchers/create.js.erb +1 -0
- data/app/views/active_metadata/watchers/destroy.js.erb +1 -0
- data/app/views/active_metadata/watchers/index.html.erb +5 -0
- data/config/active_metadata.yml +17 -0
- data/config/application.rb +0 -0
- data/config/database.yml +11 -0
- data/config/initializers/inflections.rb +7 -0
- data/config/mongoid.yml +28 -0
- data/config/routes.rb +30 -0
- data/db/development.sqlite3 +0 -0
- data/db/migrate/001_create_document.rb +12 -0
- data/db/migrate/002_add_surname_to_document.rb +9 -0
- data/db/migrate/003_create_section.rb +13 -0
- data/db/migrate/004_create_user.rb +14 -0
- data/db/migrate/005_create_inboxes.rb +19 -0
- data/db/migrate/006_create_alert_message.rb +37 -0
- data/db/migrate/007_create_notes.rb +22 -0
- data/db/migrate/008_create_history.rb +20 -0
- data/db/migrate/009_create_watcher.rb +21 -0
- data/db/migrate/010_create_attachment.rb +26 -0
- data/db/migrate/011_add_created_by_to_histories.rb +10 -0
- data/db/test.sqlite3 +0 -0
- data/features/step_definitions/add_a_user_to_a_watcher_steps.rb +29 -0
- data/features/step_definitions/trigger_alert_on_modify_steps.rb +86 -0
- data/features/supports/file.txt +1 -0
- data/features/supports/initializer.rb +1 -0
- data/features/supports/updated_file.txt +1 -0
- data/features/watchlist/add_a_user_to_a_watcher.feature +19 -0
- data/features/watchlist/trigger_alert_on_modify.feature +90 -0
- data/lib/active_metadata/base.rb +59 -0
- data/lib/active_metadata/persistence/active_record/attachment.rb +42 -0
- data/lib/active_metadata/persistence/active_record/history.rb +22 -0
- data/lib/active_metadata/persistence/active_record/note.rb +45 -0
- data/lib/active_metadata/persistence/active_record/watcher.rb +45 -0
- data/lib/active_metadata/persistence/active_record.rb +26 -0
- data/lib/active_metadata/persistence/mongoid/attachment.rb +45 -0
- data/lib/active_metadata/persistence/mongoid/history.rb +26 -0
- data/lib/active_metadata/persistence/mongoid/note.rb +48 -0
- data/lib/active_metadata/persistence/mongoid/watcher.rb +43 -0
- data/lib/active_metadata/persistence/mongoid.rb +30 -0
- data/lib/active_metadata/persistence/persistence.rb +13 -0
- data/lib/active_metadata/railtie.rb +6 -0
- data/lib/active_metadata/version.rb +1 -1
- data/lib/active_metadata.rb +6 -12
- data/lib/application_controller.rb +28 -0
- data/lib/application_helper.rb +7 -0
- data/lib/engine.rb +29 -0
- data/lib/model/active_record/attachment.rb +18 -0
- data/lib/model/active_record/history.rb +2 -0
- data/lib/model/active_record/note.rb +2 -0
- data/lib/model/active_record/watcher.rb +4 -0
- data/lib/model/mongoid/active_meta.rb +6 -0
- data/lib/model/mongoid/attachment.rb +25 -0
- data/lib/model/mongoid/history.rb +9 -0
- data/lib/model/mongoid/label.rb +14 -0
- data/lib/model/mongoid/note.rb +10 -0
- data/lib/model/mongoid/watcher.rb +24 -0
- data/lib/rails/railties/tasks.rake +8 -0
- data/lib/rake/active_record_tasks.rb +77 -0
- data/lib/rake/task.rb +18 -0
- data/lib/templates/active_metadata.yml +17 -0
- data/lib/templates/active_metadata_migrations +67 -0
- data/lib/templates/mongoid.yml +20 -0
- data/spec/active_metadata_spec.rb +596 -0
- data/spec/benchmark_spec.rb +35 -0
- data/spec/controllers/metadata_controller_spec.rb +14 -0
- data/spec/spec_helper.rb +87 -0
- data/spec/support/document.rb +8 -0
- data/spec/support/pdf_test.pdf +0 -0
- data/spec/support/pdf_test_2.pdf +0 -0
- data/spec/support/section.rb +8 -0
- data/spec/support/user.rb +13 -0
- data/spec/support/watcher_notifier.rb +21 -0
- metadata +201 -19
- data/.gitignore +0 -4
- data/Gemfile +0 -4
- data/Rakefile +0 -1
- data/active_metadata.gemspec +0 -24
@@ -0,0 +1,47 @@
|
|
1
|
+
module ActiveMetadata
|
2
|
+
class AttachmentsController < ApplicationController
|
3
|
+
|
4
|
+
unloadable
|
5
|
+
|
6
|
+
def index
|
7
|
+
@document = eval(params[:model_name]).find params[:model_id]
|
8
|
+
@attachments = @document.attachments_for params[:field_name]
|
9
|
+
respond_to do |format|
|
10
|
+
format.html { render :layout => false}
|
11
|
+
format.xml { render :xml => @histories }
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def create
|
16
|
+
@document = eval(params[:model_name]).find params[:model_id]
|
17
|
+
@document.save_attachment_for(params[:field_name], params[:file])
|
18
|
+
|
19
|
+
#todo: if errors send back the correct answer
|
20
|
+
respond_to do |format|
|
21
|
+
format.js {render :json => {'success' => true}}
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def update
|
26
|
+
@document = eval(params[:model_name]).find params[:model_id]
|
27
|
+
@document.update_attachment_for(params[:field_name],params[:id],params[:file])
|
28
|
+
|
29
|
+
#todo: if errors send back the correct answer
|
30
|
+
respond_to do |format|
|
31
|
+
format.js {render :json => {'success' => true}}
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def destroy
|
36
|
+
@document = eval(params[:model_name]).find params[:model_id]
|
37
|
+
@document.delete_attachment_for(params[:field_name], params[:id])
|
38
|
+
|
39
|
+
#todo: if errors send back the correct answer
|
40
|
+
respond_to do |format|
|
41
|
+
# TODO redirect to index
|
42
|
+
format.js
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module ActiveMetadata
|
2
|
+
class HistoriesController < ApplicationController
|
3
|
+
|
4
|
+
unloadable
|
5
|
+
|
6
|
+
def index
|
7
|
+
@document = eval(params[:model_name]).find params[:model_id]
|
8
|
+
@histories = @document.history_for params[:field_name]
|
9
|
+
respond_to do |format|
|
10
|
+
format.html { render :layout => false}
|
11
|
+
format.xml { render :xml => @histories }
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
module ActiveMetadata
|
2
|
+
class NotesController < ApplicationController
|
3
|
+
|
4
|
+
unloadable
|
5
|
+
|
6
|
+
def index
|
7
|
+
@document = eval(params[:model_name]).find params[:model_id]
|
8
|
+
@notes = @document.notes_for params[:field_name]
|
9
|
+
respond_to do |format|
|
10
|
+
format.html { render :layout => false}
|
11
|
+
format.xml { render :xml => @notes }
|
12
|
+
format.xls { send_data @notes.to_xls_data(:columns => [:note,:created_at], :headers => [:nota,'inserita']), :filename => 'notes.xls' }
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def edit
|
17
|
+
@document = eval(params[:model_name]).find params[:model_id]
|
18
|
+
@note = @document.note_for params[:field_name],params[:id]
|
19
|
+
end
|
20
|
+
|
21
|
+
def show
|
22
|
+
@document = eval(params[:model_name]).find params[:model_id]
|
23
|
+
@note = @document.note_for params[:field_name],params[:id]
|
24
|
+
end
|
25
|
+
|
26
|
+
def create
|
27
|
+
@document = eval(params[:model_name]).find params[:model_id]
|
28
|
+
@document.create_note_for(params[:field_name], params[:note])
|
29
|
+
respond_to do |format|
|
30
|
+
# TODO redirect to edit
|
31
|
+
format.js
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def update
|
36
|
+
@document = eval(params[:model_name]).find params[:model_id]
|
37
|
+
@note = @document.note_for params[:field_name],params[:id]
|
38
|
+
|
39
|
+
respond_to do |format|
|
40
|
+
if @document.update_note(params[:id],params[:note][:note])
|
41
|
+
format.html { redirect_to(active_metadata_show_note_path(@document.class,@document.id,@note.label,@note.id), :notice => 'Note was successfully updated.') }
|
42
|
+
format.xml { head :ok }
|
43
|
+
else
|
44
|
+
format.html { render :action => "edit" }
|
45
|
+
format.xml { render :xml => @note.errors, :status => :unprocessable_entity }
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def destroy
|
51
|
+
@document = eval(params[:model_name]).find params[:model_id]
|
52
|
+
@document.delete_note_for(params[:field_name],params[:id])
|
53
|
+
respond_to do |format|
|
54
|
+
# TODO redirect to index
|
55
|
+
format.js
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module ActiveMetadata
|
2
|
+
class WatchersController < ApplicationController
|
3
|
+
unloadable
|
4
|
+
|
5
|
+
def index
|
6
|
+
@document = eval(params[:model_name]).find params[:model_id]
|
7
|
+
|
8
|
+
@watchers = @document.watchers_for params[:field_name]
|
9
|
+
|
10
|
+
respond_to do |format|
|
11
|
+
format.html { render :layout => false}
|
12
|
+
format.xml { render :xml => @watchers }
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def create
|
17
|
+
@document = eval(params[:model_name]).find params[:model_id]
|
18
|
+
@document.create_watcher_for params[:field_name], User.find(params[:user_id])
|
19
|
+
|
20
|
+
respond_to do |format|
|
21
|
+
format.js
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def destroy
|
26
|
+
@document = eval(params[:model_name]).find params[:model_id]
|
27
|
+
@document.delete_watcher_for params[:field_name], User.find(params[:user_id])
|
28
|
+
respond_to do |format|
|
29
|
+
format.js
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
<ul>
|
2
|
+
<% @attachments.each do |item| %>
|
3
|
+
<li>
|
4
|
+
<%= link_to "File: #{item.attach.original_filename}", item.attach.url %><br/>
|
5
|
+
<%= "Path: #{item.attach.path}"%>
|
6
|
+
<%= "Size: #{item.attach.size}"%>
|
7
|
+
<%= "Updated at: #{item.attach.instance_read(:updated_at)}"%> <br/>
|
8
|
+
<%= link_to "Elimina", active_metadata_destroy_attachment_path(@document.class,@document.id,item.label,item.id), :method => :delete, :remote => true %>
|
9
|
+
</li>
|
10
|
+
<% end %>
|
11
|
+
</ul>
|
@@ -0,0 +1,23 @@
|
|
1
|
+
<%= form_for(@note,:url => active_metadata_update_note_path(@document.class,@document.id,@note.label,@note.id)) do |f| %>
|
2
|
+
|
3
|
+
<% if @document.errors.any? %>
|
4
|
+
<div id = "error_explanation">
|
5
|
+
<h2><%= pluralize(@note.errors.count, "error") %> prohibited this document from being saved:</h2>
|
6
|
+
<ul>
|
7
|
+
<% @note.errors.full_messages.each do |msg| %>
|
8
|
+
<li><%= msg %></li>
|
9
|
+
<% end %>
|
10
|
+
</ul>
|
11
|
+
</div>
|
12
|
+
<% end %>
|
13
|
+
|
14
|
+
<div class = "field">
|
15
|
+
<%= f.label :note %><br/>
|
16
|
+
<%= f.text_field :note %>
|
17
|
+
</div>
|
18
|
+
|
19
|
+
<div class = "actions">
|
20
|
+
<%= f.submit %>
|
21
|
+
</div>
|
22
|
+
|
23
|
+
<% end %>
|
@@ -0,0 +1,11 @@
|
|
1
|
+
<ul>
|
2
|
+
<% @notes.each do |note| %>
|
3
|
+
<li>
|
4
|
+
<b><%= note.note %></b><br/>
|
5
|
+
<%= "Inserita da: #{note.created_by}<br/>" unless note.created_by.nil? %>
|
6
|
+
Il: <%= note.created_at.strftime("%m/%d/%Y at %I:%M:%S") %> <br/>
|
7
|
+
<%= link_to "Edit", active_metadata_edit_note_path(@document.class,@document.id,note.label,note.id) %>
|
8
|
+
<%= link_to "Destroy", active_metadata_destroy_note_path(@document.class,@document.id,note.label,note.id), :method => :delete, :remote => true %>
|
9
|
+
</li>
|
10
|
+
<% end %>
|
11
|
+
</ul>
|
@@ -0,0 +1 @@
|
|
1
|
+
$(".name_notes").html("<%= escape_javascript(render(:partial => 'active_metadata/notes/notes', :locals => { :field_name => 'name' } )) %>");
|
@@ -0,0 +1,9 @@
|
|
1
|
+
<p id="notice"><%= notice %></p>
|
2
|
+
|
3
|
+
<p>
|
4
|
+
<b>Note:</b>
|
5
|
+
<%= @note.note %>
|
6
|
+
</p>
|
7
|
+
|
8
|
+
<%= link_to "Edit", active_metadata_edit_note_path(@document.class,@document.id,@note.label,@note.id) %>|
|
9
|
+
<%= link_to 'Back', active_metadata_notes_path(@document.class,@document.id,@note.label) %>
|
@@ -0,0 +1 @@
|
|
1
|
+
alert('Watcher created');
|
@@ -0,0 +1 @@
|
|
1
|
+
alert('Watcher deleted');
|
@@ -0,0 +1,17 @@
|
|
1
|
+
development:
|
2
|
+
persists_with: "active_record"
|
3
|
+
history_skip_fields:
|
4
|
+
- 'id'
|
5
|
+
- 'created_at'
|
6
|
+
- 'updated_at'
|
7
|
+
attachment_base_path: "public/system/metadata_attachments"
|
8
|
+
attachment_base_url: "/system/metadata_attachments"
|
9
|
+
|
10
|
+
test:
|
11
|
+
persists_with: "active_record"
|
12
|
+
history_skip_fields:
|
13
|
+
- 'id'
|
14
|
+
- 'created_at'
|
15
|
+
- 'updated_at'
|
16
|
+
attachment_base_path: "public/system/metadata_attachments"
|
17
|
+
attachment_base_url: "/system/metadata_attachments"
|
File without changes
|
data/config/database.yml
ADDED
data/config/mongoid.yml
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
development:
|
2
|
+
host: localhost
|
3
|
+
database: metadata_d
|
4
|
+
max_retries_on_connection_failure: 50
|
5
|
+
|
6
|
+
test:
|
7
|
+
hosts:
|
8
|
+
- - localhost
|
9
|
+
- 27017
|
10
|
+
- - localhost
|
11
|
+
- 27018
|
12
|
+
- - localhost
|
13
|
+
- 27019
|
14
|
+
database: metadata_t
|
15
|
+
max_retries_on_connection_failure: 50
|
16
|
+
|
17
|
+
# set these environment variables on your prod server
|
18
|
+
production:
|
19
|
+
host: <%= ENV['MONGOID_HOST'] %>
|
20
|
+
port: <%= ENV['MONGOID_PORT'] %>
|
21
|
+
username: <%= ENV['MONGOID_USERNAME'] %>
|
22
|
+
password: <%= ENV['MONGOID_PASSWORD'] %>
|
23
|
+
database: <%= ENV['MONGOID_DATABASE'] %>
|
24
|
+
# slaves:
|
25
|
+
# - host: slave1.local
|
26
|
+
# port: 27018
|
27
|
+
# - host: slave2.local
|
28
|
+
# port: 27019
|
data/config/routes.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
Rails.application.routes.draw do
|
2
|
+
|
3
|
+
mount_at = ActiveMetadata::Engine.config.mount_at
|
4
|
+
|
5
|
+
namespace "active_metadata" do
|
6
|
+
#note
|
7
|
+
match ':model_name/:model_id/:field_name/notes' => 'notes#index', :via => :get, :as => "notes", :path_prefix => mount_at
|
8
|
+
match ':model_name/:model_id/:field_name/notes' => 'notes#create', :via => :post, :as => "create_note", :path_prefix => mount_at
|
9
|
+
match ':model_name/:model_id/:field_name/note/:id' => 'notes#destroy', :via => :delete, :as => "destroy_note", :path_prefix => mount_at
|
10
|
+
match ':model_name/:model_id/:field_name/note/:id/edit' => 'notes#edit', :via => :get, :as => "edit_note", :path_prefix => mount_at
|
11
|
+
match ':model_name/:model_id/:field_name/note/:id' => 'notes#update', :via => :put, :as => "update_note", :path_prefix => mount_at
|
12
|
+
match ':model_name/:model_id/:field_name/note/:id' => 'notes#show', :via => :get, :as => "show_note", :path_prefix => mount_at
|
13
|
+
|
14
|
+
#history
|
15
|
+
match ':model_name/:model_id/:field_name/histories' => 'histories#index', :via => :get, :as => "histories", :path_prefix => mount_at
|
16
|
+
|
17
|
+
#attachments
|
18
|
+
match ':model_name/:model_id/:field_name/attachments' => 'attachments#index', :via => :get, :as => "attachments", :path_prefix => mount_at
|
19
|
+
match ':model_name/:model_id/:field_name/attachments' => 'attachments#create', :via => :post, :as => "create_attachment", :path_prefix => mount_at
|
20
|
+
match ':model_name/:model_id/:field_name/attachments/:id' => 'attachments#destroy', :via => :delete, :as => "destroy_attachment", :path_prefix => mount_at
|
21
|
+
match ':model_name/:model_id/:field_name/attachments/:id' => 'attachments#update', :via => :put, :as => "update_attachment", :path_prefix => mount_at
|
22
|
+
|
23
|
+
#alerts
|
24
|
+
get ':model_name/:model_id/:field_name/watchers' => 'watchers#index', :as => "watchers", :path_prefix => mount_at
|
25
|
+
post ':model_name/:model_id/:field_name/watchers/:user_id' => 'watchers#create',:as => "set_watcher", :path_prefix => mount_at
|
26
|
+
delete ':model_name/:model_id/:field_name/watchers/:user_id' => 'watchers#destroy',:as => "unset_watcher", :path_prefix => mount_at
|
27
|
+
# TODO missing routes to notice of a read message
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
Binary file
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class CreateInboxes < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :inboxes do |t|
|
4
|
+
t.string :label
|
5
|
+
t.string :object_class
|
6
|
+
t.integer :object_id
|
7
|
+
t.string :alert_type
|
8
|
+
t.string :old_value
|
9
|
+
t.string :new_value
|
10
|
+
t.text :content
|
11
|
+
t.integer :user_id
|
12
|
+
t.timestamps
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.down
|
17
|
+
drop_table :inboxes
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
class CreateAlertMessage < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
drop_table :inboxes
|
4
|
+
|
5
|
+
create_table :inboxes do |t|
|
6
|
+
t.integer :user_id
|
7
|
+
end
|
8
|
+
|
9
|
+
create_table :alert_messages do |t|
|
10
|
+
t.string :label
|
11
|
+
t.string :model_class
|
12
|
+
t.integer :model_id
|
13
|
+
t.string :alert_type
|
14
|
+
t.text :old_value
|
15
|
+
t.text :new_value
|
16
|
+
t.integer :inbox_id
|
17
|
+
t.boolean :read
|
18
|
+
|
19
|
+
t.timestamps
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.down
|
24
|
+
drop_table :alert_messages
|
25
|
+
create_table :inboxes do |t|
|
26
|
+
t.string :label
|
27
|
+
t.string :object_class
|
28
|
+
t.integer :object_id
|
29
|
+
t.string :alert_type
|
30
|
+
t.string :old_value
|
31
|
+
t.string :new_value
|
32
|
+
t.text :content
|
33
|
+
t.integer :user_id
|
34
|
+
t.timestamps
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
class CreateNotes < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :notes do |t|
|
4
|
+
t.text :note
|
5
|
+
t.string :label
|
6
|
+
t.integer :document_id
|
7
|
+
t.integer :created_by
|
8
|
+
t.integer :updated_by
|
9
|
+
t.timestamps
|
10
|
+
end
|
11
|
+
|
12
|
+
add_index :notes, :document_id
|
13
|
+
add_index :notes, :label
|
14
|
+
add_index :notes, :updated_at
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.down
|
19
|
+
drop_table :notes
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
class CreateHistory < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :histories do |t|
|
4
|
+
t.text :value
|
5
|
+
t.string :label
|
6
|
+
t.integer :document_id
|
7
|
+
t.timestamps
|
8
|
+
end
|
9
|
+
|
10
|
+
add_index :histories, :document_id
|
11
|
+
add_index :histories, :label
|
12
|
+
add_index :histories, :created_at
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.down
|
17
|
+
drop_table :histories
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class CreateWatcher < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :watchers do |t|
|
4
|
+
t.integer :owner_id
|
5
|
+
t.string :label
|
6
|
+
t.integer :document_id
|
7
|
+
t.timestamps
|
8
|
+
end
|
9
|
+
|
10
|
+
add_index :watchers, :document_id
|
11
|
+
add_index :watchers, :label
|
12
|
+
add_index :watchers, :owner_id
|
13
|
+
add_index :watchers, :created_at
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.down
|
18
|
+
drop_table :watchers
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
class CreateAttachment < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :attachments do |t|
|
4
|
+
t.string :label
|
5
|
+
t.integer :document_id
|
6
|
+
t.integer :created_by
|
7
|
+
t.integer :updated_by
|
8
|
+
t.integer :counter
|
9
|
+
t.string :attach_file_name
|
10
|
+
t.string :attach_content_type
|
11
|
+
t.integer :attach_file_size
|
12
|
+
t.datetime :attach_updated_at
|
13
|
+
t.timestamps
|
14
|
+
end
|
15
|
+
|
16
|
+
add_index :attachments, :document_id
|
17
|
+
add_index :attachments, :label
|
18
|
+
add_index :attachments, :attach_updated_at
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.down
|
23
|
+
drop_table :attachments
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
data/db/test.sqlite3
ADDED
Binary file
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
### Background #
|
4
|
+
Given /^an ActiveRecord object instance of 'Document'$/ do
|
5
|
+
raise unless Document.ancestors.include?(::ActiveRecord::Base)
|
6
|
+
@document = Document.create!(:name => 'Fractal', :surname => 'Garden' )
|
7
|
+
end
|
8
|
+
|
9
|
+
Given /^an ActiveRecord object instance of 'User'$/ do
|
10
|
+
raise unless User.ancestors.include?(::ActiveRecord::Base)
|
11
|
+
end
|
12
|
+
|
13
|
+
### Scenarios #
|
14
|
+
Given /^a User "([^"]*)"$/ do |email|
|
15
|
+
@current_user = User.create!(:email => email, :firstname => 'John', :lastname => 'smith' )
|
16
|
+
end
|
17
|
+
|
18
|
+
When /^adding the user to the watcherslist of an attribute "([^"]*)"$/ do |attribute|
|
19
|
+
@attribute = attribute
|
20
|
+
@document.create_watcher_for(@attribute, @current_user)
|
21
|
+
end
|
22
|
+
|
23
|
+
Then /^it should be created a new watcher for that field$/ do
|
24
|
+
@document.watchers_for(@attribute).should_not be_nil
|
25
|
+
end
|
26
|
+
|
27
|
+
Then /^added a user to the list of the watcher$/ do
|
28
|
+
@document.watchers_for(@attribute).first.owner_id.should be == @current_user.id
|
29
|
+
end
|