rolify 3.1.0 → 4.0.0

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.
Files changed (78) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +4 -1
  3. data/.travis.yml +44 -11
  4. data/CHANGELOG.rdoc +70 -0
  5. data/CONTRIBUTORS +6 -0
  6. data/Gemfile +21 -2
  7. data/README.md +130 -68
  8. data/Rakefile +29 -4
  9. data/UPGRADE.rdoc +22 -0
  10. data/circle.yml +13 -0
  11. data/gemfiles/Gemfile.rails-3.2 +27 -0
  12. data/gemfiles/Gemfile.rails-4.0 +33 -0
  13. data/gemfiles/Gemfile.rails-4.1 +37 -0
  14. data/lib/generators/active_record/rolify_generator.rb +54 -0
  15. data/lib/generators/active_record/templates/README +8 -0
  16. data/lib/generators/active_record/templates/migration.rb +19 -0
  17. data/lib/generators/mongoid/rolify_generator.rb +55 -0
  18. data/lib/generators/mongoid/templates/README-mongoid +4 -0
  19. data/lib/generators/rolify/rolify_generator.rb +35 -0
  20. data/lib/generators/rolify/{role/templates/README-mongoid → templates/README} +1 -5
  21. data/lib/generators/rolify/templates/initializer.rb +7 -0
  22. data/lib/generators/rolify/templates/role-active_record.rb +11 -0
  23. data/lib/generators/rolify/{role/templates → templates}/role-mongoid.rb +9 -9
  24. data/lib/generators/rolify/user_generator.rb +39 -0
  25. data/lib/rolify/adapters/active_record/resource_adapter.rb +36 -6
  26. data/lib/rolify/adapters/active_record/role_adapter.rb +25 -13
  27. data/lib/rolify/adapters/active_record/scopes.rb +27 -0
  28. data/lib/rolify/adapters/base.rb +9 -0
  29. data/lib/rolify/adapters/mongoid/resource_adapter.rb +27 -6
  30. data/lib/rolify/adapters/mongoid/role_adapter.rb +35 -11
  31. data/lib/rolify/adapters/mongoid/scopes.rb +27 -0
  32. data/lib/rolify/configure.rb +36 -5
  33. data/lib/rolify/finders.rb +40 -0
  34. data/lib/rolify/matchers.rb +31 -0
  35. data/lib/rolify/railtie.rb +1 -1
  36. data/lib/rolify/resource.rb +19 -10
  37. data/lib/rolify/role.rb +33 -13
  38. data/lib/rolify/version.rb +1 -1
  39. data/lib/rolify.rb +46 -20
  40. data/rolify.gemspec +18 -24
  41. data/spec/README.rdoc +24 -0
  42. data/spec/generators/rolify/rolify_activerecord_generator_spec.rb +165 -0
  43. data/spec/generators/rolify/rolify_mongoid_generator_spec.rb +113 -0
  44. data/spec/generators_helper.rb +27 -0
  45. data/spec/rolify/config_spec.rb +20 -21
  46. data/spec/rolify/custom_spec.rb +11 -6
  47. data/spec/rolify/matchers_spec.rb +24 -0
  48. data/spec/rolify/namespace_spec.rb +24 -0
  49. data/spec/rolify/resource_spec.rb +135 -37
  50. data/spec/rolify/resourcifed_and_rolifed_spec.rb +24 -0
  51. data/spec/rolify/role_spec.rb +8 -9
  52. data/spec/rolify/shared_contexts.rb +22 -3
  53. data/spec/rolify/shared_examples/shared_examples_for_add_role.rb +10 -17
  54. data/spec/rolify/shared_examples/shared_examples_for_callbacks.rb +65 -0
  55. data/spec/rolify/shared_examples/shared_examples_for_dynamic.rb +64 -27
  56. data/spec/rolify/shared_examples/shared_examples_for_finders.rb +81 -0
  57. data/spec/rolify/shared_examples/shared_examples_for_has_all_roles.rb +29 -29
  58. data/spec/rolify/shared_examples/shared_examples_for_has_any_role.rb +35 -35
  59. data/spec/rolify/shared_examples/shared_examples_for_has_role.rb +38 -38
  60. data/spec/rolify/shared_examples/shared_examples_for_only_has_role.rb +174 -0
  61. data/spec/rolify/shared_examples/shared_examples_for_remove_role.rb +28 -59
  62. data/spec/rolify/shared_examples/shared_examples_for_roles.rb +58 -32
  63. data/spec/rolify/shared_examples/shared_examples_for_scopes.rb +38 -0
  64. data/spec/spec_helper.rb +39 -3
  65. data/spec/support/adapters/active_record.rb +58 -7
  66. data/spec/support/adapters/mongoid.rb +110 -17
  67. data/spec/support/adapters/mongoid.yml +6 -0
  68. data/spec/support/data.rb +18 -15
  69. data/spec/support/schema.rb +31 -16
  70. data/spec/support/stream_helpers.rb +18 -0
  71. metadata +88 -84
  72. data/lib/generators/rolify/role/role_generator.rb +0 -41
  73. data/lib/generators/rolify/role/templates/README +0 -11
  74. data/lib/generators/rolify/role/templates/README-active_record +0 -21
  75. data/lib/generators/rolify/role/templates/initializer.rb +0 -7
  76. data/lib/generators/rolify/role/templates/migration.rb +0 -19
  77. data/lib/generators/rolify/role/templates/role-active_record.rb +0 -4
  78. data/spec/generators/rolify/role/role_generator_spec.rb +0 -197
