acts_as_favoritor 1.0.0 → 1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fa5428168c7b8609f60f208889cdc00039ec182e
4
- data.tar.gz: 0c44c7a38d6a165069afa96cba0eeff74eee1d16
3
+ metadata.gz: 51b26144e2f4621c21c2733217190573550f4457
4
+ data.tar.gz: 7ac65f0fd1d99f1a22186a975d11031cc79ed047
5
5
  SHA512:
6
- metadata.gz: 675ee97d8c2d37bd81627d738fa629eff5dff73558962b8e3e3862f4095ca420b278e000a066ad06cc8182d5d25a2143ba693f2a78e747b863b87d4c36d0a73a
7
- data.tar.gz: 64e88864d50a179520792857dfcdb70f9b759f3097b92a23271f02b709d59bbd8d0722986872255613d2085f7a3de289aa4b13e6c34a05f15d1c4ecbcd273408
6
+ metadata.gz: bbb04b517631931b8fc8cd4eb091eb43f3a1b09635ca7aecc2d5d0979731177989db605b8114bcf7de871a58ea5ee9744b20b22fc0f00fee74ac4206d5102c13
7
+ data.tar.gz: d710797509f89e5bf16936a9f8da7f8d72f47cf0eb635dc229b04b23d9081be374e2a3718db12855c1044cb5bcd13b139baacffa1139fa2176b09d0eb3c29d05
data/.gitignore CHANGED
@@ -4,5 +4,4 @@ rdoc
4
4
  memory
5
5
  *.gem
6
6
  .rvmrc
7
- Gemfile.lock
8
7
  log
