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
@@ -1,224 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/test_helper'
|
2
|
-
|
3
|
-
class ActsAsFavoritorTest < 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? :favorited?
|
12
|
-
assert @sam.respond_to? :favorites_count
|
13
|
-
assert @sam.respond_to? :favorite
|
14
|
-
assert @sam.respond_to? :remove_favorite
|
15
|
-
assert @sam.respond_to? :favorites_by_type
|
16
|
-
assert @sam.respond_to? :all_favorites
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
context 'acts_as_favoritor' do
|
21
|
-
setup do
|
22
|
-
@sam = FactoryGirl.create :sam
|
23
|
-
@jon = FactoryGirl.create :jon
|
24
|
-
@oasis = FactoryGirl.create :oasis
|
25
|
-
@sam.favorite @jon
|
26
|
-
@sam.favorite @oasis
|
27
|
-
end
|
28
|
-
|
29
|
-
context 'favorited' do
|
30
|
-
should 'return favorited_status' do
|
31
|
-
assert_equal true, @sam.favorited?(@jon)
|
32
|
-
assert_equal false, @jon.favorited?(@sam)
|
33
|
-
end
|
34
|
-
|
35
|
-
should 'return favorites_count' do
|
36
|
-
assert_equal 2, @sam.favorites_count
|
37
|
-
assert_equal 0, @jon.favorites_count
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
context 'favorite a friend' do
|
42
|
-
setup do
|
43
|
-
@jon.favorite @sam
|
44
|
-
end
|
45
|
-
|
46
|
-
should_change('Favorite count', by: 1) { Favorite.count }
|
47
|
-
should_change('@jon.favorites_count', by: 1) { @jon.favorites_count }
|
48
|
-
|
49
|
-
should "set the favoritor" do
|
50
|
-
assert_equal @jon, Favorite.last.favoritor
|
51
|
-
end
|
52
|
-
|
53
|
-
should "set the favoritable" do
|
54
|
-
assert_equal @sam, Favorite.last.favoritable
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
context "favorite yourself" do
|
59
|
-
setup do
|
60
|
-
@jon.favorite @jon
|
61
|
-
end
|
62
|
-
|
63
|
-
should_not_change('Favorite count') { Favorite.count }
|
64
|
-
should_not_change('@jon.favorites_count') { @jon.favorites_count }
|
65
|
-
|
66
|
-
should 'not set the favoritor' do
|
67
|
-
assert_not_equal @jon, Favorite.last.favoritor
|
68
|
-
end
|
69
|
-
|
70
|
-
should 'not set the favoritable' do
|
71
|
-
assert_not_equal @jon, Favorite.last.favoritable
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
context 'remove_favorite' do
|
76
|
-
setup do
|
77
|
-
@sam.remove_favorite @jon
|
78
|
-
end
|
79
|
-
|
80
|
-
should_change('Favorite count', by: -1) { Favorite.count }
|
81
|
-
should_change('@sam.favorites_count', by: -1) { @sam.favorites_count }
|
82
|
-
end
|
83
|
-
|
84
|
-
context 'favorites' do
|
85
|
-
setup do
|
86
|
-
@band_favorite = Favorite.where('favoritor_id = ? and favoritor_type = "User" and favoritable_id = ? and favoritable_type = "Band"', @sam.id, @oasis.id).first
|
87
|
-
@user_favorite = Favorite.where('favoritor_id = ? and favoritor_type = "User" and favoritable_id = ? and favoritable_type = "User"', @sam.id, @jon.id).first
|
88
|
-
end
|
89
|
-
|
90
|
-
context 'favorites_by_type' do
|
91
|
-
should 'only return requested favorites' do
|
92
|
-
assert_equal [@band_favorite], @sam.favorites_by_type('Band')
|
93
|
-
assert_equal [@user_favorite], @sam.favorites_by_type('User')
|
94
|
-
end
|
95
|
-
|
96
|
-
should 'accept AR options' do
|
97
|
-
@metallica = FactoryGirl.create :metallica
|
98
|
-
@sam.favorite @metallica
|
99
|
-
assert_equal 1, @sam.favorites_by_type('Band', limit: 1).count
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
context 'favorited_by_type_count' do
|
104
|
-
should 'return the count of the requested type' do
|
105
|
-
@metallica = FactoryGirl.create :metallica
|
106
|
-
@sam.favorite @metallica
|
107
|
-
assert_equal 2, @sam.favorited_by_type_count('Band')
|
108
|
-
assert_equal 1, @sam.favorited_by_type_count('User')
|
109
|
-
assert_equal 0, @jon.favorited_by_type_count('Band')
|
110
|
-
@jon.block @sam
|
111
|
-
assert_equal 0, @sam.favorited_by_type_count('User')
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
context 'all_favorites' do
|
116
|
-
should 'return all favorites' do
|
117
|
-
assert_equal 2, @sam.all_favorites.size
|
118
|
-
assert @sam.all_favorites.include?(@band_favorite)
|
119
|
-
assert @sam.all_favorites.include?(@user_favorite)
|
120
|
-
assert_equal [], @jon.all_favorites
|
121
|
-
end
|
122
|
-
|
123
|
-
should 'accept AR options' do
|
124
|
-
assert_equal 1, @sam.all_favorites(limit: 1).count
|
125
|
-
end
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
context 'all_favorited' do
|
130
|
-
should 'return the actual favorite records' do
|
131
|
-
assert_equal 2, @sam.all_favorited.size
|
132
|
-
assert @sam.all_favorited.include?(@oasis)
|
133
|
-
assert @sam.all_favorited.include?(@jon)
|
134
|
-
assert_equal [], @jon.all_favorited
|
135
|
-
end
|
136
|
-
|
137
|
-
should 'accept AR limit option' do
|
138
|
-
assert_equal 1, @sam.all_favorited(limit: 1).count
|
139
|
-
end
|
140
|
-
|
141
|
-
should 'accept AR where option' do
|
142
|
-
assert_equal 1, @sam.all_favorited(where: { id: @oasis.id }).count
|
143
|
-
end
|
144
|
-
end
|
145
|
-
|
146
|
-
context 'favorited_by_type' do
|
147
|
-
should 'return only requested records' do
|
148
|
-
assert_equal [@oasis], @sam.favorited_by_type('Band')
|
149
|
-
assert_equal [@jon], @sam.favorited_by_type('User')
|
150
|
-
end
|
151
|
-
|
152
|
-
should 'accept AR options' do
|
153
|
-
@metallica = FactoryGirl.create :metallica
|
154
|
-
@sam.favorite @metallica
|
155
|
-
assert_equal 1, @sam.favorited_by_type('Band', limit: 1).to_a.size
|
156
|
-
end
|
157
|
-
end
|
158
|
-
|
159
|
-
context 'method_missing' do
|
160
|
-
should 'call favorited_by_type' do
|
161
|
-
assert_equal [@oasis], @sam.favorited_bands
|
162
|
-
assert_equal [@jon], @sam.favorited_users
|
163
|
-
end
|
164
|
-
|
165
|
-
should 'call favorited_by_type_count' do
|
166
|
-
@metallica = FactoryGirl.create :metallica
|
167
|
-
@sam.favorite @metallica
|
168
|
-
assert_equal 2, @sam.favorited_bands_count
|
169
|
-
assert_equal 1, @sam.favorited_users_count
|
170
|
-
assert_equal 0, @jon.favorited_bands_count
|
171
|
-
@jon.block @sam
|
172
|
-
assert_equal 0, @sam.favorited_users_count
|
173
|
-
end
|
174
|
-
|
175
|
-
should 'raise on no method' do
|
176
|
-
assert_raises (NoMethodError) { @sam.foobar }
|
177
|
-
end
|
178
|
-
end
|
179
|
-
|
180
|
-
context 'respond_to?' do
|
181
|
-
should 'advertise that it responds to favorited methods' do
|
182
|
-
assert @sam.respond_to?(:favorited_users)
|
183
|
-
assert @sam.respond_to?(:favorited_users_count)
|
184
|
-
end
|
185
|
-
|
186
|
-
should 'return false when called with a nonexistent method' do
|
187
|
-
assert (not @sam.respond_to?(:foobar))
|
188
|
-
end
|
189
|
-
end
|
190
|
-
|
191
|
-
context 'destroying favoritor' do
|
192
|
-
setup do
|
193
|
-
@jon.destroy
|
194
|
-
end
|
195
|
-
|
196
|
-
should_change('Favorite.count', by: -1) { Favorite.count }
|
197
|
-
should_change('@sam.favorites_count', by: -1) { @sam.favorites_count }
|
198
|
-
end
|
199
|
-
|
200
|
-
context "blocked by favoritable" do
|
201
|
-
setup do
|
202
|
-
@jon.block @sam
|
203
|
-
end
|
204
|
-
|
205
|
-
should 'return favorited_status' do
|
206
|
-
assert_equal false, @sam.favorited?(@jon)
|
207
|
-
end
|
208
|
-
|
209
|
-
should 'return favorites_count' do
|
210
|
-
assert_equal 1, @sam.favorites_count
|
211
|
-
end
|
212
|
-
|
213
|
-
should 'not return record of the blocked favorites' do
|
214
|
-
assert_equal 1, @sam.all_favorites.size
|
215
|
-
assert !@sam.all_favorites.include?(@user_favorite)
|
216
|
-
assert !@sam.all_favorited.include?(@jon)
|
217
|
-
assert_equal [], @sam.favorited_by_type('User')
|
218
|
-
assert_equal [], @sam.favorites_by_type('User')
|
219
|
-
assert_equal [], @sam.favorited_users
|
220
|
-
end
|
221
|
-
end
|
222
|
-
end
|
223
|
-
|
224
|
-
end
|
data/test/dummy30/Gemfile
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
gem 'rails', '~> 5.1.3'
|
data/test/dummy30/Rakefile
DELETED
data/test/dummy30/config.ru
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
require File.expand_path '../boot', __FILE__
|
2
|
-
|
3
|
-
require 'active_model/railtie'
|
4
|
-
require 'active_record/railtie'
|
5
|
-
|
6
|
-
Bundler.require
|
7
|
-
require 'acts_as_favoritor'
|
8
|
-
|
9
|
-
module Dummy
|
10
|
-
class Application < Rails::Application
|
11
|
-
config.encoding = 'utf-8'
|
12
|
-
config.filter_parameters += [:password]
|
13
|
-
end
|
14
|
-
end
|
data/test/dummy30/config/boot.rb
DELETED
@@ -1,9 +0,0 @@
|
|
1
|
-
ActsAsFavoritor.configure do |config|
|
2
|
-
|
3
|
-
# Specify your default scope. Learn more about scopes here: https://github.com/jonhue/acts_as_favoritor#scopes
|
4
|
-
# config.default_scope = 'favorite'
|
5
|
-
|
6
|
-
# Enable caching. Learn more about caching here: https://github.com/jonhue/acts_as_favoritor#caching
|
7
|
-
# config.cache = false
|
8
|
-
|
9
|
-
end
|
@@ -1 +0,0 @@
|
|
1
|
-
Dummy::Application.config.secret_token = '7b0ce915dc4c2ee60581c2769798abb5e4078292ad23670fc8d728953fc13aec19863558873234816b58a54f6a35be58b2b0a26749a7dfddcd2f02ee82d7e94f'
|
@@ -1 +0,0 @@
|
|
1
|
-
Dummy::Application.config.session_store :cookie_store, key: '_dummy_session'
|
data/test/factories/bands.rb
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
FactoryGirl.define do
|
2
|
-
factory :oasis, class: Band do |b|
|
3
|
-
b.name 'Oasis'
|
4
|
-
end
|
5
|
-
|
6
|
-
factory :metallica, class: Band do |b|
|
7
|
-
b.name 'Metallica'
|
8
|
-
end
|
9
|
-
|
10
|
-
factory :green_day, class: Band::Punk do |b|
|
11
|
-
b.name 'Green Day'
|
12
|
-
end
|
13
|
-
|
14
|
-
factory :blink_182, class: Band::Punk::PopPunk do |b|
|
15
|
-
b.name 'Blink 182'
|
16
|
-
end
|
17
|
-
end
|
data/test/factories/somes.rb
DELETED
data/test/factories/users.rb
DELETED
data/test/favorite_test.rb
DELETED
data/test/schema.rb
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
ActiveRecord::Schema.define version: 0 do
|
2
|
-
|
3
|
-
create_table :favorites, force: true do |t|
|
4
|
-
t.integer 'favoritable_id', null: false
|
5
|
-
t.string 'favoritable_type', null: false
|
6
|
-
t.integer 'favoritor_id', null: false
|
7
|
-
t.string 'favoritor_type', null: false
|
8
|
-
t.string :scope, default: ActsAsFavoritor.configuration.default_scope, null: false
|
9
|
-
t.boolean 'blocked', default: false, null: false
|
10
|
-
t.datetime 'created_at'
|
11
|
-
t.datetime 'updated_at'
|
12
|
-
end
|
13
|
-
|
14
|
-
create_table :users, force: true do |t|
|
15
|
-
t.column :name, :string
|
16
|
-
end
|
17
|
-
|
18
|
-
create_table :bands, force: true do |t|
|
19
|
-
t.column :name, :string
|
20
|
-
end
|
21
|
-
|
22
|
-
create_table :somes, force: true do |t|
|
23
|
-
t.column :name, :string
|
24
|
-
end
|
25
|
-
|
26
|
-
end
|