@@ -1,38 +1,39 @@
1
1
  require "rolify/shared_contexts"
2
2
  require "rolify/shared_examples/shared_examples_for_add_role"
3
3
  require "rolify/shared_examples/shared_examples_for_has_role"
4
+ require "rolify/shared_examples/shared_examples_for_only_has_role"
4
5
  require "rolify/shared_examples/shared_examples_for_has_all_roles"
5
6
  require "rolify/shared_examples/shared_examples_for_has_any_role"
6
7
  require "rolify/shared_examples/shared_examples_for_remove_role"
7
-
8
+ require "rolify/shared_examples/shared_examples_for_finders"
8
9
 
9
10
  shared_examples_for Rolify::Role do
10
11
  before(:all) do
11
12
  reset_defaults
12
13
  Rolify.dynamic_shortcuts = false
13
- user_class.rolify :role_cname => role_class.to_s
14
+ rolify_options = { :role_cname => role_class.to_s }
15
+ rolify_options[:role_join_table_name] = join_table if defined? join_table
16
+ silence_warnings { user_class.rolify rolify_options }
14
17
  role_class.destroy_all
15
- Forum.resourcify :role_cname => role_class.to_s
16
- Group.resourcify :role_cname => role_class.to_s
18
+ Forum.resourcify :roles, :role_cname => role_class.to_s
19
+ Group.resourcify :roles, :role_cname => role_class.to_s
20
+ Organization.resourcify :roles, :role_cname => role_class.to_s
17
21
  end
18
22
 
19
- context "in a Instance level" do
23
+ context "in the Instance level" do
20
24
  before(:all) do
21
25
  admin = user_class.first
22
26
  admin.add_role :admin
23
27
  admin.add_role :moderator, Forum.first
24
- admin
25
28
  end
26
29
 
27
- subject do
28
- user_class.first
29
- end
30
+ subject { user_class.first }
30
31
 
31
- [ :has_role, :grant, :add_role ].each do |method_alias|
32
+ [ :grant, :add_role ].each do |method_alias|
32
33
  it { should respond_to(method_alias.to_sym).with(1).arguments }
33
34
  it { should respond_to(method_alias.to_sym).with(2).arguments }
34
35
  end
35
-
36
+
36
37
  it { should respond_to(:has_role?).with(1).arguments }
