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.
@@ -0,0 +1,224 @@
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? :favorite_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 favorite_count' do
36
+ assert_equal 2, @sam.favorite_count
37
+ assert_equal 0, @jon.favorite_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.favorite_count', by: 1) { @jon.favorite_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.favorite_count') { @jon.favorite_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.favorite_count', by: -1) { @sam.favorite_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.favorite_count', by: -1) { @sam.favorite_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 favorite_count' do
210
+ assert_equal 1, @sam.favorite_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
@@ -1,6 +1,3 @@
1
- # Add your own tasks in files placed in lib/tasks ending in .rake,
2
- # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
-
4
1
  require File.expand_path '../config/application', __FILE__
5
2
  require 'rake'
6
3
 
@@ -1,4 +1,2 @@
1
- # This file is used by Rack-based servers to start the application.
2
-
3
1
  require ::File.expand_path '../config/environment', __FILE__
4
2
  run Dummy::Application
@@ -8,35 +8,7 @@ require 'acts_as_favoritor'
8
8
 
9
9
  module Dummy
10
10
  class Application < Rails::Application
11
- # Settings in config/environments/* take precedence over those specified here.
12
- # Application configuration should go into files in config/initializers
13
- # -- all .rb files in that directory are automatically loaded.
14
-
15
- # Custom directories with classes and modules you want to be autoloadable.
16
- # config.autoload_paths += %W(#{config.root}/extras)
17
-
18
- # Only load the plugins named here, in the order given (default is alphabetical).
19
- # :all can be used as a placeholder for all plugins not explicitly named.
20
- # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
21
-
22
- # Activate observers that should always be running.
23
- # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
24
-
25
- # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
26
- # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
27
- # config.time_zone = 'Central Time (US & Canada)'
28
-
29
- # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
30
- # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
31
- # config.i18n.default_locale = :de
32
-
33
- # JavaScript files you want as :defaults (application.js is always included).
34
- # config.action_view.javascript_expansions[:defaults] = %w(jquery rails)
35
-
36
- # Configure the default encoding used in templates for Ruby 1.9.
37
11
  config.encoding = 'utf-8'
38
-
39
- # Configure sensitive parameters which will be filtered from the log file.
40
12
  config.filter_parameters += [:password]
41
13
  end
42
14
  end
@@ -1,18 +1,6 @@
1
1
  Dummy::Application.configure do
2
- # Settings specified here will take precedence over those in config/application.rb
3
-
4
- # In the development environment your application's code is reloaded on
5
- # every request. This slows down response time but is perfect for development
6
- # since you don't have to restart the webserver when you make code changes.
7
2
  config.cache_classes = false
8
-
9
- # Log error messages when you accidentally call methods on nil.
10
3
  config.whiny_nils = true
11
-
12
- # Show full error reports and disable caching
13
4
  config.consider_all_requests_local = true
14
-
15
- # Print deprecation notices to the Rails logger
16
5
  config.active_support.deprecation = :log
17
-
18
6
  end
@@ -1,20 +1,5 @@
1
1
  Dummy::Application.configure do
2
- # Settings specified here will take precedence over those in config/application.rb
3
-
4
- # The test environment is used exclusively to run your application's
5
- # test suite. You never need to work with it otherwise. Remember that
6
- # your test database is "scratch space" for the test suite and is wiped
7
- # and recreated between test runs. Don't rely on the data there!
8
2
  config.cache_classes = true
9
-
10
- # Show full error reports and disable caching
11
3
  config.consider_all_requests_local = true
12
-
13
- # Use SQL instead of Active Record's schema dumper when creating the test database.
14
- # This is necessary if your schema can't be completely dumped by the schema dumper,
15
- # like if you have constraints or database-specific column types
16
- # config.active_record.schema_format = :sql
17
-
18
- # Print deprecation notices to the stderr
19
4
  config.active_support.deprecation = :stderr
20
5
  end
@@ -1,7 +1 @@
1
- # Be sure to restart your server when you modify this file.
2
-
3
- # Your secret key for verifying the integrity of signed cookies.
4
- # If you change this key, all old signed cookies will become invalid!
5
- # Make sure the secret is at least 30 characters and all random,
6
- # no regular words or you'll be exposed to dictionary attacks.
7
1
  Dummy::Application.config.secret_token = '7b0ce915dc4c2ee60581c2769798abb5e4078292ad23670fc8d728953fc13aec19863558873234816b58a54f6a35be58b2b0a26749a7dfddcd2f02ee82d7e94f'
@@ -1,8 +1 @@
1
- # Be sure to restart your server when you modify this file.
2
-
3
1
  Dummy::Application.config.session_store :cookie_store, key: '_dummy_session'
4
-
5
- # Use the database for sessions instead of the cookie-based default,
6
- # which shouldn't be used to store highly confidential information
7
- # (create the session table with "rails generate session_migration")
8
- # Dummy::Application.config.session_store :active_record_store
@@ -1,5 +1,2 @@
1
- # Sample localization file for English. Add more files in this directory for other locales.
2
- # See http://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
3
-
4
1
  en:
5
2
  hello: 'Hello world'
@@ -0,0 +1,28 @@
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
+ context 'configuration with setters' do
11
+ should 'contain custom parents' do
12
+ ActsAsFavoritor.custom_parent_classes = [CustomRecord]
13
+
14
+ assert_equal [CustomRecord], ActsAsFavoritor.custom_parent_classes
15
+ end
16
+ end
17
+
18
+ context '#setup' do
19
+ should 'contain custom parents via setup' do
20
+ ActsAsFavoritor.setup do |c|
21
+ c.custom_parent_classes = [CustomRecord]
22
+ end
23
+
24
+ assert_equal [CustomRecord], ActsAsFavoritor.custom_parent_classes
25
+ end
26
+ end
27
+
28
+ end
data/test/schema.rb CHANGED
@@ -1,10 +1,11 @@
1
1
  ActiveRecord::Schema.define version: 0 do
2
2
 
3
- create_table :follows, force: true do |t|
4
- t.integer 'followable_id', null: false
5
- t.string 'followable_type', null: false
6
- t.integer 'follower_id', null: false
7
- t.string 'follower_type', null: false
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 'lists', default: [:favorites].to_yaml, null: false
8
9
  t.boolean 'blocked', default: false, null: false
9
10
  t.datetime 'created_at'
10
11
  t.datetime 'updated_at'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts_as_favoritor
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonas Hübotter
@@ -30,56 +30,56 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '1'
33
+ version: '1.3'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '1'
40
+ version: '1.3'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: shoulda_create
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: '0.0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '0'
54
+ version: '0.0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: shoulda
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '3'
61
+ version: '3.5'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '3'
68
+ version: '3.5'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: factory_girl
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '4'
75
+ version: '4.8'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '4'
82
+ version: '4.8'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: rails
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -106,7 +106,9 @@ extra_rdoc_files: []
106
106
  files:
107
107
  - ".gitignore"
108
108
  - ".travis.yml"
109
+ - CHANGELOG.md
109
110
  - Gemfile
111
+ - Gemfile.lock
110
112
  - LICENSE
111
113
  - README.md
112
114
  - Rakefile
@@ -120,12 +122,12 @@ files:
120
122
  - lib/acts_as_favoritor/railtie.rb
121
123
  - lib/acts_as_favoritor/version.rb
122
124
  - lib/generators/USAGE
123
- - lib/generators/acts_as_follower_generator.rb
125
+ - lib/generators/acts_as_favoritor_generator.rb
124
126
  - lib/generators/templates/migration.rb.erb
125
127
  - lib/generators/templates/model.rb
126
128
  - test/README
127
- - test/acts_as_followable_test.rb
128
- - test/acts_as_follower_test.rb
129
+ - test/acts_as_favoritable_test.rb
130
+ - test/acts_as_favoritor_test.rb
129
131
  - test/dummy30/Gemfile
130
132
  - test/dummy30/Rakefile
131
133
  - test/dummy30/app/models/application_record.rb
@@ -142,8 +144,6 @@ files:
142
144
  - test/dummy30/config/environment.rb
143
145
  - test/dummy30/config/environments/development.rb
144
146
  - test/dummy30/config/environments/test.rb
145
- - test/dummy30/config/initializers/backtrace_silencers.rb
146
- - test/dummy30/config/initializers/inflections.rb
147
147
  - test/dummy30/config/initializers/secret_token.rb
148
148
  - test/dummy30/config/initializers/session_store.rb
149
149
  - test/dummy30/config/locales/en.yml
@@ -151,7 +151,7 @@ files:
151
151
  - test/factories/bands.rb
152
152
  - test/factories/somes.rb
153
153
  - test/factories/users.rb
154
- - test/follow_test.rb
154
+ - test/favorite_test.rb
155
155
  - test/schema.rb
156
156
  - test/test_helper.rb
157
157
  homepage: https://github.com/slooob/acts_as_favoritor
@@ -166,14 +166,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
166
166
  requirements:
167
167
  - - ">="
168
168
  - !ruby/object:Gem::Version
169
- version: '0'
169
+ version: '2.0'
170
170
  required_rubygems_version: !ruby/object:Gem::Requirement
171
171
  requirements:
172
172
  - - ">="
173
173
  - !ruby/object:Gem::Version
174
174
  version: '0'
175
175
  requirements: []
176
- rubyforge_project: acts_as_follower
176
+ rubyforge_project:
177
177
  rubygems_version: 2.6.12
178
178
  signing_key:
179
179
  specification_version: 4