troles 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (243) hide show
  1. data/.rspec +1 -0
  2. data/Gemfile +26 -0
  3. data/Gemfile.lock +161 -0
  4. data/MIT-LICENSE +20 -0
  5. data/README.textile +686 -0
  6. data/Rakefile +48 -0
  7. data/VERSION +1 -0
  8. data/config/database.yml +4 -0
  9. data/development.sqlite3 +0 -0
  10. data/lib/trole/adapters/active_record/config.rb +23 -0
  11. data/lib/trole/adapters/active_record/storage.rb +0 -0
  12. data/lib/trole/adapters/active_record/strategy.rb +0 -0
  13. data/lib/trole/adapters/active_record.rb +8 -0
  14. data/lib/trole/adapters/mongoid/config.rb +34 -0
  15. data/lib/trole/adapters/mongoid/storage.rb +0 -0
  16. data/lib/trole/adapters/mongoid/strategy.rb +0 -0
  17. data/lib/trole/adapters/mongoid.rb +0 -0
  18. data/lib/trole/api/cache.rb +9 -0
  19. data/lib/trole/api/config.rb +12 -0
  20. data/lib/trole/api/core.rb +20 -0
  21. data/lib/trole/api/event.rb +9 -0
  22. data/lib/trole/api/read.rb +14 -0
  23. data/lib/trole/api/validation.rb +9 -0
  24. data/lib/trole/api/write.rb +25 -0
  25. data/lib/trole/api.rb +41 -0
  26. data/lib/trole/config.rb +15 -0
  27. data/lib/trole/macros.rb +5 -0
  28. data/lib/trole/operations/read.rb +12 -0
  29. data/lib/trole/operations/write.rb +11 -0
  30. data/lib/trole/operations.rb +34 -0
  31. data/lib/trole/storage/base_one.rb +46 -0
  32. data/lib/trole/storage/bit_one.rb +43 -0
  33. data/lib/trole/storage/embed_one.rb +36 -0
  34. data/lib/trole/storage/ref_one.rb +39 -0
  35. data/lib/trole/storage/string_one.rb +50 -0
  36. data/lib/trole/storage.rb +14 -0
  37. data/lib/trole/strategy.rb +35 -0
  38. data/lib/trole.rb +10 -0
  39. data/lib/troles/adapters/active_record/Design Notes.textile +4 -0
  40. data/lib/troles/adapters/active_record/config.rb +51 -0
  41. data/lib/troles/adapters/active_record/storage/embed_many.rb +8 -0
  42. data/lib/troles/adapters/active_record/storage.rb +5 -0
  43. data/lib/troles/adapters/active_record/strategy.rb +11 -0
  44. data/lib/troles/adapters/active_record.rb +8 -0
  45. data/lib/troles/adapters/mongoid/Design Notes.textile +3 -0
  46. data/lib/troles/adapters/mongoid/config.rb +45 -0
  47. data/lib/troles/adapters/mongoid.rb +8 -0
  48. data/lib/troles/api/cache.rb +4 -0
  49. data/lib/troles/api/config.rb +9 -0
  50. data/lib/troles/api/core.rb +9 -0
  51. data/lib/troles/api/event.rb +4 -0
  52. data/lib/troles/api/read.rb +4 -0
  53. data/lib/troles/api/validation.rb +4 -0
  54. data/lib/troles/api/write.rb +4 -0
  55. data/lib/troles/api.rb +40 -0
  56. data/lib/troles/common/api/cache.rb +12 -0
  57. data/lib/troles/common/api/config.rb +4 -0
  58. data/lib/troles/common/api/core.rb +52 -0
  59. data/lib/troles/common/api/event.rb +39 -0
  60. data/lib/troles/common/api/read.rb +44 -0
  61. data/lib/troles/common/api/validation.rb +44 -0
  62. data/lib/troles/common/api/write.rb +76 -0
  63. data/lib/troles/common/api.rb +28 -0
  64. data/lib/troles/common/config/schema.rb +72 -0
  65. data/lib/troles/common/config/schema_helpers.rb +95 -0
  66. data/lib/troles/common/config/static_roles.rb +14 -0
  67. data/lib/troles/common/config/valid_roles.rb +21 -0
  68. data/lib/troles/common/config.rb +96 -0
  69. data/lib/troles/common/dependencies.rb +9 -0
  70. data/lib/troles/common/event_manager.rb +40 -0
  71. data/lib/troles/common/macros/configuration/base_loader.rb +40 -0
  72. data/lib/troles/common/macros/configuration/config_loader.rb +19 -0
  73. data/lib/troles/common/macros/configuration/storage_loader.rb +20 -0
  74. data/lib/troles/common/macros/configuration/strategy_loader.rb +38 -0
  75. data/lib/troles/common/macros/configuration.rb +89 -0
  76. data/lib/troles/common/macros/static_roles.rb +9 -0
  77. data/lib/troles/common/macros/strategy_options.rb +21 -0
  78. data/lib/troles/common/macros.rb +38 -0
  79. data/lib/troles/common/marshaller/bitmask.rb +43 -0
  80. data/lib/troles/common/marshaller/generic.rb +24 -0
  81. data/lib/troles/common/marshaller.rb +14 -0
  82. data/lib/troles/common/operations/read.rb +28 -0
  83. data/lib/troles/common/operations/write.rb +42 -0
  84. data/lib/troles/common/operations.rb +33 -0
  85. data/lib/troles/common/storage.rb +73 -0
  86. data/lib/troles/common.rb +17 -0
  87. data/lib/troles/config.rb +15 -0
  88. data/lib/troles/macros.rb +7 -0
  89. data/lib/troles/meta.rb +5 -0
  90. data/lib/troles/operations/read.rb +6 -0
  91. data/lib/troles/operations/write.rb +6 -0
  92. data/lib/troles/operations.rb +12 -0
  93. data/lib/troles/storage/base_many.rb +25 -0
  94. data/lib/troles/storage/bit_many.rb +56 -0
  95. data/lib/troles/storage/embed_many.rb +58 -0
  96. data/lib/troles/storage/ref_many.rb +44 -0
  97. data/lib/troles/storage/string_many.rb +41 -0
  98. data/lib/troles/storage.rb +13 -0
  99. data/lib/troles/strategy.rb +34 -0
  100. data/lib/troles.rb +11 -0
  101. data/playbox/old_rake +25 -0
  102. data/spec/Guide to running specs.textile +16 -0
  103. data/spec/active_record/migrations/many/bit_many.rb +16 -0
  104. data/spec/active_record/migrations/many/ref_many.rb +31 -0
  105. data/spec/active_record/migrations/many/string_many.rb +16 -0
  106. data/spec/active_record/migrations/one/bit_one.rb +14 -0
  107. data/spec/active_record/migrations/one/ref_one.rb +20 -0
  108. data/spec/active_record/migrations/one/string_one.rb +14 -0
  109. data/spec/active_record/models/ref_many.rb +10 -0
  110. data/spec/active_record/models/ref_one.rb +10 -0
  111. data/spec/active_record/models/role.rb +2 -0
  112. data/spec/active_record/models/user.rb +5 -0
  113. data/spec/active_record/models.rb +2 -0
  114. data/spec/active_record/strategies/many/bit_many_spec.rb +41 -0
  115. data/spec/active_record/strategies/many/ref_many_spec.rb +45 -0
  116. data/spec/active_record/strategies/many/string_many_spec.rb +39 -0
  117. data/spec/active_record/strategies/one/bit_one_spec.rb +35 -0
  118. data/spec/active_record/strategies/one/ref_one_spec.rb +41 -0
  119. data/spec/active_record/strategies/one/string_one_spec.rb +35 -0
  120. data/spec/active_record/strategy_helper.rb +4 -0
  121. data/spec/active_record_helper.rb +50 -0
  122. data/spec/db/database.yml +4 -0
  123. data/spec/dummy/Gemfile.lock +108 -0
  124. data/spec/dummy/Rakefile +7 -0
  125. data/spec/dummy/app/assets/images/rails.png +0 -0
  126. data/spec/dummy/app/assets/javascripts/application.js +9 -0
  127. data/spec/dummy/app/assets/stylesheets/application.css +7 -0
  128. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  129. data/spec/dummy/app/controllers/main_controller.rb +16 -0
  130. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  131. data/spec/dummy/app/mailers/.gitkeep +0 -0
  132. data/spec/dummy/app/models/.gitkeep +0 -0
  133. data/spec/dummy/app/models/ref_many_user.rb +7 -0
  134. data/spec/dummy/app/models/ref_one_user.rb +3 -0
  135. data/spec/dummy/app/models/role.rb +4 -0
  136. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  137. data/spec/dummy/app/views/main/index.html.erb +3 -0
  138. data/spec/dummy/config/application.rb +54 -0
  139. data/spec/dummy/config/boot.rb +10 -0
  140. data/spec/dummy/config/database.yml +25 -0
  141. data/spec/dummy/config/environment.rb +5 -0
  142. data/spec/dummy/config/environments/development.rb +24 -0
  143. data/spec/dummy/config/environments/production.rb +52 -0
  144. data/spec/dummy/config/environments/test.rb +39 -0
  145. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  146. data/spec/dummy/config/initializers/inflections.rb +10 -0
  147. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  148. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  149. data/spec/dummy/config/initializers/session_store.rb +8 -0
  150. data/spec/dummy/config/initializers/troles.rb +3 -0
  151. data/spec/dummy/config/initializers/wrap_parameters.rb +12 -0
  152. data/spec/dummy/config/locales/en.yml +5 -0
  153. data/spec/dummy/config/routes.rb +60 -0
  154. data/spec/dummy/config.ru +4 -0
  155. data/spec/dummy/db/migrate/01_create_roles.rb +14 -0
  156. data/spec/dummy/db/migrate/02_create_ref_many_users.rb +20 -0
  157. data/spec/dummy/db/schema.rb +32 -0
  158. data/spec/dummy/db/seeds.rb +4 -0
  159. data/spec/dummy/log/.gitkeep +0 -0
  160. data/spec/dummy/public/404.html +26 -0
  161. data/spec/dummy/public/422.html +26 -0
  162. data/spec/dummy/public/500.html +26 -0
  163. data/spec/dummy/public/favicon.ico +0 -0
  164. data/spec/dummy/script/rails +6 -0
  165. data/spec/dummy_spec_helper.rb +33 -0
  166. data/spec/factories.rb +8 -0
  167. data/spec/generic/models/accounts/admin_account.rb +7 -0
  168. data/spec/generic/models/accounts/blogger_account.rb +7 -0
  169. data/spec/generic/models/accounts/user_account.rb +7 -0
  170. data/spec/generic/models/accounts.rb +1 -0
  171. data/spec/generic/models/base_user.rb +27 -0
  172. data/spec/generic/models/role.rb +37 -0
  173. data/spec/generic/models/user.rb +7 -0
  174. data/spec/generic/models.rb +3 -0
  175. data/spec/integration/navigation_spec.rb +9 -0
  176. data/spec/integration/troles/Running dummy tests.textile +35 -0
  177. data/spec/integration/troles/navigation_spec.rb +49 -0
  178. data/spec/mongoid/models/ref_many.rb +15 -0
  179. data/spec/mongoid/models/ref_one.rb +15 -0
  180. data/spec/mongoid/models/role.rb +5 -0
  181. data/spec/mongoid/models/user.rb +9 -0
  182. data/spec/mongoid/models.rb +2 -0
  183. data/spec/mongoid/strategies/many/bit_many_spec.rb +35 -0
  184. data/spec/mongoid/strategies/many/ref_many_spec.rb +35 -0
  185. data/spec/mongoid/strategies/many/string_many_spec.rb +30 -0
  186. data/spec/mongoid/strategies/one/bit_one_spec.rb +26 -0
  187. data/spec/mongoid/strategies/one/ref_one_spec.rb +31 -0
  188. data/spec/mongoid/strategies/one/string_one_spec.rb +26 -0
  189. data/spec/mongoid/strategy_helper.rb +4 -0
  190. data/spec/mongoid_helper.rb +19 -0
  191. data/spec/playbox/rspec_examples.rb +381 -0
  192. data/spec/support/shared_examples.rb +1 -0
  193. data/spec/trole/Trole Design.textile +4 -0
  194. data/spec/trole/api/cache_api_spec.rb +2 -0
  195. data/spec/trole/api/core_api_spec.rb +4 -0
  196. data/spec/trole/api/event_api.rb +2 -0
  197. data/spec/trole/api/operations_api_spec.rb +2 -0
  198. data/spec/trole/api/read_api_spec.rb +5 -0
  199. data/spec/trole/api/validation_api_spec.rb +2 -0
  200. data/spec/trole/api/write_api_spec.rb +2 -0
  201. data/spec/trole/api_spec.rb +60 -0
  202. data/spec/trole/multi_roles_spec.rb +163 -0
  203. data/spec/trole/operations/read_spec.rb +18 -0
  204. data/spec/trole/operations/write_spec.rb +0 -0
  205. data/spec/trole/playbox/shared_examples.rb +107 -0
  206. data/spec/trole/strategies/bit_one_spec.rb +22 -0
  207. data/spec/trole/strategies/embed_one_spec.rb +32 -0
  208. data/spec/trole/strategies/ref_one_spec.rb +29 -0
  209. data/spec/trole/strategies/string_one_spec.rb +26 -0
  210. data/spec/trole/strategy_helper.rb +3 -0
  211. data/spec/trole/two_roles_spec.rb +76 -0
  212. data/spec/trole_spec.rb +12 -0
  213. data/spec/trole_spec_helper.rb +20 -0
  214. data/spec/troles/api/cache_api_spec.rb +2 -0
  215. data/spec/troles/api/core_api_spec.rb +4 -0
  216. data/spec/troles/api/event_api.rb +2 -0
  217. data/spec/troles/api/read_api_spec.rb +2 -0
  218. data/spec/troles/api/validation_api_spec.rb +2 -0
  219. data/spec/troles/api/write_api_spec.rb +2 -0
  220. data/spec/troles/api_spec.rb +41 -0
  221. data/spec/troles/common/api/cache_api_spec.rb +31 -0
  222. data/spec/troles/common/api/config_api.rb +0 -0
  223. data/spec/troles/common/api/core_api_spec.rb +14 -0
  224. data/spec/troles/common/api/event_api_spec.rb +9 -0
  225. data/spec/troles/common/api/operations_api_spec.rb +55 -0
  226. data/spec/troles/common/api/read_api_spec.rb +23 -0
  227. data/spec/troles/common/api/validation_api_spec.rb +46 -0
  228. data/spec/troles/common/api/write_api_spec.rb +81 -0
  229. data/spec/troles/common/api_spec.rb +101 -0
  230. data/spec/troles/common/config_spec.rb +11 -0
  231. data/spec/troles/common/multi_roles_spec.rb +142 -0
  232. data/spec/troles/marshaller/bitmask_spec.rb +14 -0
  233. data/spec/troles/operations/read_ops_spec.rb +0 -0
  234. data/spec/troles/operations/write_ops_spec.rb +0 -0
  235. data/spec/troles/playbox/shared_examples.rb +68 -0
  236. data/spec/troles/strategies/bit_many_spec.rb +30 -0
  237. data/spec/troles/strategies/embed_many_spec.rb +35 -0
  238. data/spec/troles/strategies/ref_many_spec.rb +36 -0
  239. data/spec/troles/strategies/string_many_spec.rb +32 -0
  240. data/spec/troles/strategy_helper.rb +3 -0
  241. data/spec/troles_spec.rb +10 -0
  242. data/troles.gemspec +325 -0
  243. metadata +469 -0