data/CHANGELOG.md ADDED
@@ -0,0 +1,11 @@
1
+ ### unreleased
2
+
3
+ * nothing yet
4
+
5
+ ### 1.0.1 - 2017-08-22
6
+
7
+ * bug fixes
8
+
9
+ ### 1.0.0 - 2017-08-22
10
+
11
+ Initial release
data/Gemfile.lock ADDED
@@ -0,0 +1,131 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ acts_as_favoritor (1.0.1)
5
+ activerecord (>= 4.0)
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ actioncable (5.1.3)
11
+ actionpack (= 5.1.3)
12
+ nio4r (~> 2.0)
13
+ websocket-driver (~> 0.6.1)
14
+ actionmailer (5.1.3)
15
+ actionpack (= 5.1.3)
16
+ actionview (= 5.1.3)
17
+ activejob (= 5.1.3)
18
+ mail (~> 2.5, >= 2.5.4)
19
+ rails-dom-testing (~> 2.0)
20
+ actionpack (5.1.3)
21
+ actionview (= 5.1.3)
22
+ activesupport (= 5.1.3)
23
+ rack (~> 2.0)
24
+ rack-test (~> 0.6.3)
25
+ rails-dom-testing (~> 2.0)
26
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
27
+ actionview (5.1.3)
28
+ activesupport (= 5.1.3)
29
+ builder (~> 3.1)
30
+ erubi (~> 1.4)
31
+ rails-dom-testing (~> 2.0)
32
+ rails-html-sanitizer (~> 1.0, >= 1.0.3)
33
+ activejob (5.1.3)
34
+ activesupport (= 5.1.3)
35
+ globalid (>= 0.3.6)
36
+ activemodel (5.1.3)
37
+ activesupport (= 5.1.3)
38
+ activerecord (5.1.3)
39
+ activemodel (= 5.1.3)
40
+ activesupport (= 5.1.3)
41
+ arel (~> 8.0)
42
+ activesupport (5.1.3)
43
+ concurrent-ruby (~> 1.0, >= 1.0.2)
44
+ i18n (~> 0.7)
45
+ minitest (~> 5.1)
46
+ tzinfo (~> 1.1)
47
+ arel (8.0.0)
48
+ builder (3.2.3)
49
+ concurrent-ruby (1.0.5)
50
+ erubi (1.6.1)
51
+ factory_girl (4.8.0)
52
+ activesupport (>= 3.0.0)
53
+ globalid (0.4.0)
54
+ activesupport (>= 4.2.0)
55
+ i18n (0.8.6)
56
+ loofah (2.0.3)
57
+ nokogiri (>= 1.5.9)
58
+ mail (2.6.6)
59
+ mime-types (>= 1.16, < 4)
60
+ method_source (0.8.2)
61
+ mime-types (3.1)
62
+ mime-types-data (~> 3.2015)
63
+ mime-types-data (3.2016.0521)
64
+ mini_portile2 (2.2.0)
65
+ minitest (5.10.3)
66
+ nio4r (2.1.0)
67
+ nokogiri (1.8.0-x86-mingw32)
68
+ mini_portile2 (~> 2.2.0)
69
+ rack (2.0.3)
70
+ rack-test (0.6.3)
71
+ rack (>= 1.0)
72
+ rails (5.1.3)
73
+ actioncable (= 5.1.3)
74
+ actionmailer (= 5.1.3)
75
+ actionpack (= 5.1.3)
76
+ actionview (= 5.1.3)
77
+ activejob (= 5.1.3)
78
+ activemodel (= 5.1.3)
79
+ activerecord (= 5.1.3)
80
+ activesupport (= 5.1.3)
81
+ bundler (>= 1.3.0)
82
+ railties (= 5.1.3)
83
+ sprockets-rails (>= 2.0.0)
84
+ rails-dom-testing (2.0.3)
85
+ activesupport (>= 4.2.0)
86
+ nokogiri (>= 1.6)
87
+ rails-html-sanitizer (1.0.3)
88
+ loofah (~> 2.0)
89
+ railties (5.1.3)
90
+ actionpack (= 5.1.3)
91
+ activesupport (= 5.1.3)
92
+ method_source
93
+ rake (>= 0.8.7)
94
+ thor (>= 0.18.1, < 2.0)
95
+ rake (12.0.0)
96
+ shoulda (3.5.0)
97
+ shoulda-context (~> 1.0, >= 1.0.1)
98
+ shoulda-matchers (>= 1.4.1, < 3.0)
99
+ shoulda-context (1.2.2)
100
+ shoulda-matchers (2.8.0)
101
+ activesupport (>= 3.0.0)
102
+ shoulda_create (0.0.9)
103
+ sprockets (3.7.1)
104
+ concurrent-ruby (~> 1.0)
105
+ rack (> 1, < 3)
106
+ sprockets-rails (3.2.0)
107
+ actionpack (>= 4.0)
108
+ activesupport (>= 4.0)
109
+ sprockets (>= 3.0.0)
110
+ sqlite3 (1.3.13-x86-mingw32)
111
+ thor (0.20.0)
112
+ thread_safe (0.3.6)
113
+ tzinfo (1.2.3)
114
+ thread_safe (~> 0.1)
115
+ websocket-driver (0.6.5)
116
+ websocket-extensions (>= 0.1.0)
117
+ websocket-extensions (0.1.2)
118
+
119
+ PLATFORMS
120
+ x86-mingw32
121
+
122
+ DEPENDENCIES
123
+ acts_as_favoritor!
124
+ factory_girl (~> 4.8)
125
+ rails (>= 4.0)
126
+ shoulda (~> 3.5)
127
+ shoulda_create (~> 0.0)
128
+ sqlite3 (~> 1.3)
129
+
130
+ BUNDLED WITH
131
+ 1.15.4
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # acts_as_favoitor - Add Favorites to you Rails app
1
+ # acts_as_favoritor - Add Favorites to you Rails app
2
2
 
3
3
  <img src="https://travis-ci.org/slooob/acts_as_favoritor.svg?branch=master" />
4
4
 
@@ -2,28 +2,28 @@
2
2
  $:.push File.expand_path('../lib', __FILE__)
3
3
  require 'acts_as_favoritor/version'
4
4
 
