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 CHANGED
@@ -1,4 +1,8 @@
1
1
  source :rubygems
2
2
 
3
3
  # Specify your gem's dependencies in groupify.gemspec
4
- gemspec
4
+ gemspec
5
+
6
+ platform :ruby, :mswin, :mingw do
7
+ gem "bson_ext", "~> 1.6.4"
8
+ end
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
@@ -1,3 +1,3 @@
1
1
  module Groupify
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -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
@@ -0,0 +1,9 @@
1
+ development:
2
+ database: groupify_development
3
+ host: localhost
4
+ port: 27017
5
+
6
+ test:
7
+ database: groupify_test
8
+ host: localhost
9
+ port: 27017
data/spec/mongoid3.yml ADDED
@@ -0,0 +1,13 @@
1
+ development:
2
+ sessions:
3
+ default:
4
+ database: groupify_development
5
+ hosts:
6
+ - localhost:27017
7
+
8
+ test:
9
+ sessions:
10
+ default:
11
+ database: groupify_test
12
+ hosts:
13
+ - localhost:27017
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
- date: 2012-08-25 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.2'
22
- type: :development
23
- prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
27
- - - ~>
28
- - !ruby/object:Gem::Version
29
- version: '3.2'
30
- - !ruby/object:Gem::Dependency
31
- name: rspec
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: mongoid
48
- requirement: !ruby/object:Gem::Requirement
49
- none: false
50
- requirements:
51
- - - ~>
52
- - !ruby/object:Gem::Version
53
- version: '3.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: '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
- files:
85
- - .gitignore
86
- - .travis.yml
87
- - Gemfile
88
- - LICENSE
89
- - README.md
90
- - Rakefile
91
- - groupify.gemspec
92
- - lib/groupify.rb
93
- - lib/groupify/version.rb
94
- - spec/groupify/mongoid_spec.rb
95
- - spec/spec_helper.rb
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
- require_paths:
101
- - lib
102
- required_ruby_version: !ruby/object:Gem::Requirement
87
+
88
+ require_paths:
89
+ - lib
90
+ required_ruby_version: !ruby/object:Gem::Requirement
103
91
  none: false
104
- requirements:
105
- - - ! '>='
106
- - !ruby/object:Gem::Version
107
- version: '0'
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
- - !ruby/object:Gem::Version
113
- version: '0'
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: "0"
114
102
  requirements: []
103
+
115
104
  rubyforge_project:
116
- rubygems_version: 1.8.24
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/spec_helper.rb
123
- has_rdoc:
109
+ test_files:
110
+ - spec/groupify/mongoid_spec.rb
111
+ - spec/mongoid2.yml
112
+ - spec/mongoid3.yml
113
+ - spec/spec_helper.rb