@@ -0,0 +1,10 @@
1
+ require "active_record/migrations/many/ref_many"
2
+
3
+ class User < ActiveRecord::Base
4
+ # has_and_belongs_to_many :troles, :class_name => 'Role'
5
+ end
6
+
7
+ class Role < ActiveRecord::Base
8
+ # has_and_belongs_to_many :accounts, :class_name => 'User'
9
+ end
10
+
@@ -0,0 +1,10 @@
1
+ require "active_record/migrations/one/ref_one"
2
+
3
+ class User < ActiveRecord::Base
4
+ # belongs_to :trole, :class_name => 'Role'
5
+ end
6
+
7
+ class Role < ActiveRecord::Base
8
+ # has_many :users, :class_name => 'User'
9
+ end
10
+
@@ -0,0 +1,2 @@
1
+ class Role < ActiveRecord::Base
2
+ end
@@ -0,0 +1,5 @@
1
+ class User < ActiveRecord::Base
2
+ def role_list_value
3
+ instance_variable_get "@role_list"
4
+ end
5
+ end
@@ -0,0 +1,2 @@
1
+ require 'active_record/models/user'
2
+ require 'active_record/models/role'
@@ -0,0 +1,41 @@
1
+ require "active_record/strategy_helper"
2
+ require "active_record/migrations/many/bit_many"
3
+
4
+ def migrate_up
5
+ CreateBitMany.up # run migration
6
+ end
7
+
8
+ def migrate_down
9
+ CreateBitMany.down
10
+ end
11
+
12
+
13
+ User.troles_strategy :bit_many do |c|
14
+ c.valid_roles = [:user, :admin, :blogger, :editor]
15
+ end.configure!
16
+
17
+ module UserSetup
18
+ def create_no_roles_user
19
+ Factory.create :user, :name => 'no roles', :troles => 0
20
+ end
21
+
22
+ def create_user
23
+ Factory.create :user, :name => 'normal', :troles => 1
24
+ end
25
+
26
+ def create_admin_user
27
+ Factory.create :user, :name => 'admin', :troles => 2
28
+ end
29
+
30
+ def create_complex_user
31
+ Factory.create :user, :name => 'user and admin', :troles => 3
32
+ end
33
+ end
34
+
35
+
36
+ require 'troles/common/api_spec' # Common API examples
37
+
38
+ describe 'Troles strategy :bit_many' do
39
+ it_should_behave_like "Common API"
40
+ # it_should_behave_like "Troles API"
41
+ end
@@ -0,0 +1,45 @@
1
+ require "active_record/strategy_helper"
2
+ require 'active_record/models/ref_many'
3
+
4
+ def migrate_up
5
+ CreateRefMany.up # run migration
6
+ Config.add_roles [:user, :admin, :editor, :blogger]
7
+ end
8
+
9
+ def migrate_down
10
+ CreateRefMany.down
11
+ end
12
+
13
+ User.troles_strategy :ref_many do |c|
14
+ c.valid_roles = [:user, :admin, :blogger, :editor]
15
+ end.configure!
16
+
17
+ module UserSetup
18
+ def find_role name
19
+ Role.where(:name => name.to_sym).first
20
+ end
21
+
22
+ def create_no_roles_user
23
+ Factory.create :user, :name => 'no roles', :troles => []
24
+ end
25
+
26
+ def create_user
27
+ Factory.create :user, :name => 'normal', :troles => [ find_role(:user) ]
28
+ end
29
+
30
+ def create_admin_user
31
+ Factory.create :user, :name => 'admin', :troles => [ find_role(:admin) ]
32
+ end
33
+
34
+ def create_complex_user
35
+ Factory.create :user, :name => 'user and admin', :troles => [ find_role(:user), find_role(:admin) ]
36
+ end
37
+ end
38
+
39
+
40
+ require 'troles/common/api_spec' # Common API examples
41
+
42
+ describe 'Troles strategy :ref_many' do
43
+ it_should_behave_like "Common API"
44
+ # it_should_behave_like "Troles API"
45
+ end
@@ -0,0 +1,39 @@
1
+ require "active_record/strategy_helper"
2
+ require "active_record/migrations/many/string_many"
3
+
4
+ def migrate_up
5
+ CreateStringMany.up # run migration
6
+ end
7
+
8
+ def migrate_down
9
+ CreateStringMany.down
10
+ end
11
+
12
+ User.troles_strategy :string_many do |c|
13
+ c.valid_roles = [:user, :admin, :blogger, :editor]
14
+ end.configure!
15
+
16
+ module UserSetup
17
+ def create_no_roles_user
18
+ Factory.create :user, :name => 'no roles', :troles => ''
19
+ end
20
+
21
+ def create_user
22
+ Factory.create :user, :name => 'normal', :troles => 'user'
23
+ end
24
+
25
+ def create_admin_user
26
+ Factory.create :user, :name => 'admin', :troles => 'admin'
27
+ end
28
+
29
+ def create_complex_user
30
+ Factory.create :user, :name => 'user and admin', :troles => 'user,admin'
31
+ end
32
+ end
33
+
34
+ require 'troles/common/api_spec' # Common API examples
35
+
36
+ describe 'Troles strategy :string_many' do
37
+ it_should_behave_like "Common API"
38
+ # it_should_behave_like "Troles API"
39
+ end
@@ -0,0 +1,35 @@
1
+ require "active_record/strategy_helper"
2
+ require "active_record/migrations/one/bit_one"
3
+
4
+ def migrate_up
5
+ CreateBitOne.up # run migration
6
+ end
7
+
8
+ def migrate_down
9
+ CreateBitOne.down
10
+ end
11
+
12
+ User.troles_strategy :bit_one do |c|
13
+ c.valid_roles = [:user, :admin]
14
+ end.configure!
15
+
16
+ module UserSetup
17
+ def create_no_roles_user
18
+ Factory.create :user, :name => 'no roles', :trole => false
19
+ end
20
+
21
+ def create_user
22
+ Factory.create :user, :name => 'normal', :trole => false
23
+ end
24
+
25
+ def create_admin_user
26
+ Factory.create :user, :name => 'admin', :trole => true
27
+ end
28
+ end
29
+
30
+ require 'troles/common/api_spec' # Common API examples
31
+
32
+ describe 'Troles strategy :bit_one' do
33
+ it_should_behave_like "Common API"
34
+ # it_should_behave_like "Troles API"
35
+ end
@@ -0,0 +1,41 @@
1
+ require "active_record/strategy_helper"
2
+ require 'active_record/models/ref_one'
3
+
4
+ def migrate_up
5
+ CreateRefOne.up # run migration
6
+ Config.add_roles [:user, :admin, :editor, :blogger]
7
+ end
8
+
9
+ def migrate_down
10
+ CreateRefOne.down
11
+ end
12
+
13
+ User.troles_strategy :ref_one do |c|
14
+ c.valid_roles = [:user, :admin, :blogger, :editor]
15
+ end.configure!
16
+
17
+ module UserSetup
18
+ def find_role name
19
+ Role.where(:name => name.to_sym).first
20
+ end
21
+
22
+ def create_no_roles_user
23
+ Factory.create :user, :name => 'no roles', :trole => nil
24
+ end
25
+
26
+ def create_user
27
+ Factory.create :user, :name => 'normal', :trole => find_role(:user)
28
+ end
29
+
30
+ def create_admin_user
31
+ Factory.create :user, :name => 'admin', :trole => find_role(:admin)
32
+ end
33
+ end
34
+
35
+
36
+ require 'troles/common/api_spec' # Common API examples
37
+
38
+ describe 'Troles strategy :ref_one' do
39
+ it_should_behave_like "Common API"
40
+ # it_should_behave_like "Troles API"
41
+ end
@@ -0,0 +1,35 @@
1
+ require "active_record/strategy_helper"
2
+ require "active_record/migrations/one/string_one"
3
+
4
+ def migrate_up
5
+ CreateStringOne.up # run migration
6
+ end
7
+
8
+ def migrate_down
9
+ CreateStringOne.down
10
+ end
11
+
12
+ User.troles_strategy :string_one do |c|
13
+ c.valid_roles = [:user, :admin, :blogger, :editor]
14
+ end.configure!
15
+
16
+ module UserSetup
17
+ def create_no_roles_user
18
+ Factory.create :user, :name => 'no roles', :trole => ''
19
+ end
20
+
21
+ def create_user
22
+ Factory.create :user, :name => 'normal', :trole => 'user'
23
+ end
24
+
25
+ def create_admin_user
26
+ Factory.create :user, :name => 'admin', :trole => 'admin'
27
+ end
28
+ end
29
+
30
+ require 'troles/common/api_spec' # Common API examples
31
+
32
+ describe 'Troles strategy :string_one' do
33
+ it_should_behave_like "Common API"
34
+ # it_should_behave_like "Troles API"
35
+ end
@@ -0,0 +1,4 @@
1
+ require 'active_record_helper'
2
+ require 'trole'
3
+ require 'troles'
4
+ require 'troles/macros'
@@ -0,0 +1,50 @@
1
+ require 'troles'
2
+ require 'trole_spec_helper'
3
+ require 'active_record'
4
+ require 'yaml'
5
+ require 'logger'
6
+ require 'database_cleaner'
7
+ require 'require_all'
8
+ require 'active_record/models'
9
+
10
+ Troles::Config.default_orm = :active_record
11
+ Troles::Config.auto_load = true
12
+ Troles::Config.log_on = true
13
+
14
+ dbconfig_path = File.dirname(__FILE__) + '/db/database.yml'
15
+ dbfile = File.open(dbconfig_path)
16
+ dbconfig = YAML::load(dbfile)
17
+
18
+ ActiveRecord::Base.establish_connection(dbconfig)
19
+ ActiveRecord::Base.logger = Logger.new(STDERR)
20
+
21
+ DatabaseCleaner.strategy = :truncation
22
+
23
+ def migration_folder(name)
24
+ path = File.dirname(__FILE__) + "/migrations/#{name}"
25
+ end
26
+
27
+ def migrate(name)
28
+ singularity = (name =~/_many/) ? :many : :one
29
+ ActiveRecord::Migrator.migrate migration_folder File.join(singularity, name)
30
+ end
31
+
32
+ RSpec.configure do |config|
33
+ config.before(:suite) do
34
+ DatabaseCleaner.strategy = :transaction
35
+ DatabaseCleaner.clean_with(:truncation)
36
+ end
37
+
38
+ config.before(:each) do
39
+ DatabaseCleaner.start
40
+ DatabaseCleaner.drop_tables :users, :roles, :users_roles
41
+ migrate_up
42
+ # api_migrate
43
+ end
44
+
45
+ config.after(:each) do
46
+ DatabaseCleaner.clean
47
+ end
48
+ end
49
+
50
+
@@ -0,0 +1,4 @@
1
+ adapter: sqlite3
2
+ database: development.sqlite3
3
+ pool: 5
4
+ timeout: 5000
@@ -0,0 +1,108 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ actionmailer (3.1.0.rc1)
5
+ actionpack (= 3.1.0.rc1)
6
+ mail (~> 2.3.0)
7
+ actionpack (3.1.0.rc1)
8
+ activemodel (= 3.1.0.rc1)
9
+ activesupport (= 3.1.0.rc1)
10
+ builder (~> 3.0.0)
11
+ erubis (~> 2.7.0)
12
+ i18n (~> 0.6.0beta1)
13
+ rack (~> 1.3.0.beta2)
14
+ rack-cache (~> 1.0.1)
15
+ rack-mount (~> 0.8.1)
16
+ rack-test (~> 0.6.0)
17
+ sprockets (~> 2.0.0.beta.5)
18
+ tzinfo (~> 0.3.27)
19
+ activemodel (3.1.0.rc1)
20
+ activesupport (= 3.1.0.rc1)
21
+ bcrypt-ruby (~> 2.1.4)
22
+ builder (~> 3.0.0)
23
+ i18n (~> 0.6.0beta1)
24
+ activerecord (3.1.0.rc1)
25
+ activemodel (= 3.1.0.rc1)
26
+ activesupport (= 3.1.0.rc1)
27
+ arel (~> 2.1.1)
28
+ tzinfo (~> 0.3.27)
29
+ activeresource (3.1.0.rc1)
30
+ activemodel (= 3.1.0.rc1)
31
+ activesupport (= 3.1.0.rc1)
32
+ activesupport (3.1.0.rc1)
33
+ multi_json (~> 1.0)
34
+ ansi (1.2.5)
35
+ arel (2.1.1)
36
+ bcrypt-ruby (2.1.4)
37
+ builder (3.0.0)
38
+ coffee-script (2.2.0)
39
+ coffee-script-source
40
+ execjs
41
+ coffee-script-source (1.1.1)
42
+ erubis (2.7.0)
43
+ execjs (1.0.0)
44
+ multi_json (~> 1.0)
45
+ hike (1.0.0)
46
+ i18n (0.6.0)
47
+ jquery-rails (1.0.7)
48
+ railties (~> 3.0)
49
+ thor (~> 0.14)
50
+ mail (2.3.0)
51
+ i18n (>= 0.4.0)
52
+ mime-types (~> 1.16)
53
+ treetop (~> 1.4.8)
54
+ mime-types (1.16)
55
+ multi_json (1.0.3)
56
+ polyglot (0.3.1)
57
+ rack (1.3.0)
58
+ rack-cache (1.0.2)
59
+ rack (>= 0.4)
60
+ rack-mount (0.8.1)
61
+ rack (>= 1.0.0)
62
+ rack-ssl (1.3.2)
63
+ rack
64
+ rack-test (0.6.0)
65
+ rack (>= 1.0)
66
+ rails (3.1.0.rc1)
67
+ actionmailer (= 3.1.0.rc1)
68
+ actionpack (= 3.1.0.rc1)
69
+ activerecord (= 3.1.0.rc1)
70
+ activeresource (= 3.1.0.rc1)
71
+ activesupport (= 3.1.0.rc1)
72
+ bundler (~> 1.0)
73
+ railties (= 3.1.0.rc1)
74
+ railties (3.1.0.rc1)
75
+ actionpack (= 3.1.0.rc1)
76
+ activesupport (= 3.1.0.rc1)
77
+ rack-ssl (~> 1.3.2)
78
+ rake (>= 0.8.7)
79
+ thor (~> 0.14.6)
80
+ rake (0.9.0)
81
+ sass (3.1.1)
82
+ sprockets (2.0.0.beta.8)
83
+ hike (~> 1.0)
84
+ rack (~> 1.0)
85
+ tilt (!= 1.3.0, ~> 1.1)
86
+ sqlite3 (1.3.3)
87
+ thor (0.14.6)
88
+ tilt (1.3.1)
89
+ treetop (1.4.9)
90
+ polyglot (>= 0.3.1)
91
+ turn (0.8.2)
92
+ ansi (>= 1.2.2)
93
+ tzinfo (0.3.27)
94
+ uglifier (0.5.4)
95
+ execjs (>= 0.3.0)
96
+ multi_json (>= 1.0.2)
97
+
98
+ PLATFORMS
99
+ ruby
100
+
101
+ DEPENDENCIES
102
+ coffee-script
103
+ jquery-rails
104
+ rails (= 3.1.0.rc1)
105
+ sass
106
+ sqlite3
107
+ turn
108
+ uglifier
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env rake
2
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
3
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
4
+
5
+ require File.expand_path('../config/application', __FILE__)
6
+
7
+ Dummy::Application.load_tasks
@@ -0,0 +1,9 @@
1
+ // This is a manifest file that'll be compiled into including all the files listed below.
2
+ // Add new JavaScript/Coffee code in separate files in this directory and they'll automatically
3
+ // be included in the compiled file accessible from http://example.com/assets/application.js
4
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
5
+ // the compiled file.
6
+ //
7
+ //= require jquery
8
+ //= require jquery_ujs
9
+ //= require_tree .
@@ -0,0 +1,7 @@
1
+ /*
2
+ * This is a manifest file that'll automatically include all the stylesheets available in this directory
3
+ * and any sub-directories. You're free to add application-wide styles to this file and they'll appear at
4
+ * the top of the compiled file, but it's generally better to create a new file per style scope.
5
+ *= require_self
6
+ *= require_tree .
7
+ */
@@ -0,0 +1,3 @@
1
+ class ApplicationController < ActionController::Base
2
+ protect_from_forgery
3
+ end
@@ -0,0 +1,16 @@
1
+ class MainController < ApplicationController
2
+
3
+ def index
4
+ @users = RefManyUser.all
5
+
6
+ first_user = @users.first
7
+
8
+ # puts "Clearing roles of first user"
9
+ first_user.clear_roles!
10
+
11
+ # puts "Adding role admin to first user"
12
+ first_user.roles << :admin
13
+
14
+ # puts "#{first_user.name} has role :admin? #{first_user.has_role? :admin}"
15
+ end
16
+ end
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end
File without changes
File without changes
@@ -0,0 +1,7 @@
1
+ class RefManyUser < ActiveRecord::Base
2
+ # has_and_belongs_to_many :troles, :class_name => 'Role'
3
+
4
+ troles_strategy :ref_many do |c|
5
+ c.valid_roles = [:user, :admin, :blogger, :editor]
6
+ end.configure!
7
+ end
@@ -0,0 +1,3 @@
1
+ class RefOneUser < ActiveRecord::Base
2
+ # belongs_to :trole, :class_name => 'Role'
3
+ end
@@ -0,0 +1,4 @@
1
+ class Role < ActiveRecord::Base
2
+ # has_and_belongs_to_many :accounts, :class_name => 'User'
3
+ # has_many :refone_users, :class_name => 'RefoneUser'
4
+ end
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Dummy</title>
5
+ <%= stylesheet_link_tag "application" %>
6
+ <%= javascript_include_tag "application" %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
@@ -0,0 +1,3 @@
1
+ <% @users.each do |user| %>
2
+ <%= "#{user.name} has roles #{user.role_list.map(&:to_s).join(',') } " %>
3
+ <% end %>
@@ -0,0 +1,54 @@
1
+ require File.expand_path('../boot', __FILE__)
2
+
3
+ require "active_model/railtie"
4
+ require "active_record/railtie"
5
+ require "action_controller/railtie"
6
+ require "action_view/railtie"
7
+ require "action_mailer/railtie"
8
+
9
+ Bundler.require
10
+ # require 'trole'
11
+ require "troles"
12
+ require 'troles/macros'
13
+
14
+ module Dummy
15
+ class Application < Rails::Application
16
+ # Settings in config/environments/* take precedence over those specified here.
17
+ # Application configuration should go into files in config/initializers
18
+ # -- all .rb files in that directory are automatically loaded.
19
+
20
+ # Custom directories with classes and modules you want to be autoloadable.
21
+ # config.autoload_paths += %W(#{config.root}/extras)
22
+
23
+ # Only load the plugins named here, in the order given (default is alphabetical).
24
+ # :all can be used as a placeholder for all plugins not explicitly named.
25
+ # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
26
+
27
+ # Activate observers that should always be running.
28
+ # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
29
+
30
+ # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
31
+ # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
32
+ # config.time_zone = 'Central Time (US & Canada)'
33
+
34
+ # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
35
+ # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
36
+ # config.i18n.default_locale = :de
37
+
38
+ # Please note that JavaScript expansions are *ignored altogether* if the asset
39
+ # pipeline is enabled (see config.assets.enabled below). Put your defaults in
40
+ # app/assets/javascripts/application.js in that case.
41
+ #
42
+ # JavaScript files you want as :defaults (application.js is always included).
43
+ # config.action_view.javascript_expansions[:defaults] = %w(prototype prototype_ujs)
44
+
45
+ # Configure the default encoding used in templates for Ruby 1.9.
46
+ config.encoding = "utf-8"
47
+
48
+ # Configure sensitive parameters which will be filtered from the log file.
49
+ config.filter_parameters += [:password]
50
+
51
+ # Enable the asset pipeline
52
+ config.assets.enabled = true
53
+ end
54
+ end
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ gemfile = File.expand_path('../../../../Gemfile', __FILE__)
3
+
4
+ if File.exist?(gemfile)
5
+ ENV['BUNDLE_GEMFILE'] = gemfile
6
+ require 'bundler'
7
+ Bundler.setup
8
+ end
9
+
10
+ $:.unshift File.expand_path('../../../../lib', __FILE__)
@@ -0,0 +1,25 @@
1
+ # SQLite version 3.x
2
+ # gem install sqlite3
3
+ #
4
+ # Ensure the SQLite 3 gem is defined in your Gemfile
5
+ # gem 'sqlite3'
6
+ development:
7
+ adapter: sqlite3
8
+ database: db/development.sqlite3
9
+ pool: 5
10
+ timeout: 5000
11
+
12
+ # Warning: The database defined as "test" will be erased and
13
+ # re-generated from your development database when you run "rake".
14
+ # Do not set this db to the same as development or production.
15
+ test:
16
+ adapter: sqlite3
17
+ database: db/test.sqlite3
18
+ pool: 5
19
+ timeout: 5000
20
+
21
+ production:
22
+ adapter: sqlite3
23
+ database: db/production.sqlite3
24
+ pool: 5
25
+ timeout: 5000
@@ -0,0 +1,5 @@
1
+ # Load the rails application
2
+ require File.expand_path('../application', __FILE__)
3
+
4
+ # Initialize the rails application
5
+ Dummy::Application.initialize!
@@ -0,0 +1,24 @@
1
+ Dummy::Application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb
3
+
4
+ # In the development environment your application's code is reloaded on
5
+ # every request. This slows down response time but is perfect for development
6
+ # since you don't have to restart the web server when you make code changes.
7
+ config.cache_classes = false
8
+
9
+ # Log error messages when you accidentally call methods on nil.
10
+ config.whiny_nils = true
11
+
12
+ # Show full error reports and disable caching
13
+ config.consider_all_requests_local = true
14
+ config.action_controller.perform_caching = false
15
+
16
+ # Don't care if the mailer can't send
17
+ config.action_mailer.raise_delivery_errors = false
18
+
19
+ # Print deprecation notices to the Rails logger
20
+ config.active_support.deprecation = :log
21
+
22
+ # Only use best-standards-support built into browsers
23
+ config.action_dispatch.best_standards_support = :builtin
24
+ end