acts_as_friendable 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +22 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +104 -0
- data/Rakefile +6 -0
- data/acts_as_friendable.gemspec +26 -0
- data/lib/acts_as_friendable.rb +26 -0
- data/lib/acts_as_friendable/friendships.rb +5 -0
- data/lib/acts_as_friendable/model_additions.rb +29 -0
- data/lib/acts_as_friendable/version.rb +3 -0
- data/lib/generators/acts_as_friendable/install/install_generator.rb +24 -0
- data/lib/generators/acts_as_friendable/install/templates/migration.rb +11 -0
- data/rails/init.rb +1 -0
- data/spec/acts_as_friendable/friendships_spec.rb +14 -0
- data/spec/acts_as_friendable/model_additions_spec.rb +120 -0
- data/spec/config/database.yml.sample +19 -0
- data/spec/config/models.rb +3 -0
- data/spec/config/schema.rb +16 -0
- data/spec/generators/install_generator_spec.rb +23 -0
- data/spec/spec_helper.rb +62 -0
- metadata +157 -0
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/*.log
|
15
|
+
spec/config/database.yml
|
16
|
+
spec/reports
|
17
|
+
/spec/tmp/*
|
18
|
+
*.sqlite3
|
19
|
+
test/tmp
|
20
|
+
test/version_tmp
|
21
|
+
tmp
|
22
|
+
.DS_Store
|
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Jeremy Ward
|
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,104 @@
|
|
1
|
+
# ActsAsFriendable
|
2
|
+
|
3
|
+
ActsAsFriendable provides a Friendship model, relevent scopes, and many instance methods to quickly and easily add Social Networking functionality to your Rails application.
|
4
|
+
|
5
|
+
## Overview
|
6
|
+
|
7
|
+
ActsAsFriendable defines a "friendship" as a two-way relationship which is initiated by one user and approved by the other user. So, we have two states of a friendship (not-approved-yet or approved) and we have two directions of friendship relative to the current user: friendships requested by the current user (we’ll call these “direct” friendships), and friendships requested to the current user (we’ll call these “inverse” friendships).
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add ActsAsFriendable to you Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'acts_as_friendable'
|
15
|
+
```
|
16
|
+
|
17
|
+
And then intall it with bundler by executing:
|
18
|
+
|
19
|
+
```shell
|
20
|
+
bundle install
|
21
|
+
```
|
22
|
+
|
23
|
+
Install and run the migrations:
|
24
|
+
|
25
|
+
```shell
|
26
|
+
rails g acts_as_friendable:install
|
27
|
+
rails db:migrate
|
28
|
+
```
|
29
|
+
|
30
|
+
## Usage
|
31
|
+
|
32
|
+
ActsAsFriendable is meant to be used on one Active Record model. The model can be named anything you like, but it will most frequently be 'User'. **Note:** you'll need to manually add ActsAsFriendable to your model class.
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
class User < ActiveRecord::Base
|
36
|
+
include ActsAsFriendable
|
37
|
+
end
|
38
|
+
```
|
39
|
+
|
40
|
+
`include ActsAsFriendable` adds all of the ActsAsFriendable goodness to the model.
|
41
|
+
|
42
|
+
### Scopes and Methods
|
43
|
+
|
44
|
+
Given the "friendship" definition in the Overview, we have 4 possible states of Friendship:
|
45
|
+
|
46
|
+
1. direct approved
|
47
|
+
2. indirect approved
|
48
|
+
3. direct not-approved
|
49
|
+
4. indirect not-approved
|
50
|
+
|
51
|
+
States #1 and #2 are simply what we will be calling "friends." They are approved relationships, no matter the direction. Because we don’t care who requested the friendship once it’s approved, we will group these together.
|
52
|
+
|
53
|
+
State #3 is what we call "pending friends." Other users whom the current user has requested to be friends with and which are awaiting approval. These are out of of the control of the current user and just waiting to be approved or rejected.
|
54
|
+
|
55
|
+
State #4 is what we call "requested friends." Other user who have requested that the current user be their friend and are awaiting the approval of the current user. These are the actionable items for the current user to approve or reject. Ignoring a friend request simply deletes the non-approved Friendship (similar to Facebook). It doesn't the the other person they were reject but allows them to send another friend request if they want.
|
56
|
+
|
57
|
+
With that understanding we have the following scopes / "lookup" methods available to us:
|
58
|
+
|
59
|
+
```ruby
|
60
|
+
class User < ActiveRecord::Base
|
61
|
+
include ActsAsFriendable
|
62
|
+
end
|
63
|
+
|
64
|
+
@user = User.find(1) # assuming there is a user in the database
|
65
|
+
|
66
|
+
@user.friendships
|
67
|
+
@user.inverse_friendships
|
68
|
+
@user.direct_friends
|
69
|
+
@user.inverse_friends
|
70
|
+
@user.pending_friends
|
71
|
+
@user.requested_friendships
|
72
|
+
@user.friends # => amalgamation of direct_friends and inverse_friends
|
73
|
+
|
74
|
+
# Additionally, we have several convenience methods to help in sorting, listing, finding, etc.
|
75
|
+
|
76
|
+
# provides a map of the current user's friend's ids
|
77
|
+
@user.friend_ids
|
78
|
+
|
79
|
+
# provides a map of ids of all current and requested friends of the current user
|
80
|
+
# - useful in querying for new friends
|
81
|
+
@user.pending_and_friend_ids
|
82
|
+
|
83
|
+
# includes the current user's id in the map of friend's ids
|
84
|
+
# - useful when you need to inlude the current user in a collection (Activities, Comments, Leaderboards, etc.)
|
85
|
+
@user.friend_ids_and_me
|
86
|
+
|
87
|
+
|
88
|
+
```
|
89
|
+
|
90
|
+
## Testing
|
91
|
+
|
92
|
+
ActsAsFriendable uses RSpec for its test coverage. Inside the gem directory, you can run the specs with:
|
93
|
+
|
94
|
+
```shell
|
95
|
+
rake
|
96
|
+
```
|
97
|
+
|
98
|
+
## Contributing
|
99
|
+
|
100
|
+
1. Fork it
|
101
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
102
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
103
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
104
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,26 @@
|
|
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_friendable/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "acts_as_friendable"
|
8
|
+
spec.version = ActsAsFriendable::VERSION
|
9
|
+
spec.authors = ["Jeremy Ward"]
|
10
|
+
spec.email = ["jrmy.ward@gmail.com"]
|
11
|
+
spec.description = %q{ActsAsFriendable provides a Friendship model, relevent scopes, and many instance methods to quickly and easily add Social Networking functionality to your Rails application.}
|
12
|
+
spec.summary = %q{A drop-in solution to add Friendship functionality to a Rails application.}
|
13
|
+
spec.homepage = "https://github.com/jrmyward/acts_as_friendable"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_runtime_dependency 'rails', '~> 3.0'
|
22
|
+
spec.add_development_dependency 'sqlite3'
|
23
|
+
spec.add_development_dependency 'rspec'
|
24
|
+
spec.add_development_dependency 'ammeter'
|
25
|
+
spec.add_development_dependency "database_cleaner"
|
26
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require "active_record"
|
2
|
+
require "active_record/version"
|
3
|
+
require "acts_as_friendable/model_additions"
|
4
|
+
require "acts_as_friendable/friendships"
|
5
|
+
require "acts_as_friendable/version"
|
6
|
+
|
7
|
+
module ActsAsFriendable
|
8
|
+
def self.included(receiver)
|
9
|
+
receiver.class_eval do
|
10
|
+
has_many :friendships, :class_name => "ActsAsFriendable::Friendship", :dependent => :destroy
|
11
|
+
has_many :inverse_friendships, :class_name => "ActsAsFriendable::Friendship", :foreign_key => "friend_id", :dependent => :destroy
|
12
|
+
has_many :direct_friends, :through => :friendships, :conditions => ["approved = ?", true], :source => :friend
|
13
|
+
has_many :inverse_friends, :through => :inverse_friendships, :conditions => ["approved = ?", true], :source => :user
|
14
|
+
has_many :pending_friends, :through => :friendships, :conditions => ["approved = ?", false], :source => :friend
|
15
|
+
has_many :requested_friendships, :through => :inverse_friendships, :conditions => ["approved = ?", false], :source => :user
|
16
|
+
end
|
17
|
+
|
18
|
+
ActsAsFriendable::Friendship.class_eval do
|
19
|
+
belongs_to "#{receiver.to_s.underscore}".to_sym, :class_name => "#{receiver.to_s}", :foreign_key => "user_id"
|
20
|
+
belongs_to :friend, :class_name => "#{receiver.to_s}", :foreign_key => "friend_id"
|
21
|
+
end
|
22
|
+
|
23
|
+
receiver.extend ClassMethods
|
24
|
+
receiver.send :include, InstanceMethods
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module ActsAsFriendable
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
|
4
|
+
module ClassMethods
|
5
|
+
|
6
|
+
end
|
7
|
+
|
8
|
+
module InstanceMethods
|
9
|
+
def friends
|
10
|
+
direct_friends | inverse_friends
|
11
|
+
end
|
12
|
+
|
13
|
+
def friend_ids
|
14
|
+
friends.map {|f| f.id}
|
15
|
+
end
|
16
|
+
|
17
|
+
def friend_ids_and_me
|
18
|
+
friend_ids << id
|
19
|
+
end
|
20
|
+
|
21
|
+
def pending_and_friend_ids
|
22
|
+
pending_and_friend_ids = []
|
23
|
+
pending_and_friend_ids << friend_ids
|
24
|
+
pending_and_friend_ids << pending_friends.map {|f| f.id}
|
25
|
+
pending_and_friend_ids.flatten
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'rails/generators/migration'
|
2
|
+
|
3
|
+
module ActsAsFriendable
|
4
|
+
module Generators
|
5
|
+
class InstallGenerator < ::Rails::Generators::Base
|
6
|
+
include Rails::Generators::Migration
|
7
|
+
source_root File.expand_path('../templates', __FILE__)
|
8
|
+
desc "Generates Friendship migration"
|
9
|
+
|
10
|
+
def self.next_migration_number(path)
|
11
|
+
unless @prev_migration_nr
|
12
|
+
@prev_migration_nr = Time.now.utc.strftime("%Y%m%d%H%M%S").to_i
|
13
|
+
else
|
14
|
+
@prev_migration_nr += 1
|
15
|
+
end
|
16
|
+
@prev_migration_nr.to_s
|
17
|
+
end
|
18
|
+
|
19
|
+
def copy_migration
|
20
|
+
migration_template 'migration.rb', 'db/migrate/acts_as_friendable.rb'
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/rails/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'acts_as_friendable'
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ActsAsFriendable::Friendship do
|
4
|
+
let(:user) { User.create!({ first_name: 'James', last_name: 'Bond' }) }
|
5
|
+
|
6
|
+
it "should respond to user" do
|
7
|
+
ActsAsFriendable::Friendship.instance_methods.include?(:user).should be_true
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should respond to friend" do
|
11
|
+
ActsAsFriendable::Friendship.instance_methods.include?(:friend).should be_true
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
@@ -0,0 +1,120 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ActsAsFriendable do
|
4
|
+
let(:user) { User.create!({ first_name: 'Bruce', last_name: 'Wayne' }) }
|
5
|
+
let(:user_2) { User.create!({ first_name: 'Clark', last_name: 'Kent' }) }
|
6
|
+
let(:user_3) { User.create!({ first_name: 'Peter', last_name: 'Parker' }) }
|
7
|
+
let(:user_4) { User.create!({ first_name: 'Bruce', last_name: 'Banner' }) }
|
8
|
+
let(:user_5) { User.create!({ first_name: 'Tony', last_name: 'Stark' }) }
|
9
|
+
|
10
|
+
before(:each) do
|
11
|
+
ActsAsFriendable::Friendship.create({user_id: user.id, friend_id: user_2.id, approved: true})
|
12
|
+
ActsAsFriendable::Friendship.create({user_id: user_3.id, friend_id: user.id, approved: true})
|
13
|
+
ActsAsFriendable::Friendship.create({user_id: user_4.id, friend_id: user.id, approved: false})
|
14
|
+
ActsAsFriendable::Friendship.create({user_id: user.id, friend_id: user_5.id, approved: false})
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "Reciever" do
|
18
|
+
it "should respond to friendships" do
|
19
|
+
user.should respond_to(:friendships)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should respond to inverse_friendships" do
|
23
|
+
user.should respond_to(:inverse_friendships)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should respond to direct_friends" do
|
27
|
+
user.should respond_to(:direct_friends)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should respond to inverse_friends" do
|
31
|
+
user.should respond_to(:inverse_friends)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should respond to pending_friends" do
|
35
|
+
user.should respond_to(:pending_friends)
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should respond to requested_friendships" do
|
39
|
+
user.should respond_to(:requested_friendships)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe "Scope" do
|
44
|
+
|
45
|
+
describe "friendships" do
|
46
|
+
it "collects all user-initiated relationships" do
|
47
|
+
r = user.friendships
|
48
|
+
r[0].friend_id.should == user_2.id
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe "inverse_friendships" do
|
53
|
+
it "collects all stranger-initiated relationships" do
|
54
|
+
r = user.inverse_friendships
|
55
|
+
r[0].user_id.should == user_3.id
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe "direct_friends" do
|
60
|
+
it "collects approved user-initiated relationships" do
|
61
|
+
r = user.direct_friends
|
62
|
+
r[0].id.should == user_2.id
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe "inverse_friends" do
|
67
|
+
it "collects approved stranger-initiated relationships" do
|
68
|
+
r = user.inverse_friends
|
69
|
+
r[0].id.should == user_3.id
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe "pending_friends" do
|
74
|
+
it "collects un-approved user-initiated relationships" do
|
75
|
+
r = user_4.pending_friends
|
76
|
+
r[0].id.should == user.id
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
describe "requested_friendships" do
|
81
|
+
it "collects un-approved stranger-initiated relationships" do
|
82
|
+
r = user.requested_friendships
|
83
|
+
r[0].id.should == user_4.id
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
describe "friends" do
|
88
|
+
it "collects a user's approved direct_friends and inverse_friends" do
|
89
|
+
r = user.friends
|
90
|
+
r[0].id.should == user_2.id
|
91
|
+
r[1].id.should == user_3.id
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
describe "Instance Method" do
|
97
|
+
|
98
|
+
describe "friend_ids" do
|
99
|
+
it "should return an array of all direct_friends and inverse_friends ids" do
|
100
|
+
user.friend_ids.include?(user_2.id).should be_true
|
101
|
+
user.friend_ids.include?(user_5.id).should be_false
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
describe "friend_ids_and_me" do
|
106
|
+
it "should return an array of approved friend ids plus the current user's id" do
|
107
|
+
user_3.friend_ids_and_me.should == [user.id, user_3.id]
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
describe "pending_and_friend_ids" do
|
112
|
+
it "should return an array of all approved friends and user-initiated pending friends" do
|
113
|
+
user.pending_and_friend_ids.include?(user_2.id).should be_true
|
114
|
+
user.pending_and_friend_ids.include?(user_5.id).should be_true
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
end
|
119
|
+
|
120
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
sqlite3:
|
2
|
+
adapter: sqlite3
|
3
|
+
database: acts_as_friendable.sqlite3
|
4
|
+
|
5
|
+
mysql:
|
6
|
+
adapter: mysql2
|
7
|
+
hostname: localhost
|
8
|
+
username: root
|
9
|
+
password:
|
10
|
+
database: acts_as_friendable
|
11
|
+
charset: utf8
|
12
|
+
|
13
|
+
postgresql:
|
14
|
+
adapter: postgresql
|
15
|
+
hostname: localhost
|
16
|
+
username: postgres
|
17
|
+
password:
|
18
|
+
database: acts_as_friendable
|
19
|
+
encoding: utf8
|
@@ -0,0 +1,16 @@
|
|
1
|
+
ActiveRecord::Schema.define :version => 0 do
|
2
|
+
|
3
|
+
create_table "friendships", :force => true do |t|
|
4
|
+
t.integer "user_id"
|
5
|
+
t.integer "friend_id"
|
6
|
+
t.boolean "approved"
|
7
|
+
t.datetime "created_at", :null => false
|
8
|
+
t.datetime "updated_at", :null => false
|
9
|
+
end
|
10
|
+
|
11
|
+
create_table "users", :force => true do |t|
|
12
|
+
t.string "first_name"
|
13
|
+
t.string "last_name"
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
# Generators are NOT automatically loaded by Rails
|
4
|
+
require 'generators/acts_as_friendable/install/install_generator'
|
5
|
+
|
6
|
+
describe ActsAsFriendable::Generators::InstallGenerator do
|
7
|
+
# Tell the generator where to put its output (what it thinks of as Rails.root)
|
8
|
+
destination File.expand_path("../../../tmp", __FILE__)
|
9
|
+
|
10
|
+
before do
|
11
|
+
prepare_destination
|
12
|
+
Rails::Generators.options[:rails][:orm] = :active_record
|
13
|
+
end
|
14
|
+
|
15
|
+
describe 'no arguments' do
|
16
|
+
before { run_generator }
|
17
|
+
|
18
|
+
describe 'db/migrate/acts_as_friendable.rb' do
|
19
|
+
subject { file('db/migrate/acts_as_friendable.rb') }
|
20
|
+
it { should be_a_migration }
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'acts_as_friendable'
|
3
|
+
require 'ammeter/init'
|
4
|
+
require 'database_cleaner'
|
5
|
+
|
6
|
+
# set adapter to use, default is sqlite3
|
7
|
+
# to use an alternative adapter run => rake spec DB='postgresql'
|
8
|
+
db_name = ENV['DB'] || 'sqlite3'
|
9
|
+
database_yml = File.expand_path('../config/database.yml', __FILE__)
|
10
|
+
|
11
|
+
if File.exists?(database_yml)
|
12
|
+
active_record_configuration = YAML.load_file(database_yml)
|
13
|
+
|
14
|
+
ActiveRecord::Base.configurations = active_record_configuration
|
15
|
+
config = ActiveRecord::Base.configurations[db_name]
|
16
|
+
|
17
|
+
begin
|
18
|
+
ActiveRecord::Base.establish_connection(db_name)
|
19
|
+
ActiveRecord::Base.connection
|
20
|
+
rescue
|
21
|
+
case db_name
|
22
|
+
when /mysql/
|
23
|
+
ActiveRecord::Base.establish_connection(config.merge('database' => nil))
|
24
|
+
ActiveRecord::Base.connection.create_database(config['database'], {:charset => 'utf8', :collation => 'utf8_unicode_ci'})
|
25
|
+
when 'postgresql'
|
26
|
+
ActiveRecord::Base.establish_connection(config.merge('database' => 'postgres', 'schema_search_path' => 'public'))
|
27
|
+
ActiveRecord::Base.connection.create_database(config['database'], config.merge('encoding' => 'utf8'))
|
28
|
+
end
|
29
|
+
|
30
|
+
ActiveRecord::Base.establish_connection(config)
|
31
|
+
end
|
32
|
+
|
33
|
+
ActiveRecord::Base.logger = Logger.new(File.join(File.dirname(__FILE__), "debug.log"))
|
34
|
+
ActiveRecord::Base.default_timezone = :utc
|
35
|
+
|
36
|
+
ActiveRecord::Base.silence do
|
37
|
+
ActiveRecord::Migration.verbose = false
|
38
|
+
|
39
|
+
load(File.expand_path('../config/schema.rb', __FILE__))
|
40
|
+
load(File.expand_path('../config/models.rb', __FILE__))
|
41
|
+
end
|
42
|
+
|
43
|
+
else
|
44
|
+
raise "Please create #{database_yml} first to configure your database. Take a look at: spec/config/database.yml.sample"
|
45
|
+
end
|
46
|
+
|
47
|
+
RSpec.configure do |config|
|
48
|
+
config.mock_with :rspec
|
49
|
+
|
50
|
+
config.before(:suite) do
|
51
|
+
DatabaseCleaner.strategy = :transaction
|
52
|
+
DatabaseCleaner.clean_with(:truncation)
|
53
|
+
end
|
54
|
+
|
55
|
+
config.before(:each) do
|
56
|
+
DatabaseCleaner.start
|
57
|
+
end
|
58
|
+
|
59
|
+
config.after(:each) do
|
60
|
+
DatabaseCleaner.clean
|
61
|
+
end
|
62
|
+
end
|
metadata
ADDED
@@ -0,0 +1,157 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: acts_as_friendable
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.5.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Jeremy Ward
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-03-08 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rails
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '3.0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '3.0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: sqlite3
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rspec
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: ammeter
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: database_cleaner
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
description: ActsAsFriendable provides a Friendship model, relevent scopes, and many
|
95
|
+
instance methods to quickly and easily add Social Networking functionality to your
|
96
|
+
Rails application.
|
97
|
+
email:
|
98
|
+
- jrmy.ward@gmail.com
|
99
|
+
executables: []
|
100
|
+
extensions: []
|
101
|
+
extra_rdoc_files: []
|
102
|
+
files:
|
103
|
+
- .gitignore
|
104
|
+
- .rspec
|
105
|
+
- Gemfile
|
106
|
+
- LICENSE.txt
|
107
|
+
- README.md
|
108
|
+
- Rakefile
|
109
|
+
- acts_as_friendable.gemspec
|
110
|
+
- lib/acts_as_friendable.rb
|
111
|
+
- lib/acts_as_friendable/friendships.rb
|
112
|
+
- lib/acts_as_friendable/model_additions.rb
|
113
|
+
- lib/acts_as_friendable/version.rb
|
114
|
+
- lib/generators/acts_as_friendable/install/install_generator.rb
|
115
|
+
- lib/generators/acts_as_friendable/install/templates/migration.rb
|
116
|
+
- rails/init.rb
|
117
|
+
- spec/acts_as_friendable/friendships_spec.rb
|
118
|
+
- spec/acts_as_friendable/model_additions_spec.rb
|
119
|
+
- spec/config/database.yml.sample
|
120
|
+
- spec/config/models.rb
|
121
|
+
- spec/config/schema.rb
|
122
|
+
- spec/generators/install_generator_spec.rb
|
123
|
+
- spec/spec_helper.rb
|
124
|
+
homepage: https://github.com/jrmyward/acts_as_friendable
|
125
|
+
licenses:
|
126
|
+
- MIT
|
127
|
+
post_install_message:
|
128
|
+
rdoc_options: []
|
129
|
+
require_paths:
|
130
|
+
- lib
|
131
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
132
|
+
none: false
|
133
|
+
requirements:
|
134
|
+
- - ! '>='
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: '0'
|
137
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
138
|
+
none: false
|
139
|
+
requirements:
|
140
|
+
- - ! '>='
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
version: '0'
|
143
|
+
requirements: []
|
144
|
+
rubyforge_project:
|
145
|
+
rubygems_version: 1.8.23
|
146
|
+
signing_key:
|
147
|
+
specification_version: 3
|
148
|
+
summary: A drop-in solution to add Friendship functionality to a Rails application.
|
149
|
+
test_files:
|
150
|
+
- spec/acts_as_friendable/friendships_spec.rb
|
151
|
+
- spec/acts_as_friendable/model_additions_spec.rb
|
152
|
+
- spec/config/database.yml.sample
|
153
|
+
- spec/config/models.rb
|
154
|
+
- spec/config/schema.rb
|
155
|
+
- spec/generators/install_generator_spec.rb
|
156
|
+
- spec/spec_helper.rb
|
157
|
+
has_rdoc:
|