37
38
  it { should respond_to(:has_role?).with(2).arguments }
38
39
 
@@ -49,30 +50,55 @@ shared_examples_for Rolify::Role do
49
50
 
50
51
  it { should_not respond_to(:is_admin?) }
51
52
  it { should_not respond_to(:is_moderator_of?) }
52
- end
53
53
 
54
- describe "#has_role" do
55
- it_should_behave_like "#add_role_examples", "String", :to_s
56
- it_should_behave_like "#add_role_examples", "Symbol", :to_sym
57
- end
54
+ describe "#has_role?" do
55
+ it_should_behave_like "#has_role?_examples", "String", :to_s
56
+ it_should_behave_like "#has_role?_examples", "Symbol", :to_sym
57
+ end
58
58
 
59
- describe "#has_role?" do
60
- it_should_behave_like "#has_role?_examples", "String", :to_s
61
- it_should_behave_like "#has_role?_examples", "Symbol", :to_sym
62
- end
59
+ describe "#only_has_role?" do
60
+ it_should_behave_like "#only_has_role?_examples", "String", :to_s
61
+ it_should_behave_like "#only_has_role?_examples", "Symbol", :to_sym
62
+ end
63
+
64
+ describe "#has_all_roles?" do
65
+ it_should_behave_like "#has_all_roles?_examples", "String", :to_s
66
+ it_should_behave_like "#has_all_roles?_examples", "Symbol", :to_sym
67
+ end
63
68
 
64
- describe "#has_all_roles?" do
65
- it_should_behave_like "#has_all_roles?_examples", "String", :to_s
66
- it_should_behave_like "#has_all_roles?_examples", "Symbol", :to_sym
69
+ describe "#has_any_role?" do
70
+ it_should_behave_like "#has_any_role?_examples", "String", :to_s
71
+ it_should_behave_like "#has_any_role?_examples", "Symbol", :to_sym
72
+ end
73
+
74
+ describe "#has_no_role" do
75
+ it_should_behave_like "#remove_role_examples", "String", :to_s
76
+ it_should_behave_like "#remove_role_examples", "Symbol", :to_sym
77
+ end
67
78
  end
68
-
69
- describe "#has_any_role?" do
70
- it_should_behave_like "#has_any_role?_examples", "String", :to_s
71
- it_should_behave_like "#has_any_role?_examples", "Symbol", :to_sym
79
+
80
+ context "with a new instance" do
81
+ let(:user) { user_class.new }
82
+
83
+ before do
84
+ user.add_role :admin
85
+ user.add_role :moderator, Forum.first
86
+ end
87
+
88
+ subject { user }
89
+
90
+ it { should have_role :admin }
91
+ # it { should have_role :admin, Forum }
92
+ # it { should have_role :admin, :any }
93
+ # it { should have_role :moderator, Forum.first }
94
+ # it { should have_role :moderator, :any }
95
+ # it { should_not have_role :moderator }
96
+ # it { should_not have_role :moderator, Forum }
97
+ it { subject.has_any_role?(:admin).should be_truthy }
72
98
  end
73
-
74
- describe "#has_no_role" do
75
- it_should_behave_like "#remove_role_examples", "String", :to_s
76
- it_should_behave_like "#remove_role_examples", "Symbol", :to_sym
99
+
100
+ context "on the Class level ", :scope => :mixed do
101
+ it_should_behave_like :finders, "String", :to_s
102
+ it_should_behave_like :finders, "Symbol", :to_sym
77
103
  end
