social_connections 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/Gemfile.lock +14 -0
- data/{README → README.md} +31 -26
- data/lib/app/models/social_activity.rb +20 -5
- data/lib/app/views/digest_mailer/digest.html.erb +27 -1
- data/lib/db/migrate/20110516181115_create_social_connections.rb +3 -0
- data/lib/generators/social_connections/install/install_generator.rb +25 -0
- data/lib/generators/social_connections/install/templates/create_social_connections_tables.rb +27 -0
- data/lib/social_connections/acts_as_connectable.rb +6 -1
- data/lib/social_connections/social_aggregator.rb +26 -3
- data/lib/social_connections/version.rb +1 -1
- data/lib/social_connections.rb +1 -1
- data/lib/tasks/social_connections.rake +1 -0
- data/run-tests.sh +6 -0
- data/spec/activities_aggregator_spec.rb +31 -5
- data/spec/social_activities_spec.rb +37 -33
- data/test/acts_as_connectable_test.rb +3 -1
- data/test/schema.rb +3 -0
- data/test/test_helper.rb +17 -2
- metadata +8 -6
data/.gitignore
CHANGED
data/Gemfile.lock
ADDED
data/{README → README.md}
RENAMED
@@ -1,4 +1,5 @@
|
|
1
|
-
|
1
|
+
SocialConnections
|
2
|
+
=================
|
2
3
|
|
3
4
|
Enables
|
4
5
|
|
@@ -9,59 +10,64 @@ Enables
|
|
9
10
|
This gem is work in progress and my playground, and currently my playground, don't use it!
|
10
11
|
|
11
12
|
|
12
|
-
|
13
|
+
Setup
|
14
|
+
-----
|
13
15
|
|
14
16
|
Install as a gem
|
15
17
|
|
16
|
-
|
18
|
+
gem install social_connections
|
17
19
|
|
18
20
|
or reference in your Gemfile
|
19
21
|
|
20
|
-
|
22
|
+
gem 'social_connections'
|
21
23
|
|
22
24
|
and run
|
23
25
|
|
24
|
-
|
26
|
+
bundle install
|
25
27
|
|
26
28
|
|
27
|
-
Next, you need to add the migration
|
29
|
+
Next, you need to add the migration by using the install generator of the gem:
|
28
30
|
|
29
|
-
|
31
|
+
rails g social_connections:install
|
30
32
|
|
31
|
-
which adds the required
|
33
|
+
which adds the required migration(s). Doing a migration
|
34
|
+
will generate the required tables:
|
35
|
+
|
36
|
+
rake db:migrate
|
32
37
|
|
33
38
|
Now, every model that is supposed to act as a connectable thing (so that friends can connect
|
34
39
|
other friend or users can like books, or similar), add to all those models
|
35
40
|
|
36
|
-
|
41
|
+
acts_as_connectable :verbs => [ :likes, :recommends, :comments ]
|
37
42
|
|
38
43
|
where the verbs specify what you want to allow those connectables to do to other connectables.
|
39
44
|
See the example below, that may make it clearer.
|
40
45
|
|
41
|
-
|
46
|
+
Example
|
47
|
+
-------
|
42
48
|
|
43
49
|
Users can like books, and they can comment on books.
|
44
50
|
|
45
51
|
Enable model User to be connected to other users and things (books, in this example):
|
46
52
|
|
47
|
-
|
53
|
+
acts_as_connectable :verbs => [ :likes, :comments ]
|
48
54
|
|
49
55
|
Given a user `u` and a book `b`, you can now say
|
50
56
|
|
51
|
-
|
57
|
+
u.likes(b)
|
52
58
|
|
53
59
|
and
|
54
60
|
|
55
|
-
|
61
|
+
u.comments(b, :comment => 'awesome book!')
|
56
62
|
|
57
63
|
. This creates activities for the user and the book. These activities can be
|
58
64
|
queried:
|
59
65
|
|
60
|
-
|
66
|
+
b.likes_by_count
|
61
67
|
|
62
68
|
Gives the number of users (or other 'connectables') that liked this book. Same for
|
63
69
|
|
64
|
-
|
70
|
+
b.comments_by_count
|
65
71
|
|
66
72
|
. For more examples, see the spec files.
|
67
73
|
|
@@ -71,31 +77,30 @@ Gives the number of users (or other 'connectables') that liked this book. Same f
|
|
71
77
|
Assuming that `current_user` gives you the currently logged in user, a controller
|
72
78
|
responding to a 'like' button could look as follows:
|
73
79
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
+
class CurrentUserLikesController < ApplicationController
|
81
|
+
def likes_book
|
82
|
+
@book = Book.find(params[:id])
|
83
|
+
current_user.likes(@book) unless current_user.likes?(@book)
|
84
|
+
end
|
85
|
+
end
|
80
86
|
|
81
87
|
A route in config/routes.rb might then look as follows:
|
82
88
|
|
83
|
-
|
89
|
+
match '/current_user_likes_book/:id' => 'current_user_likes#likes_book', :as => :current_user_likes_book
|
84
90
|
|
85
91
|
The view (e.g. `app/views/books/show.html.erb`) may then contain the following 'like' button:
|
86
92
|
|
87
|
-
|
93
|
+
<%= link_to('I like this', current_user_likes_book_path(@book) %>
|
88
94
|
|
89
95
|
|
90
96
|
== How to run the Tests (in the gem itself, not in your Rails app)
|
91
97
|
|
92
98
|
Run test in ./test:
|
93
99
|
|
94
|
-
|
100
|
+
rake
|
95
101
|
|
96
102
|
Run specs in ./spec:
|
97
103
|
|
98
|
-
|
99
|
-
|
104
|
+
rspec spec
|
100
105
|
|
101
106
|
Copyright (c) 2011 Chris Oloff, released under the MIT license
|
@@ -8,6 +8,15 @@ class SocialActivity < ActiveRecord::Base
|
|
8
8
|
JSON.parse options_as_json
|
9
9
|
end
|
10
10
|
|
11
|
+
def to_s
|
12
|
+
"SocialActivity #{subject} #{verb} #{target} (owned by #{owner})"
|
13
|
+
end
|
14
|
+
|
15
|
+
def consume
|
16
|
+
self.unseen = false
|
17
|
+
self.save
|
18
|
+
end
|
19
|
+
|
11
20
|
def self.create_activities(subject, verb, object, options = {})
|
12
21
|
# TODO: we may want to delay this
|
13
22
|
activities = []
|
@@ -31,17 +40,23 @@ class SocialActivity < ActiveRecord::Base
|
|
31
40
|
end
|
32
41
|
|
33
42
|
def self.unseen_activities(for_whom)
|
34
|
-
SocialActivity.where('owner_id = ? and owner_type = ? and unseen = ?',
|
43
|
+
SocialActivity.where('owner_id = ? and owner_type = ? and unseen = ?',
|
44
|
+
for_whom.id, for_whom.class.name,
|
45
|
+
true).order("created_at DESC")
|
35
46
|
end
|
36
47
|
|
37
48
|
def self.exists(subject, verb, object)
|
38
|
-
SocialActivity.where('subject_id = ? and subject_type = ? and verb = ?
|
39
|
-
|
49
|
+
SocialActivity.where('subject_id = ? and subject_type = ? and verb = ? ' +
|
50
|
+
'and target_id = ? and target_type = ?',
|
51
|
+
subject.id, subject.class.name, verb, object.id,
|
52
|
+
object.class.name).exists?
|
40
53
|
end
|
41
54
|
|
42
55
|
def self.objects_by_verb_count(object, verb)
|
43
|
-
SocialActivity.where('target_id = ? and target_type = ? and verb = ?
|
44
|
-
|
56
|
+
SocialActivity.where('target_id = ? and target_type = ? and verb = ? ' +
|
57
|
+
'and owner_id = ? and owner_type = ?',
|
58
|
+
object.id, object.class.name, verb, object.id,
|
59
|
+
object.class.name).count
|
45
60
|
end
|
46
61
|
|
47
62
|
end
|
@@ -1 +1,27 @@
|
|
1
|
-
<p>
|
1
|
+
<p>Note: This view serves as an example only, please set up your own
|
2
|
+
view at app/views/digest_mailer/digest.html.erb</p>
|
3
|
+
|
4
|
+
<p>Hi, <%= @feed.who %></p>
|
5
|
+
|
6
|
+
<p>You have got <%= pluralize @feed.activities.count, 'activity' %> in total,
|
7
|
+
and
|
8
|
+
<%= pluralize @feed.excluding_self.activities.count, 'activity' %> excluding your own activities.</p>
|
9
|
+
|
10
|
+
<% @feed.excluding_self.by_verb.keys.each do |verb| %>
|
11
|
+
<p>All the <%= verb.to_s %> of those you are connected with:</p>
|
12
|
+
<ul>
|
13
|
+
<% @feed.excluding_self.by_verb[verb].each do |a| %>
|
14
|
+
<li><%= a.to_s %></li>
|
15
|
+
<% end %>
|
16
|
+
</ul>
|
17
|
+
<% end %>
|
18
|
+
|
19
|
+
<p>All activities, including your own ones:</p>
|
20
|
+
<ul>
|
21
|
+
<% @feed.activities.each do |a| %>
|
22
|
+
<li><%= a.to_s %>, <%= time_ago_in_words a.created_at %> ago</li>
|
23
|
+
<% end %>
|
24
|
+
</ul>
|
25
|
+
|
26
|
+
<p>That's all for now...</p>
|
27
|
+
|
@@ -1,10 +1,12 @@
|
|
1
1
|
class CreateSocialConnections < ActiveRecord::Migration
|
2
2
|
def self.up
|
3
|
+
puts "Warning: Migrating via rake is deprecated for social_connections, use 'rails g social_connections:install' instead"
|
3
4
|
create_table :social_connections do |t|
|
4
5
|
t.integer :source_id
|
5
6
|
t.string :source_type
|
6
7
|
t.integer :target_id
|
7
8
|
t.string :target_type
|
9
|
+
t.timestamps
|
8
10
|
end
|
9
11
|
create_table :social_activities do |t|
|
10
12
|
t.integer :owner_id
|
@@ -16,6 +18,7 @@ class CreateSocialConnections < ActiveRecord::Migration
|
|
16
18
|
t.string :verb
|
17
19
|
t.text :options_as_json
|
18
20
|
t.boolean :unseen, :default => true
|
21
|
+
t.timestamps
|
19
22
|
end
|
20
23
|
end
|
21
24
|
def self.down
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'rails/generators/migration'
|
2
|
+
|
3
|
+
module SocialConnections
|
4
|
+
module Generators
|
5
|
+
class InstallGenerator < ::Rails::Generators::Base
|
6
|
+
include Rails::Generators::Migration
|
7
|
+
source_root File.expand_path('../templates', __FILE__)
|
8
|
+
desc "add the migrations"
|
9
|
+
|
10
|
+
def self.next_migration_number(path)
|
11
|
+
unless @prev_migration_nr
|
12
|
+
@prev_migration_nr = Time.now.utc.strftime("%Y%m%d%H%M%S").to_i
|
13
|
+
else
|
14
|
+
@prev_migration_nr += 1
|
15
|
+
end
|
16
|
+
@prev_migration_nr.to_s
|
17
|
+
end
|
18
|
+
|
19
|
+
def copy_migrations
|
20
|
+
migration_template "create_social_connections_tables.rb", "db/migrate/create_social_connections.rb"
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
class CreateSocialConnections < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :social_connections do |t|
|
4
|
+
t.integer :source_id
|
5
|
+
t.string :source_type
|
6
|
+
t.integer :target_id
|
7
|
+
t.string :target_type
|
8
|
+
t.timestamps
|
9
|
+
end
|
10
|
+
create_table :social_activities do |t|
|
11
|
+
t.integer :owner_id
|
12
|
+
t.string :owner_type
|
13
|
+
t.integer :subject_id
|
14
|
+
t.string :subject_type
|
15
|
+
t.integer :target_id
|
16
|
+
t.string :target_type
|
17
|
+
t.string :verb
|
18
|
+
t.text :options_as_json
|
19
|
+
t.boolean :unseen, :default => true
|
20
|
+
t.timestamps
|
21
|
+
end
|
22
|
+
end
|
23
|
+
def self.down
|
24
|
+
drop_table :social_connections
|
25
|
+
drop_table :social_activities
|
26
|
+
end
|
27
|
+
end
|
@@ -31,9 +31,15 @@ module SocialConnections
|
|
31
31
|
c = SocialConnection.new
|
32
32
|
c.target = other
|
33
33
|
c.source = self
|
34
|
+
c.save
|
34
35
|
c
|
35
36
|
end
|
36
37
|
|
38
|
+
def connected_to?(other)
|
39
|
+
SocialConnection.where("source_id = ? and source_type = ? and target_id = ? and target_type = ?",
|
40
|
+
self.id, self.class.name, other.id, other.class.name).exists?
|
41
|
+
end
|
42
|
+
|
37
43
|
def acts_as_connectable_verbs
|
38
44
|
acts_as_connectable_options[:verbs] || [ :likes ]
|
39
45
|
end
|
@@ -43,7 +49,6 @@ module SocialConnections
|
|
43
49
|
end
|
44
50
|
|
45
51
|
def method_missing(name, *args)
|
46
|
-
puts "BLABLA"
|
47
52
|
if acts_as_connectable_verbs.include? name
|
48
53
|
verb = name
|
49
54
|
object = args[0]
|
@@ -1,14 +1,37 @@
|
|
1
1
|
module SocialConnections
|
2
2
|
|
3
|
-
class
|
4
|
-
attr_accessor :activities
|
3
|
+
class AggregatedActivities
|
4
|
+
attr_accessor :activities, :by_verb
|
5
5
|
def initialize(activities)
|
6
6
|
self.activities = activities
|
7
|
+
self.by_verb = activities_by_verb(activities)
|
8
|
+
end
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
def activities_by_verb(activities)
|
13
|
+
by_verb = {}
|
14
|
+
activities.collect {|a| a.verb }.uniq.each do |verb|
|
15
|
+
by_verb[verb.to_sym] = activities.select {|b| b.verb == verb }
|
16
|
+
end
|
17
|
+
by_verb
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
class Feed
|
23
|
+
attr_accessor :who, :activities, :by_verb, :excluding_self
|
24
|
+
def initialize(who)
|
25
|
+
self.who = who
|
26
|
+
self.activities = SocialActivity.unseen_activities(who)
|
27
|
+
aggreg = AggregatedActivities.new(activities)
|
28
|
+
self.by_verb = aggreg.by_verb
|
29
|
+
self.excluding_self = AggregatedActivities.new( activities.select {|a| a.subject != who} )
|
7
30
|
end
|
8
31
|
end
|
9
32
|
|
10
33
|
def self.aggregate(who)
|
11
|
-
Feed.new(
|
34
|
+
Feed.new(who)
|
12
35
|
end
|
13
36
|
|
14
37
|
end
|
data/lib/social_connections.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
require 'social_connections/acts_as_connectable'
|
4
4
|
require 'social_connections/social_aggregator'
|
5
5
|
|
6
|
-
unless ENV['TEST']
|
6
|
+
unless ENV['TEST'] == 'TRUE'
|
7
7
|
class SocialConnectionsTasks < Rails::Railtie
|
8
8
|
rake_tasks do
|
9
9
|
Dir[File.join(File.dirname(__FILE__),'tasks/*.rake')].each { |f| load f }
|
@@ -6,6 +6,7 @@ namespace :db do
|
|
6
6
|
task :social_connections => :environment do
|
7
7
|
ActiveRecord::Migration.verbose = true
|
8
8
|
ActiveRecord::Migrator.migrate(File.join(File.dirname(__FILE__), '../db/migrate/'), ENV['VERSION'] ? ENV['VERSION'].to_i : nil)
|
9
|
+
ActiveSupport::Deprecation.warn "Migration via rake is deprecated, use 'rails generate social_connections:install' instead." # mhm, this doesn't display when migrating...
|
9
10
|
Rake::Task["db:schema:dump"].invoke if ActiveRecord::Base.schema_format == :ruby
|
10
11
|
end
|
11
12
|
end
|
data/run-tests.sh
ADDED
@@ -13,27 +13,53 @@ describe "Aggregation" do
|
|
13
13
|
@tim.comments(@tom, :comment => "This is cool")
|
14
14
|
feed_tim = SocialConnections.aggregate(@tim)
|
15
15
|
feed_tim.activities.count.should be_>(1)
|
16
|
-
feed_tim.activities.each {|a| puts "For Tim: #{a.subject} #{a.verb} #{a.target}, options=#{a.options}"}
|
17
16
|
feed_tom = SocialConnections.aggregate(@tom)
|
18
|
-
feed_tom.activities.each {|a| puts "For Tom: #{a.subject} #{a.verb} #{a.target}, options=#{a.options}"}
|
19
17
|
feed_tom.activities.count.should be_>(1)
|
20
18
|
end
|
21
19
|
|
20
|
+
describe "When Tim and Tom interacted" do
|
21
|
+
|
22
|
+
before(:each) do
|
23
|
+
@tim.likes(@tom)
|
24
|
+
@tim.comments(@tom, :comment => "Got news for you")
|
25
|
+
@tom.comments(@tim, :comment => "What news?")
|
26
|
+
end
|
27
|
+
|
28
|
+
it "aggregates unseen activities only" do
|
29
|
+
feed_tim = SocialConnections.aggregate(@tim)
|
30
|
+
feed_tim.activities.count.should be_>(1)
|
31
|
+
feed_tim.activities.each { |a| a.consume }
|
32
|
+
SocialConnections.aggregate(@tim).activities.count.should be(0)
|
33
|
+
SocialConnections.aggregate(@tom).activities.count.should be_>(0)
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
22
38
|
describe DigestMailer do
|
23
39
|
|
24
40
|
before(:each) do
|
25
41
|
@tim.likes(@tom)
|
26
42
|
@tim.comments(@tom, :comment => "This is boring...")
|
43
|
+
@tom.comments(@tim, :comment => "Maybe boring, but it documents this gem :)")
|
27
44
|
@feed_tim = SocialConnections.aggregate(@tim)
|
28
|
-
@mail = DigestMailer.digest(@feed_tim, @tim.email)
|
45
|
+
@mail = DigestMailer.digest(@feed_tim, @tim.email).deliver
|
46
|
+
end
|
47
|
+
|
48
|
+
it "determines activities and activities by verb" do
|
49
|
+
@feed_tim.activities.count.should eql(3)
|
50
|
+
@feed_tim.by_verb.should_not eql(nil)
|
51
|
+
@feed_tim.by_verb[:comments].count.should eql(2)
|
52
|
+
@feed_tim.by_verb[:likes].count.should eql(1)
|
53
|
+
@feed_tim.by_verb[:recommends].blank?.should be(true)
|
54
|
+
@feed_tim.excluding_self.by_verb[:comments].count.should eql(1)
|
55
|
+
@feed_tim.excluding_self.by_verb[:likes].blank?.should be(true)
|
29
56
|
end
|
30
57
|
|
31
|
-
it "delivers an email
|
58
|
+
it "delivers an email" do
|
32
59
|
@mail.subject.should eq("Digest")
|
33
60
|
@mail.to.should eq(["tim@test.com"])
|
34
61
|
@mail.from.should eq(["from@example.com"])
|
35
62
|
@mail.body.encoded.should match("Hi")
|
36
|
-
pending
|
37
63
|
end
|
38
64
|
|
39
65
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../test/test_helper'
|
2
2
|
|
3
|
-
describe "
|
3
|
+
describe "Social Activities" do
|
4
4
|
|
5
5
|
before(:each) do
|
6
6
|
load_schema
|
@@ -8,71 +8,75 @@ describe "Subjects" do
|
|
8
8
|
@obj = Connectable.create(:name => 'Tom')
|
9
9
|
end
|
10
10
|
|
11
|
-
|
12
|
-
activities = @sub.likes(@obj) # what about the 'owner'? everybody 'connected' to the subject *and*
|
13
|
-
# the object becomes an owner!
|
14
|
-
activities.should_not be_nil
|
15
|
-
activities[0].verb.should eql(:likes)
|
16
|
-
end
|
11
|
+
describe "Subjects" do
|
17
12
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
13
|
+
it "can emit activities" do
|
14
|
+
activities = @sub.likes(@obj) # what about the 'owner'? everybody 'connected' to the subject *and*
|
15
|
+
# the object becomes an owner!
|
16
|
+
activities.should_not be_nil
|
17
|
+
activities[0].verb.should eql(:likes)
|
18
|
+
end
|
23
19
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
20
|
+
it "allow the verbs given, but no other verbs" do
|
21
|
+
@sub.likes(@obj)
|
22
|
+
@sub.recommends(@obj)
|
23
|
+
lambda { @sub.suggests(@obj) }.should raise_error
|
24
|
+
end
|
25
|
+
|
26
|
+
it "know if subject/verb/object occured before" do
|
27
|
+
@sub.likes @obj
|
28
|
+
@sub.likes?(@obj).should be_true
|
29
|
+
@sub.recommends?(@obj).should be_false
|
30
|
+
@sub.recommends @obj
|
31
|
+
@sub.recommends?(@obj).should be_true
|
32
|
+
end
|
33
|
+
|
34
|
+
it "count by how many an object is liked by (or any other verb)" do
|
35
|
+
@obj.likes_by_count.should eql(0)
|
36
|
+
@sub.likes @obj
|
37
|
+
@obj.likes_by_count.should eql(1)
|
38
|
+
end
|
31
39
|
|
32
|
-
it "counts by how many an object is liked by (or any other verb)" do
|
33
|
-
@obj.likes_by_count.should eql(0)
|
34
|
-
@sub.likes @obj
|
35
|
-
@obj.likes_by_count.should eql(1)
|
36
40
|
end
|
37
41
|
|
38
|
-
it "
|
42
|
+
it "allow options on activities (e.g. a comment)" do
|
39
43
|
activities = @sub.comments(@obj, :comment => 'This is a silly comment on Tom')
|
40
44
|
activities[0].options['comment'].should eql('This is a silly comment on Tom')
|
41
45
|
end
|
42
46
|
|
43
|
-
it "
|
47
|
+
it "create an activity for both subject and object" do
|
44
48
|
activities = @sub.likes(@obj)
|
45
49
|
activities.select {|a| a.owner == @sub}.should_not be_empty # one activity owned by the subject
|
46
50
|
activities.select {|a| a.owner == @obj}.should_not be_empty # ... and one owned by the object
|
47
51
|
end
|
48
52
|
|
49
|
-
it "
|
53
|
+
it "create activities for those connected to the subject" do
|
50
54
|
mary = Connectable.create(:name => 'Mary')
|
51
|
-
mary.connect_to(@sub)
|
55
|
+
mary.connect_to(@sub) # mary is now connected to Tim
|
52
56
|
activities = @sub.likes(@obj)
|
53
57
|
activities.select {|a| a.owner == mary}.should_not be_empty # Mary gets an activity, because she's connected to Tim
|
54
58
|
end
|
55
59
|
|
56
|
-
it "
|
60
|
+
it "do *not* create activities for those the subject is connected to" do
|
57
61
|
mary = Connectable.create(:name => 'Mary')
|
58
|
-
@sub.connect_to(mary)
|
62
|
+
@sub.connect_to(mary) # Tim is now connected to Mary
|
59
63
|
activities = @sub.likes(@obj)
|
60
64
|
# Mary does not get an activity,
|
61
65
|
# because she's *not* connected to Tim (Tim is connected to Mary, though)
|
62
66
|
activities.select {|a| a.owner == mary}.should be_empty
|
63
67
|
end
|
64
68
|
|
65
|
-
it "
|
69
|
+
it "create activities for those connected to the object" do
|
66
70
|
anne = Connectable.create(:name => 'Anne')
|
67
|
-
anne.connect_to(@obj)
|
71
|
+
anne.connect_to(@obj)
|
68
72
|
activities = @sub.likes(@obj)
|
69
73
|
# Anne gets an activity
|
70
74
|
activities.select {|a| a.owner == anne}.should_not be_empty
|
71
75
|
end
|
72
76
|
|
73
|
-
it "
|
77
|
+
it "do *not* create an activity for those the subject is connected to" do
|
74
78
|
anne = Connectable.create(:name => 'Anne')
|
75
|
-
@obj.connect_to(anne)
|
79
|
+
@obj.connect_to(anne)
|
76
80
|
activities = @sub.likes(@obj)
|
77
81
|
# Anne does not get an activity
|
78
82
|
activities.select {|a| a.owner == anne}.should be_empty
|
@@ -23,7 +23,9 @@ class ActsAsConnectableTest < ActiveSupport::TestCase
|
|
23
23
|
end
|
24
24
|
|
25
25
|
test "should allow adding connections" do
|
26
|
-
@connectable1.
|
26
|
+
assert @connectable1.connected_to?(@connectable2) == false
|
27
|
+
@connectable1.connect_to(@connectable2)
|
28
|
+
assert @connectable1.connected_to?(@connectable2) == true
|
27
29
|
assert @connectable1.outgoing_social_connections.count == 1
|
28
30
|
assert @connectable1.incoming_social_connections.count == 0
|
29
31
|
assert @connectable2.outgoing_social_connections.count == 0
|
data/test/schema.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
ActiveRecord::Schema.define(:version => 0) do
|
2
|
+
# TODO: not DRY: Same in lib/generators/social_connections/install/templates/
|
2
3
|
create_table :social_connections, :force => true do |t|
|
3
4
|
t.integer :source_id
|
4
5
|
t.string :source_type
|
5
6
|
t.integer :target_id
|
6
7
|
t.string :target_type
|
8
|
+
t.timestamps
|
7
9
|
end
|
8
10
|
create_table :social_activities, :force => true do |t|
|
9
11
|
t.integer :owner_id
|
@@ -15,6 +17,7 @@ ActiveRecord::Schema.define(:version => 0) do
|
|
15
17
|
t.string :verb
|
16
18
|
t.text :options_as_json
|
17
19
|
t.boolean :unseen, :default => true
|
20
|
+
t.timestamps
|
18
21
|
end
|
19
22
|
|
20
23
|
# the 'connectables' table is for the tests
|
data/test/test_helper.rb
CHANGED
@@ -42,7 +42,22 @@ def load_schema
|
|
42
42
|
raise "No DB Adapter selected. Pass the DB= option to pick one, or install Sqlite or Sqlite3."
|
43
43
|
end
|
44
44
|
|
45
|
-
|
46
|
-
|
45
|
+
# helper needed here only
|
46
|
+
def capture_stdout &block
|
47
|
+
real_out, $stdout = $stdout, StringIO.new
|
48
|
+
yield
|
49
|
+
$stdout.string
|
50
|
+
ensure
|
51
|
+
$stdout = real_out
|
52
|
+
end
|
53
|
+
|
54
|
+
capture_stdout do # we ignore stdout for this, it pollutes the output
|
55
|
+
ActiveRecord::Base.establish_connection(config[db_adapter])
|
56
|
+
load(File.dirname(__FILE__) + "/schema.rb")
|
57
|
+
end
|
58
|
+
|
47
59
|
end
|
48
60
|
|
61
|
+
ActionMailer::Base.delivery_method = :file
|
62
|
+
ActionMailer::Base.file_settings = { :location => 'tmp/mails' }
|
63
|
+
ActionMailer::Base.raise_delivery_errors = true
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: social_connections
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.7
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Chris
|
@@ -10,8 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-
|
14
|
-
default_executable:
|
13
|
+
date: 2011-08-16 00:00:00 Z
|
15
14
|
dependencies: []
|
16
15
|
|
17
16
|
description: The idea is to provide pluggable social connections, activities and a method to digest those activities (e.g. in daily emails).
|
@@ -27,8 +26,9 @@ files:
|
|
27
26
|
- .gitignore
|
28
27
|
- .yardopts
|
29
28
|
- Gemfile
|
29
|
+
- Gemfile.lock
|
30
30
|
- MIT-LICENSE
|
31
|
-
- README
|
31
|
+
- README.md
|
32
32
|
- Rakefile
|
33
33
|
- db/keep-this-dir.txt
|
34
34
|
- init.rb
|
@@ -38,11 +38,14 @@ files:
|
|
38
38
|
- lib/app/models/social_connection.rb
|
39
39
|
- lib/app/views/digest_mailer/digest.html.erb
|
40
40
|
- lib/db/migrate/20110516181115_create_social_connections.rb
|
41
|
+
- lib/generators/social_connections/install/install_generator.rb
|
42
|
+
- lib/generators/social_connections/install/templates/create_social_connections_tables.rb
|
41
43
|
- lib/social_connections.rb
|
42
44
|
- lib/social_connections/acts_as_connectable.rb
|
43
45
|
- lib/social_connections/social_aggregator.rb
|
44
46
|
- lib/social_connections/version.rb
|
45
47
|
- lib/tasks/social_connections.rake
|
48
|
+
- run-tests.sh
|
46
49
|
- social_connections.gemspec
|
47
50
|
- spec/activities_aggregator_spec.rb
|
48
51
|
- spec/social_activities_spec.rb
|
@@ -53,7 +56,6 @@ files:
|
|
53
56
|
- test/social_connection_test.rb
|
54
57
|
- test/test_helper.rb
|
55
58
|
- uninstall.rb
|
56
|
-
has_rdoc: true
|
57
59
|
homepage: https://sites.google.com/site/socialconnections7/
|
58
60
|
licenses: []
|
59
61
|
|
@@ -77,7 +79,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
77
79
|
requirements: []
|
78
80
|
|
79
81
|
rubyforge_project: social_connections
|
80
|
-
rubygems_version: 1.
|
82
|
+
rubygems_version: 1.8.5
|
81
83
|
signing_key:
|
82
84
|
specification_version: 3
|
83
85
|
summary: Social connections for ActiveRecord.
|