socialization 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. data/.gitignore +9 -0
  2. data/Appraisals +11 -0
  3. data/Gemfile +3 -0
  4. data/LICENSE +20 -0
  5. data/README.rdoc +126 -0
  6. data/Rakefile +16 -0
  7. data/demo/demo_app/.gitignore +15 -0
  8. data/demo/demo_app/Gemfile +35 -0
  9. data/demo/demo_app/README.rdoc +261 -0
  10. data/demo/demo_app/Rakefile +7 -0
  11. data/demo/demo_app/app/assets/images/rails.png +0 -0
  12. data/demo/demo_app/app/assets/javascripts/application.js +15 -0
  13. data/demo/demo_app/app/assets/stylesheets/application.css +13 -0
  14. data/demo/demo_app/app/controllers/application_controller.rb +3 -0
  15. data/demo/demo_app/app/helpers/application_helper.rb +2 -0
  16. data/demo/demo_app/app/mailers/.gitkeep +0 -0
  17. data/demo/demo_app/app/models/.gitkeep +0 -0
  18. data/demo/demo_app/app/models/celebrity.rb +4 -0
  19. data/demo/demo_app/app/models/follow.rb +3 -0
  20. data/demo/demo_app/app/models/like.rb +3 -0
  21. data/demo/demo_app/app/models/movie.rb +3 -0
  22. data/demo/demo_app/app/models/user.rb +6 -0
  23. data/demo/demo_app/app/views/layouts/application.html.erb +14 -0
  24. data/demo/demo_app/config.ru +4 -0
  25. data/demo/demo_app/config/application.rb +59 -0
  26. data/demo/demo_app/config/boot.rb +6 -0
  27. data/demo/demo_app/config/database.yml +25 -0
  28. data/demo/demo_app/config/environment.rb +5 -0
  29. data/demo/demo_app/config/environments/development.rb +37 -0
  30. data/demo/demo_app/config/environments/production.rb +67 -0
  31. data/demo/demo_app/config/environments/test.rb +37 -0
  32. data/demo/demo_app/config/initializers/backtrace_silencers.rb +7 -0
  33. data/demo/demo_app/config/initializers/inflections.rb +15 -0
  34. data/demo/demo_app/config/initializers/mime_types.rb +5 -0
  35. data/demo/demo_app/config/initializers/secret_token.rb +7 -0
  36. data/demo/demo_app/config/initializers/session_store.rb +8 -0
  37. data/demo/demo_app/config/initializers/wrap_parameters.rb +14 -0
  38. data/demo/demo_app/config/locales/en.yml +5 -0
  39. data/demo/demo_app/config/routes.rb +58 -0
  40. data/demo/demo_app/db/migrate/20120115051222_create_users.rb +9 -0
  41. data/demo/demo_app/db/migrate/20120115051234_create_movies.rb +9 -0
  42. data/demo/demo_app/db/migrate/20120115051255_create_celebrities.rb +9 -0
  43. data/demo/demo_app/db/migrate/20120115054646_create_follows.rb +14 -0
  44. data/demo/demo_app/db/migrate/20120115054647_create_likes.rb +14 -0
  45. data/demo/demo_app/db/schema.rb +56 -0
  46. data/demo/demo_app/db/seeds.rb +14 -0
  47. data/demo/demo_app/doc/README_FOR_APP +2 -0
  48. data/demo/demo_app/lib/assets/.gitkeep +0 -0
  49. data/demo/demo_app/lib/tasks/.gitkeep +0 -0
  50. data/demo/demo_app/public/404.html +26 -0
  51. data/demo/demo_app/public/422.html +26 -0
  52. data/demo/demo_app/public/500.html +25 -0
  53. data/demo/demo_app/public/favicon.ico +0 -0
  54. data/demo/demo_app/public/index.html +204 -0
  55. data/demo/demo_app/public/robots.txt +5 -0
  56. data/demo/demo_app/script/rails +6 -0
  57. data/demo/demo_app/test/fixtures/.gitkeep +0 -0
  58. data/demo/demo_app/test/fixtures/celebrities.yml +7 -0
  59. data/demo/demo_app/test/fixtures/movies.yml +7 -0
  60. data/demo/demo_app/test/fixtures/users.yml +7 -0
  61. data/demo/demo_app/test/functional/.gitkeep +0 -0
  62. data/demo/demo_app/test/integration/.gitkeep +0 -0
  63. data/demo/demo_app/test/performance/browsing_test.rb +12 -0
  64. data/demo/demo_app/test/test_helper.rb +13 -0
  65. data/demo/demo_app/test/unit/.gitkeep +0 -0
  66. data/demo/demo_app/test/unit/celebrity_test.rb +7 -0
  67. data/demo/demo_app/test/unit/movie_test.rb +7 -0
  68. data/demo/demo_app/test/unit/user_test.rb +7 -0
  69. data/demo/demo_app/vendor/assets/javascripts/.gitkeep +0 -0
  70. data/demo/demo_app/vendor/assets/stylesheets/.gitkeep +0 -0
  71. data/demo/demo_app/vendor/plugins/.gitkeep +0 -0
  72. data/generators/socialization/USAGE +1 -0
  73. data/generators/socialization/socialization_generator.rb +11 -0
  74. data/generators/socialization/templates/migration_follows.rb +14 -0
  75. data/generators/socialization/templates/migration_likes.rb +14 -0
  76. data/generators/socialization/templates/model_follow.rb +3 -0
  77. data/generators/socialization/templates/model_like.rb +3 -0
  78. data/init.rb +1 -0
  79. data/lib/generators/socialization/socialization_generator.rb +23 -0
  80. data/lib/socialization.rb +6 -0
  81. data/lib/socialization/follow_store.rb +14 -0
  82. data/lib/socialization/followable.rb +23 -0
  83. data/lib/socialization/follower.rb +31 -0
  84. data/lib/socialization/hello.rb +37 -0
  85. data/lib/socialization/like_store.rb +14 -0
  86. data/lib/socialization/likeable.rb +23 -0
  87. data/lib/socialization/liker.rb +31 -0
  88. data/lib/socialization/version.rb +3 -0
  89. data/socialization.gemspec +29 -0
  90. data/test/follow_test.rb +37 -0
  91. data/test/like_test.rb +46 -0
  92. data/test/test_helper.rb +67 -0
  93. metadata +200 -0