5
- Gem::Specification.new do |s|
6
- s.name = 'acts_as_favoritor'
7
- s.version = ActsAsFavoritor::VERSION
8
- s.authors = ['Jonas Hübotter']
9
- s.email = ['developer@slooob.com']
10
- s.homepage = 'https://github.com/slooob/acts_as_favoritor'
11
- s.summary = 'A Rubygem to add Favorite functionality for ActiveRecord models'
12
- s.description = 'acts_as_favoritor is a Rubygem to allow any ActiveRecord model to favorite any other model. This is accomplished through a double polymorphic relationship on the Favorite model. There is also built in support for blocking/un-blocking favorite records.'
13
- s.license = 'MIT'
5
+ Gem::Specification.new do |gem|
6
+ gem.name = 'acts_as_favoritor'
7
+ gem.version = ActsAsFavoritor::VERSION
8
+ gem.authors = ['Jonas Hübotter']
9
+ gem.email = ['developer@slooob.com']
10
+ gem.homepage = 'https://github.com/slooob/acts_as_favoritor'
11
+ gem.summary = 'A Rubygem to add Favorite functionality for ActiveRecord models'
12
+ gem.description = 'acts_as_favoritor is a Rubygem to allow any ActiveRecord model to favorite any other model. This is accomplished through a double polymorphic relationship on the Favorite model. There is also built in support for blocking/un-blocking favorite records.'
13
+ gem.license = 'MIT'
14
14
 
15
- s.rubyforge_project = 'acts_as_follower'
15
+ gem.files = `git ls-files`.split("\n")
16
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
+ gem.require_paths = ['lib']
16
19
 
17
- s.files = `git ls-files`.split("\n")
18
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
- s.require_paths = ['lib']
20
+ gem.required_ruby_version = '>= 2.0'
21
21
 
22
- s.add_dependency 'activerecord', '>= 4.0'
22
+ gem.add_dependency 'activerecord', '>= 4.0'
23
23
 
24
- s.add_development_dependency 'sqlite3', '~> 1'
25
- s.add_development_dependency 'shoulda_create', '~> 0'
26
- s.add_development_dependency 'shoulda', '~> 3'
27
- s.add_development_dependency 'factory_girl', '~> 4'
28
- s.add_development_dependency 'rails', '>= 4.0'
24
+ gem.add_development_dependency 'sqlite3', '~> 1.3'
25
+ gem.add_development_dependency 'shoulda_create', '~> 0.0'
26
+ gem.add_development_dependency 'shoulda', '~> 3.5'
27
+ gem.add_development_dependency 'factory_girl', '~> 4.8'
28
+ gem.add_development_dependency 'rails', '>= 4.0'
29
29
  end
@@ -30,6 +30,6 @@ module ActsAsFavoritor
30
30
 
31
31
  setup
32
32
 
33
- require 'favoritor/railtie' if defined?(Rails) && Rails::VERSION::MAJOR >= 3
34
-
33
+ require 'acts_as_favoritor/railtie' if defined?(Rails)
34
+
35
35
  end
@@ -25,9 +25,9 @@ module ActsAsFavoritor #:nodoc:
25
25
  favorites = favoritor_type.constantize.
26
26
  joins(:favorites).
27
27
  where('favorites.blocked': false,
28
- 'favorites.followable_id': self.id,
29
- 'favorites.followable_type': parent_class_name(self),
30
- 'favorites.follower_type': favoritor_type)
28
+ 'favorites.favoritable_id': self.id,
29
+ 'favorites.favoritable_type': parent_class_name(self),
30
+ 'favorites.favoritor_type': favoritor_type)
31
31
  if options.has_key? :limit
32
32
  favorites = favorites.limit options[:limit]
33
33
  end
@@ -1,5 +1,5 @@
1
1
  module ActsAsFavoritor #:nodoc:
2
- module Follower
2
+ module Favoritor
3
3
 
4
4
  def self.included base
5
5
  base.extend ClassMethods
@@ -15,12 +15,12 @@ module ActsAsFavoritor #:nodoc:
15
15
 
