social_connections 0.0.7 → 0.0.8

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/Gemfile.lock CHANGED
@@ -1,14 +1,96 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- social_connections (0.0.6)
4
+ social_connections (0.0.7)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
8
8
  specs:
9
+ abstract (1.0.0)
10
+ actionmailer (3.0.5)
11
+ actionpack (= 3.0.5)
12
+ mail (~> 2.2.15)
13
+ actionpack (3.0.5)
14
+ activemodel (= 3.0.5)
15
+ activesupport (= 3.0.5)
16
+ builder (~> 2.1.2)
17
+ erubis (~> 2.6.6)
18
+ i18n (~> 0.4)
19
+ rack (~> 1.2.1)
20
+ rack-mount (~> 0.6.13)
21
+ rack-test (~> 0.5.7)
22
+ tzinfo (~> 0.3.23)
23
+ activemodel (3.0.5)
24
+ activesupport (= 3.0.5)
25
+ builder (~> 2.1.2)
26
+ i18n (~> 0.4)
27
+ activerecord (3.0.5)
28
+ activemodel (= 3.0.5)
29
+ activesupport (= 3.0.5)
30
+ arel (~> 2.0.2)
31
+ tzinfo (~> 0.3.23)
32
+ activesupport (3.0.5)
33
+ ansi (1.3.0)
34
+ arel (2.0.10)
35
+ builder (2.1.2)
36
+ diff-lcs (1.1.3)
37
+ erubis (2.6.6)
38
+ abstract (>= 1.0.0)
39
+ factory_girl (2.0.5)
40
+ factory_girl_rails (1.1.0)
41
+ factory_girl (~> 2.0.0)
42
+ railties (>= 3.0.0)
43
+ i18n (0.6.0)
44
+ mail (2.2.19)
45
+ activesupport (>= 2.3.6)
46
+ i18n (>= 0.4.0)
47
+ mime-types (~> 1.16)
48
+ treetop (~> 1.4.8)
49
+ mime-types (1.16)
50
+ polyglot (0.3.2)
51
+ rack (1.2.3)
52
+ rack-mount (0.6.14)
53
+ rack (>= 1.0.0)
54
+ rack-test (0.5.7)
55
+ rack (>= 1.0)
56
+ railties (3.0.5)
57
+ actionpack (= 3.0.5)
58
+ activesupport (= 3.0.5)
59
+ rake (>= 0.8.7)
60
+ thor (~> 0.14.4)
61
+ rake (0.9.2)
62
+ rspec (2.6.0)
63
+ rspec-core (~> 2.6.0)
64
+ rspec-expectations (~> 2.6.0)
65
+ rspec-mocks (~> 2.6.0)
66
+ rspec-core (2.6.4)
67
+ rspec-expectations (2.6.0)
68
+ diff-lcs (~> 1.1.2)
69
+ rspec-mocks (2.6.0)
70
+ rspec-rails (2.6.1)
71
+ actionpack (~> 3.0)
72
+ activesupport (~> 3.0)
73
+ railties (~> 3.0)
74
+ rspec (~> 2.6.0)
75
+ sqlite3 (1.3.4)
76
+ thor (0.14.6)
77
+ treetop (1.4.10)
78
+ polyglot
79
+ polyglot (>= 0.3.1)
80
+ turn (0.8.2)
81
+ ansi (>= 1.2.2)
82
+ tzinfo (0.3.29)
9
83
 
10
84
  PLATFORMS
11
85
  ruby
12
86
 
13
87
  DEPENDENCIES
88
+ actionmailer
89
+ activerecord
90
+ factory_girl_rails
91
+ i18n
92
+ rspec
93
+ rspec-rails
14
94
  social_connections!
95
+ sqlite3
96
+ turn
data/README.md CHANGED
@@ -60,8 +60,16 @@ and
60
60
 
61
61
  u.comments(b, :comment => 'awesome book!')
