likes_tracker 0.0.1

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.
Files changed (46) hide show
  1. data/.gitignore +22 -0
  2. data/Gemfile +10 -0
  3. data/LICENSE +22 -0
  4. data/README.md +129 -0
  5. data/Rakefile +9 -0
  6. data/lib/likes_tracker.rb +84 -0
  7. data/lib/likes_tracker/version.rb +3 -0
  8. data/likes_tracker.gemspec +25 -0
  9. data/spec/dummy/README.rdoc +261 -0
  10. data/spec/dummy/Rakefile +7 -0
  11. data/spec/dummy/app/assets/javascripts/application.js +13 -0
  12. data/spec/dummy/app/assets/stylesheets/application.css +13 -0
  13. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  14. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  15. data/spec/dummy/app/mailers/.gitkeep +0 -0
  16. data/spec/dummy/app/models/.gitkeep +0 -0
  17. data/spec/dummy/app/models/post.rb +6 -0
  18. data/spec/dummy/app/models/user.rb +7 -0
  19. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  20. data/spec/dummy/config.ru +4 -0
  21. data/spec/dummy/config/application.rb +62 -0
  22. data/spec/dummy/config/boot.rb +10 -0
  23. data/spec/dummy/config/database.yml +25 -0
  24. data/spec/dummy/config/environment.rb +5 -0
  25. data/spec/dummy/config/environments/development.rb +37 -0
  26. data/spec/dummy/config/environments/production.rb +67 -0
  27. data/spec/dummy/config/environments/test.rb +37 -0
  28. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  29. data/spec/dummy/config/initializers/inflections.rb +15 -0
  30. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  31. data/spec/dummy/config/initializers/redis.rb +4 -0
  32. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  33. data/spec/dummy/config/initializers/session_store.rb +8 -0
  34. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  35. data/spec/dummy/config/locales/en.yml +5 -0
  36. data/spec/dummy/config/routes.rb +2 -0
  37. data/spec/dummy/db/migrate/20120726155403_create_users.rb +9 -0
  38. data/spec/dummy/db/migrate/20120726155456_create_posts.rb +9 -0
  39. data/spec/dummy/db/schema.rb +28 -0
  40. data/spec/dummy/lib/assets/.gitkeep +0 -0
  41. data/spec/dummy/log/.gitkeep +0 -0
  42. data/spec/dummy/script/rails +6 -0
  43. data/spec/likes_tracker_spec.rb +116 -0
  44. data/spec/spec_helper.rb +24 -0
  45. data/spec/support/factories.rb +12 -0
  46. metadata +193 -0