16
16
  module InstanceMethods
17
17
 
18
- # Returns true if this instance is following the object passed as an argument.
18
+ # Returns true if this instance has favorited the object passed as an argument.
19
19
  def favorited? favoritable
20
20
  0 < Favorite.unblocked.for_favoritor(self).for_favoritable(favoritable).count
21
21
  end
22
22
 
23
- # Returns the number of objects this instance is following.
23
+ # Returns the number of objects this instance has favorited.
24
24
  def favorites_count
25
25
  Favorite.unblocked.for_favoritor(self).count
26
26
  end
@@ -36,7 +36,7 @@ module ActsAsFavoritor #:nodoc:
36
36
 
37
37
  # Deletes the favorite record if it exists.
38
38
  def remove_favorite favoritable
39
- if favorite = get_Favoritor favoritable
39
+ if favorite = get_Favoritor(favoritable)
40
40
  favorite.destroy
41
41
  end
42
42
  end
@@ -47,7 +47,7 @@ module ActsAsFavoritor #:nodoc:
47
47
  end
48
48
 
49
49
  # Returns the favorite records related to this instance by type.
50
- def favorites_by_type favoritable_type, options={}
50
+ def favorites_by_type favoritable_type, options = {}
51
51
  favorites_scope = favorites_scoped.for_favoritable_type favoritable_type
52
52
  favorites_scope = apply_options_to_scope favorites_scope, options
53
53
  end
@@ -60,7 +60,7 @@ module ActsAsFavoritor #:nodoc:
60
60
 
61
61
  # Returns the actual records which this instance has favorited.
62
62
  def all_favorited options = {}
63
- all_favorites(options).collect{ |f| f.favoritable }
63
+ all_favorites(options).collect{ |f| f.favoritable }
64
64
  end
65
65
 
66
66
  # Returns the actual records of a particular type which this record has fovarited.
@@ -68,9 +68,9 @@ module ActsAsFavoritor #:nodoc:
68
68
  favoritables = favoritable_type.constantize.
69
69
  joins(:favorited).
70
70
  where('favorites.blocked': false,
71
- 'favorites.favoritor_id': self.id,
72
- 'favorites.favoritor_type': parent_class_name(self),
73
- 'favorites.favoritable_type': favoritable_type)
71
+ 'favorites.favoritor_id': self.id,
72
+ 'favorites.favoritor_type': parent_class_name(self),
73
+ 'favorites.favoritable_type': favoritable_type)
74
74
  if options.has_key? :limit
75
75
  favoritables = favoritables.limit options[:limit]
76
76
  end
@@ -1,5 +1,5 @@
1
- module ActsAsFollower
2
- module FollowerLib
1
+ module ActsAsFavoritor
2
+ module FavoritorLib
3
3
 
4
4
  private
5
5
 
@@ -1,10 +1,9 @@
1
1
  require 'rails'
2
2
 
3
3
  module ActsAsFavoritor
4
-
5
4
  class Railtie < Rails::Railtie
6
5
 
7
- initializer 'acts_as_favoritor.active_record' do |app|
6
+ initializer 'acts_as_favoritor.active_record' do
8
7
  ActiveSupport.on_load :active_record do
9
8
  include ActsAsFavoritor::Favoritor
10
9
  include ActsAsFavoritor::Favoritable
@@ -12,5 +11,4 @@ module ActsAsFavoritor
12
11
  end
13
12
 
14
13
  end
15
-
16
14
  end
@@ -1,5 +1,5 @@
1
1
  module ActsAsFavoritor
2
2
 
3
- VERSION = '1.0.0'
4
-
3
+ VERSION = '1.0.1'
4
+
5
5
  end
@@ -1,7 +1,7 @@
1
1
  require 'rails/generators'
2
2
  require 'rails/generators/migration'
3
3
 
4
- class ActsAsFollowerGenerator < Rails::Generators::Base
4
+ class ActsAsFavoritorGenerator < Rails::Generators::Base
5
5
 
