acts_as_favoritor 2.0.0 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/LICENSE +1 -1
- data/README.md +1 -3
- data/lib/acts_as_favoritor.rb +2 -11
- data/lib/acts_as_favoritor/configuration.rb +10 -0
- data/lib/acts_as_favoritor/favoritable.rb +1 -1
- data/lib/acts_as_favoritor/favorite_scopes.rb +1 -1
- data/lib/acts_as_favoritor/favoritor.rb +425 -425
- data/lib/acts_as_favoritor/railtie.rb +1 -1
- data/lib/acts_as_favoritor/version.rb +1 -1
- data/lib/generators/templates/model.rb +1 -2
- metadata +3 -44
- data/.github/issue_template.md +0 -14
- data/.github/pull_request_template.md +0 -21
- data/.gitignore +0 -8
- data/.travis.yml +0 -3
- data/CODE_OF_CONDUCT.md +0 -46
- data/CONTRIBUTING.md +0 -1
- data/DEPRECATIONS.md +0 -5
- data/Gemfile +0 -9
- data/INSTALL.md +0 -3
- data/Rakefile +0 -16
- data/acts_as_favoritor.gemspec +0 -30
- data/init.rb +0 -1
- data/test/acts_as_favoritable_test.rb +0 -283
- data/test/acts_as_favoritor_test.rb +0 -224
- data/test/dummy30/Gemfile +0 -1
- data/test/dummy30/Rakefile +0 -4
- data/test/dummy30/app/models/application_record.rb +0 -3
- data/test/dummy30/app/models/band.rb +0 -4
- data/test/dummy30/app/models/band/punk.rb +0 -4
- data/test/dummy30/app/models/band/punk/pop_punk.rb +0 -4
- data/test/dummy30/app/models/custom_record.rb +0 -3
- data/test/dummy30/app/models/some.rb +0 -5
- data/test/dummy30/app/models/user.rb +0 -5
- data/test/dummy30/config.ru +0 -2
- data/test/dummy30/config/application.rb +0 -14
- data/test/dummy30/config/boot.rb +0 -10
- data/test/dummy30/config/database.yml +0 -6
- data/test/dummy30/config/environment.rb +0 -5
- data/test/dummy30/config/environments/development.rb +0 -7
- data/test/dummy30/config/environments/test.rb +0 -6
- data/test/dummy30/config/initializers/acts_as_favoritor.rb +0 -9
- data/test/dummy30/config/initializers/secret_token.rb +0 -1
- data/test/dummy30/config/initializers/session_store.rb +0 -1
- data/test/dummy30/config/locales/en.yml +0 -2
- data/test/dummy30/config/routes.rb +0 -2
- data/test/factories/bands.rb +0 -17
- data/test/factories/somes.rb +0 -9
- data/test/factories/users.rb +0 -13
- data/test/favorite_test.rb +0 -10
- data/test/schema.rb +0 -26
- data/test/test_helper.rb +0 -22
@@ -3,12 +3,11 @@ class Favorite < ActiveRecord::Base
|
|
3
3
|
extend ActsAsFavoritor::FavoritorLib
|
4
4
|
extend ActsAsFavoritor::FavoriteScopes
|
5
5
|
|
6
|
-
# NOTE: Favorites belong to the 'favoritable' and 'favoritor' interface
|
7
6
|
belongs_to :favoritable, polymorphic: true
|
8
7
|
belongs_to :favoritor, polymorphic: true
|
9
8
|
|
10
9
|
def block!
|
11
|
-
self.
|
10
|
+
self.update_attributes blocked: true
|
12
11
|
end
|
13
12
|
|
14
13
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: acts_as_favoritor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jonas Hübotter
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-01-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -119,21 +119,9 @@ executables: []
|
|
119
119
|
extensions: []
|
120
120
|
extra_rdoc_files: []
|
121
121
|
files:
|
122
|
-
- ".github/issue_template.md"
|
123
|
-
- ".github/pull_request_template.md"
|
124
|
-
- ".gitignore"
|
125
|
-
- ".travis.yml"
|
126
122
|
- CHANGELOG.md
|
127
|
-
- CODE_OF_CONDUCT.md
|
128
|
-
- CONTRIBUTING.md
|
129
|
-
- DEPRECATIONS.md
|
130
|
-
- Gemfile
|
131
|
-
- INSTALL.md
|
132
123
|
- LICENSE
|
133
124
|
- README.md
|
134
|
-
- Rakefile
|
135
|
-
- acts_as_favoritor.gemspec
|
136
|
-
- init.rb
|
137
125
|
- lib/acts_as_favoritor.rb
|
138
126
|
- lib/acts_as_favoritor/configuration.rb
|
139
127
|
- lib/acts_as_favoritor/favoritable.rb
|
@@ -147,35 +135,6 @@ files:
|
|
147
135
|
- lib/generators/templates/initializer.rb
|
148
136
|
- lib/generators/templates/migration.rb.erb
|
149
137
|
- lib/generators/templates/model.rb
|
150
|
-
- test/acts_as_favoritable_test.rb
|
151
|
-
- test/acts_as_favoritor_test.rb
|
152
|
-
- test/dummy30/Gemfile
|
153
|
-
- test/dummy30/Rakefile
|
154
|
-
- test/dummy30/app/models/application_record.rb
|
155
|
-
- test/dummy30/app/models/band.rb
|
156
|
-
- test/dummy30/app/models/band/punk.rb
|
157
|
-
- test/dummy30/app/models/band/punk/pop_punk.rb
|
158
|
-
- test/dummy30/app/models/custom_record.rb
|
159
|
-
- test/dummy30/app/models/some.rb
|
160
|
-
- test/dummy30/app/models/user.rb
|
161
|
-
- test/dummy30/config.ru
|
162
|
-
- test/dummy30/config/application.rb
|
163
|
-
- test/dummy30/config/boot.rb
|
164
|
-
- test/dummy30/config/database.yml
|
165
|
-
- test/dummy30/config/environment.rb
|
166
|
-
- test/dummy30/config/environments/development.rb
|
167
|
-
- test/dummy30/config/environments/test.rb
|
168
|
-
- test/dummy30/config/initializers/acts_as_favoritor.rb
|
169
|
-
- test/dummy30/config/initializers/secret_token.rb
|
170
|
-
- test/dummy30/config/initializers/session_store.rb
|
171
|
-
- test/dummy30/config/locales/en.yml
|
172
|
-
- test/dummy30/config/routes.rb
|
173
|
-
- test/factories/bands.rb
|
174
|
-
- test/factories/somes.rb
|
175
|
-
- test/factories/users.rb
|
176
|
-
- test/favorite_test.rb
|
177
|
-
- test/schema.rb
|
178
|
-
- test/test_helper.rb
|
179
138
|
homepage: https://github.com/jonhue/acts_as_favoritor
|
180
139
|
licenses:
|
181
140
|
- MIT
|
@@ -199,7 +158,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
199
158
|
version: '0'
|
200
159
|
requirements: []
|
201
160
|
rubyforge_project:
|
202
|
-
rubygems_version: 2.7.
|
161
|
+
rubygems_version: 2.7.4
|
203
162
|
signing_key:
|
204
163
|
specification_version: 4
|
205
164
|
summary: A Rubygem to add Favorite, Follow, Vote, etc. functionality to ActiveRecord
|
data/.github/issue_template.md
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
### Summary
|
2
|
-
|
3
|
-
Provide a general description of the code changes in your pull
|
4
|
-
request... were there any bugs you had fixed? If so, mention them. If
|
5
|
-
these bugs have open GitHub issues, be sure to tag them here as well,
|
6
|
-
to keep the conversation linked together.
|
7
|
-
|
8
|
-
### Other Information
|
9
|
-
|
10
|
-
If there's anything else that's important and relevant to your pull
|
11
|
-
request, mention that information here. This could include
|
12
|
-
benchmarks, or other information.
|
13
|
-
|
14
|
-
If you are updating any of the CHANGELOG files or are asked to update the
|
15
|
-
CHANGELOG files by reviewers, please add the CHANGELOG entry at the top of the file.
|
16
|
-
|
17
|
-
Finally, if your pull request affects documentation or any non-code
|
18
|
-
changes, guidelines for those changes are [available
|
19
|
-
here](https://github.com/jonhue/acts_as_favoritor/blob/master/CONTRIBUTING.md)
|
20
|
-
|
21
|
-
Thanks for contributing to acts_as_favoritor!
|
data/.gitignore
DELETED
data/.travis.yml
DELETED
data/CODE_OF_CONDUCT.md
DELETED
@@ -1,46 +0,0 @@
|
|
1
|
-
# Contributor Covenant Code of Conduct
|
2
|
-
|
3
|
-
## Our Pledge
|
4
|
-
|
5
|
-
In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
|
6
|
-
|
7
|
-
## Our Standards
|
8
|
-
|
9
|
-
Examples of behavior that contributes to creating a positive environment include:
|
10
|
-
|
11
|
-
* Using welcoming and inclusive language
|
12
|
-
* Being respectful of differing viewpoints and experiences
|
13
|
-
* Gracefully accepting constructive criticism
|
14
|
-
* Focusing on what is best for the community
|
15
|
-
* Showing empathy towards other community members
|
16
|
-
|
17
|
-
Examples of unacceptable behavior by participants include:
|
18
|
-
|
19
|
-
* The use of sexualized language or imagery and unwelcome sexual attention or advances
|
20
|
-
* Trolling, insulting/derogatory comments, and personal or political attacks
|
21
|
-
* Public or private harassment
|
22
|
-
* Publishing others' private information, such as a physical or electronic address, without explicit permission
|
23
|
-
* Other conduct which could reasonably be considered inappropriate in a professional setting
|
24
|
-
|
25
|
-
## Our Responsibilities
|
26
|
-
|
27
|
-
Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
|
28
|
-
|
29
|
-
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
|
30
|
-
|
31
|
-
## Scope
|
32
|
-
|
33
|
-
This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
|
34
|
-
|
35
|
-
## Enforcement
|
36
|
-
|
37
|
-
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at help@slooob.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
|
38
|
-
|
39
|
-
Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
|
40
|
-
|
41
|
-
## Attribution
|
42
|
-
|
43
|
-
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
|
44
|
-
|
45
|
-
[homepage]: http://contributor-covenant.org
|
46
|
-
[version]: http://contributor-covenant.org/version/1/4/
|
data/CONTRIBUTING.md
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
# Contributing
|
data/DEPRECATIONS.md
DELETED
data/Gemfile
DELETED
data/INSTALL.md
DELETED
data/Rakefile
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
require 'bundler'
|
2
|
-
Bundler::GemHelper.install_tasks
|
3
|
-
|
4
|
-
require 'rake'
|
5
|
-
require 'rake/testtask'
|
6
|
-
require 'rdoc/task'
|
7
|
-
|
8
|
-
desc 'Default: run unit tests.'
|
9
|
-
task default: :test
|
10
|
-
|
11
|
-
desc 'Test the acts_as_favoritor gem.'
|
12
|
-
Rake::TestTask.new(:test) do |t|
|
13
|
-
t.libs << 'lib'
|
14
|
-
t.pattern = 'test/**/*_test.rb'
|
15
|
-
t.verbose = true
|
16
|
-
end
|
data/acts_as_favoritor.gemspec
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
require File.expand_path(File.join('..', 'lib', 'acts_as_favoritor', 'version'), __FILE__)
|
3
|
-
|
4
|
-
Gem::Specification.new do |gem|
|
5
|
-
gem.name = 'acts_as_favoritor'
|
6
|
-
gem.version = ActsAsFavoritor::VERSION
|
7
|
-
gem.platform = Gem::Platform::RUBY
|
8
|
-
gem.summary = 'A Rubygem to add Favorite, Follow, Vote, etc. functionality to ActiveRecord models'
|
9
|
-
gem.description = 'acts_as_favoritor is a Rubygem to allow any ActiveRecord model to associate any other model including the option for multiple relationships per association with scopes. You are able to differentiate followers, favorites, watchers, votes and whatever else you can imagine through a single relationship. This is accomplished by a double polymorphic relationship on the Favorite model. There is also built in support for blocking/un-blocking favorite records as well as caching.'
|
10
|
-
gem.authors = 'Jonas Hübotter'
|
11
|
-
gem.email = 'jonas.huebotter@gmail.com'
|
12
|
-
gem.homepage = 'https://github.com/jonhue/acts_as_favoritor'
|
13
|
-
gem.license = 'MIT'
|
14
|
-
|
15
|
-
gem.files = `git ls-files`.split("\n")
|
16
|
-
gem.require_paths = ['lib']
|
17
|
-
|
18
|
-
gem.post_install_message = IO.read('INSTALL.md')
|
19
|
-
|
20
|
-
gem.required_ruby_version = '>= 2.3'
|
21
|
-
|
22
|
-
gem.add_dependency 'activerecord', '>= 5.0'
|
23
|
-
|
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', '>= 5.0'
|
29
|
-
gem.add_development_dependency 'tzinfo-data', '~> 1.2017'
|
30
|
-
end
|
data/init.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
require 'acts_as_favoritor'
|
@@ -1,283 +0,0 @@
|
|
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
|