groupify 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +5 -1
- data/lib/groupify.rb +6 -1
- data/lib/groupify/version.rb +1 -1
- data/spec/groupify/mongoid_spec.rb +47 -1
- data/spec/mongoid2.yml +9 -0
- data/spec/mongoid3.yml +13 -0
- data/spec/spec_helper.rb +10 -1
- metadata +92 -102
data/Gemfile
CHANGED
data/lib/groupify.rb
CHANGED
@@ -11,7 +11,7 @@ module Groupify
|
|
11
11
|
include Groupify::Group
|
12
12
|
|
13
13
|
if (member_klass = opts.delete :default_members)
|
14
|
-
default_member_class = member_klass.to_s.classify.constantize
|
14
|
+
self.default_member_class = member_klass.to_s.classify.constantize
|
15
15
|
end
|
16
16
|
|
17
17
|
if (member_klasses = opts.delete :members)
|
@@ -50,9 +50,14 @@ module Groupify
|
|
50
50
|
end
|
51
51
|
|
52
52
|
module ClassMethods
|
53
|
+
def with_member(member)
|
54
|
+
criteria.for_ids(member.group_ids)
|
55
|
+
end
|
56
|
+
|
53
57
|
def default_member_class; @default_member_class || User; end
|
54
58
|
def default_member_class=(klass); @default_member_class = klass; end
|
55
59
|
|
60
|
+
# Define which classes are members of this group
|
56
61
|
def has_members(name)
|
57
62
|
klass = name.to_s.classify.constantize
|
58
63
|
define_method name.to_s.pluralize.underscore do
|
data/lib/groupify/version.rb
CHANGED
@@ -19,7 +19,7 @@ class MongoidGroup
|
|
19
19
|
include Mongoid::Document
|
20
20
|
|
21
21
|
acts_as_group :members => [:mongoid_users, :mongoid_tasks], :default_members => :mongoid_users
|
22
|
-
|
22
|
+
alias_method :users, :mongoid_users
|
23
23
|
end
|
24
24
|
|
25
25
|
describe MongoidGroup do
|
@@ -36,4 +36,50 @@ describe MongoidUser do
|
|
36
36
|
|
37
37
|
# Mongoid specific
|
38
38
|
it { should have_and_belong_to_many(:groups).of_type(MongoidGroup) }
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "MongoidUser" do
|
42
|
+
let!(:user) { MongoidUser.create }
|
43
|
+
let!(:group) { MongoidGroup.create }
|
44
|
+
|
45
|
+
it "can have a group added to it" do
|
46
|
+
user.groups << group
|
47
|
+
user.groups.should include(group)
|
48
|
+
group.members.should include(user)
|
49
|
+
group.users.should include(user)
|
50
|
+
end
|
51
|
+
|
52
|
+
it "can be added to a group" do
|
53
|
+
group.add user
|
54
|
+
user.groups.should include(group)
|
55
|
+
group.members.should include(user)
|
56
|
+
end
|
57
|
+
|
58
|
+
it "can be found by group" do
|
59
|
+
group.add user
|
60
|
+
|
61
|
+
MongoidUser.in_group(group).first.should eql(user)
|
62
|
+
end
|
63
|
+
|
64
|
+
it "can find the group it belongs to" do
|
65
|
+
group.add user
|
66
|
+
|
67
|
+
MongoidGroup.with_member(user).first.should == group
|
68
|
+
end
|
69
|
+
|
70
|
+
it "can belong to many groups" do
|
71
|
+
user.groups << group
|
72
|
+
group2 = MongoidGroup.create
|
73
|
+
user.groups << group2
|
74
|
+
|
75
|
+
user.groups.should include(group)
|
76
|
+
user.groups.should include(group2)
|
77
|
+
|
78
|
+
MongoidUser.in_group(group).first.should eql(user)
|
79
|
+
MongoidUser.in_group(group2).first.should eql(user)
|
80
|
+
|
81
|
+
MongoidUser.in_any_group(group).first.should eql(user)
|
82
|
+
MongoidUser.in_all_groups(group, group2).first.should eql(user)
|
83
|
+
MongoidUser.in_all_groups([group, group2]).first.should eql(user)
|
84
|
+
end
|
39
85
|
end
|
data/spec/mongoid2.yml
ADDED
data/spec/mongoid3.yml
ADDED
data/spec/spec_helper.rb
CHANGED
@@ -6,4 +6,13 @@ Bundler.require(:default)
|
|
6
6
|
require 'active_support'
|
7
7
|
require 'active_support/all'
|
8
8
|
require 'rails'
|
9
|
-
require 'active_record'
|
9
|
+
require 'active_record'
|
10
|
+
|
11
|
+
# Load mongoid config
|
12
|
+
if Mongoid::VERSION < '3'
|
13
|
+
ENV["MONGOID_ENV"] = "test"
|
14
|
+
Mongoid.load!('./spec/mongoid2.yml')
|
15
|
+
else
|
16
|
+
Mongoid.load!('./spec/mongoid3.yml', :test)
|
17
|
+
end
|
18
|
+
#Mongoid.logger.level = :info
|
metadata
CHANGED
@@ -1,123 +1,113 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: groupify
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.0
|
3
|
+
version: !ruby/object:Gem::Version
|
5
4
|
prerelease:
|
5
|
+
version: 0.1.1
|
6
6
|
platform: ruby
|
7
|
-
authors:
|
8
|
-
- dwbutler
|
7
|
+
authors:
|
8
|
+
- dwbutler
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
- - ~>
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '3.0'
|
62
|
-
- !ruby/object:Gem::Dependency
|
63
|
-
name: mongoid-rspec
|
64
|
-
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
|
-
requirements:
|
67
|
-
- - ~>
|
68
|
-
- !ruby/object:Gem::Version
|
69
|
-
version: 1.5.1
|
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: 1.5.1
|
12
|
+
|
13
|
+
date: 2012-08-30 00:00:00 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rails
|
17
|
+
prerelease: false
|
18
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ~>
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "3.2"
|
24
|
+
type: :development
|
25
|
+
version_requirements: *id001
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: rspec
|
28
|
+
prerelease: false
|
29
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
30
|
+
none: false
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: "0"
|
35
|
+
type: :development
|
36
|
+
version_requirements: *id002
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: mongoid
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: "2.0"
|
46
|
+
type: :development
|
47
|
+
version_requirements: *id003
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: mongoid-rspec
|
50
|
+
prerelease: false
|
51
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - "="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: 1.4.5
|
57
|
+
type: :development
|
58
|
+
version_requirements: *id004
|
78
59
|
description: Adds group and membership functionality to Rails models
|
79
|
-
email:
|
80
|
-
- dwbutler@ucla.edu
|
60
|
+
email:
|
61
|
+
- dwbutler@ucla.edu
|
81
62
|
executables: []
|
63
|
+
|
82
64
|
extensions: []
|
65
|
+
|
83
66
|
extra_rdoc_files: []
|
84
|
-
|
85
|
-
|
86
|
-
- .
|
87
|
-
-
|
88
|
-
-
|
89
|
-
-
|
90
|
-
-
|
91
|
-
-
|
92
|
-
-
|
93
|
-
- lib/groupify
|
94
|
-
-
|
95
|
-
- spec/
|
67
|
+
|
68
|
+
files:
|
69
|
+
- .gitignore
|
70
|
+
- .travis.yml
|
71
|
+
- Gemfile
|
72
|
+
- LICENSE
|
73
|
+
- README.md
|
74
|
+
- Rakefile
|
75
|
+
- groupify.gemspec
|
76
|
+
- lib/groupify.rb
|
77
|
+
- lib/groupify/version.rb
|
78
|
+
- spec/groupify/mongoid_spec.rb
|
79
|
+
- spec/mongoid2.yml
|
80
|
+
- spec/mongoid3.yml
|
81
|
+
- spec/spec_helper.rb
|
96
82
|
homepage: https://github.com/dwbutler/groupify
|
97
83
|
licenses: []
|
84
|
+
|
98
85
|
post_install_message:
|
99
86
|
rdoc_options: []
|
100
|
-
|
101
|
-
|
102
|
-
|
87
|
+
|
88
|
+
require_paths:
|
89
|
+
- lib
|
90
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
103
91
|
none: false
|
104
|
-
requirements:
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: "0"
|
96
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
109
97
|
none: false
|
110
|
-
requirements:
|
111
|
-
|
112
|
-
|
113
|
-
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: "0"
|
114
102
|
requirements: []
|
103
|
+
|
115
104
|
rubyforge_project:
|
116
|
-
rubygems_version: 1.8.
|
105
|
+
rubygems_version: 1.8.15
|
117
106
|
signing_key:
|
118
107
|
specification_version: 3
|
119
108
|
summary: Group functionality for Rails
|
120
|
-
test_files:
|
121
|
-
- spec/groupify/mongoid_spec.rb
|
122
|
-
- spec/
|
123
|
-
|
109
|
+
test_files:
|
110
|
+
- spec/groupify/mongoid_spec.rb
|
111
|
+
- spec/mongoid2.yml
|
112
|
+
- spec/mongoid3.yml
|
113
|
+
- spec/spec_helper.rb
|