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.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +5 -0
  3. data/LICENSE +1 -1
  4. data/README.md +1 -3
  5. data/lib/acts_as_favoritor.rb +2 -11
  6. data/lib/acts_as_favoritor/configuration.rb +10 -0
  7. data/lib/acts_as_favoritor/favoritable.rb +1 -1
  8. data/lib/acts_as_favoritor/favorite_scopes.rb +1 -1
  9. data/lib/acts_as_favoritor/favoritor.rb +425 -425
  10. data/lib/acts_as_favoritor/railtie.rb +1 -1
  11. data/lib/acts_as_favoritor/version.rb +1 -1
  12. data/lib/generators/templates/model.rb +1 -2
  13. metadata +3 -44
  14. data/.github/issue_template.md +0 -14
  15. data/.github/pull_request_template.md +0 -21
  16. data/.gitignore +0 -8
  17. data/.travis.yml +0 -3
  18. data/CODE_OF_CONDUCT.md +0 -46
  19. data/CONTRIBUTING.md +0 -1
  20. data/DEPRECATIONS.md +0 -5
  21. data/Gemfile +0 -9
  22. data/INSTALL.md +0 -3
  23. data/Rakefile +0 -16
  24. data/acts_as_favoritor.gemspec +0 -30
  25. data/init.rb +0 -1
  26. data/test/acts_as_favoritable_test.rb +0 -283
  27. data/test/acts_as_favoritor_test.rb +0 -224
  28. data/test/dummy30/Gemfile +0 -1
  29. data/test/dummy30/Rakefile +0 -4
  30. data/test/dummy30/app/models/application_record.rb +0 -3
  31. data/test/dummy30/app/models/band.rb +0 -4
  32. data/test/dummy30/app/models/band/punk.rb +0 -4
  33. data/test/dummy30/app/models/band/punk/pop_punk.rb +0 -4
  34. data/test/dummy30/app/models/custom_record.rb +0 -3
  35. data/test/dummy30/app/models/some.rb +0 -5
  36. data/test/dummy30/app/models/user.rb +0 -5
  37. data/test/dummy30/config.ru +0 -2
  38. data/test/dummy30/config/application.rb +0 -14
  39. data/test/dummy30/config/boot.rb +0 -10
  40. data/test/dummy30/config/database.yml +0 -6
  41. data/test/dummy30/config/environment.rb +0 -5
  42. data/test/dummy30/config/environments/development.rb +0 -7
  43. data/test/dummy30/config/environments/test.rb +0 -6
  44. data/test/dummy30/config/initializers/acts_as_favoritor.rb +0 -9
  45. data/test/dummy30/config/initializers/secret_token.rb +0 -1
  46. data/test/dummy30/config/initializers/session_store.rb +0 -1
  47. data/test/dummy30/config/locales/en.yml +0 -2
  48. data/test/dummy30/config/routes.rb +0 -2
  49. data/test/factories/bands.rb +0 -17
  50. data/test/factories/somes.rb +0 -9
  51. data/test/factories/users.rb +0 -13
  52. data/test/favorite_test.rb +0 -10
  53. data/test/schema.rb +0 -26
  54. 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'
@@ -1,4 +0,0 @@
1
- require File.expand_path '../config/application', __FILE__
2
- require 'rake'
3
-
4
- Dummy::Application.load_tasks
@@ -1,3 +0,0 @@
1
- class ApplicationRecord < ActiveRecord::Base
2
- self.abstract_class = true
3
- end
@@ -1,4 +0,0 @@
1
- class Band < ApplicationRecord
2
- validates_presence_of :name
3
- acts_as_favoritable
4
- end
@@ -1,4 +0,0 @@
1
- class Band::Punk < Band
2
- validates_presence_of :name
3
- acts_as_favoritable
4
- end
@@ -1,4 +0,0 @@
1
- class Band::Punk::PopPunk < Band::Punk
2
- validates_presence_of :name
3
- acts_as_favoritable
4
- end
@@ -1,3 +0,0 @@
1
- class CustomRecord < ActiveRecord::Base
2
- self.abstract_class = true
3
- end
@@ -1,5 +0,0 @@
1
- class Some < CustomRecord
2
- validates_presence_of :name
3
- acts_as_favoritor
4
- acts_as_favoritable
5
- end
@@ -1,5 +0,0 @@
1
- class User < ApplicationRecord
2
- validates_presence_of :name
3
- acts_as_favoritor
4
- acts_as_favoritable
5
- end
@@ -1,2 +0,0 @@
1
- require ::File.expand_path '../config/environment', __FILE__
2
- run Dummy::Application
@@ -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
@@ -1,10 +0,0 @@
1
- require 'rubygems'
2
- gemfile = File.expand_path '../../../../Gemfile', __FILE__
3
-
4
- if File.exist?(gemfile)
5
- ENV['BUNDLE_GEMFILE'] = gemfile
6
- require 'bundler'
7
- Bundler.setup
8
- end
9
-
10
- $:.unshift File.expand_path '../../../../lib', __FILE__
@@ -1,6 +0,0 @@
1
- test:
2
- adapter: sqlite3
3
- database: ':memory:'
4
- development:
5
- adapter: sqlite3
6
- database: ':memory:'
@@ -1,5 +0,0 @@
1
- # Load the rails application
2
- require File.expand_path '../application', __FILE__
3
-
4
- # Initialize the rails application
5
- Dummy::Application.initialize!
@@ -1,7 +0,0 @@
1
- Dummy::Application.configure do
2
- config.cache_classes = false
3
- config.whiny_nils = true
4
- config.consider_all_requests_local = true
5
- config.active_support.deprecation = :log
6
- config.eager_load = false
7
- end
@@ -1,6 +0,0 @@
1
- Dummy::Application.configure do
2
- config.cache_classes = true
3
- config.consider_all_requests_local = true
4
- config.active_support.deprecation = :stderr
5
- config.eager_load = false
6
- end
@@ -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'
@@ -1,2 +0,0 @@
1
- en:
2
- hello: 'Hello world'
@@ -1,2 +0,0 @@
1
- Dummy::Application.routes.draw do
2
- end
@@ -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
@@ -1,9 +0,0 @@
1
- FactoryGirl.define do
2
- factory :daddy, class: Some do |b|
3
- b.name 'Daddy'
4
- end
5
-
6
- factory :mommy, class: Some do |b|
7
- b.name 'Mommy'
8
- end
9
- end
@@ -1,13 +0,0 @@
1
- FactoryGirl.define do
2
- factory :jon, class: User do |u|
3
- u.name 'Jon'
4
- end
5
-
6
- factory :sam, class: User do |u|
7
- u.name 'Sam'
8
- end
9
-
10
- factory :bob, class: User do |u|
11
- u.name 'Bob'
12
- end
13
- end
@@ -1,10 +0,0 @@
1
- require File.dirname(__FILE__) + '/test_helper'
2
-
3
- class FavoriteTest < ActiveSupport::TestCase
4
-
5
- # Replace with real tests
6
- def test_assert_true_should_be_true
7
- assert true
8
- end
9
-
10
- end
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