78
- end
104
+ end
@@ -0,0 +1,38 @@
1
+ require "rolify/shared_contexts"
2
+
3
+ shared_examples_for "Role.scopes" do
4
+ before do
5
+ role_class.destroy_all
6
+ end
7
+
8
+ subject { user_class.first }
9
+
10
+ describe ".global" do
11
+ let!(:admin_role) { subject.add_role :admin }
12
+ let!(:staff_role) { subject.add_role :staff }
13
+
14
+ it { subject.roles.global.should == [ admin_role, staff_role ] }
15
+ end
16
+
17
+ describe ".class_scoped" do
18
+ let!(:manager_role) { subject.add_role :manager, Group }
19
+ let!(:moderator_role) { subject.add_role :moderator, Forum }
20
+
21
+ it { subject.roles.class_scoped.should =~ [ manager_role, moderator_role ] }
22
+ it { subject.roles.class_scoped(Group).should =~ [ manager_role ] }
23
+ it { subject.roles.class_scoped(Forum).should =~ [ moderator_role ] }
24
+ end
25
+
26
+ describe ".instance_scoped" do
27
+ let!(:visitor_role) { subject.add_role :visitor, Forum.first }
28
+ let!(:zombie_role) { subject.add_role :visitor, Forum.last }
29
+ let!(:anonymous_role) { subject.add_role :anonymous, Group.last }
30
+
31
+ it { subject.roles.instance_scoped.to_a.entries.should =~ [ visitor_role, zombie_role, anonymous_role ] }
32
+ it { subject.roles.instance_scoped(Forum).should =~ [ visitor_role, zombie_role ] }
33
+ it { subject.roles.instance_scoped(Forum.first).should =~ [ visitor_role ] }
34
+ it { subject.roles.instance_scoped(Forum.last).should =~ [ zombie_role ] }
35
+ it { subject.roles.instance_scoped(Group.last).should =~ [ anonymous_role ] }
36
+ it { subject.roles.instance_scoped(Group.first).should be_empty }
37
+ end
38
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,13 +1,49 @@
1
+ require "codeclimate-test-reporter"
2
+ CodeClimate::TestReporter.start
3
+
1
4
  require 'rubygems'
5
+ require "bundler/setup"
6
+
2
7
  require 'rolify'
3
- require 'ammeter/init'
8
+ require 'rolify/matchers'
9
+ require 'rails'
10
+ begin
11
+ require 'its'
12
+ rescue LoadError
13
+ end
14
+ require 'coveralls'
15
+ Coveralls.wear_merged!
4
16
 
5
17
  ENV['ADAPTER'] ||= 'active_record'
6
18
 
7
19
  load File.dirname(__FILE__) + "/support/adapters/#{ENV['ADAPTER']}.rb"
8
20
  load File.dirname(__FILE__) + '/support/data.rb'
9
21
 
22
+ begin
23
+ require 'pry'
24
+ rescue LoadError
25
+ end
26
+
10
27
  def reset_defaults
11
28
  Rolify.use_defaults
12
- Rolify.use_mongoid if ENV['ADAPTER'] == "mongoid"
13
- end
29
+ Rolify.use_mongoid if ENV['ADAPTER'] == 'mongoid'
30
+ end
31
+
32
+ def provision_user(user, roles)
33
+ roles.each do |role|
34
+ if role.is_a? Array
35
+ user.add_role *role
36
+ else
37
+ user.add_role role
38
+ end
39
+ end
40
+ user
41
+ end
42
+
43
+ def silence_warnings(&block)
44
+ warn_level = $VERBOSE
45
+ $VERBOSE = nil
46
+ result = block.call
47
+ $VERBOSE = warn_level
48
+ result
49
+ end
@@ -1,11 +1,12 @@
1
1
  require 'active_record'
2
2
 
3
+ RSpec::Matchers::BuiltIn::OperatorMatcher.register(ActiveRecord::Relation, '=~', RSpec::Matchers::BuiltIn::MatchArray)
3
4
  ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
4
5
  ActiveRecord::Base.extend Rolify
5
6
 
6
7
  load File.dirname(__FILE__) + '/../schema.rb'
7
8
 
8
- # ActiveRecord models
9
+ # Standard user and role classes
9
10
  class User < ActiveRecord::Base
10
11
  rolify
11
12
  end