6
6
  include Rails::Generators::Migration
7
7
 
@@ -22,7 +22,7 @@ class ActsAsFollowerGenerator < Rails::Generators::Base
22
22
  end
23
23
 
24
24
  def create_model
25
- template 'model.rb', 'app/models/follow.rb'
25
+ template 'model.rb', 'app/models/favorite.rb'
26
26
  end
27
27
 
28
28
  end
@@ -1,9 +1,9 @@
1
- class ActsAsFavoritorMigration < ActiveRecord::Migration<% if Rails::VERSION::MAJOR >= 5 %>[<%= Rails::VERSION %>]<% end %>
1
+ class ActsAsFavoritorMigration < ActiveRecord::Migration<% if Rails::VERSION::MAJOR >= 5 %>[Rails::VERSION::STRING[0..2].to_f]<% end %>
2
2
  def self.up
3
3
  create_table :favorites, force: true do |t|
4
4
  t.references :favoritable, polymorphic: true, null: false
5
5
  t.references :favoritor, polymorphic: true, null: false
6
- t.string :types, default: [:favorite].to_yaml, null: false
6
+ t.string :lists, default: [:favorites].to_yaml, null: false
7
7
  t.boolean :blocked, default: false, null: false
8
8
  t.timestamps
9
9
  end
@@ -3,9 +3,9 @@ class Favorite < ActiveRecord::Base
3
3
  extend ActsAsFavoritor::FavoritorLib
4
4
  extend ActsAsFavoritor::FavoriteScopes
5
5
 
6
- serialize :types
6
+ serialize :lists
7
7
 
8
- # NOTE: Follows belong to the 'favoritable' and 'favoritor' interface
8
+ # NOTE: Favorites belong to the 'favoritable' and 'favoritor' interface
9
9
  belongs_to :favoritable, polymorphic: true
10
10
  belongs_to :favoritor, polymorphic: true
11
11
 