@@ -0,0 +1,28 @@
1
+ # encoding: UTF-8
2
+ # This file is auto-generated from the current state of the database. Instead
3
+ # of editing this file, please use the migrations feature of Active Record to
4
+ # incrementally modify your database, and then regenerate this schema definition.
5
+ #
6
+ # Note that this schema.rb definition is the authoritative source for your
7
+ # database schema. If you need to create the application database on another
8
+ # system, you should be using db:schema:load, not running all the migrations
9
+ # from scratch. The latter is a flawed and unsustainable approach (the more migrations
10
+ # you'll amass, the slower it'll run and the greater likelihood for issues).
11
+ #
12
+ # It's strongly recommended to check this file into your version control system.
13
+
14
+ ActiveRecord::Schema.define(:version => 20120726155456) do
15
+
16
+ create_table "posts", :force => true do |t|
17
+ t.string "title"
18
+ t.datetime "created_at", :null => false
19
+ t.datetime "updated_at", :null => false
20
+ end
21
+
22
+ create_table "users", :force => true do |t|
23
+ t.string "username"
24
+ t.datetime "created_at", :null => false
25
+ t.datetime "updated_at", :null => false
26
+ end
27
+
28
+ end
File without changes
File without changes
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
3
+
4
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
5
+ require File.expand_path('../../config/boot', __FILE__)
6
+ require 'rails/commands'
@@ -0,0 +1,116 @@
1
+ require 'spec_helper'
2
+
3
+ describe LikesTracker do
4
+ let(:user) { FactoryGirl.create :user }
5
+ let(:post) { FactoryGirl.create :post }
6
+
7
+ before(:each) do
8
+ $redis.flushdb
9
+ end
10
+
11
+ context ".acts_as_liker_for" do
12
+ it "includes LikesTracker module" do
13
+ user.class.ancestors.should include(LikesTracker)
14
+ end
15
+
16
+ describe "#like_post!" do
17
+ it "adds like to a post" do
18
+ user.like_post! post
19
+ user.liked_posts.should == [post]
20
+ end
21
+
22
+ it "doesn't add like to an already liked post" do
23
+ user.like_post! post
24
+ user.like_post! post
25
+ user.liked_posts.should == [post]
26
+ end
27
+ end # like_post!
28
+
29
+ describe "#unlike_post!" do
30
+ before(:each) do
31
+ user.like_post! post
32
+ end
33
+
34
+ it "removes like from a post" do
35
+ user.unlike_post! post
36
+
37
+ user.liked_posts.should_not == [post]
38
+ end
39
+
40
+ it "doesn't remove like from a non-liked post" do
41
+ user.unlike_post! post
42
+ user.liked_posts.should == []
43
+
44
+ # repeat above ops, check it does nothing
45
+ user.unlike_post! post
46
+ user.liked_posts.should == []
47
+ end
48
+
49
+ end # unlike_post!
50
+
51
+ describe "#likes_post?" do
52
+ it "is true if a post is liked by user" do
53
+ user.like_post! post
54
+ user.likes_post?(post).should be_true
55
+ end
56
+
57
+ it "is false if a post isn't liked by user" do
58
+ user.likes_post?(post).should_not be_true
59
+ end
60
+
61
+ end # likes_post?
62
+
63
+ describe "#liked_posts" do
64
+ it "returns an ActiveRecord::Relation" do
65
+ user.liked_posts.should be_a(ActiveRecord::Relation)
66
+ end
67
+
68
+ it "return posts liked by user" do
69
+ user.like_post! post
70
+ user.liked_posts.should include(post)
71
+ end
72
+
73
+ end # liked_posts
74
+
75
+ end # .acts_as_liker_for
76
+
77
+ context ".acts_as_liked_by" do
78
+ it "includes LikesTracker module" do
79
+ post.class.ancestors.should include(LikesTracker)
80
+ end
81
+
82
+ describe "#likes_users_count" do
83
+ it "returns the number of users who liked this post" do
84
+ post.likes_users_count.should == 0
85
+
86
+ user.like_post! post
87
+ post.likes_users_count.should == 1
88
+ end
89
+
90
+ end # likes_users_count
91
+
92
+ describe ".most_liked" do
93
+ it "returns an ActiveRecord::Relation" do
94
+ Post.most_liked(5).should be_a(ActiveRecord::Relation)
95
+ end
96
+
97
+ it "return most liked posts" do
98
+ user.like_post! post
99
+
100
+ user2 = FactoryGirl.create :user
101
+ post2 = FactoryGirl.create :post
102
+
103
+ user.like_post! post2
104
+ user2.like_post! post
105
+
106
+ post.likes_users_count.should == 2
107
+ post2.likes_users_count.should == 1
108
+
109
+ Post.most_liked(5).should == [post, post2]
110
+ end
111
+
112
+ end # .most_liked
113
+
114
+ end # .acts_as_liked_by
115
+
116
+ end
@@ -0,0 +1,24 @@
1
+ ENV["RAILS_ENV"] = "test"
2
+
3
+ require File.expand_path("../dummy/config/environment.rb", __FILE__)
4
+ require "rails/test_help"
5
+ require "rspec/rails"
6
+ require 'factory_girl'
7
+
8
+ Rails.backtrace_cleaner.remove_silencers!
9
+
10
+ # Run any available migration
11
+ ActiveRecord::Migrator.migrate File.expand_path("../dummy/db/migrate/", __FILE__)
12
+
13
+ # Load support files
14
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
15
+
16
+ RSpec.configure do |config|
17
+ # Remove this line if you don't want RSpec's should and should_not
18
+ # methods or matchers
19
+ require 'rspec/expectations'
20
+ config.include RSpec::Matchers
21
+
22
+ # == Mock Framework
23
+ config.mock_with :rspec
24
+ end
@@ -0,0 +1,12 @@
1
+ # Read about factories at http://github.com/thoughtbot/factory_girl
2
+
3
+ FactoryGirl.define do
4
+ factory :user do
5
+ sequence(:username) {|n| "username#{n}" }
6
+ end
7
+
8
+ factory :post do
9
+ sequence(:title) {|n| "A dummy title #{n}" }
10
+ end
11
+
12
+ end
metadata ADDED
@@ -0,0 +1,193 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: likes_tracker
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Andrea Pavoni
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-07-26 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 3.0.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 3.0.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: redis
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 3.0.1
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 3.0.1
46
+ - !ruby/object:Gem::Dependency
47
+ name: factory_girl_rails
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 3.5.0
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 3.5.0
62
+ - !ruby/object:Gem::Dependency
63
+ name: rspec-rails
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: 2.10.0
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: 2.10.0
78
+ description: track likes between rails models using Redis backend
79
+ email:
80
+ - andrea.pavoni@gmail.com
81
+ executables: []
82
+ extensions: []
83
+ extra_rdoc_files: []
84
+ files:
85
+ - .gitignore
86
+ - Gemfile
87
+ - LICENSE
88
+ - README.md
89
+ - Rakefile
90
+ - lib/likes_tracker.rb
91
+ - lib/likes_tracker/version.rb
92
+ - likes_tracker.gemspec
93
+ - spec/dummy/README.rdoc
94
+ - spec/dummy/Rakefile
95
+ - spec/dummy/app/assets/javascripts/application.js
96
+ - spec/dummy/app/assets/stylesheets/application.css
97
+ - spec/dummy/app/controllers/application_controller.rb
98
+ - spec/dummy/app/helpers/application_helper.rb
99
+ - spec/dummy/app/mailers/.gitkeep
100
+ - spec/dummy/app/models/.gitkeep
101
+ - spec/dummy/app/models/post.rb
102
+ - spec/dummy/app/models/user.rb
103
+ - spec/dummy/app/views/layouts/application.html.erb
104
+ - spec/dummy/config.ru
105
+ - spec/dummy/config/application.rb
106
+ - spec/dummy/config/boot.rb
107
+ - spec/dummy/config/database.yml
108
+ - spec/dummy/config/environment.rb
109
+ - spec/dummy/config/environments/development.rb
110
+ - spec/dummy/config/environments/production.rb
111
+ - spec/dummy/config/environments/test.rb
112
+ - spec/dummy/config/initializers/backtrace_silencers.rb
113
+ - spec/dummy/config/initializers/inflections.rb
114
+ - spec/dummy/config/initializers/mime_types.rb
115
+ - spec/dummy/config/initializers/redis.rb
116
+ - spec/dummy/config/initializers/secret_token.rb
117
+ - spec/dummy/config/initializers/session_store.rb
118
+ - spec/dummy/config/initializers/wrap_parameters.rb
119
+ - spec/dummy/config/locales/en.yml
120
+ - spec/dummy/config/routes.rb
121
+ - spec/dummy/db/migrate/20120726155403_create_users.rb
122
+ - spec/dummy/db/migrate/20120726155456_create_posts.rb
123
+ - spec/dummy/db/schema.rb
124
+ - spec/dummy/lib/assets/.gitkeep
125
+ - spec/dummy/log/.gitkeep
126
+ - spec/dummy/script/rails
127
+ - spec/likes_tracker_spec.rb
128
+ - spec/spec_helper.rb
129
+ - spec/support/factories.rb
130
+ homepage: http://github.com/apeacox/likes_tracker
131
+ licenses: []
132
+ post_install_message:
133
+ rdoc_options: []
134
+ require_paths:
135
+ - lib
136
+ required_ruby_version: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ required_rubygems_version: !ruby/object:Gem::Requirement
143
+ none: false
144
+ requirements:
145
+ - - ! '>='
146
+ - !ruby/object:Gem::Version
147
+ version: '0'
148
+ requirements: []
149
+ rubyforge_project:
150
+ rubygems_version: 1.8.24
151
+ signing_key:
152
+ specification_version: 3
153
+ summary: ! 'LikesTracker tracks likes between ActiveModel compliant models using a
154
+ Redis backend. Once you include this lib, you can add/remove likes from an object
155
+ to another (eg: a User likes a Post), plus a bunch of useful method helpers.'
156
+ test_files:
157
+ - spec/dummy/README.rdoc
158
+ - spec/dummy/Rakefile
159
+ - spec/dummy/app/assets/javascripts/application.js
160
+ - spec/dummy/app/assets/stylesheets/application.css
161
+ - spec/dummy/app/controllers/application_controller.rb
162
+ - spec/dummy/app/helpers/application_helper.rb
163
+ - spec/dummy/app/mailers/.gitkeep
164
+ - spec/dummy/app/models/.gitkeep
165
+ - spec/dummy/app/models/post.rb
166
+ - spec/dummy/app/models/user.rb
167
+ - spec/dummy/app/views/layouts/application.html.erb
168
+ - spec/dummy/config.ru
169
+ - spec/dummy/config/application.rb
170
+ - spec/dummy/config/boot.rb
171
+ - spec/dummy/config/database.yml
172
+ - spec/dummy/config/environment.rb
173
+ - spec/dummy/config/environments/development.rb
174
+ - spec/dummy/config/environments/production.rb
175
+ - spec/dummy/config/environments/test.rb
176
+ - spec/dummy/config/initializers/backtrace_silencers.rb
177
+ - spec/dummy/config/initializers/inflections.rb
178
+ - spec/dummy/config/initializers/mime_types.rb
179
+ - spec/dummy/config/initializers/redis.rb
180
+ - spec/dummy/config/initializers/secret_token.rb
181
+ - spec/dummy/config/initializers/session_store.rb
182
+ - spec/dummy/config/initializers/wrap_parameters.rb
183
+ - spec/dummy/config/locales/en.yml
184
+ - spec/dummy/config/routes.rb
185
+ - spec/dummy/db/migrate/20120726155403_create_users.rb
186
+ - spec/dummy/db/migrate/20120726155456_create_posts.rb
187
+ - spec/dummy/db/schema.rb
188
+ - spec/dummy/lib/assets/.gitkeep
189
+ - spec/dummy/log/.gitkeep
190
+ - spec/dummy/script/rails
191
+ - spec/likes_tracker_spec.rb
192
+ - spec/spec_helper.rb
193
+ - spec/support/factories.rb