@@ -13,16 +14,17 @@ end
13
14
  class Role < ActiveRecord::Base
14
15
  has_and_belongs_to_many :users, :join_table => :users_roles
15
16
  belongs_to :resource, :polymorphic => true
16
- end
17
17
 
18
- class Forum < ActiveRecord::Base
19
- #resourcify done during specs setup to be able to use custom user classes
18
+ extend Rolify::Adapter::Scopes
20
19
  end
21
20
 
22
- class Group < ActiveRecord::Base
23
- #resourcify done during specs setup to be able to use custom user classes
21
+ # Resourcifed and rolifed at the same time
22
+ class HumanResource < ActiveRecord::Base
23
+ resourcify :resources
24
+ rolify
24
25
  end
25
26
 
27
+ # Custom role and class names
26
28
  class Customer < ActiveRecord::Base
27
29
  rolify :role_cname => "Privilege"
28
30
  end
@@ -30,4 +32,53 @@ end
30
32
  class Privilege < ActiveRecord::Base
31
33
  has_and_belongs_to_many :customers, :join_table => :customers_privileges
32
34
  belongs_to :resource, :polymorphic => true
33
- end
35
+
36
+ extend Rolify::Adapter::Scopes
37
+ end
38
+
39
+ # Namespaced models
40
+ module Admin
41
+ def self.table_name_prefix
42
+ 'admin_'
43
+ end
44
+
45
+ class Moderator < ActiveRecord::Base
46
+ rolify :role_cname => "Admin::Right", :role_join_table_name => "moderators_rights"
47
+ end
48
+
49
+ class Right < ActiveRecord::Base
50
+ has_and_belongs_to_many :moderators, :class_name => "Admin::Moderator", :join_table => "moderators_rights"
51
+ belongs_to :resource, :polymorphic => true
52
+
53
+ extend Rolify::Adapter::Scopes
54
+ end
55
+ end
56
+
57
+
58
+ # Resources classes
59
+ class Forum < ActiveRecord::Base
60
+ #resourcify done during specs setup to be able to use custom user classes
61
+ end
62
+
63
+ class Group < ActiveRecord::Base
64
+ #resourcify done during specs setup to be able to use custom user classes
65
+
66
+ def subgroups
67
+ Group.where(:parent_id => id)
68
+ end
69
+ end
70
+
71
+ class Team < ActiveRecord::Base
72
+ #resourcify done during specs setup to be able to use custom user classes
73
+ self.primary_key = "team_code"
74
+
75
+ default_scope { order(:team_code) }
76
+ end
77
+
78
+ class Organization < ActiveRecord::Base
79
+
80
+ end
81
+
82
+ class Company < Organization
83
+
84
+ end
@@ -1,8 +1,6 @@
1
1
  require 'mongoid'
2
2
 
3
- Mongoid.configure do |config|
4
- config.master = Mongo::Connection.new.db("godfather")
5
- end
3
+ Mongoid.load!("spec/support/adapters/mongoid.yml", :test)
6
4
 
7
5
  ::Mongoid::Document.module_eval do
8
6
  def self.included(base)
@@ -12,11 +10,11 @@ end
12
10
 
13
11
  Rolify.use_mongoid
14
12
 
15
- # Mongoid models
13
+ # Standard user and role classes
16
14
  class User
17
15
  include Mongoid::Document
18
16
  rolify
19
-
17
+
20
18
  field :login, :type => String
21
19
  end
22
20
 
@@ -24,35 +22,130 @@ class Role
24
22
  include Mongoid::Document
25
23
  has_and_belongs_to_many :users
26
24
  belongs_to :resource, :polymorphic => true
27
-
25
+
28
26
  field :name, :type => String
27
+ index(
28
+ {
29
+ :name => 1,
30
+ :resource_type => 1,
31
+ :resource_id => 1
32
+ },
33
+ { :unique => true }
34
+ )
35
+
36
+ scopify
29
37
  end
30
38
 