62
62
 
63
- . This creates activities for the user and the book. These activities can be
64
- queried:
63
+ . This creates activities for the user and the book. Activities are _only_ created for
64
+ those connected to the subject and/or object of the activity--in the example, user `u`
65
+ is the subject and book `b` is the object. A user `v` can connect to user `u` by saying
66
+
67
+ v.connect_to(u)
68
+
69
+ . If this is issued before invoking `likes` and `comments` as above, user `v`
70
+ receives 2 activities.
71
+
72
+ These activities can be queried:
65
73
 
66
74
  b.likes_by_count
67
75
 
@@ -72,7 +80,8 @@ Gives the number of users (or other 'connectables') that liked this book. Same f
72
80
  . For more examples, see the spec files.
73
81
 
74
82
 
75
- === Controllers for Activities
83
+ Controllers for Activities
84
+ --------------------------
76
85
 
77
86
  Assuming that `current_user` gives you the currently logged in user, a controller
78
87
  responding to a 'like' button could look as follows:
@@ -93,7 +102,8 @@ The view (e.g. `app/views/books/show.html.erb`) may then contain the following '
93
102
  <%= link_to('I like this', current_user_likes_book_path(@book) %>
94
103
 
95
104
 
96
- == How to run the Tests (in the gem itself, not in your Rails app)
105
+ How to run the Tests (in the gem itself, not in your Rails app)
106
+ --------------------
97
107
 
98
108
  Run test in ./test:
99
109
 
@@ -0,0 +1,17 @@
1
+ class MuteAndCuriousGuest < ActiveRecord::Base
2
+
3
+ acts_as_connectable :verbs => []
4
+
5
+ def self.activities
6
+ SocialConnections.aggregate(self.instance).activities
7
+ end
8
+
9
+ def self.instance
10
+ if MuteAndCuriousGuest.count == 0
11
+ MuteAndCuriousGuest.create
12
+ else
13
+ MuteAndCuriousGuest.first
14
+ end
15
+ end
16
+
17
+ end
@@ -20,21 +20,24 @@ class SocialActivity < ActiveRecord::Base
20
20
  def self.create_activities(subject, verb, object, options = {})
21
21
  # TODO: we may want to delay this
22
22
  activities = []
23
- [ subject, object ].each do |owner| # one activity for the subject, and one for the object
23
+ [ subject, object ].uniq.each do |owner| # one activity for the subject, and one for the object
24
24
  activities << SocialActivity.create(:owner => owner,
25
25
  :subject => subject,
26
26
  :verb => verb,
27
27
  :target => object,
28
28
  :options_as_json => options.to_json)
29
29
  end
30
- [ subject, object ].each do |who| # for both subject and object...
31
- who.incoming_social_connections.each do |connection|
32
- activities << SocialActivity.create(:owner => connection.source, # ... an activity for each one connected
33
- :subject => subject,
34
- :verb => verb,
35
- :target => object,
36
- :options_as_json => options.to_json)
37
- end
30
+ # TODO: ugly and hard to read code below, refactor!
31
+ who = []
32
+ [subject, object].uniq.each do |w|
33
+ who.concat(w.incoming_social_connections)
34
+ end
35
+ who.collect{|w| w.source}.uniq.each do |connection|
36
+ activities << SocialActivity.create(:owner => connection, # ... an activity for each one connected
37
+ :subject => subject,
38
+ :verb => verb,
39
+ :target => object,
40
+ :options_as_json => options.to_json)
38
41
  end
39
42
  activities
40
43
  end
@@ -1,7 +1,9 @@
1
1
  require 'rails/generators/migration'
2
2
 
3
3
  module SocialConnections
4
+
4
5
  module Generators
6
+ puts "in 'Generators' module"
5
7
  class InstallGenerator < ::Rails::Generators::Base
6
8
  include Rails::Generators::Migration
7
9
  source_root File.expand_path('../templates', __FILE__)
@@ -18,6 +20,7 @@ module SocialConnections
18
20
 
19
21
  def copy_migrations
20
22
  migration_template "create_social_connections_tables.rb", "db/migrate/create_social_connections.rb"
23
+ migration_template "create_mute_and_curious_guests.rb", "db/migrate/create_mute_and_curious_guests.rb"
21
24
  end
22
25
 
23
26
  end
@@ -0,0 +1,11 @@
1
+ class CreateMuteAndCuriousGuests < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :mute_and_curious_guests do |t|
4
+ t.timestamps
5
+ end
6
+ end
7
+
8
+ def self.down
9
+ drop_table :mute_and_curious_guests
10
+ end
11
+ end
@@ -1,3 +1,3 @@
1
1
  module SocialConnections
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
@@ -6,7 +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
+ warn "Migration via rake is deprecated, use 'rails generate social_connections:install' instead."
10
10
  Rake::Task["db:schema:dump"].invoke if ActiveRecord::Base.schema_format == :ruby
11
11
  end
12
12
  end
@@ -19,4 +19,8 @@ Gem::Specification.new do |s|
19
19
  # s.test_files.reject! { |fn| fn.include? ".swp" }
20
20
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
21
21
  s.require_paths = ["lib"]
22
+ s.add_development_dependency('rspec')
23
+ [ 'sqlite3', 'rspec-rails', 'turn', 'factory_girl_rails', 'activerecord', 'actionmailer', 'i18n', 'pry' ].each do |d|
24
+ s.add_development_dependency d
25
+ end
22
26
  end
@@ -3,7 +3,6 @@ require File.dirname(__FILE__) + '/../test/test_helper'
3
3
  describe "Aggregation" do
4
4
 
5
5
  before(:each) do
6
- load_schema
7
6
  @tim = Connectable.create(:name => 'Tim', :email => 'tim@test.com')
8
7
  @tom = Connectable.create(:name => 'Tom', :email => 'tom@test.com')
9
8
  end
@@ -17,6 +16,16 @@ describe "Aggregation" do
17
16
  feed_tom.activities.count.should be_>(1)
18
17
  end
19
18
 
19
+ it "aggregates activities for 'passive' users" do
20
+ stalker = Connectable.create(:name => 'Tony', :email => 'tony@test.com')
21
+ stalker.connect_to(@tom)
22
+ aggregate = SocialConnections.aggregate(stalker)
23
+ aggregate.activities.count.should eq(0)
24
+ @tim.comments(@tom, :comment => 'Tony is listening...')
25
+ aggregate = SocialConnections.aggregate(stalker)
26
+ aggregate.activities.count.should eq(1)
27
+ end
28
+
20
29
  describe "When Tim and Tom interacted" do
21
30
 
22
31
  before(:each) do
@@ -0,0 +1,17 @@
1
+
2
+ describe MuteAndCuriousGuest do
3
+ it "has a single instance" do
4
+ MuteAndCuriousGuest.instance.should_not be(nil)
5
+ end
6
+ it "can connect to things" do
7
+ tim = Connectable.new(:name => 'Tim')
8
+ MuteAndCuriousGuest.instance.connect_to(tim)
9
+ end
10
+ it "receives activities when something happens with a connected thing" do
11
+ tim = Connectable.new(:name => 'Tim')
12
+ tom = Connectable.new(:name => 'Tom')
13
+ MuteAndCuriousGuest.instance.connect_to(tim)
14
+ tim.comments(tom)
15
+ SocialConnections.aggregate(MuteAndCuriousGuest.instance).activities.count.should be(1)
16
+ end
17
+ end
@@ -3,7 +3,6 @@ require File.dirname(__FILE__) + '/../test/test_helper'
3
3
  describe "Social Activities" do
4
4
 
5
5
  before(:each) do
6
- load_schema
7
6
  @sub = Connectable.create(:name => 'Tim')
8
7
  @obj = Connectable.create(:name => 'Tom')
9
8
  end
@@ -39,6 +38,25 @@ describe "Social Activities" do
39
38
 
40
39
  end
41
40
 
41
+ describe "when connected to both object and subject" do
42
+ before(:each) do
43
+ @stalker = Connectable.create(:name => 'Steve, the Stalker')
44
+ @stalker.connect_to(@sub)
45
+ @stalker.connect_to(@obj)
46
+ end
47
+ it "creates one activity, not two" do
48
+ activities = @sub.likes @obj
49
+ activities.select { |a| a.owner == @stalker }.count.should eql(1)
50
+ end
51
+ describe "when subject and object are identical" do
52
+ it "creates one activity, not two" do
53
+ activities = @sub.likes @sub
54
+ activities.select {|a| a.owner == @stalker}.count.should eql(1)
55
+ end
56
+ end
57
+ end
58
+
59
+
42
60
  it "allow options on activities (e.g. a comment)" do
43
61
  activities = @sub.comments(@obj, :comment => 'This is a silly comment on Tom')
44
62
  activities[0].options['comment'].should eql('This is a silly comment on Tom')
data/test/schema.rb CHANGED
@@ -1,4 +1,11 @@
1
1
  ActiveRecord::Schema.define(:version => 0) do
2
+
3
+ # TODO: very ugly and messy: Maybe at the beginning of a spec run
4
+ # drop the database and migrate-up via the template files?
5
+ require File.dirname(__FILE__) + '/../lib/generators/social_connections/install/templates/create_mute_and_curious_guests.rb'
6
+ CreateMuteAndCuriousGuests.migrate(:down)
7
+ CreateMuteAndCuriousGuests.migrate(:up)
8
+
2
9
  # TODO: not DRY: Same in lib/generators/social_connections/install/templates/
3
10
  create_table :social_connections, :force => true do |t|
4
11
  t.integer :source_id
data/test/test_helper.rb CHANGED
@@ -12,7 +12,7 @@ require 'action_mailer'
12
12
  require File.dirname(__FILE__) + '/../init'
13
13
 
14
14
  class Connectable < ActiveRecord::Base
15
- acts_as_connectable :verbs => [ :likes, :recommends, :comments ]
15
+ acts_as_connectable :verbs => [ :likes, :recommends, :comments, :follows ]
16
16
  def to_s
17
17
  "Connectable '#{self.name}'"
18
18
  end
@@ -58,6 +58,8 @@ def load_schema
58
58
 
59
59
  end
60
60
 
61
+ load_schema
62
+
61
63
  ActionMailer::Base.delivery_method = :file
62
64
  ActionMailer::Base.file_settings = { :location => 'tmp/mails' }
63
65
  ActionMailer::Base.raise_delivery_errors = true
metadata CHANGED
@@ -1,28 +1,123 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: social_connections
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.8
4
5
  prerelease:
5
- version: 0.0.7
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Chris
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2011-08-16 00:00:00 Z
14
- dependencies: []
15
-
16
- description: The idea is to provide pluggable social connections, activities and a method to digest those activities (e.g. in daily emails).
17
- email:
12
+ date: 2011-08-29 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: &2157760460 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *2157760460
25
+ - !ruby/object:Gem::Dependency
26
+ name: sqlite3
27
+ requirement: &2157759880 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *2157759880
36
+ - !ruby/object:Gem::Dependency
37
+ name: rspec-rails
38
+ requirement: &2152015320 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *2152015320
47
+ - !ruby/object:Gem::Dependency
48
+ name: turn
49
+ requirement: &2152014920 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *2152014920
58
+ - !ruby/object:Gem::Dependency
59
+ name: factory_girl_rails
60
+ requirement: &2152014520 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *2152014520
69
+ - !ruby/object:Gem::Dependency
70
+ name: activerecord
71
+ requirement: &2152014120 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *2152014120
80
+ - !ruby/object:Gem::Dependency
81
+ name: actionmailer
82
+ requirement: &2152013720 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: *2152013720
91
+ - !ruby/object:Gem::Dependency
92
+ name: i18n
93
+ requirement: &2152013320 !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ! '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ type: :development
100
+ prerelease: false
101
+ version_requirements: *2152013320
102
+ - !ruby/object:Gem::Dependency
103
+ name: pry
104
+ requirement: &2152012920 !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: *2152012920
113
+ description: The idea is to provide pluggable social connections, activities and a
114
+ method to digest those activities (e.g. in daily emails).
115
+ email:
18
116
  - christian.oloff+gem@gmail.com
19
117
  executables: []
20
-
21
118
  extensions: []
22
-
23
119
  extra_rdoc_files: []
24
-
25
- files:
120
+ files:
26
121
  - .gitignore
27
122
  - .yardopts
28
123
  - Gemfile
@@ -34,11 +129,13 @@ files:
34
129
  - init.rb
35
130
  - install.rb
36
131
  - lib/app/mailers/digest_mailer.rb
132
+ - lib/app/models/mute_and_curious_guest.rb
37
133
  - lib/app/models/social_activity.rb
38
134
  - lib/app/models/social_connection.rb
39
135
  - lib/app/views/digest_mailer/digest.html.erb
40
136
  - lib/db/migrate/20110516181115_create_social_connections.rb
41
137
  - lib/generators/social_connections/install/install_generator.rb
138
+ - lib/generators/social_connections/install/templates/create_mute_and_curious_guests.rb
42
139
  - lib/generators/social_connections/install/templates/create_social_connections_tables.rb
43
140
  - lib/social_connections.rb
44
141
  - lib/social_connections/acts_as_connectable.rb
@@ -48,6 +145,7 @@ files:
48
145
  - run-tests.sh
49
146
  - social_connections.gemspec
50
147
  - spec/activities_aggregator_spec.rb
148
+ - spec/mute_and_curious_guest_spec.rb
51
149
  - spec/social_activities_spec.rb
52
150
  - test/activities_test.rb
53
151
  - test/acts_as_connectable_test.rb
@@ -58,33 +156,31 @@ files:
58
156
  - uninstall.rb
59
157
  homepage: https://sites.google.com/site/socialconnections7/
60
158
  licenses: []
61
-
62
159
  post_install_message:
63
160
  rdoc_options: []
64
-
65
- require_paths:
161
+ require_paths:
66
162
  - lib
67
- required_ruby_version: !ruby/object:Gem::Requirement
163
+ required_ruby_version: !ruby/object:Gem::Requirement
68
164
  none: false
69
- requirements:
70
- - - ">="
71
- - !ruby/object:Gem::Version
72
- version: "0"
73
- required_rubygems_version: !ruby/object:Gem::Requirement
165
+ requirements:
166
+ - - ! '>='
167
+ - !ruby/object:Gem::Version
168
+ version: '0'
169
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
170
  none: false
75
- requirements:
76
- - - ">="
77
- - !ruby/object:Gem::Version
78
- version: "0"
171
+ requirements:
172
+ - - ! '>='
173
+ - !ruby/object:Gem::Version
174
+ version: '0'
79
175
  requirements: []
80
-
81
176
  rubyforge_project: social_connections
82
- rubygems_version: 1.8.5
177
+ rubygems_version: 1.8.6
83
178
  signing_key:
84
179
  specification_version: 3
85
180
  summary: Social connections for ActiveRecord.
86
- test_files:
181
+ test_files:
87
182
  - spec/activities_aggregator_spec.rb
183
+ - spec/mute_and_curious_guest_spec.rb
88
184
  - spec/social_activities_spec.rb
89
185
  - test/activities_test.rb
90
186
  - test/acts_as_connectable_test.rb