acts_as_scribe 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -0
- data/MIT-LICENSE +20 -0
- data/README.markdown +80 -0
- data/Rakefile +51 -0
- data/VERSION.yml +4 -0
- data/acts_as_scribe.gemspec +65 -0
- data/features/scribe.feature +26 -0
- data/features/steps/scribe_steps.rb +19 -0
- data/features/support/env.rb +24 -0
- data/generators/acts_as_scribe_migration/USAGE +8 -0
- data/generators/acts_as_scribe_migration/acts_as_scribe_migration_generator.rb +13 -0
- data/generators/acts_as_scribe_migration/templates/migration.rb +19 -0
- data/init.rb +1 -0
- data/lib/activity.rb +44 -0
- data/lib/acts_as_scribe.rb +4 -0
- data/lib/scribe.rb +54 -0
- data/spec/factories.rb +14 -0
- data/spec/models.rb +20 -0
- data/spec/models/activity_spec.rb +73 -0
- data/spec/schema.rb +24 -0
- data/spec/spec.opts +4 -0
- data/spec/spec_helper.rb +19 -0
- metadata +82 -0
data/.gitignore
ADDED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2008 Linking Paths (http://www.linkingpaths.com)
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.markdown
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
ActsAsScribe
|
2
|
+
============
|
3
|
+
A simple plugin that allows to keep history records of the users activities. Common uses could be user's wall, public timeline portlets, etc...
|
4
|
+
|
5
|
+
> Scribe (From Wikipedia, the free encyclopedia):
|
6
|
+
"A scribe was traditionally a person who could read and write. This usually indicated secretarial and administrative duties such as dictation and keeping business, judicial, and history records for kings, nobles, temples, and cities."
|
7
|
+
|
8
|
+
Resources
|
9
|
+
=========
|
10
|
+
|
11
|
+
Install
|
12
|
+
-------
|
13
|
+
|
14
|
+
* Run the following command:
|
15
|
+
|
16
|
+
`script/plugin install git://github.com/linkingpaths/acts_as_scribe.git`
|
17
|
+
|
18
|
+
* Generate the tables via the given generator:
|
19
|
+
|
20
|
+
`script/generate acts_as_scribe_migration`
|
21
|
+
|
22
|
+
* And finally...
|
23
|
+
|
24
|
+
`rake db:migrate`
|
25
|
+
|
26
|
+
Record activities in your models
|
27
|
+
---------------------------------------------
|
28
|
+
|
29
|
+
<pre>
|
30
|
+
class Comment < ActiveRecord::Base
|
31
|
+
record_activity_of :user
|
32
|
+
end
|
33
|
+
</pre>
|
34
|
+
You can use any association that is related to an user:
|
35
|
+
<pre>
|
36
|
+
class Post < ActiveRecord::Base
|
37
|
+
belongs_to :author, :class_name => "User"
|
38
|
+
record_activity_of :author
|
39
|
+
end
|
40
|
+
</pre>
|
41
|
+
|
42
|
+
This will register automatically a new activity when you create or destroy a new record. If you want control over the activities registration based on your model's state just use the :if option
|
43
|
+
|
44
|
+
<pre>
|
45
|
+
class Post < ActiveRecord::Base
|
46
|
+
belongs_to :author, :class_name => "User"
|
47
|
+
record_activity_of :author, :if => Proc.new { |post| post.private == false }
|
48
|
+
end
|
49
|
+
</pre>
|
50
|
+
|
51
|
+
|
52
|
+
Record activities without related item
|
53
|
+
--------------------------------------
|
54
|
+
|
55
|
+
If you want to record activities not related to any specific model just use `Activity.report` in your code:
|
56
|
+
<pre>
|
57
|
+
def grant_admin(user)
|
58
|
+
user.admin = true
|
59
|
+
Activity.report(current_user, :grant_admin, user)
|
60
|
+
end
|
61
|
+
</pre>
|
62
|
+
If the action is not related to any item, just don't use it.
|
63
|
+
<pre>
|
64
|
+
def login
|
65
|
+
current_user = User.find(…)
|
66
|
+
Activity.report(current_user, :login)
|
67
|
+
end
|
68
|
+
</pre>
|
69
|
+
|
70
|
+
|
71
|
+
|
72
|
+
More
|
73
|
+
-------
|
74
|
+
|
75
|
+
[http://github.com/linkingpaths/acts\_as\_scribe](http://github.com/linkingpaths/acts_as_scribe)
|
76
|
+
|
77
|
+
[http://github.com/linkingpaths/acts\_as\_scribe/wikis](http://github.com/linkingpaths/acts_as_scribe/wikis)
|
78
|
+
|
79
|
+
|
80
|
+
Copyright (c) 2008 Linking Paths, released under the MIT license
|
data/Rakefile
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'rake'
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'jeweler'
|
5
|
+
Jeweler::Tasks.new do |s|
|
6
|
+
s.name = "acts_as_scribe"
|
7
|
+
s.summary = %Q{A simple plugin that allows to keep track of the users activity. Common uses could be user's wall, public timeline portlets, etc...}
|
8
|
+
s.email = "aitor@linkingpaths.com"
|
9
|
+
s.homepage = "http://github.com/linkingpaths/acts_as_scribe"
|
10
|
+
s.description = "A simple plugin that allows to keep track of the users activity. Common uses could be user's wall, public timeline portlets, etc..."
|
11
|
+
s.authors = ["Linking Paths", "Aitor García", "Roberto Salicio"]
|
12
|
+
end
|
13
|
+
rescue LoadError
|
14
|
+
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
15
|
+
end
|
16
|
+
|
17
|
+
require 'rake/rdoctask'
|
18
|
+
Rake::RDocTask.new do |rdoc|
|
19
|
+
rdoc.rdoc_dir = 'rdoc'
|
20
|
+
rdoc.title = 'acts_as_scribe'
|
21
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
22
|
+
rdoc.rdoc_files.include('README*')
|
23
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
24
|
+
end
|
25
|
+
|
26
|
+
require 'rake/testtask'
|
27
|
+
Rake::TestTask.new(:test) do |t|
|
28
|
+
t.libs << 'lib' << 'test'
|
29
|
+
t.pattern = 'test/**/*_test.rb'
|
30
|
+
t.verbose = false
|
31
|
+
end
|
32
|
+
|
33
|
+
begin
|
34
|
+
require 'rcov/rcovtask'
|
35
|
+
Rcov::RcovTask.new do |t|
|
36
|
+
t.libs << 'test'
|
37
|
+
t.test_files = FileList['test/**/*_test.rb']
|
38
|
+
t.verbose = true
|
39
|
+
end
|
40
|
+
rescue LoadError
|
41
|
+
puts "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
42
|
+
end
|
43
|
+
|
44
|
+
begin
|
45
|
+
require 'cucumber/rake/task'
|
46
|
+
Cucumber::Rake::Task.new(:features)
|
47
|
+
rescue LoadError
|
48
|
+
puts "Cucumber is not available. In order to run features, you must: sudo gem install cucumber"
|
49
|
+
end
|
50
|
+
|
51
|
+
task :default => :test
|
data/VERSION.yml
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{acts_as_scribe}
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Linking Paths", "Aitor Garc\303\255a", "Roberto Salicio"]
|
12
|
+
s.date = %q{2009-12-23}
|
13
|
+
s.description = %q{A simple plugin that allows to keep track of the users activity. Common uses could be user's wall, public timeline portlets, etc...}
|
14
|
+
s.email = %q{aitor@linkingpaths.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"README.markdown"
|
17
|
+
]
|
18
|
+
s.files = [
|
19
|
+
".gitignore",
|
20
|
+
"MIT-LICENSE",
|
21
|
+
"README.markdown",
|
22
|
+
"Rakefile",
|
23
|
+
"VERSION.yml",
|
24
|
+
"acts_as_scribe.gemspec",
|
25
|
+
"features/scribe.feature",
|
26
|
+
"features/steps/scribe_steps.rb",
|
27
|
+
"features/support/env.rb",
|
28
|
+
"generators/acts_as_scribe_migration/USAGE",
|
29
|
+
"generators/acts_as_scribe_migration/acts_as_scribe_migration_generator.rb",
|
30
|
+
"generators/acts_as_scribe_migration/templates/migration.rb",
|
31
|
+
"init.rb",
|
32
|
+
"lib/activity.rb",
|
33
|
+
"lib/acts_as_scribe.rb",
|
34
|
+
"lib/scribe.rb",
|
35
|
+
"spec/factories.rb",
|
36
|
+
"spec/models.rb",
|
37
|
+
"spec/models/activity_spec.rb",
|
38
|
+
"spec/schema.rb",
|
39
|
+
"spec/spec.opts",
|
40
|
+
"spec/spec_helper.rb"
|
41
|
+
]
|
42
|
+
s.homepage = %q{http://github.com/linkingpaths/acts_as_scribe}
|
43
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
44
|
+
s.require_paths = ["lib"]
|
45
|
+
s.rubygems_version = %q{1.3.5}
|
46
|
+
s.summary = %q{A simple plugin that allows to keep track of the users activity. Common uses could be user's wall, public timeline portlets, etc...}
|
47
|
+
s.test_files = [
|
48
|
+
"spec/spec_helper.rb",
|
49
|
+
"spec/models/activity_spec.rb",
|
50
|
+
"spec/factories.rb",
|
51
|
+
"spec/schema.rb",
|
52
|
+
"spec/models.rb"
|
53
|
+
]
|
54
|
+
|
55
|
+
if s.respond_to? :specification_version then
|
56
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
57
|
+
s.specification_version = 3
|
58
|
+
|
59
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
60
|
+
else
|
61
|
+
end
|
62
|
+
else
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
@@ -0,0 +1,26 @@
|
|
1
|
+
Feature: Activity Streams
|
2
|
+
In order to represent activity streams
|
3
|
+
As a developer
|
4
|
+
I want to bea able to add activity registration hooks on the AR models
|
5
|
+
|
6
|
+
Scenario: Action executed by actor
|
7
|
+
Given I'm a user
|
8
|
+
When I create a membership
|
9
|
+
Then a new activity should be reported
|
10
|
+
And the activity should be related to me
|
11
|
+
|
12
|
+
# USE CASES
|
13
|
+
#
|
14
|
+
# [ACTOR-S] [ACTION] [OBJECT]
|
15
|
+
#
|
16
|
+
# Obie Fernandez escribió una nueva nota.
|
17
|
+
# Obie Fernandez y Steven Bustos son amigos.
|
18
|
+
# Manuel Gonzalez Noriega se ha hecho fan de Monkey Island.
|
19
|
+
# Manuel Gonzalez Noriega se ha unido al grupo Do you poken?
|
20
|
+
# Obie Fernandez y Rogelio J. Samour ahora son amigos(as) gracias a "Personas que quizá conozcas".
|
21
|
+
# Obie Fernandez posted “Rane and Serano (instead of working)."
|
22
|
+
# Angela Lerma se hizo fan de "Soy 100% Colombiano!"
|
23
|
+
# Obie Fernandez subió desde el móvil una foto
|
24
|
+
# Obie Fernandez [puso su status a] "is crazy for staying up this late."
|
25
|
+
# Fulano ha compartido el post 'De Fulanos y Menganos' con el grupo 'Futaneros'
|
26
|
+
# Aitor ha jugado un partido +3 en el campo 'meaztegi'
|
@@ -0,0 +1,19 @@
|
|
1
|
+
Given /^I'm a user$/ do
|
2
|
+
@me = Factory :user
|
3
|
+
end
|
4
|
+
|
5
|
+
When /^I create a membership$/ do
|
6
|
+
@creating_membership = lambda do
|
7
|
+
@membership = Factory :membership, :user => @me
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
Then /^a new activity should be reported$/ do
|
12
|
+
@creating_membership.should change(Activity, :count).by(1)
|
13
|
+
end
|
14
|
+
Then /^the activity should be related to me$/ do
|
15
|
+
acts = Activity.by_item(@membership)
|
16
|
+
acts.should have(1).things
|
17
|
+
acts.first.user.should == @me
|
18
|
+
end
|
19
|
+
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
gem 'activerecord'
|
3
|
+
require 'active_record'
|
4
|
+
require 'factory_girl'
|
5
|
+
require 'redgreen'
|
6
|
+
require 'spec'
|
7
|
+
|
8
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__) + '/../../lib')
|
9
|
+
require 'acts_as_scribe'
|
10
|
+
require 'activity'
|
11
|
+
|
12
|
+
ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :dbfile => ":memory:")
|
13
|
+
load(File.dirname(__FILE__) + "/../../spec/schema.rb")
|
14
|
+
load(File.dirname(__FILE__) + "/../../spec/models.rb")
|
15
|
+
|
16
|
+
|
17
|
+
require 'test/unit/assertions'
|
18
|
+
|
19
|
+
World do |world|
|
20
|
+
|
21
|
+
world.extend(Test::Unit::Assertions)
|
22
|
+
|
23
|
+
world
|
24
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
Description:
|
2
|
+
The migration generator creates a migration to add the activities table to your database and takes no arguments.
|
3
|
+
|
4
|
+
Example:
|
5
|
+
./script/generate acts_as_scribe_migration
|
6
|
+
|
7
|
+
Migration: db/migrate/add_activities_table.rb
|
8
|
+
The Activity model lives in the lib directory of this plugin. You can move that model into your models directory and modify it if you like.
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class ActsAsScribeMigration < ActiveRecord::Migration
|
2
|
+
|
3
|
+
def self.up
|
4
|
+
create_table :activities do |t|
|
5
|
+
t.integer :user_id
|
6
|
+
t.string :action
|
7
|
+
t.integer :item_id
|
8
|
+
t.string :item_type
|
9
|
+
t.timestamps
|
10
|
+
end
|
11
|
+
add_index :activities, [:item_type, :item_id]
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.down
|
15
|
+
remove_index :activities, [:item_type, :item_id]
|
16
|
+
drop_table :activities
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'acts_as_scribe'
|
data/lib/activity.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
class Activity < ActiveRecord::Base
|
2
|
+
named_scope :by_user, lambda { |users|
|
3
|
+
{ :conditions => { :user_id => users}}
|
4
|
+
}
|
5
|
+
|
6
|
+
named_scope :by_action, lambda { |action|
|
7
|
+
{ :conditions => { :action => action.to_s }}
|
8
|
+
}
|
9
|
+
|
10
|
+
named_scope :by_item, lambda { |item|
|
11
|
+
{ :conditions => { :item_type => item.class.name, :item_id => item.id }}
|
12
|
+
}
|
13
|
+
|
14
|
+
named_scope :created_since, lambda { |time_ago|
|
15
|
+
{ :conditions => ['created_at > ?', time_ago]}
|
16
|
+
}
|
17
|
+
|
18
|
+
|
19
|
+
belongs_to :user
|
20
|
+
belongs_to :item, :polymorphic => true
|
21
|
+
validates_presence_of :user_id
|
22
|
+
|
23
|
+
def self.created_by(user)
|
24
|
+
raise "Activity.created_by(user) has been deprecated. Use Activity.by_user(user) instead."
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.without_model_created_by(user)
|
28
|
+
raise "Activity.without_model_created_by(user) has been deprecated. Use Activity.by_user(user) and filter the results instead."
|
29
|
+
end
|
30
|
+
|
31
|
+
def without_model?
|
32
|
+
item.nil?
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.report(user, action, object=nil)
|
36
|
+
returning Activity.new do |a|
|
37
|
+
a.item = object if object
|
38
|
+
a.action = action.to_s
|
39
|
+
a.user = user
|
40
|
+
a.save!
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
data/lib/scribe.rb
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
module LinkingPaths
|
2
|
+
module Acts #:nodoc:
|
3
|
+
module Scribe #:nodoc:
|
4
|
+
|
5
|
+
def self.included(base) # :nodoc:
|
6
|
+
base.extend ClassMethods
|
7
|
+
end
|
8
|
+
|
9
|
+
module ClassMethods
|
10
|
+
activity_options ||= {}
|
11
|
+
|
12
|
+
def record_activity_of(actor, options = {})
|
13
|
+
include_scribe_instance_methods {
|
14
|
+
has_many :activities, :as => :item, :dependent => :destroy
|
15
|
+
after_create do |record|
|
16
|
+
unless options[:if].kind_of?(Proc) and not options[:if].call(record)
|
17
|
+
user = record.send(activity_options[:actor])
|
18
|
+
Activity.report(user, :create, record)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
after_destroy do |record|
|
22
|
+
unless options[:if].kind_of?(Proc) and not options[:if].call(record)
|
23
|
+
user = record.send(activity_options[:actor])
|
24
|
+
Activity.report(user, :destroy, record)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
}
|
28
|
+
self.activity_options.merge! :actor => actor
|
29
|
+
end
|
30
|
+
|
31
|
+
def record_activities(actions = [])
|
32
|
+
raise "record_activities(#{actions.join ','}) has been deprecated. Use Activity.report(user, #{actions.first}), etc. instead."
|
33
|
+
end
|
34
|
+
|
35
|
+
def include_scribe_instance_methods(&block)
|
36
|
+
unless included_modules.include? InstanceMethods
|
37
|
+
yield if block_given?
|
38
|
+
class_inheritable_accessor :activity_options
|
39
|
+
self.activity_options ||= {}
|
40
|
+
include InstanceMethods
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
module InstanceMethods
|
47
|
+
def record_activity(action)
|
48
|
+
raise "record_activity has been deprecated. Use Activity.report(actor, action, item)."
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
data/spec/factories.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
Factory.define :user do |user|
|
2
|
+
end
|
3
|
+
Factory.define :group do |group|
|
4
|
+
end
|
5
|
+
Factory.define :activity do |activity|
|
6
|
+
activity.association :user
|
7
|
+
end
|
8
|
+
Factory.define :membership do |membership|
|
9
|
+
membership.association :user
|
10
|
+
end
|
11
|
+
Factory.define :post do |post|
|
12
|
+
post.private false
|
13
|
+
post.association :author, :factory => :user
|
14
|
+
end
|
data/spec/models.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
class Post < ActiveRecord::Base
|
2
|
+
belongs_to :author, :class_name => "User"
|
3
|
+
record_activity_of :author, :if => Proc.new { |post| post.private == false }
|
4
|
+
end
|
5
|
+
|
6
|
+
|
7
|
+
class Membership < ActiveRecord::Base
|
8
|
+
belongs_to :user
|
9
|
+
belongs_to :group
|
10
|
+
record_activity_of :user
|
11
|
+
end
|
12
|
+
|
13
|
+
class Group < ActiveRecord::Base
|
14
|
+
has_many :users, :through => :memberships
|
15
|
+
end
|
16
|
+
|
17
|
+
class User < ActiveRecord::Base
|
18
|
+
has_many :groups, :through => :memberships
|
19
|
+
end
|
20
|
+
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe "Activity" do
|
4
|
+
|
5
|
+
describe "when creating an instance of a model with a actor != user" do
|
6
|
+
before do
|
7
|
+
@p = Factory :post
|
8
|
+
@act = Activity.last
|
9
|
+
end
|
10
|
+
it "should find the created activity by the user" do
|
11
|
+
@act.user.should == @p.author
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "when creating an instance of a model with a :if option" do
|
16
|
+
before do
|
17
|
+
@p = Factory(:post, :private => true)
|
18
|
+
end
|
19
|
+
it "should not create the activity" do
|
20
|
+
Activity.by_item(@p).should have(0).things
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "when creating a new instance of a tracked model" do
|
25
|
+
before do
|
26
|
+
@m = Factory :membership
|
27
|
+
@act = Activity.last
|
28
|
+
end
|
29
|
+
it "should find the created activity by the user" do
|
30
|
+
Activity.by_user(@m.user).should include(@act)
|
31
|
+
end
|
32
|
+
it "should find the created activity by an users list" do
|
33
|
+
Activity.by_user([@m.user, Factory(:user)]).should include(@act)
|
34
|
+
end
|
35
|
+
it "should find the created activity by the action" do
|
36
|
+
Activity.by_action(:create).should include(@act)
|
37
|
+
end
|
38
|
+
it "should find the created activity by the item" do
|
39
|
+
Activity.by_item(@m).should include(@act)
|
40
|
+
end
|
41
|
+
it "should find the created activity by the creation date" do
|
42
|
+
Activity.created_since(5.second.ago).should include(@act)
|
43
|
+
end
|
44
|
+
it "should be related to an user" do
|
45
|
+
@act.should respond_to(:user)
|
46
|
+
end
|
47
|
+
it "should be related to an item" do
|
48
|
+
@act.should respond_to(:item)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe "when destroying an instance of a tracked model" do
|
53
|
+
before do
|
54
|
+
Factory(:membership).destroy
|
55
|
+
@act = Activity.last
|
56
|
+
end
|
57
|
+
it "should find the created activity by the action" do
|
58
|
+
Activity.by_action(:destroy).should include(@act)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe "when reporting a specific action" do
|
63
|
+
it "should create a new activity" do
|
64
|
+
lambda {
|
65
|
+
Activity.report(Factory(:user), :grant_admin, Factory(:group))
|
66
|
+
}.should change(Activity, :count).by(1)
|
67
|
+
end
|
68
|
+
it "should allow to report actions without a item" do
|
69
|
+
Activity.report(Factory(:user), :login)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
data/spec/schema.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
ActiveRecord::Schema.define(:version => 1) do
|
2
|
+
create_table :activities do |t|
|
3
|
+
t.integer :user_id
|
4
|
+
t.string :action
|
5
|
+
t.integer :item_id
|
6
|
+
t.string :item_type
|
7
|
+
t.timestamps
|
8
|
+
end
|
9
|
+
create_table :users do |t|
|
10
|
+
t.string :login
|
11
|
+
end
|
12
|
+
create_table :groups do |t|
|
13
|
+
t.string :name
|
14
|
+
end
|
15
|
+
create_table :memberships do |t|
|
16
|
+
t.integer :user_id
|
17
|
+
t.integer :group_id
|
18
|
+
end
|
19
|
+
create_table :posts do |t|
|
20
|
+
t.integer :author_id
|
21
|
+
t.boolean :private
|
22
|
+
t.string :title
|
23
|
+
end
|
24
|
+
end
|
data/spec/spec.opts
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
gem 'activerecord'
|
3
|
+
require 'active_record'
|
4
|
+
require 'factory_girl'
|
5
|
+
require 'spec'
|
6
|
+
|
7
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib')
|
8
|
+
require 'acts_as_scribe'
|
9
|
+
require 'activity'
|
10
|
+
|
11
|
+
ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :dbfile => ":memory:")
|
12
|
+
load(File.dirname(__FILE__) + "/schema.rb")
|
13
|
+
load(File.dirname(__FILE__) + "/models.rb")
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
Spec::Runner.configure do |config|
|
18
|
+
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: acts_as_scribe
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Linking Paths
|
8
|
+
- "Aitor Garc\xC3\xADa"
|
9
|
+
- Roberto Salicio
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
|
14
|
+
date: 2009-12-23 00:00:00 +01:00
|
15
|
+
default_executable:
|
16
|
+
dependencies: []
|
17
|
+
|
18
|
+
description: A simple plugin that allows to keep track of the users activity. Common uses could be user's wall, public timeline portlets, etc...
|
19
|
+
email: aitor@linkingpaths.com
|
20
|
+
executables: []
|
21
|
+
|
22
|
+
extensions: []
|
23
|
+
|
24
|
+
extra_rdoc_files:
|
25
|
+
- README.markdown
|
26
|
+
files:
|
27
|
+
- .gitignore
|
28
|
+
- MIT-LICENSE
|
29
|
+
- README.markdown
|
30
|
+
- Rakefile
|
31
|
+
- VERSION.yml
|
32
|
+
- acts_as_scribe.gemspec
|
33
|
+
- features/scribe.feature
|
34
|
+
- features/steps/scribe_steps.rb
|
35
|
+
- features/support/env.rb
|
36
|
+
- generators/acts_as_scribe_migration/USAGE
|
37
|
+
- generators/acts_as_scribe_migration/acts_as_scribe_migration_generator.rb
|
38
|
+
- generators/acts_as_scribe_migration/templates/migration.rb
|
39
|
+
- init.rb
|
40
|
+
- lib/activity.rb
|
41
|
+
- lib/acts_as_scribe.rb
|
42
|
+
- lib/scribe.rb
|
43
|
+
- spec/factories.rb
|
44
|
+
- spec/models.rb
|
45
|
+
- spec/models/activity_spec.rb
|
46
|
+
- spec/schema.rb
|
47
|
+
- spec/spec.opts
|
48
|
+
- spec/spec_helper.rb
|
49
|
+
has_rdoc: true
|
50
|
+
homepage: http://github.com/linkingpaths/acts_as_scribe
|
51
|
+
licenses: []
|
52
|
+
|
53
|
+
post_install_message:
|
54
|
+
rdoc_options:
|
55
|
+
- --charset=UTF-8
|
56
|
+
require_paths:
|
57
|
+
- lib
|
58
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: "0"
|
63
|
+
version:
|
64
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: "0"
|
69
|
+
version:
|
70
|
+
requirements: []
|
71
|
+
|
72
|
+
rubyforge_project:
|
73
|
+
rubygems_version: 1.3.5
|
74
|
+
signing_key:
|
75
|
+
specification_version: 3
|
76
|
+
summary: A simple plugin that allows to keep track of the users activity. Common uses could be user's wall, public timeline portlets, etc...
|
77
|
+
test_files:
|
78
|
+
- spec/spec_helper.rb
|
79
|
+
- spec/models/activity_spec.rb
|
80
|
+
- spec/factories.rb
|
81
|
+
- spec/schema.rb
|
82
|
+
- spec/models.rb
|