39
+ # Resourcifed and rolifed at the same time
40
+ class HumanResource
41
+ include Mongoid::Document
42
+ resourcify :resources
43
+ rolify
44
+
45
+ field :login, :type => String
46
+ end
47
+
48
+ #class Power
49
+ # include Mongoid::Document
50
+ # has_and_belongs_to_many :human_resources
51
+ # belongs_to :resource, :polymorphic => true
52
+ # scopify
53
+ #
54
+ # field :name, :type => String
55
+ # index(
56
+ # {
57
+ # :name => 1,
58
+ # :resource_type => 1,
59
+ # :resource_id => 1
60
+ # },
61
+ # { :unique => true }
62
+ # )
63
+ #end
64
+
65
+ # Custom role and class names
66
+ class Customer
67
+ include Mongoid::Document
68
+ rolify :role_cname => "Privilege"
69
+
70
+ field :login, :type => String
71
+ end
72
+
73
+ class Privilege
74
+ include Mongoid::Document
75
+ has_and_belongs_to_many :customers
76
+ belongs_to :resource, :polymorphic => true
77
+ scopify
78
+
79
+ field :name, :type => String
80
+ index(
81
+ {
82
+ :name => 1,
83
+ :resource_type => 1,
84
+ :resource_id => 1
85
+ },
86
+ { :unique => true }
87
+ )
88
+ end
89
+
90
+ # Namespaced models
91
+ module Admin
92
+ class Moderator
93
+ include Mongoid::Document
94
+ rolify :role_cname => "Admin::Right"
95
+
96
+ field :login, :type => String
97
+ end
98
+
99
+ class Right
100
+ include Mongoid::Document
101
+ has_and_belongs_to_many :moderators, :class_name => 'Admin::Moderator'
102
+ belongs_to :resource, :polymorphic => true
103
+ scopify
104
+
105
+ field :name, :type => String
106
+ index(
107
+ {
108
+ :name => 1,
109
+ :resource_type => 1,
110
+ :resource_id => 1
111
+ },
112
+ { :unique => true }
113
+ )
114
+ end
115
+ end
116
+
117
+ # Resources classes
31
118
  class Forum
32
119
  include Mongoid::Document
33
120
  #resourcify done during specs setup to be able to use custom user classes
34
-
121
+
35
122
  field :name, :type => String
36
123
  end
37
124
 
38
125
  class Group
39
126
  include Mongoid::Document
40
127
  #resourcify done during specs setup to be able to use custom user classes
41
-
128
+
42
129
  field :name, :type => String
130
+ field :parent_id, :type => Integer
131
+
132
+ def subgroups
133
+ Group.in(:parent_id => _id)
134
+ end
43
135
  end
44
136
 
45
- class Customer
137
+ class Team
46
138
  include Mongoid::Document
47
- rolify :role_cname => "Privilege"
48
-
49
- field :login, :type => String
139
+ #resourcify done during specs setup to be able to use custom user classes
140
+
141
+ field :team_code, :type => Integer
142
+ field :name, :type => String
50
143
  end
51
144
 
52
- class Privilege
145
+ class Organization
53
146
  include Mongoid::Document
54
- has_and_belongs_to_many :customers
55
- belongs_to :resource, :polymorphic => true
56
-
57
- field :name, :type => String
58
147
  end
148
+
149
+ class Company < Organization
150
+
151
+ end
@@ -0,0 +1,6 @@
1
+ test:
2
+ sessions:
3
+ default:
4
+ database: godfather
5
+ hosts:
6
+ - localhost:27017
data/spec/support/data.rb CHANGED
@@ -1,20 +1,17 @@
1
- User.destroy_all
2
- Role.destroy_all
3
- Forum.destroy_all
4
- Group.destroy_all
5
- Privilege.destroy_all
6
- Customer.destroy_all
7
-
8
1
  # Users
