dm-is-friendly 0.10.2 → 0.10.25
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.
- data/LICENSE +1 -1
- data/README.markdown +51 -39
- data/Rakefile +20 -13
- data/VERSION +1 -1
- data/dm-is-friendly.gemspec +3 -4
- data/lib/dm-is-friendly.rb +0 -12
- data/lib/is/friendly.rb +23 -7
- data/spec/dm-is-friendly_spec.rb +143 -139
- data/spec/spec.opts +1 -2
- data/spec/spec_helper.rb +39 -11
- metadata +36 -18
- data/lib/is/version.rb +0 -10
data/LICENSE
CHANGED
data/README.markdown
CHANGED
@@ -1,63 +1,75 @@
|
|
1
|
-
|
1
|
+
dm-is-friendly
|
2
|
+
==============
|
2
3
|
|
3
4
|
DataMapper plugin that adds self-referential friendship functionality to your models.
|
4
5
|
|
5
|
-
**Note: This is NOT officially part of the DataMapper (dm-core, dm-more) project, it just works with DataMapper.
|
6
|
-
|
7
6
|
## Why is this plugin useful? ##
|
8
7
|
|
9
|
-
If you're building
|
8
|
+
If you're building an app that require this type of relation then it will probably save some time to use this instead of rolling our own :)
|
10
9
|
|
11
10
|
## Installation ##
|
12
11
|
|
13
|
-
|
14
|
-
|
15
|
-
$ sudo gem install kabari-dm-is-friendly.
|
12
|
+
$ [sudo] gem install dm-is-friendly.
|
16
13
|
|
17
|
-
Create a file for the friendship (or whatever you want to call it) class.
|
14
|
+
Create a file for the friendship (or whatever you want to call it) class.
|
18
15
|
|
19
|
-
## Example DataMapper
|
16
|
+
## Example DataMapper model ##
|
20
17
|
|
21
|
-
# /app/models/friendship.rb
|
22
18
|
class Friendship
|
23
19
|
include DataMapper::Resource
|
24
|
-
|
25
|
-
# you need all of this
|
26
20
|
property :person_id, Integer, :key => true
|
27
21
|
property :friend_id, Integer, :key => true
|
28
|
-
property :accepted_at, DateTime
|
29
|
-
|
30
|
-
belongs_to :person
|
31
|
-
belongs_to :friend, :
|
32
|
-
|
22
|
+
property :accepted_at, DateTime
|
23
|
+
|
24
|
+
belongs_to :person
|
25
|
+
belongs_to :friend, :model => "Person", :child_key => [:friend_id]
|
26
|
+
|
33
27
|
end
|
34
|
-
|
35
|
-
# /app/models/person.rb
|
28
|
+
|
36
29
|
class Person
|
37
30
|
include DataMapper::Resource
|
38
|
-
property :id,
|
31
|
+
property :id, Serial
|
39
32
|
property :name, String
|
40
|
-
|
41
|
-
|
42
|
-
is :friendly
|
33
|
+
|
34
|
+
is :friendly #, :friendship_class => "Friendship", :require_acceptance => true
|
43
35
|
end
|
36
|
+
|
37
|
+
## Use It ##
|
38
|
+
|
39
|
+
@quentin = Person.create(:name => "quentin")
|
40
|
+
@joe = Person.create(:name => "joe")
|
44
41
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
42
|
+
# request friendship
|
43
|
+
@joe.request_friendship(@quentin)
|
44
|
+
|
45
|
+
# Find friend requests sent
|
46
|
+
@joe.friendship_requests # => [#<Person @id=1 @name="quentin">]
|
47
|
+
@joe.friendship_requested?(@quentin) # => true
|
48
|
+
|
49
|
+
# Find recieve friend requests
|
50
|
+
@quentin.friendships_to_accept # => [#<Person @id=2 @name="joe">]
|
51
|
+
@quentin.friendship_to_accept?(@joe) # => true
|
52
|
+
|
53
|
+
# Check friendships
|
54
|
+
@quentin.is_friends_with?(@joe) # => false
|
55
|
+
|
56
|
+
# Accept friendships
|
57
|
+
@quentin.confirm_friendship_with(@joe)
|
58
|
+
@quentin.is_friends_with?(@joe) # => true
|
59
|
+
|
60
|
+
# End friendships :(
|
61
|
+
@quentin.end_friendship_with(@joe) # => true
|
62
|
+
|
63
|
+
### Options ###
|
64
|
+
|
65
|
+
**:require_acceptance**
|
66
|
+
Set this if friendships should be accepted before showing up in the query of friends.
|
67
|
+
Default: true
|
68
|
+
**Must provide the :accepted_at Property*
|
69
|
+
|
70
|
+
**:friendship_class**
|
71
|
+
Set this to something other than "Friendship" if you want.
|
72
|
+
Default: "Friendship"
|
52
73
|
|
53
|
-
belongs_to :gangster
|
54
|
-
belongs_to :homie, :child_key => [:friend_id]
|
55
|
-
end
|
56
74
|
|
57
|
-
# /some/folder/gangster.rb
|
58
|
-
class Gangster
|
59
|
-
is :friendly, :friendship_class => "Homie", :require_acceptance => false
|
60
|
-
end
|
61
|
-
|
62
|
-
This would change the friendship class to Homie, and make it not require friendships to be accepted. I admit, it was kind of dumb to do it that way, but I just made this into a gem so that it wasn't lying around my code base. I'll make it more useful in the next run.
|
63
75
|
|
data/Rakefile
CHANGED
@@ -1,20 +1,17 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'rake'
|
3
|
-
require File.join(File.dirname(__FILE__), *%w[lib is version])
|
4
|
-
|
5
|
-
version = DataMapper::Is::Friendly::VERSION
|
6
3
|
|
7
4
|
begin
|
8
5
|
require 'jeweler'
|
9
|
-
Jeweler::Tasks.new do |
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
6
|
+
Jeweler::Tasks.new do |gemspec|
|
7
|
+
gemspec.name = "dm-is-friendly"
|
8
|
+
gemspec.summary = %Q{DataMapper plugin that adds self-referential friendship functionality to your models.}
|
9
|
+
gemspec.email = "kabari@gmail.com"
|
10
|
+
gemspec.homepage = "http://github.com/kabari/dm-is-friendly"
|
11
|
+
gemspec.authors = ["Kabari Hendrick"]
|
12
|
+
gemspec.add_dependency("extlib", "~> 0.9.14")
|
13
|
+
gemspec.add_dependency("dm-core", "~> 0.10.2")
|
14
|
+
gemspec.add_dependency("dm-aggregates", "~> 0.10.2")
|
18
15
|
end
|
19
16
|
Jeweler::GemcutterTasks.new
|
20
17
|
rescue LoadError
|
@@ -40,8 +37,18 @@ require 'rake/rdoctask'
|
|
40
37
|
|
41
38
|
Rake::RDocTask.new do |rdoc|
|
42
39
|
rdoc.rdoc_dir = 'rdoc'
|
43
|
-
rdoc.title = "dm-is-friendly
|
40
|
+
rdoc.title = "dm-is-friendly 0.10.21"
|
44
41
|
rdoc.rdoc_files.include('README*')
|
45
42
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
46
43
|
end
|
47
44
|
|
45
|
+
begin
|
46
|
+
require 'yard'
|
47
|
+
YARD::Rake::YardocTask.new do |t|
|
48
|
+
t.files = ['lib/**/*.rb', 'README.markdown', 'LICENSE']
|
49
|
+
end
|
50
|
+
rescue LoadError
|
51
|
+
task :yard do
|
52
|
+
abort "YARD is not available. In order to run yardoc, you must: sudo gem install yard"
|
53
|
+
end
|
54
|
+
end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.10.
|
1
|
+
0.10.25
|
data/dm-is-friendly.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{dm-is-friendly}
|
8
|
-
s.version = "0.10.
|
8
|
+
s.version = "0.10.25"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Kabari Hendrick"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-03-14}
|
13
13
|
s.email = %q{kabari@gmail.com}
|
14
14
|
s.extra_rdoc_files = [
|
15
15
|
"LICENSE",
|
@@ -25,7 +25,6 @@ Gem::Specification.new do |s|
|
|
25
25
|
"dm-is-friendly.gemspec",
|
26
26
|
"lib/dm-is-friendly.rb",
|
27
27
|
"lib/is/friendly.rb",
|
28
|
-
"lib/is/version.rb",
|
29
28
|
"spec/dm-is-friendly_spec.rb",
|
30
29
|
"spec/spec.opts",
|
31
30
|
"spec/spec_helper.rb"
|
@@ -33,7 +32,7 @@ Gem::Specification.new do |s|
|
|
33
32
|
s.homepage = %q{http://github.com/kabari/dm-is-friendly}
|
34
33
|
s.rdoc_options = ["--charset=UTF-8"]
|
35
34
|
s.require_paths = ["lib"]
|
36
|
-
s.rubygems_version = %q{1.3.
|
35
|
+
s.rubygems_version = %q{1.3.6}
|
37
36
|
s.summary = %q{DataMapper plugin that adds self-referential friendship functionality to your models.}
|
38
37
|
s.test_files = [
|
39
38
|
"spec/dm-is-friendly_spec.rb",
|
data/lib/dm-is-friendly.rb
CHANGED
@@ -1,17 +1,5 @@
|
|
1
|
-
# Needed to import datamapper and other gems
|
2
|
-
require 'rubygems'
|
3
1
|
require 'pathname'
|
4
2
|
|
5
|
-
# Add all external dependencies for the plugin here
|
6
|
-
gem 'extlib', '~>0.9.14'
|
7
|
-
require "extlib"
|
8
|
-
|
9
|
-
gem 'dm-core', '~>0.10.2'
|
10
|
-
require 'dm-core'
|
11
|
-
|
12
|
-
gem 'dm-aggregates', '~>0.10.2'
|
13
|
-
require "dm-aggregates"
|
14
|
-
|
15
3
|
# Require plugin-files
|
16
4
|
require Pathname(__FILE__).dirname.expand_path / 'is' / 'friendly'
|
17
5
|
|
data/lib/is/friendly.rb
CHANGED
@@ -43,39 +43,47 @@ module DataMapper
|
|
43
43
|
module InstanceMethods
|
44
44
|
|
45
45
|
# returns all of the friends this person has that are accepted
|
46
|
+
# @return [DataMapper::Collection] All the person's friends
|
46
47
|
def friends
|
47
48
|
friendship_requests(nil,true).union(friendships_to_accept(nil,true))
|
48
49
|
end
|
49
50
|
|
50
51
|
# returns all the people I have requested frienship from
|
52
|
+
# @param friend (nil)
|
53
|
+
# @param include_accepted (false)
|
54
|
+
# @return [DataMapper::Collection] All the people that the person has sent friendship requests to
|
51
55
|
def friendship_requests(friend = nil, include_accepted = false)
|
52
56
|
conditions = {}
|
53
57
|
friend_acceptance_condition(conditions, include_accepted)
|
54
58
|
friend_scope_condition(conditions, friend)
|
55
59
|
|
56
60
|
conditions[friendly_options.friendship_foreign_key] = self.id
|
57
|
-
|
58
|
-
self.class.all( :id => ids)
|
61
|
+
friendly_options.friendship_class.all(conditions).friend
|
59
62
|
end
|
60
63
|
|
61
64
|
# returns all the people that have requested my friendship
|
65
|
+
# @param friend (nil)
|
66
|
+
# @param include_accepted (false)
|
67
|
+
# @return [DataMapper::Collection] All the people that have requested friendship
|
62
68
|
def friendships_to_accept(friend = nil, include_accepted = false)
|
63
69
|
conditions = {}
|
64
70
|
friend_acceptance_condition(conditions, include_accepted)
|
65
71
|
friend_scope_condition(conditions, friend, true)
|
66
72
|
|
67
|
-
conditions[:friend_id] = self.id
|
68
|
-
|
69
|
-
self.class.all(:id => ids)
|
73
|
+
conditions[:friend_id] = self.id
|
74
|
+
friendly_options.friendship_class.all(conditions).send(friendly_options.friend_class.name.downcase)
|
70
75
|
end
|
71
76
|
|
72
77
|
# see if there is a pending friendship request from this person to another
|
78
|
+
# @param friend
|
79
|
+
# @return [true, false]
|
73
80
|
def friendship_requested?(friend)
|
74
|
-
# return false unless friendly_options.require_acceptance?
|
75
81
|
!friendship_requests(friend).empty?
|
76
82
|
end
|
77
83
|
|
78
84
|
# see if user has a friend request to accept from this person
|
85
|
+
# @param friend
|
86
|
+
# @return [true, false]
|
79
87
|
def friendship_to_accept?(friend)
|
80
88
|
return false unless friendly_options.require_acceptance?
|
81
89
|
!friendships_to_accept(friend).empty?
|
@@ -83,17 +91,23 @@ module DataMapper
|
|
83
91
|
|
84
92
|
# Accepts a user object and returns true if both users are
|
85
93
|
# friends and the friendship has been accepted.
|
94
|
+
# @param friend
|
95
|
+
# @return [true, false]
|
86
96
|
def is_friends_with?(friend)
|
87
97
|
!self.friendship(friend).nil?
|
88
98
|
end
|
89
99
|
|
90
100
|
# request friendship from "friend"
|
101
|
+
# @param friend The friend who's friendship is being requested
|
102
|
+
# @return The instance of the friendship_class
|
91
103
|
def request_friendship(friend)
|
92
104
|
return false if friendship(friend)
|
93
105
|
self.friendships.create(:friend => friend)
|
94
106
|
end
|
95
107
|
|
96
108
|
# Accepts a user and updates an existing friendship to be accepted.
|
109
|
+
# @param friend The friend that needs to be confirmed
|
110
|
+
# @return [self]
|
97
111
|
def confirm_friendship_with(friend)
|
98
112
|
self.friendship(friend,{:accepted_at => nil}).update({:accepted_at => Time.now})
|
99
113
|
# reload so old relationship won't be lingering in the IdentityMap
|
@@ -102,12 +116,14 @@ module DataMapper
|
|
102
116
|
end
|
103
117
|
|
104
118
|
# Accepts a user and deletes a friendship between both users.
|
119
|
+
# @param friend The friend who's friendship will now end
|
120
|
+
# @return [true, false] Outcome of model.destroy
|
105
121
|
def end_friendship_with(friend)
|
106
122
|
self.friendship(friend).destroy if self.is_friends_with?(friend)
|
107
123
|
end
|
108
124
|
|
109
125
|
protected
|
110
|
-
# Accepts a user and returns the friendship associated with both users.
|
126
|
+
# Accepts a user and returns the friendship instance associated with both users.
|
111
127
|
def friendship(friend, opts = {})
|
112
128
|
friendly_options.friendship_class.first({:conditions => ["(#{friendly_options.friendship_foreign_key} = ? AND friend_id = ?) OR (friend_id = ? AND #{friendly_options.friendship_foreign_key} = ?)", self.id, friend.id, self.id, friend.id]}.merge(opts) )
|
113
129
|
end
|
data/spec/dm-is-friendly_spec.rb
CHANGED
@@ -4,7 +4,7 @@ class Friendship
|
|
4
4
|
include DataMapper::Resource
|
5
5
|
property :person_id, Integer, :key => true
|
6
6
|
property :friend_id, Integer, :key => true
|
7
|
-
property :accepted_at, DateTime
|
7
|
+
property :accepted_at, DateTime
|
8
8
|
|
9
9
|
belongs_to :person
|
10
10
|
belongs_to :friend, :model => "Person", :child_key => [:friend_id]
|
@@ -15,175 +15,179 @@ class Person
|
|
15
15
|
include DataMapper::Resource
|
16
16
|
property :id, Serial
|
17
17
|
property :name, String
|
18
|
+
property :deleted_at, ParanoidDateTime
|
18
19
|
|
19
20
|
is :friendly
|
20
21
|
end
|
21
22
|
|
23
|
+
# new classes
|
24
|
+
class Homie
|
25
|
+
include DataMapper::Resource
|
26
|
+
property :gangster_id, Integer, :key => true
|
27
|
+
property :friend_id, Integer, :key => true
|
28
|
+
|
29
|
+
belongs_to :gangster
|
30
|
+
belongs_to :friend, :model => "Gangster", :child_key => [:friend_id]
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
class Gangster
|
35
|
+
include DataMapper::Resource
|
36
|
+
property :id, Serial
|
37
|
+
property :name, String
|
38
|
+
is :friendly, :friendship_class => "Homie", :require_acceptance => false
|
39
|
+
end
|
40
|
+
|
22
41
|
describe 'DataMapper::Is::Friendly' do
|
23
|
-
|
24
|
-
|
25
|
-
|
42
|
+
with_adapters do
|
43
|
+
before(:all) do
|
44
|
+
Friendship.auto_migrate!; Person.auto_migrate!
|
45
|
+
end
|
26
46
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
end
|
47
|
+
it "should have proper options set" do
|
48
|
+
Person.friendly_options.friendship_class.should == Friendship
|
49
|
+
Person.friendly_options.friend_class.should == Person
|
50
|
+
Person.friendly_options.friendship_foreign_key.should == :person_id
|
51
|
+
Person.friendly_options.require_acceptance?.should == true
|
52
|
+
end
|
34
53
|
|
35
|
-
describe
|
36
|
-
|
37
|
-
|
54
|
+
describe "with friendships" do
|
55
|
+
before(:all) do
|
56
|
+
Friendship.auto_migrate!; Person.auto_migrate!
|
38
57
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
58
|
+
@quentin = Person.create(:name => "quentin")
|
59
|
+
@aaron = Person.create(:name => "aaron") # state: "pending"
|
60
|
+
@joe = Person.create(:name => "joe")
|
61
|
+
end
|
43
62
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
63
|
+
it "should work" do
|
64
|
+
lambda do
|
65
|
+
@joe.request_friendship(@quentin)
|
66
|
+
end.should change(Friendship, :count).by(1)
|
67
|
+
end
|
49
68
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
69
|
+
it "should only recognize friends that are confirmed" do
|
70
|
+
@joe.friends.should_not include(@quentin)
|
71
|
+
@quentin.friends.should_not include(@joe)
|
72
|
+
end
|
54
73
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
74
|
+
it "should set the proper relationships" do
|
75
|
+
# see if associations are correct
|
76
|
+
log("@quention.friendship_requests")
|
77
|
+
@quentin.friendship_requests.should_not include(@joe)
|
78
|
+
log("@joe.friendship_requests")
|
79
|
+
@joe.friendship_requests.should include(@quentin)
|
80
|
+
log("@quention.friendships_to_accept")
|
81
|
+
@quentin.friendships_to_accept.should include(@joe)
|
82
|
+
log("@joe.friendships_to_accept")
|
83
|
+
@joe.friendships_to_accept.should_not include(@quentin)
|
84
|
+
end
|
66
85
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
86
|
+
it "should also work with convenience methods" do
|
87
|
+
@quentin.friendship_to_accept?(@joe).should be_true
|
88
|
+
@joe.friendship_requested?(@quentin).should be_true
|
89
|
+
end
|
71
90
|
|
72
|
-
|
73
|
-
|
74
|
-
|
91
|
+
it "should have to be confirmed" do
|
92
|
+
# confirm the request
|
93
|
+
@quentin.confirm_friendship_with(@joe)
|
75
94
|
|
76
|
-
|
77
|
-
|
78
|
-
|
95
|
+
# see if associations are correct
|
96
|
+
@quentin.friends.should include(@joe)
|
97
|
+
@joe.friends.should include(@quentin)
|
79
98
|
|
80
|
-
|
81
|
-
|
82
|
-
|
99
|
+
@quentin.friendship_to_accept?(@joe).should be_false
|
100
|
+
@joe.friendship_requested?(@quentin).should be_false
|
101
|
+
end
|
83
102
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
103
|
+
it "should not be added twice" do
|
104
|
+
lambda do
|
105
|
+
@joe.request_friendship(@quentin)
|
106
|
+
@joe.should have(1).friends
|
107
|
+
@quentin.should have(1).friends
|
108
|
+
end.should_not change(Friendship,:count)
|
109
|
+
end
|
91
110
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
111
|
+
it "should be able to have multiple friends" do
|
112
|
+
@joe.request_friendship(@aaron)
|
113
|
+
@joe.friendship_requested?(@aaron).should be_true
|
114
|
+
@aaron.friendship_to_accept?(@joe).should be_true
|
115
|
+
end
|
97
116
|
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
117
|
+
it "should be able to delete friendships" do
|
118
|
+
lambda do
|
119
|
+
# joe sleeps with quentin's wife perhaps
|
120
|
+
@quentin.end_friendship_with(@joe)
|
121
|
+
end.should change(Friendship,:count)
|
103
122
|
|
104
|
-
|
123
|
+
@quentin.reload; @joe.reload
|
105
124
|
|
106
|
-
|
107
|
-
|
108
|
-
|
125
|
+
@quentin.friends.should_not include(@joe)
|
126
|
+
@joe.friends.should_not include(@quentin)
|
127
|
+
end
|
109
128
|
|
110
|
-
end
|
129
|
+
end
|
111
130
|
|
112
|
-
# new classes
|
113
|
-
class Homie
|
114
|
-
include DataMapper::Resource
|
115
|
-
property :gangster_id, Integer, :key => true
|
116
|
-
property :friend_id, Integer, :key => true
|
117
|
-
|
118
|
-
belongs_to :gangster
|
119
|
-
belongs_to :friend, :model => "Gangster", :child_key => [:friend_id]
|
120
|
-
|
121
|
-
end
|
122
131
|
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
property :name, String
|
127
|
-
is :friendly, :friendship_class => "Homie", :require_acceptance => false
|
128
|
-
end
|
129
|
-
|
130
|
-
describe 'DataMapper::Is::Friendly', "without requiring acceptance" do
|
131
|
-
before(:all) do
|
132
|
-
Homie.auto_migrate!; Gangster.auto_migrate!
|
132
|
+
describe "without requiring acceptance" do
|
133
|
+
before(:all) do
|
134
|
+
Homie.auto_migrate!; Gangster.auto_migrate!
|
133
135
|
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
136
|
+
@quentin = Gangster.create(:name => "quentin")
|
137
|
+
@aaron = Gangster.create(:name => "aaron") # state: "pending"
|
138
|
+
@joe = Gangster.create(:name => "joe")
|
139
|
+
end
|
138
140
|
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
141
|
+
it "should work" do
|
142
|
+
lambda do
|
143
|
+
@joe.request_friendship(@quentin)
|
144
|
+
end.should change(Homie, :count).by(1)
|
145
|
+
end
|
144
146
|
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
147
|
+
it "should recognize every friend request" do
|
148
|
+
@joe.friends.should include(@quentin)
|
149
|
+
@quentin.friends.should include(@joe)
|
150
|
+
end
|
149
151
|
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
152
|
+
it "should set the proper relationships" do
|
153
|
+
# see if associations are correct
|
154
|
+
@quentin.friendship_requests.should_not include(@joe)
|
155
|
+
@joe.friendship_requests.should include(@quentin)
|
156
|
+
@quentin.friendships_to_accept.should include(@joe)
|
157
|
+
@joe.friendships_to_accept.should_not include(@quentin)
|
158
|
+
end
|
157
159
|
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
160
|
+
it "should not need acceptance" do
|
161
|
+
@quentin.friendship_to_accept?(@joe).should be_false
|
162
|
+
@joe.friendship_requested?(@quentin).should be_true
|
163
|
+
end
|
162
164
|
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
165
|
+
it "should not be added twice" do
|
166
|
+
lambda do
|
167
|
+
@joe.request_friendship(@quentin)
|
168
|
+
@joe.should have(1).friends
|
169
|
+
@quentin.should have(1).friends
|
170
|
+
end.should_not change(Homie,:count)
|
171
|
+
end
|
170
172
|
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
173
|
+
it "should be able to have multiple friends" do
|
174
|
+
@joe.request_friendship(@aaron)
|
175
|
+
@joe.friendship_requested?(@aaron).should be_true
|
176
|
+
@aaron.friendship_to_accept?(@joe).should be_false
|
177
|
+
end
|
176
178
|
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
179
|
+
it "should be able to delete friendships" do
|
180
|
+
lambda do
|
181
|
+
# joe sleeps with quentin's wife perhaps
|
182
|
+
@quentin.end_friendship_with(@joe)
|
183
|
+
end.should change(Homie,:count)
|
182
184
|
|
183
|
-
|
185
|
+
@quentin.reload; @joe.reload
|
184
186
|
|
185
|
-
|
186
|
-
|
187
|
-
|
187
|
+
@quentin.friends.should_not include(@joe)
|
188
|
+
@joe.friends.should_not include(@quentin)
|
189
|
+
end
|
188
190
|
|
189
|
-
end
|
191
|
+
end
|
192
|
+
end
|
193
|
+
end
|
data/spec/spec.opts
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -1,19 +1,28 @@
|
|
1
|
-
# path to my git clones of the latest dm-core
|
1
|
+
# path to my git clones of the latest dm-core and extlib
|
2
2
|
$LOAD_PATH.unshift File.expand_path(File.join(File.dirname(__FILE__), *%w[.. ..]))
|
3
3
|
|
4
4
|
require 'pathname'
|
5
5
|
require 'rubygems'
|
6
|
-
|
7
|
-
gem 'rspec', '~>1.2.9'
|
8
6
|
require 'spec'
|
9
7
|
|
8
|
+
# Add all external dependencies for the plugin here
|
9
|
+
gem 'extlib', '~>0.9.14'
|
10
|
+
require "extlib"
|
11
|
+
|
12
|
+
gem 'dm-core', '~>0.10.2'
|
13
|
+
require 'dm-core'
|
14
|
+
|
15
|
+
gem 'dm-aggregates', '~>0.10.2'
|
16
|
+
require "dm-aggregates"
|
17
|
+
|
10
18
|
require Pathname(__FILE__).dirname.expand_path.parent + 'lib/dm-is-friendly'
|
11
19
|
|
12
20
|
DataMapper::Logger.new("test.log", :debug)
|
21
|
+
# DataMapper.logger.auto_flush = true
|
13
22
|
|
14
23
|
def load_driver(name, default_uri)
|
15
|
-
return false
|
16
|
-
|
24
|
+
return false unless DRIVERS[name]
|
25
|
+
|
17
26
|
begin
|
18
27
|
DataMapper.setup(name, ENV["#{name.to_s.upcase}_SPEC_URI"] || default_uri)
|
19
28
|
DataMapper::Repository.adapters[:default] = DataMapper::Repository.adapters[name]
|
@@ -24,12 +33,31 @@ def load_driver(name, default_uri)
|
|
24
33
|
end
|
25
34
|
end
|
26
35
|
|
27
|
-
ENV['
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
36
|
+
ENV['ADAPTERS'] ||= 'sqlite3 mysql'
|
37
|
+
|
38
|
+
DRIVERS = {
|
39
|
+
:sqlite3 => 'sqlite3::memory:',
|
40
|
+
:mysql => 'mysql://root:pass@localhost/dm_is_friendly_test',
|
41
|
+
:postgres => 'postgres://postgres@localhost/dm_is_friendly_test'
|
42
|
+
}
|
43
|
+
|
44
|
+
ADAPTERS = ENV["ADAPTERS"].split(' ')
|
45
|
+
|
46
|
+
module SpecAdapterHelper
|
47
|
+
def with_adapters(&block)
|
48
|
+
::ADAPTERS.each do |adapter|
|
49
|
+
describe "with #{adapter} adapter" do
|
50
|
+
before(:all) do
|
51
|
+
load_driver(adapter.to_sym, ::DRIVERS[adapter.to_sym])
|
52
|
+
end
|
53
|
+
|
54
|
+
instance_eval(&block)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
32
59
|
|
33
60
|
Spec::Runner.configure do |conf|
|
34
61
|
def log(msg); DataMapper.logger.push("****** #{msg}"); end
|
35
|
-
|
62
|
+
conf.extend(SpecAdapterHelper)
|
63
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dm-is-friendly
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 10
|
8
|
+
- 25
|
9
|
+
version: 0.10.25
|
5
10
|
platform: ruby
|
6
11
|
authors:
|
7
12
|
- Kabari Hendrick
|
@@ -9,39 +14,51 @@ autorequire:
|
|
9
14
|
bindir: bin
|
10
15
|
cert_chain: []
|
11
16
|
|
12
|
-
date: 2010-
|
17
|
+
date: 2010-03-14 00:00:00 -06:00
|
13
18
|
default_executable:
|
14
19
|
dependencies:
|
15
20
|
- !ruby/object:Gem::Dependency
|
16
21
|
name: extlib
|
17
|
-
|
18
|
-
|
19
|
-
version_requirements: !ruby/object:Gem::Requirement
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
24
|
requirements:
|
21
25
|
- - ~>
|
22
26
|
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 0
|
29
|
+
- 9
|
30
|
+
- 14
|
23
31
|
version: 0.9.14
|
24
|
-
|
32
|
+
type: :runtime
|
33
|
+
version_requirements: *id001
|
25
34
|
- !ruby/object:Gem::Dependency
|
26
35
|
name: dm-core
|
27
|
-
|
28
|
-
|
29
|
-
version_requirements: !ruby/object:Gem::Requirement
|
36
|
+
prerelease: false
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
30
38
|
requirements:
|
31
39
|
- - ~>
|
32
40
|
- !ruby/object:Gem::Version
|
41
|
+
segments:
|
42
|
+
- 0
|
43
|
+
- 10
|
44
|
+
- 2
|
33
45
|
version: 0.10.2
|
34
|
-
|
46
|
+
type: :runtime
|
47
|
+
version_requirements: *id002
|
35
48
|
- !ruby/object:Gem::Dependency
|
36
49
|
name: dm-aggregates
|
37
|
-
|
38
|
-
|
39
|
-
version_requirements: !ruby/object:Gem::Requirement
|
50
|
+
prerelease: false
|
51
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
40
52
|
requirements:
|
41
53
|
- - ~>
|
42
54
|
- !ruby/object:Gem::Version
|
55
|
+
segments:
|
56
|
+
- 0
|
57
|
+
- 10
|
58
|
+
- 2
|
43
59
|
version: 0.10.2
|
44
|
-
|
60
|
+
type: :runtime
|
61
|
+
version_requirements: *id003
|
45
62
|
description:
|
46
63
|
email: kabari@gmail.com
|
47
64
|
executables: []
|
@@ -61,7 +78,6 @@ files:
|
|
61
78
|
- dm-is-friendly.gemspec
|
62
79
|
- lib/dm-is-friendly.rb
|
63
80
|
- lib/is/friendly.rb
|
64
|
-
- lib/is/version.rb
|
65
81
|
- spec/dm-is-friendly_spec.rb
|
66
82
|
- spec/spec.opts
|
67
83
|
- spec/spec_helper.rb
|
@@ -78,18 +94,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
78
94
|
requirements:
|
79
95
|
- - ">="
|
80
96
|
- !ruby/object:Gem::Version
|
97
|
+
segments:
|
98
|
+
- 0
|
81
99
|
version: "0"
|
82
|
-
version:
|
83
100
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
101
|
requirements:
|
85
102
|
- - ">="
|
86
103
|
- !ruby/object:Gem::Version
|
104
|
+
segments:
|
105
|
+
- 0
|
87
106
|
version: "0"
|
88
|
-
version:
|
89
107
|
requirements: []
|
90
108
|
|
91
109
|
rubyforge_project:
|
92
|
-
rubygems_version: 1.3.
|
110
|
+
rubygems_version: 1.3.6
|
93
111
|
signing_key:
|
94
112
|
specification_version: 3
|
95
113
|
summary: DataMapper plugin that adds self-referential friendship functionality to your models.
|