acts_as_favourites 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/:memory +0 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +82 -0
- data/Rakefile +8 -0
- data/acts_as_favorite.gemspec +29 -0
- data/converalls.yml +1 -0
- data/lib/acts_as_favorite/favor.rb +45 -0
- data/lib/acts_as_favorite/favoriter.rb +42 -0
- data/lib/acts_as_favorite/version.rb +3 -0
- data/lib/acts_as_favorite.rb +12 -0
- data/lib/generators/favorable_generator.rb +24 -0
- data/lib/generators/templates/migrator.rb +18 -0
- data/lib/generators/templates/model.rb +4 -0
- data/spec/favor_spec.rb +68 -0
- data/spec/favoriter_spec.rb +88 -0
- data/spec/spec_helper.rb +101 -0
- data/spec/support/favorite_factory.rb +5 -0
- data/spec/support/models.rb +12 -0
- data/spec/support/schema.rb +25 -0
- metadata +200 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: af08814ec9d098191b68eec475713a9b82c9f90a
|
4
|
+
data.tar.gz: e2c1ad6eab2d6e75c98bdeea779743786517cf94
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 133779855d6b987b050a953473bbea495d431db8f124e3b9c571787112aa6f8264baff1ed758477b22d8f6ff5ee6710bb487c28ac2cb9e69ba727041a1ced148
|
7
|
+
data.tar.gz: bd8079991854c7af3aec4bd51fbdeee0a15d3d572ec3a9a1dbf75a513904302d43d7d86607c88f5b6e2b93dea626988feffc8903a615d2b95a6a06e278443cb7
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/:memory
ADDED
Binary file
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Rajarshi
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
Add favorite fuctionalities to any Active Record models through polymorphic association.
|
2
|
+
|
3
|
+
|
4
|
+
## Installation
|
5
|
+
|
6
|
+
Add this line to your application's Gemfile:
|
7
|
+
|
8
|
+
```ruby
|
9
|
+
gem 'acts_as_favorite'
|
10
|
+
```
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
|
14
|
+
$ bundle
|
15
|
+
|
16
|
+
Run generator:
|
17
|
+
|
18
|
+
$ rails generate favorable
|
19
|
+
|
20
|
+
And don't forget to migrate your database
|
21
|
+
|
22
|
+
$ rake db:migrate
|
23
|
+
|
24
|
+
## Usage
|
25
|
+
|
26
|
+
### Favorable models
|
27
|
+
|
28
|
+
Add `acts_as_favorable` to any models, and its instances can be favorite by other models.
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
class Post < ActiveRecord::Base
|
32
|
+
acts_as_favorable
|
33
|
+
end
|
34
|
+
```
|
35
|
+
|
36
|
+
### Favoriter models
|
37
|
+
|
38
|
+
Add `acts_as_favoriter` to any models, and it can favorite instances of other models.
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
class User < ActiveRecord::Base
|
42
|
+
acts_as_favoriter
|
43
|
+
end
|
44
|
+
```
|
45
|
+
|
46
|
+
It is not necessary to use both `acts_as_favorable` and `acts_as_favoriter` . You can use one to execute.
|
47
|
+
|
48
|
+
### API
|
49
|
+
|
50
|
+
```ruby
|
51
|
+
# Count the number of favorites of @post
|
52
|
+
@post.favorites_count
|
53
|
+
|
54
|
+
# Check if @post is favorited by @user
|
55
|
+
@post.favorite_by?(@user)
|
56
|
+
|
57
|
+
# Create a new favorite record for @user, and @post
|
58
|
+
@post.favorite_by(@user)
|
59
|
+
|
60
|
+
# Destroy the favorite record
|
61
|
+
@post.unfavorite_by(@user)
|
62
|
+
|
63
|
+
#Update
|
64
|
+
@post.update_favorite(@user)
|
65
|
+
```
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
```ruby
|
70
|
+
# Create a new favorite record for @user, and @post
|
71
|
+
@user.favorite(@post)
|
72
|
+
|
73
|
+
# Destroy the favorite record
|
74
|
+
@user.unfavorite(@post)
|
75
|
+
|
76
|
+
# Check if @user favorite the @post
|
77
|
+
@user.favorite?(@post)
|
78
|
+
```
|
79
|
+
|
80
|
+
## Contributing
|
81
|
+
|
82
|
+
Issues and pull reqeusts are welcomed.
|
data/Rakefile
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'acts_as_favorite/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "acts_as_favourites"
|
8
|
+
spec.version = Favorable::VERSION
|
9
|
+
spec.authors = ["Rajarshi Das"]
|
10
|
+
spec.email = ["rajarshi2576@gmail.com"]
|
11
|
+
spec.summary = %q{Add favorite feature to any Active Record models}
|
12
|
+
spec.homepage = "https://github.com/rajcybage/acts_as_favourites"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
21
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
22
|
+
spec.add_development_dependency "rspec"
|
23
|
+
spec.add_development_dependency "guard"
|
24
|
+
spec.add_development_dependency "guard-rspec"
|
25
|
+
spec.add_development_dependency "sqlite3"
|
26
|
+
spec.add_development_dependency "activerecord"
|
27
|
+
spec.add_development_dependency "generator_spec"
|
28
|
+
spec.add_development_dependency "coveralls"
|
29
|
+
end
|
data/converalls.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
service_name: travis-ci
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module ActsAsFavorite
|
2
|
+
module Favor
|
3
|
+
|
4
|
+
def self.included(base)
|
5
|
+
base.extend ClassMethods
|
6
|
+
end
|
7
|
+
|
8
|
+
module ClassMethods
|
9
|
+
def acts_as_favorable
|
10
|
+
has_many :favorites, as: :favorable, dependent: :destroy
|
11
|
+
include ActsAsFavorite::Favor::InstanceMethods
|
12
|
+
end
|
13
|
+
|
14
|
+
def favorable?
|
15
|
+
true
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
module InstanceMethods
|
21
|
+
#instance methods
|
22
|
+
def favorites_count
|
23
|
+
favorites.count
|
24
|
+
end
|
25
|
+
|
26
|
+
def favorite_by?(favoriter)
|
27
|
+
favorites.find_by(favoriter_id: favoriter.id, favoriter_type: favoriter.class.base_class.name).present?
|
28
|
+
end
|
29
|
+
|
30
|
+
def favorite_by(favoriter)
|
31
|
+
favorites.create(favoriter_id: favoriter.id, favoriter_type: favoriter.class.base_class.name)
|
32
|
+
end
|
33
|
+
|
34
|
+
def unfavorite_by(favoriter)
|
35
|
+
records = favorites.find_by(favoriter_id: favoriter.id, favoriter_type: favoriter.class.base_class.name)
|
36
|
+
records.try(:destroy)
|
37
|
+
end
|
38
|
+
|
39
|
+
def update_favorite(id, favoriter)
|
40
|
+
records = favorites.find(id)
|
41
|
+
records.update_attributes(favoriter_id: favoriter.id, favoriter_type: favoriter.class.base_class.name)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module ActsAsFavorite
|
2
|
+
module Favoriter
|
3
|
+
|
4
|
+
def self.included(base)
|
5
|
+
base.extend ClassMethods
|
6
|
+
end
|
7
|
+
|
8
|
+
module ClassMethods
|
9
|
+
def acts_as_favoriter
|
10
|
+
has_many :favorites, as: :favoriter, dependent: :destroy
|
11
|
+
include ActsAsFavorite::Favoriter::InstanceMethods
|
12
|
+
end
|
13
|
+
|
14
|
+
def favorable?
|
15
|
+
true
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
module InstanceMethods
|
20
|
+
#instance methods
|
21
|
+
def favorite?(favorable)
|
22
|
+
favorites.find_by(favorable_id: favorable.id, favorable_type: favorable.class.base_class.name).present?
|
23
|
+
end
|
24
|
+
|
25
|
+
def favorite(favorable)
|
26
|
+
unless self.favorite?(favorable)
|
27
|
+
favorites.create(favorable_id: favorable.id, favorable_type: favorable.class.base_class.name)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def unfavorite(favorable)
|
32
|
+
records = favorites.find_by(favorable_id: favorable.id, favorable_type: favorable.class.base_class.name)
|
33
|
+
records.try(:destroy)
|
34
|
+
end
|
35
|
+
|
36
|
+
def update_favorite(favorable)
|
37
|
+
records = favorites.find(favorable.id)
|
38
|
+
records.update_attributes(favorable_id: favorable.id, favorable_type: favorable.class.base_class.name)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require "acts_as_favorite/version"
|
2
|
+
require "active_support"
|
3
|
+
|
4
|
+
module ActsAsFavorite
|
5
|
+
require 'acts_as_favorite/favoriter.rb'
|
6
|
+
require 'acts_as_favorite/favor.rb'
|
7
|
+
end
|
8
|
+
|
9
|
+
ActiveSupport.on_load(:active_record) do
|
10
|
+
include ActsAsFavorite::Favoriter
|
11
|
+
include ActsAsFavorite::Favor
|
12
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
require 'rails/generators/migration'
|
3
|
+
|
4
|
+
module Favorable
|
5
|
+
class FavorableGenerator < Rails::Generators::Base
|
6
|
+
include Rails::Generators::Migration
|
7
|
+
def self.source_root
|
8
|
+
File.join(File.dirname(__FILE__), "templates")
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.next_migration_number(path)
|
12
|
+
Time.now.utc.strftime("%Y%m%d%H%M%S")
|
13
|
+
end
|
14
|
+
|
15
|
+
def create_migration_file
|
16
|
+
migration_template "migrator.rb", "db/migrate/favorable_migration.rb"
|
17
|
+
end
|
18
|
+
|
19
|
+
def create_model
|
20
|
+
template "model.rb", File.join("app/models", "favorite.rb")
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class FavorableMigration < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :favorites do |t|
|
4
|
+
t.references :favorable, polymorphic: true
|
5
|
+
t.references :favoriter, polymorphic: true
|
6
|
+
|
7
|
+
t.timestamps
|
8
|
+
end
|
9
|
+
|
10
|
+
add_index :favorites, [:favorable_id, :favorable_type]
|
11
|
+
add_index :favorites, [:favoriter_id, :favoriter_type]
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
def self.down
|
16
|
+
drop_table :favorites
|
17
|
+
end
|
18
|
+
end
|
data/spec/favor_spec.rb
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Post, focus: true do
|
4
|
+
|
5
|
+
let(:charlie) { User.create(name: "Charlie") }
|
6
|
+
let(:test_post) { Post.create(name: "test_post") }
|
7
|
+
|
8
|
+
|
9
|
+
describe "Association" do
|
10
|
+
it "should have many favorites" do
|
11
|
+
association = Post.reflect_on_association(:favorites)
|
12
|
+
expect(association.macro).to eq :has_many
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should have many favorites with dependent destroy" do
|
16
|
+
association = Post.reflect_on_association(:favorites)
|
17
|
+
expect(association.options).to include :dependent => :destroy
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "#favorites_count" do
|
22
|
+
it "should count favorites" do
|
23
|
+
create_favorite(charlie, test_post)
|
24
|
+
expect(test_post.favorites_count).to eq 1
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "#favorite_by?" do
|
29
|
+
context "when user has favored post" do
|
30
|
+
it "should return true" do
|
31
|
+
create_favorite(charlie, test_post)
|
32
|
+
puts test_post.favorites.where(favoriter_id: charlie.id)
|
33
|
+
expect(test_post.favorite_by?(charlie)).to be true
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context "when user hasn't favored post" do
|
38
|
+
it "should return false" do
|
39
|
+
expect(test_post.favorite_by?(charlie)).to be false
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "#favorite_by" do
|
45
|
+
context "when user has not favorite post" do
|
46
|
+
it "should create Favorite" do
|
47
|
+
expect{
|
48
|
+
test_post.favorite_by(charlie)
|
49
|
+
}.to change(Favorite, :count).by(1)
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should set Favorite to belong to favoriter" do
|
53
|
+
test_post.favorite_by(charlie)
|
54
|
+
fav = Favorite.find_by(favorable_id: test_post.id, favorable_type: test_post.class.base_class.name, favoriter_id: charlie.id, favoriter_type: charlie.class.base_class.name)
|
55
|
+
|
56
|
+
expect(fav.favoriter).to eq charlie
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should set to belong to favor" do
|
60
|
+
test_post.favorite_by(charlie)
|
61
|
+
fav = Favorite.find_by(favorable_id: test_post.id, favorable_type: test_post.class.base_class.name, favoriter_id: charlie.id, favoriter_type: charlie.class.base_class.name)
|
62
|
+
|
63
|
+
expect(fav.favorable).to eq test_post
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe User do
|
4
|
+
|
5
|
+
let(:charlie) { User.create(name: "Charlie") }
|
6
|
+
let(:test) { Post.create(name: "test post") }
|
7
|
+
|
8
|
+
|
9
|
+
describe "instance methods" do
|
10
|
+
it "should be defined" do
|
11
|
+
expect(charlie).to respond_to(:favorite)
|
12
|
+
expect(charlie).to respond_to(:unfavorite)
|
13
|
+
expect(charlie).to respond_to(:favorite?)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "Association" do
|
18
|
+
it "should have many favoritess" do
|
19
|
+
association = User.reflect_on_association(:favorites)
|
20
|
+
expect(association.macro).to eq :has_many
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should have many favorites with dependent destroy" do
|
24
|
+
association = User.reflect_on_association(:favorites)
|
25
|
+
expect(association.options).to include :dependent => :destroy
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "#favorite?" do
|
30
|
+
context "when user has favorable" do
|
31
|
+
it "should return true" do
|
32
|
+
create_favorite(charlie, test)
|
33
|
+
expect(charlie.favorite?(test)).to be true
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context "when user has not favorited favorable" do
|
38
|
+
it "should return false" do
|
39
|
+
expect(charlie.favorite?(test)).to be false
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "#favorite" do
|
45
|
+
context "when user hasn't favorite favorable" do
|
46
|
+
it "should create a favorite record" do
|
47
|
+
expect {
|
48
|
+
charlie.favorite(test)
|
49
|
+
}.to change(Favorite, :count).by(1)
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should set association of the favorite record" do
|
53
|
+
charlie.favorite(test)
|
54
|
+
fav = Favorite.find_by(favorable_id: test.id, favorable_type: test.class.base_class.name, favoriter_id: charlie.id)
|
55
|
+
expect(fav.favoriter).to eq charlie
|
56
|
+
expect(fav.favorable).to eq test
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
context "when user has favorited post already" do
|
61
|
+
it "should do nothing" do
|
62
|
+
create_favorite(charlie, test)
|
63
|
+
expect {
|
64
|
+
charlie.favorite(test)
|
65
|
+
}.to change(Favorite, :count).by(0)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
describe "#unfavorite" do
|
71
|
+
context "when user has not favorite post " do
|
72
|
+
it "should destroy the favorite record" do
|
73
|
+
create_favorite(charlie, test)
|
74
|
+
expect {
|
75
|
+
charlie.unfavorite(test)
|
76
|
+
}.to change(Favorite, :count).by(-1)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
context "when user has not favored post" do
|
81
|
+
it "should do nothing" do
|
82
|
+
expect {
|
83
|
+
charlie.unfavorite(test)
|
84
|
+
}.to change(Favorite, :count).by(0)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
require 'acts_as_favorite'
|
2
|
+
require 'active_record'
|
3
|
+
require 'support/models.rb'
|
4
|
+
require 'coveralls'
|
5
|
+
Coveralls.wear!
|
6
|
+
require 'support/favorite_factory'
|
7
|
+
ActiveRecord::Base.establish_connection adapter: 'sqlite3', database: ":memory"
|
8
|
+
load 'support/schema.rb'
|
9
|
+
#load 'support/models.rb'
|
10
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
11
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
12
|
+
# The generated `.rspec` file contains `--require spec_helper` which will cause
|
13
|
+
# this file to always be loaded, without a need to explicitly require it in any
|
14
|
+
# files.
|
15
|
+
#
|
16
|
+
# Given that it is always loaded, you are encouraged to keep this file as
|
17
|
+
# light-weight as possible. Requiring heavyweight dependencies from this file
|
18
|
+
# will add to the boot time of your test suite on EVERY test run, even for an
|
19
|
+
# individual file that may not need all of that loaded. Instead, consider making
|
20
|
+
# a separate helper file that requires the additional dependencies and performs
|
21
|
+
# the additional setup, and require it from the spec files that actually need
|
22
|
+
# it.
|
23
|
+
#
|
24
|
+
# The `.rspec` file also contains a few flags that are not defaults but that
|
25
|
+
# users commonly want.
|
26
|
+
#
|
27
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
28
|
+
RSpec.configure do |config|
|
29
|
+
# rspec-expectations config goes here. You can use an alternate
|
30
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
31
|
+
# assertions if you prefer.
|
32
|
+
config.expect_with :rspec do |expectations|
|
33
|
+
# This option will default to `true` in RSpec 4. It makes the `description`
|
34
|
+
# and `failure_message` of custom matchers include text for helper methods
|
35
|
+
# defined using `chain`, e.g.:
|
36
|
+
# be_bigger_than(2).and_smaller_than(4).description
|
37
|
+
# # => "be bigger than 2 and smaller than 4"
|
38
|
+
# ...rather than:
|
39
|
+
# # => "be bigger than 2"
|
40
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
41
|
+
end
|
42
|
+
|
43
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
44
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
45
|
+
config.mock_with :rspec do |mocks|
|
46
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
47
|
+
# a real object. This is generally recommended, and will default to
|
48
|
+
# `true` in RSpec 4.
|
49
|
+
mocks.verify_partial_doubles = true
|
50
|
+
end
|
51
|
+
|
52
|
+
# The settings below are suggested to provide a good initial experience
|
53
|
+
# with RSpec, but feel free to customize to your heart's content.
|
54
|
+
=begin
|
55
|
+
# These two settings work together to allow you to limit a spec run
|
56
|
+
# to individual examples or groups you care about by tagging them with
|
57
|
+
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
|
58
|
+
# get run.
|
59
|
+
config.filter_run :focus
|
60
|
+
config.run_all_when_everything_filtered = true
|
61
|
+
|
62
|
+
# Limits the available syntax to the non-monkey patched syntax that is
|
63
|
+
# recommended. For more details, see:
|
64
|
+
# - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
|
65
|
+
# - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
66
|
+
# - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
|
67
|
+
config.disable_monkey_patching!
|
68
|
+
|
69
|
+
# This setting enables warnings. It's recommended, but in some cases may
|
70
|
+
# be too noisy due to issues in dependencies.
|
71
|
+
config.warnings = true
|
72
|
+
|
73
|
+
# Many RSpec users commonly either run the entire suite or an individual
|
74
|
+
# file, and it's useful to allow more verbose output when running an
|
75
|
+
# individual spec file.
|
76
|
+
if config.files_to_run.one?
|
77
|
+
# Use the documentation formatter for detailed output,
|
78
|
+
# unless a formatter has already been configured
|
79
|
+
# (e.g. via a command-line flag).
|
80
|
+
config.default_formatter = 'doc'
|
81
|
+
end
|
82
|
+
|
83
|
+
# Print the 10 slowest examples and example groups at the
|
84
|
+
# end of the spec run, to help surface which specs are running
|
85
|
+
# particularly slow.
|
86
|
+
config.profile_examples = 10
|
87
|
+
|
88
|
+
# Run specs in random order to surface order dependencies. If you find an
|
89
|
+
# order dependency and want to debug it, you can fix the order by providing
|
90
|
+
# the seed, which is printed after each run.
|
91
|
+
# --seed 1234
|
92
|
+
config.order = :random
|
93
|
+
|
94
|
+
# Seed global randomization in this process using the `--seed` CLI option.
|
95
|
+
# Setting this allows you to use `--seed` to deterministically reproduce
|
96
|
+
# test failures related to randomization by passing the same `--seed` value
|
97
|
+
# as the one that triggered the failure.
|
98
|
+
Kernel.srand config.seed
|
99
|
+
=end
|
100
|
+
config.include FavoriteFactory
|
101
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
ActiveRecord::Schema.define do
|
2
|
+
|
3
|
+
drop_table :favorites if ActiveRecord::Base.connection.table_exists? 'favorites'
|
4
|
+
drop_table :users if ActiveRecord::Base.connection.table_exists? 'users'
|
5
|
+
drop_table :posts if ActiveRecord::Base.connection.table_exists? 'posts'
|
6
|
+
|
7
|
+
create_table :favorites do |t|
|
8
|
+
t.references :favorable, polymorphic: true
|
9
|
+
t.references :favoriter, polymorphic: true
|
10
|
+
|
11
|
+
t.timestamps
|
12
|
+
end
|
13
|
+
|
14
|
+
add_index :favorites, [:favorable_id, :favorable_type]
|
15
|
+
add_index :favorites, [:favoriter_id, :favoriter_type]
|
16
|
+
|
17
|
+
|
18
|
+
create_table :users do |t|
|
19
|
+
t.string :name
|
20
|
+
end
|
21
|
+
|
22
|
+
create_table :posts do |t|
|
23
|
+
t.string :name
|
24
|
+
end
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,200 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: acts_as_favourites
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Rajarshi Das
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-06-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: guard
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: guard-rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: sqlite3
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: activerecord
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: generator_spec
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: coveralls
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
description:
|
140
|
+
email:
|
141
|
+
- rajarshi2576@gmail.com
|
142
|
+
executables: []
|
143
|
+
extensions: []
|
144
|
+
extra_rdoc_files: []
|
145
|
+
files:
|
146
|
+
- ".gitignore"
|
147
|
+
- ".rspec"
|
148
|
+
- ".travis.yml"
|
149
|
+
- ":memory"
|
150
|
+
- Gemfile
|
151
|
+
- LICENSE.txt
|
152
|
+
- README.md
|
153
|
+
- Rakefile
|
154
|
+
- acts_as_favorite.gemspec
|
155
|
+
- converalls.yml
|
156
|
+
- lib/acts_as_favorite.rb
|
157
|
+
- lib/acts_as_favorite/favor.rb
|
158
|
+
- lib/acts_as_favorite/favoriter.rb
|
159
|
+
- lib/acts_as_favorite/version.rb
|
160
|
+
- lib/generators/favorable_generator.rb
|
161
|
+
- lib/generators/templates/migrator.rb
|
162
|
+
- lib/generators/templates/model.rb
|
163
|
+
- spec/favor_spec.rb
|
164
|
+
- spec/favoriter_spec.rb
|
165
|
+
- spec/spec_helper.rb
|
166
|
+
- spec/support/favorite_factory.rb
|
167
|
+
- spec/support/models.rb
|
168
|
+
- spec/support/schema.rb
|
169
|
+
homepage: https://github.com/rajcybage/acts_as_favourites
|
170
|
+
licenses:
|
171
|
+
- MIT
|
172
|
+
metadata: {}
|
173
|
+
post_install_message:
|
174
|
+
rdoc_options: []
|
175
|
+
require_paths:
|
176
|
+
- lib
|
177
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
178
|
+
requirements:
|
179
|
+
- - ">="
|
180
|
+
- !ruby/object:Gem::Version
|
181
|
+
version: '0'
|
182
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
183
|
+
requirements:
|
184
|
+
- - ">="
|
185
|
+
- !ruby/object:Gem::Version
|
186
|
+
version: '0'
|
187
|
+
requirements: []
|
188
|
+
rubyforge_project:
|
189
|
+
rubygems_version: 2.4.7
|
190
|
+
signing_key:
|
191
|
+
specification_version: 4
|
192
|
+
summary: Add favorite feature to any Active Record models
|
193
|
+
test_files:
|
194
|
+
- spec/favor_spec.rb
|
195
|
+
- spec/favoriter_spec.rb
|
196
|
+
- spec/spec_helper.rb
|
197
|
+
- spec/support/favorite_factory.rb
|
198
|
+
- spec/support/models.rb
|
199
|
+
- spec/support/schema.rb
|
200
|
+
has_rdoc:
|