@@ -0,0 +1,46 @@
1
+ require File.dirname(__FILE__)+'/test_helper'
2
+
3
+ class LikeTest < Test::Unit::TestCase
4
+ def setup
5
+ @u_john = User.create name: 'John Doe'
6
+ @u_jane = User.create name: 'Jane Doe'
7
+ @m_seven = Movie.create name: 'Seven'
8
+ @m_pulp = Movie.create name: 'Pulp Fiction'
9
+ @m_tub = Movie.create name: 'Hot Tub Time Machine'
10
+ end
11
+
12
+ def test_the_world
13
+ assert @u_john.is_liker?
14
+ assert @u_john.is_likeable?
15
+ assert @m_seven.is_likeable?
16
+
17
+ assert @u_john.like!(@m_seven)
18
+ assert @u_john.like!(@m_pulp)
19
+ assert @u_jane.like!(@m_seven)
20
+
21
+ assert_raise ArgumentError do
22
+ @u_jane.follow!(@m_seven) # movie is not followable
23
+ end
24
+
25
+ assert_equal true, @u_john.likes?(@m_seven)
26
+ assert_equal true, @u_john.likes?(@m_pulp)
27
+ assert_equal true, @u_jane.likes?(@m_seven)
28
+ assert_equal false, @u_jane.likes?(@m_pulp)
29
+
30
+ assert_equal true, @m_seven.liked_by?(@u_john)
31
+ assert_equal false, @m_pulp.liked_by?(@u_jane)
32
+
33
+ assert @m_tub.likers.empty?
34
+
35
+ # can't have duplicate a like
36
+ assert_raise ActiveRecord::RecordInvalid do
37
+ @u_john.like!(@m_seven)
38
+ end
39
+ end
40
+
41
+ def test_user_liking_another_user
42
+ @u_john.like!(@u_jane)
43
+ assert_equal true, @u_john.likes?(@u_jane)
44
+ assert_equal false, @u_jane.likes?(@u_john)
45
+ end
46
+ end
@@ -0,0 +1,67 @@
1
+ require 'rubygems'
2
+ require 'active_record'
3
+ require 'mocha'
4
+ require 'test/unit'
5
+ require 'logger'
6
+
7
+ $:.push File.expand_path("../lib", __FILE__)
8
+ require "socialization"
9
+
10
+ ActiveRecord::Base.configurations = {'sqlite3' => {:adapter => 'sqlite3', :database => ':memory:'}}
11
+ ActiveRecord::Base.establish_connection('sqlite3')
12
+
13
+ ActiveRecord::Base.logger = Logger.new(STDERR)
14
+ ActiveRecord::Base.logger.level = Logger::WARN
15
+
16
+ ActiveRecord::Schema.define(:version => 0) do
17
+ create_table :users do |t|
18
+ t.string :name
19
+ end
20
+
21
+ create_table :celebrities do |t|
22
+ t.string :name
23
+ end
24
+
25
+ create_table :movies do |t|
26
+ t.string :name
27
+ end
28
+
29
+ create_table :follows do |t|
30
+ t.string :follower_type
31
+ t.integer :follower_id
32
+ t.string :followable_type
33
+ t.integer :followable_id
34
+ t.datetime :created_at
35
+ end
36
+
37
+ create_table :likes do |t|
38
+ t.string :liker_type
39
+ t.integer :liker_id
40
+ t.string :likeable_type
41
+ t.integer :likeable_id
42
+ t.datetime :created_at
43
+ end
44
+ end
45
+
46
+ class Celebrity < ActiveRecord::Base
47
+ acts_as_followable
48
+ end
49
+
50
+ class User < ActiveRecord::Base
51
+ acts_as_follower
52
+ acts_as_followable
53
+ acts_as_liker
54
+ acts_as_likeable
55
+ end
56
+
57
+ class Movie < ActiveRecord::Base
58
+ acts_as_likeable
59
+ end
60
+
61
+ class Follow < ActiveRecord::Base
62
+ acts_as_follow_store
63
+ end
64
+
65
+ class Like < ActiveRecord::Base
66
+ acts_as_like_store
67
+ end
metadata ADDED
@@ -0,0 +1,200 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: socialization
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Carl Mercier
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-01-15 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: activerecord
16
+ requirement: &70340782011640 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70340782011640
25
+ - !ruby/object:Gem::Dependency
26
+ name: appraisal
27
+ requirement: &70340782011220 !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: *70340782011220
36
+ - !ruby/object:Gem::Dependency
37
+ name: logger
38
+ requirement: &70340782010800 !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: *70340782010800
47
+ - !ruby/object:Gem::Dependency
48
+ name: mocha
49
+ requirement: &70340782010380 !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: *70340782010380
58
+ - !ruby/object:Gem::Dependency
59
+ name: sqlite3
60
+ requirement: &70340781925200 !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: *70340781925200
69
+ description: Socialization allow any model to Follow and/or Like any other model.
70
+ This is accomplished through a double polymorphic relationship on the Follow and
71
+ Like models. But you don't need to know that since all the complexity is hidden
72
+ from you.
73
+ email: carl@carlmercier.com
74
+ executables: []
75
+ extensions: []
76
+ extra_rdoc_files:
77
+ - README.rdoc
78
+ files:
79
+ - .gitignore
80
+ - Appraisals
81
+ - Gemfile
82
+ - LICENSE
83
+ - README.rdoc
84
+ - Rakefile
85
+ - demo/demo_app/.gitignore
86
+ - demo/demo_app/Gemfile
87
+ - demo/demo_app/README.rdoc
88
+ - demo/demo_app/Rakefile
89
+ - demo/demo_app/app/assets/images/rails.png
90
+ - demo/demo_app/app/assets/javascripts/application.js
91
+ - demo/demo_app/app/assets/stylesheets/application.css
92
+ - demo/demo_app/app/controllers/application_controller.rb
93
+ - demo/demo_app/app/helpers/application_helper.rb
94
+ - demo/demo_app/app/mailers/.gitkeep
95
+ - demo/demo_app/app/models/.gitkeep
96
+ - demo/demo_app/app/models/celebrity.rb
97
+ - demo/demo_app/app/models/follow.rb
98
+ - demo/demo_app/app/models/like.rb
99
+ - demo/demo_app/app/models/movie.rb
100
+ - demo/demo_app/app/models/user.rb
101
+ - demo/demo_app/app/views/layouts/application.html.erb
102
+ - demo/demo_app/config.ru
103
+ - demo/demo_app/config/application.rb
104
+ - demo/demo_app/config/boot.rb
105
+ - demo/demo_app/config/database.yml
106
+ - demo/demo_app/config/environment.rb
107
+ - demo/demo_app/config/environments/development.rb
108
+ - demo/demo_app/config/environments/production.rb
109
+ - demo/demo_app/config/environments/test.rb
110
+ - demo/demo_app/config/initializers/backtrace_silencers.rb
111
+ - demo/demo_app/config/initializers/inflections.rb
112
+ - demo/demo_app/config/initializers/mime_types.rb
113
+ - demo/demo_app/config/initializers/secret_token.rb
114
+ - demo/demo_app/config/initializers/session_store.rb
115
+ - demo/demo_app/config/initializers/wrap_parameters.rb
116
+ - demo/demo_app/config/locales/en.yml
117
+ - demo/demo_app/config/routes.rb
118
+ - demo/demo_app/db/migrate/20120115051222_create_users.rb
119
+ - demo/demo_app/db/migrate/20120115051234_create_movies.rb
120
+ - demo/demo_app/db/migrate/20120115051255_create_celebrities.rb
121
+ - demo/demo_app/db/migrate/20120115054646_create_follows.rb
122
+ - demo/demo_app/db/migrate/20120115054647_create_likes.rb
123
+ - demo/demo_app/db/schema.rb
124
+ - demo/demo_app/db/seeds.rb
125
+ - demo/demo_app/doc/README_FOR_APP
126
+ - demo/demo_app/lib/assets/.gitkeep
127
+ - demo/demo_app/lib/tasks/.gitkeep
128
+ - demo/demo_app/public/404.html
129
+ - demo/demo_app/public/422.html
130
+ - demo/demo_app/public/500.html
131
+ - demo/demo_app/public/favicon.ico
132
+ - demo/demo_app/public/index.html
133
+ - demo/demo_app/public/robots.txt
134
+ - demo/demo_app/script/rails
135
+ - demo/demo_app/test/fixtures/.gitkeep
136
+ - demo/demo_app/test/fixtures/celebrities.yml
137
+ - demo/demo_app/test/fixtures/movies.yml
138
+ - demo/demo_app/test/fixtures/users.yml
139
+ - demo/demo_app/test/functional/.gitkeep
140
+ - demo/demo_app/test/integration/.gitkeep
141
+ - demo/demo_app/test/performance/browsing_test.rb
142
+ - demo/demo_app/test/test_helper.rb
143
+ - demo/demo_app/test/unit/.gitkeep
144
+ - demo/demo_app/test/unit/celebrity_test.rb
145
+ - demo/demo_app/test/unit/movie_test.rb
146
+ - demo/demo_app/test/unit/user_test.rb
147
+ - demo/demo_app/vendor/assets/javascripts/.gitkeep
148
+ - demo/demo_app/vendor/assets/stylesheets/.gitkeep
149
+ - demo/demo_app/vendor/plugins/.gitkeep
150
+ - generators/socialization/USAGE
151
+ - generators/socialization/socialization_generator.rb
152
+ - generators/socialization/templates/migration_follows.rb
153
+ - generators/socialization/templates/migration_likes.rb
154
+ - generators/socialization/templates/model_follow.rb
155
+ - generators/socialization/templates/model_like.rb
156
+ - init.rb
157
+ - lib/generators/socialization/socialization_generator.rb
158
+ - lib/socialization.rb
159
+ - lib/socialization/follow_store.rb
160
+ - lib/socialization/followable.rb
161
+ - lib/socialization/follower.rb
162
+ - lib/socialization/hello.rb
163
+ - lib/socialization/like_store.rb
164
+ - lib/socialization/likeable.rb
165
+ - lib/socialization/liker.rb
166
+ - lib/socialization/version.rb
167
+ - socialization.gemspec
168
+ - test/follow_test.rb
169
+ - test/like_test.rb
170
+ - test/test_helper.rb
171
+ homepage: https://github.com/cmer/socialization
172
+ licenses: []
173
+ post_install_message:
174
+ rdoc_options:
175
+ - --charset=UTF-8
176
+ require_paths:
177
+ - lib
178
+ required_ruby_version: !ruby/object:Gem::Requirement
179
+ none: false
180
+ requirements:
181
+ - - ! '>='
182
+ - !ruby/object:Gem::Version
183
+ version: '0'
184
+ required_rubygems_version: !ruby/object:Gem::Requirement
185
+ none: false
186
+ requirements:
187
+ - - ! '>='
188
+ - !ruby/object:Gem::Version
189
+ version: '0'
190
+ requirements: []
191
+ rubyforge_project:
192
+ rubygems_version: 1.8.15
193
+ signing_key:
194
+ specification_version: 3
195
+ summary: Easily socialize your app with Likes and Follows
196
+ test_files:
197
+ - test/follow_test.rb
198
+ - test/like_test.rb
199
+ - test/test_helper.rb
200
+ has_rdoc: true