@@ -0,0 +1,283 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ class ActsAsFavoritableTest < ActiveSupport::TestCase
4
+
5
+ context 'instance methods' do
6
+ setup do
7
+ @sam = FactoryGirl.create :sam
8
+ end
9
+
10
+ should 'be defined' do
11
+ assert @sam.respond_to? :favoritors_count
12
+ assert @sam.respond_to? :favoritors
13
+ assert @sam.respond_to? :favorited_by?
14
+ end
15
+ end
16
+
17
+ context 'acts_as_favoritable' do
18
+ setup do
19
+ @sam = FactoryGirl.create :sam
20
+ @jon = FactoryGirl.create :jon
21
+ @oasis = FactoryGirl.create :oasis
22
+ @metallica = FactoryGirl.create :metallica
23
+ @green_day = FactoryGirl.create :green_day
24
+ @blink_182 = FactoryGirl.create :blink_182
25
+ @sam.favorite @jon
26
+ end
27
+
28
+ context 'favoritors_count' do
29
+ should 'return the number of favoritors' do
30
+ assert_equal 0, @sam.favoritors_count
31
+ assert_equal 1, @jon.favoritors_count
32
+ end
33
+
34
+ should 'return the proper number of multiple favoritors' do
35
+ @bob = FactoryGirl.create :bob
36
+ @sam.favorite @bob
37
+ assert_equal 0, @sam.favoritors_count
38
+ assert_equal 1, @jon.favoritors_count
39
+ assert_equal 1, @bob.favoritors_count
40
+ end
41
+ end
42
+
43
+ context 'favoritors' do
44
+ should 'return users' do
45
+ assert_equal [], @sam.favoritors
46
+ assert_equal [@sam], @jon.favoritors
47
+ end
48
+
49
+ should 'return users (multiple favoritors)' do
50
+ @bob = FactoryGirl.create :bob
51
+ @sam.favorite @bob
52
+ assert_equal [], @sam.favoritors
53
+ assert_equal [@sam], @jon.favoritors
54
+ assert_equal [@sam], @bob.favoritors
55
+ end
56
+
57
+ should 'return users (multiple favoritors, complex)' do
58
+ @bob = FactoryGirl.create :bob
59
+ @sam.favorite @bob
60
+ @jon.favorite @bob
61
+ assert_equal [], @sam.favoritors
62
+ assert_equal [@sam], @jon.favoritors
63
+ assert_equal [@sam, @jon], @bob.favoritors
64
+ end
65
+
66
+ should 'accept AR options' do
67
+ @bob = FactoryGirl.create :bob
68
+ @bob.favorite @jon
69
+ assert_equal 1, @jon.favoritors(limit: 1).count
70
+ end
71
+ end
72
+
73
+ context 'favorited_by' do
74
+ should 'return_favoritor_status' do
75
+ assert_equal true, @jon.favorited_by?(@sam)
76
+ assert_equal false, @sam.favorited_by?(@jon)
77
+ end
78
+ end
79
+
80
+ context 'destroying a favoritable' do
81
+ setup do
82
+ @jon.destroy
83
+ end
84
+
85
+ should_change ('Favorite count', by: -1) { Favorite.count }
86
+ should_change ('@sam.all_favorited.size', by: -1) { @sam.all_favorited.size }
87
+ end
88
+
89
+ context 'get favorite record' do
90
+ setup do
91
+ @bob = FactoryGirl.create :bob
92
+ @favorite = @bob.favorite @sam
93
+ end
94
+
95
+ should 'return favorite record' do
96
+ assert_equal @favorite, @sam.get_favorite_for(@bob)
97
+ end
98
+
99
+ should 'return nil' do
100
+ assert_nil @sam.get_favorite_for(@jon)
101
+ end
102
+ end
103
+
104
+ context 'blocks' do
105
+ setup do
106
+ @bob = FactoryGirl.create :bob
107
+ @jon.block @sam
108
+ @jon.block @bob
109
+ end
110
+
111
+ should 'accept AR options' do
112
+ assert_equal 1, @jon.blocks(limit: 1).count
113
+ end
114
+ end
115
+
116
+ context 'blocking a favoritor' do
117
+ context 'in my favorited list' do
118
+ setup do
119
+ @jon.block @sam
120
+ end
121
+
122
+ should 'remove him from favoritors' do
123
+ assert_equal 0, @jon.favoritors_count
124
+ end
125
+
126
+ should 'add him to the blocked favoritors' do
127
+ assert_equal 1, @jon.blocked_favoritors_count
128
+ end
129
+
130
+ should 'not be able to favorite again' do
131
+ @jon.favorite @sam
132
+ assert_equal 0, @jon.favoritors_count
133
+ end
134
+
135
+ should 'not be present when listing favoritors' do
136
+ assert_equal [], @jon.favoritors
137
+ end
138
+
139
+ should 'be in the list of blocks' do
140
+ assert_equal [@sam], @jon.blocks
141
+ end
142
+ end
143
+
144
+ context 'not in my favorited list' do
145
+ setup do
146
+ @sam.block @jon
147
+ end
148
+
149
+ should 'add him to the blocked favoritors' do
150
+ assert_equal 1, @sam.blocked_favoritors_count
151
+ end
152
+
153
+ should 'not be able to favorite again' do
154
+ @sam.favorite @jon
155
+ assert_equal 0, @sam.favoritors_count
156
+ end
157
+
158
+ should 'not be present when listing favoritors' do
159
+ assert_equal [], @sam.favoritors
160
+ end
161
+
162
+ should 'be in the list of blocks' do
163
+ assert_equal [@jon], @sam.blocks
164
+ end
165
+ end
166
+ end
167
+
168
+ context 'unblocking a blocked favorite' do
169
+ setup do
170
+ @jon.block @sam
171
+ @jon.unblock @sam
172
+ end
173
+
174
+ should 'not include the unblocked user in the list of favoritors' do
175
+ assert_equal [], @jon.favoritors
176
+ end
177
+
178
+ should 'remove him from the blocked favoritors' do
179
+ assert_equal 0, @jon.blocked_favoritors_count
180
+ assert_equal [], @jon.blocks
181
+ end
182
+ end
183
+
184
+ context 'unblock a non-existent favorite' do
185
+ setup do
186
+ @sam.remove_favorite @jon
187
+ @jon.unblock @sam
188
+ end
189
+
190
+ should 'not be in the list of favoritors' do
191
+ assert_equal [], @jon.favoritors
192
+ end
193
+
194
+ should 'not be in the blocked favoritors count' do
195
+ assert_equal 0, @jon.blocked_favoritors_count
196
+ end
197
+
198
+ should 'not be in the blocks list' do
199
+ assert_equal [], @jon.blocks
200
+ end
201
+ end
202
+
203
+ context 'favoritors_by_type' do
204
+ setup do
205
+ @sam.favorite @oasis
206
+ @jon.favorite @oasis
207
+ end
208
+
209
+ should 'return the favoritors for given type' do
210
+ assert_equal [@sam], @jon.favoritors_by_type('User')
211
+ assert_equal [@sam, @jon], @oasis.favoritors_by_type('User')
212
+ end
213
+
214
+ should 'not return block favoritors in the favoritors for a given type' do
215
+ @oasis.block @jon
216
+ assert_equal [@sam], @oasis.favoritors_by_type('User')
217
+ end
218
+
219
+ should 'return the count for favoritors_by_type_count for a given type' do
220
+ assert_equal 1, @jon.favoritors_by_type_count('User')
221
+ assert_equal 2, @oasis.favoritors_by_type_count('User')
222
+ end
223
+
224
+ should 'not count blocked favorites in the count' do
225
+ @oasis.block @sam
226
+ assert_equal 1, @oasis.favoritors_by_type_count('User')
227
+ end
228
+ end
229
+
230
+ context 'favoritors_with_sti' do
231
+ setup do
232
+ @sam.favorite @green_day
233
+ @sam.favorite @blink_182
234
+ end
235
+
236
+ should 'return the favoritors for given type' do
237
+ assert_equal @sam.favorites_by_type('Band').first.favoritable, @green_day.becomes(Band)
238
+ assert_equal @sam.favorites_by_type('Band').second.favoritable, @blink_182.becomes(Band)
239
+ assert @green_day.favoritors_by_type('User').include?(@sam)
240
+ assert @blink_182.favoritors_by_type('User').include?(@sam)
241
+ end
242
+ end
243
+
244
+ context 'method_missing' do
245
+ setup do
246
+ @sam.favorite @oasis
247
+ @jon.favorite @oasis
248
+ end
249
+
250
+ should 'return the favoritors for given type' do
251
+ assert_equal [@sam], @jon.user_favoritors
252
+ assert_equal [@sam, @jon], @oasis.user_favoritors
253
+ end
254
+
255
+ should 'not return block favoritors in the favoritors for a given type' do
256
+ @oasis.block @jon
257
+ assert_equal [@sam], @oasis.user_favoritors
258
+ end
259
+
260
+ should 'return the count for favoritors_by_type_count for a given type' do
261
+ assert_equal 1, @jon.count_user_favoritors
262
+ assert_equal 2, @oasis.count_user_favoritors
263
+ end
264
+
265
+ should 'not count blocked favorites in the count' do
266
+ @oasis.block @sam
267
+ assert_equal 1, @oasis.count_user_favoritors
268
+ end
269
+ end
270
+
271
+ context 'respond_to?' do
272
+ should 'advertise that it responds to favorited methods' do
273
+ assert @oasis.respond_to?(:user_favoritors)
274
+ assert @oasis.respond_to?(:user_favoritors_count)
275
+ end
276
+
277
+ should 'return false when called with a nonexistent method' do
278
+ assert (not @oasis.respond_to?(:foobar))
279
+ end
280
+ end
281
+
282
+ end
283
+ end