9
- User.create(:login => "admin")
10
- User.create(:login => "moderator")
11
- User.create(:login => "god")
12
- User.create(:login => "zombie")
2
+ [ User, Customer, Admin::Moderator ].each do |user|
3
+ user.destroy_all
4
+
5
+ user.create(:login => "admin")
6
+ user.create(:login => "moderator")
7
+ user.create(:login => "god")
8
+ user.create(:login => "zombie")
9
+ end
13
10
 
14
- Customer.create(:login => "admin")
15
- Customer.create(:login => "moderator")
16
- Customer.create(:login => "god")
17
- Customer.create(:login => "zombie")
11
+ # Roles
12
+ [ Role, Privilege, Admin::Right ].each do |role|
13
+ role.destroy_all
14
+ end
18
15
 
19
16
  # Resources
20
17
  Forum.create(:name => "forum 1")
@@ -23,3 +20,9 @@ Forum.create(:name => "forum 3")
23
20
 
24
21
  Group.create(:name => "group 1")
25
22
  Group.create(:name => "group 2")
23
+
24
+ Team.create(:team_code => "1", :name => "PSG")
25
+ Team.create(:team_code => "2", :name => "MU")
26
+
27
+ Organization.create
28
+ Company.create
@@ -1,41 +1,56 @@
1
1
  ActiveRecord::Schema.define do
2
2
  self.verbose = false
3
3
 
4
- create_table(:roles) do |t|
4
+ [ :roles, :privileges, :admin_rights ].each do |table|
5
+ create_table(table) do |t|
5
6
  t.string :name
6
7
  t.references :resource, :polymorphic => true
7
8
 
8
- t.timestamps
9
+ t.timestamps null: false
10
+ end
9
11
  end
10
-
11
- create_table(:users) do |t|
12
- t.string :login
12
+
13
+ [ :users, :human_resources, :customers, :admin_moderators ].each do |table|
14
+ create_table(table) do |t|
15
+ t.string :login
16
+ end
13
17
  end
14
18
 
15
19
  create_table(:users_roles, :id => false) do |t|
16
20
  t.references :user
17
21
  t.references :role
18
22
  end
19
-
23
+
24
+ create_table(:human_resources_roles, :id => false) do |t|
25
+ t.references :human_resource
26
+ t.references :role
27
+ end
28
+
29
+ create_table(:customers_privileges, :id => false) do |t|
30
+ t.references :customer
31
+ t.references :privilege
32
+ end
33
+
34
+ create_table(:moderators_rights, :id => false) do |t|
35
+ t.references :moderator
36
+ t.references :right
37
+ end
38
+
20
39
  create_table(:forums) do |t|
21
40
  t.string :name
22
41
  end
23
-
42
+
24
43
  create_table(:groups) do |t|
44
+ t.integer :parent_id
25
45
  t.string :name
26
46
  end
27
47
 
28
- create_table(:privileges) do |t|
48
+ create_table(:teams, :id => false) do |t|
49
+ t.primary_key :team_code
29
50
  t.string :name
30
- t.references :resource, :polymorphic => true
31
51
  end
32
52
 
33
- create_table(:customers) do |t|
34
- t.string :login
35
- end
36
-
37
- create_table(:customers_privileges, :id => false) do |t|
38
- t.references :customer
39
- t.references :privilege
53
+ create_table(:organizations) do |t|
54
+ t.string :type
40
55
  end
41
56
  end
@@ -0,0 +1,18 @@
1
+ module StreamHelpers
2
+ def capture(stream)
3
+ stream = stream.to_s
4
+ captured_stream = Tempfile.new(stream)
5
+ stream_io = eval("$#{stream}")
6
+ origin_stream = stream_io.dup
7
+ stream_io.reopen(captured_stream)
8
+
9
+ yield
10
+
11
+ stream_io.rewind
12
+ return captured_stream.read
13
+ ensure
14
+ captured_stream.close
15
+ captured_stream.unlink
16
+ stream_io.reopen(origin_stream)
17
+ end
18
+ end