cream 0.7.0 → 0.7.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. data/Rakefile +3 -3
  2. data/VERSION +1 -1
  3. data/cream.gemspec +15 -37
  4. data/lib/cream.rb +3 -1
  5. data/lib/cream/configure/after_init/role_config.rb +19 -15
  6. data/lib/cream/configure/rails.rb +4 -12
  7. data/lib/cream/role.rb +9 -1
  8. data/lib/cream/{configure.rb → roles_config.rb} +0 -4
  9. data/lib/generators/cancan/config/config_generator.rb +13 -3
  10. data/lib/generators/cream/app/app_generator.rb +39 -18
  11. data/lib/generators/cream/full_config/full_config_generator.rb +154 -0
  12. data/lib/generators/cream/views/haml_util.rb +1 -1
  13. data/lib/generators/cream/views/views_generator.rb +1 -1
  14. data/lib/generators/devise/config/config_generator.rb +16 -7
  15. data/lib/generators/devise/users/users_generator.rb +13 -8
  16. data/lib/generators/permits/config/config_generator.rb +14 -11
  17. data/lib/generators/roles/config/config_generator.rb +12 -6
  18. data/spec/generator_spec_helper.rb +1 -1
  19. data/spec/generators/cancan/config/cancan_config_generator_spec.rb +1 -1
  20. data/spec/generators/cream/app/app_generator_spec.rb +42 -22
  21. data/spec/generators/cream/full_config/full_config_generator_spec.rb +37 -0
  22. data/spec/generators/permits/config/permits_config_generator_spec.rb +1 -1
  23. metadata +12 -35
  24. data/lib/generators/cream/config/DESIGN NOTES.markdown +0 -79
  25. data/lib/generators/cream/config/config_generator.rb +0 -86
  26. data/lib/generators/cream/config/modules/app_config.rb +0 -48
  27. data/lib/generators/cream/config/modules/cancan_config.rb +0 -27
  28. data/lib/generators/cream/config/modules/cream_config.rb +0 -36
  29. data/lib/generators/cream/config/modules/devise_config.rb +0 -58
  30. data/lib/generators/cream/config/modules/devise_users_config.rb +0 -109
  31. data/lib/generators/cream/config/modules/helper.rb +0 -79
  32. data/lib/generators/cream/config/modules/permits_config.rb +0 -15
  33. data/lib/generators/cream/config/modules/roles_config.rb +0 -39
  34. data/spec/generators/cream/config/CONFIG_GENERATOR_SPEC.markdown +0 -15
  35. data/spec/generators/cream/config/devise/existing_devise_users.rb +0 -61
  36. data/spec/generators/cream/config/empty_app/default_args_spec.rb +0 -51
  37. data/spec/generators/cream/config/permits/existing_permits_spec.rb +0 -0
  38. data/spec/generators/cream/config/permits/no_permits_spec.rb +0 -0
  39. data/spec/generators/cream/config/roles/default_roles.rb +0 -51
  40. data/spec/generators/cream/config/roles/roles_spec.rb +0 -60
  41. data/spec/generators/cream/shared_examples.rb +0 -18
@@ -1,79 +0,0 @@
1
- module Cream::Generators
2
- module Config
3
- module Helpers
4
-
5
- ORM_MAP = {
6
- :data_mapper => 'dm-devise',
7
- :mongo_mapper => 'mm-devise',
8
- :mongoid => 'rails3-mongoid-devise'
9
- }
10
-
11
- # rails generate ...
12
- def rgen command
13
- execute "rails g #{command}"
14
- end
15
-
16
- def execute command
17
- logger.debug command
18
- run command
19
- end
20
-
21
- def strategy
22
- options[:strategy]
23
- end
24
-
25
- def logfile
26
- options[:logfile]
27
- end
28
-
29
- def users
30
- extra_users = admin_user? ? :admin : nil
31
- @users ||= ([:user] + extra_users).compact
32
- end
33
-
34
- def roles
35
- @roles ||= options[:roles].join(' ')
36
- end
37
-
38
- def roles_generator
39
- "#{orm}:roles"
40
- end
41
-
42
- def user_generator
43
- active_record? ? "#{orm}:devise" : 'devise'
44
- end
45
-
46
- def active_record?
47
- orm == 'active_record'
48
- end
49
-
50
- def orm
51
- options[:orm]
52
- end
53
-
54
- def default_roles?
55
- options[:default_roles]
56
- end
57
-
58
- def roles_config?
59
- options[:roles_config]
60
- end
61
-
62
- def permission_config?
63
- options[:permission_config]
64
- end
65
-
66
- def admin_user?
67
- options[:admin_user]
68
- end
69
-
70
- def here
71
- File.dirname(__FILE__)
72
- end
73
-
74
- def root_dir
75
- File.dirname(__FILE__).up(4)
76
- end
77
- end
78
- end
79
- end
@@ -1,15 +0,0 @@
1
- module Cream::Generators
2
- module Config
3
- module Permits
4
- def permits_gems
5
- gem 'cancan-permits'
6
- end
7
-
8
- def configure_permits
9
- logger.debug "Configure Permits"
10
- # Run permits generator to generate permit for each role
11
- rgen "permits --roles #{roles}"
12
- end
13
- end
14
- end
15
- end
@@ -1,39 +0,0 @@
1
- module Cream::Generators
2
- module Config
3
- module Roles
4
- def configure_roles
5
- create_roles
6
- set_valid_roles_cream
7
- use_roles_strategy
8
- end
9
-
10
- def roles_gems
11
- gem "roles_#{orm}"
12
- end
13
-
14
- def create_roles
15
- rgen "#{roles_generator} --strategy #{strategy} --roles #{roles} #{default_roles}"
16
- end
17
-
18
- def set_valid_roles_cream
19
- if initializer_file? :cream
20
- replace_in_model_file :user, :where => /valid_roles_are\s+[(.*)]/, :with => 'valid_roles_are Cream.roles'
21
- end
22
- end
23
-
24
- def use_roles_strategy
25
- unless read_model_file(:user) =~ /use_roles_strategy/
26
- insert_into_model :user do
27
- "use_roles_strategy :admin_flag"
28
- end
29
- end
30
- end
31
-
32
- protected
33
-
34
- def default_roles
35
- default_roles? ? '--default-roles' : '--no-default-roles'
36
- end
37
- end
38
- end
39
- end
@@ -1,15 +0,0 @@
1
- # Cream Config Generator spec Design Notes
2
-
3
- The Cream Config generator is very complex and is designed various Session, Permission and Roles aspects encapsulated by Cream.
4
-
5
- ## Modular architecture
6
-
7
- In order to achieve this, a modular Generator approach is used. Each module has responsibility to set up a particular aspect of Cream.
8
- When running the generator, this modular architecture can be leveraged, so that specific parts of the generation process can be run and not others.
9
-
10
- ## Specs
11
-
12
- This also makes it easier to test the functionality of the generator, as a single module can be tested in isolation or in combination with one or more other modules.
13
-
14
-
15
-
@@ -1,61 +0,0 @@
1
- require 'generator_spec_helper'
2
- require_generator :cream => :config
3
-
4
- LOGFILE = File.expand_path File.dirname(__FILE__) + '/../../config_generator-init.log'
5
-
6
- describe 'Cream config generator: strategy "admin_flag", init Devise user model User' do
7
- use_helpers :model, :controller, :permit, :files, :file
8
-
9
- before :each do
10
- setup_generator 'config_generator' do
11
- tests Cream::Generators::ConfigGenerator
12
- end
13
- remove_all_permits
14
- remove_locale :cream
15
-
16
- File.remove_from controller_file(:application) do
17
- %{
18
- rescue_from CanCan::AccessDenied do |exception|
19
- flash[:error] = exception.message
20
- redirect_to root_url
21
- end
22
- }
23
- end
24
- end
25
-
26
- after :each do
27
- remove_all_permits
28
- end
29
-
30
- describe "Configure Rails 3 app with Cream using init devise" do
31
- before do
32
- puts "Running generator"
33
- Dir.chdir Rails.root do
34
- @generator = with_generator do |g|
35
- arguments = "--strategy admin_flag --init-devise --logfile #{LOGFILE}".args
36
- puts "arguments: #{arguments}"
37
- g.run_generator arguments
38
- end
39
- end
40
- end # before
41
-
42
- it "should generate a Devise User with only a :guest role using :role_string strategy" do
43
- @generator.should generate_model :user do |clazz|
44
- clazz.should have_default_devise_options
45
-
46
- # clazz.should use_roles :generic
47
- # clazz.should include_module 'Roles::Generic'
48
- # clazz.should have_call :roles, :args => ':guest'
49
- # clazz.should have_call :role_strategy, :args => ":role_string"
50
- end
51
- end # it
52
-
53
- # it "should generate a Devise Admin user" do
54
- # @generator.should generate_model :admin do |clazz|
55
- # # clazz.should use_roles :generic
56
- # # clazz.should include_module 'Roles::Generic'
57
- # clazz.should inherit_from :user
58
- # end
59
- # end # it
60
- end # desc
61
- end
@@ -1,51 +0,0 @@
1
- require 'generator_spec_helper'
2
- require_generator :cream => :config
3
-
4
- LOGFILE = File.expand_path File.dirname(__FILE__) + '/../../config_generator-default.log'
5
-
6
- puts "Logfile at: #{LOGFILE}"
7
-
8
- describe 'role strategy generator: admin_flag' do
9
- use_helpers :model, :controller, :permit, :files, :file
10
-
11
- before :each do
12
- setup_generator 'roles_generator' do
13
- tests Cream::Generators::ConfigGenerator
14
- end
15
- remove_all_permits
16
- remove_locale :cream if locale_file? :cream
17
-
18
- File.remove_from controller_file(:application) do
19
- %{
20
- rescue_from CanCan::AccessDenied do |exception|
21
- flash[:error] = exception.message
22
- redirect_to root_url
23
- end
24
- }
25
- end if controller_file? :application
26
- end
27
-
28
- after :each do
29
- remove_all_permits
30
- end
31
-
32
- describe "Configure Rails 3 app with Cream using default options" do
33
- before do
34
- puts "Running generator"
35
- Dir.chdir Rails.root do
36
- @generator = with_generator do |g|
37
- arguments = "--strategy admin_flag --logfile #{LOGFILE}".args
38
- puts "arguments: #{arguments}"
39
- g.run_generator arguments
40
- end
41
- end
42
- end # before
43
-
44
- it "should generate a Devise User with only a :guest role using :role_string strategy" do
45
- @generator.should_not generate_model :user
46
- @generator.should have_gems :devise, :cancan, :roles_active_record
47
- end # it
48
- end # desc
49
- end # desc
50
-
51
-
@@ -1,51 +0,0 @@
1
- require 'generator_spec_helper'
2
- require_generator :cream => :config
3
-
4
- LOGFILE = File.expand_path File.dirname(__FILE__) + '/../../config_generator-default.log'
5
-
6
- puts "Logfile at: #{LOGFILE}"
7
-
8
- describe 'role strategy generator: admin_flag' do
9
- use_helpers :model, :controller, :permit, :files, :file
10
-
11
- before :each do
12
- setup_generator 'roles_generator' do
13
- tests Cream::Generators::ConfigGenerator
14
- end
15
- remove_all_permits
16
- remove_locale :cream if locale_file? :cream
17
-
18
- File.remove_from controller_file(:application) do
19
- %{
20
- rescue_from CanCan::AccessDenied do |exception|
21
- flash[:error] = exception.message
22
- redirect_to root_url
23
- end
24
- }
25
- end if controller_file? :application
26
- end
27
-
28
- after :each do
29
- remove_all_permits
30
- end
31
-
32
- describe "Configure Rails 3 app with Cream using default options" do
33
- before do
34
- puts "Running generator"
35
- Dir.chdir Rails.root do
36
- @generator = with_generator do |g|
37
- arguments = "--strategy admin_flag --logfile #{LOGFILE}".args
38
- puts "arguments: #{arguments}"
39
- g.run_generator arguments
40
- end
41
- end
42
- end # before
43
-
44
- it "should generate a Devise User with only a :guest role using :role_string strategy" do
45
- @generator.should_not generate_model :user
46
- @generator.should have_gems :devise, :cancan, :roles_active_record
47
- end # it
48
- end # desc
49
- end # desc
50
-
51
-
@@ -1,60 +0,0 @@
1
- require 'generator_spec_helper'
2
- require_generator :cream => :config
3
-
4
- LOGFILE = File.expand_path File.dirname(__FILE__) + '/../../config_generator-roles.log'
5
-
6
- describe 'role strategy generator: admin_flag' do
7
- use_helpers :model, :controller, :permit, :files, :file
8
-
9
- before :each do
10
- setup_generator 'config_generator' do
11
- tests Cream::Generators::ConfigGenerator
12
- end
13
- remove_all_permits
14
- remove_locale :cream
15
-
16
- File.remove_from controller_file(:application) do
17
- %{
18
- rescue_from CanCan::AccessDenied do |exception|
19
- flash[:error] = exception.message
20
- redirect_to root_url
21
- end
22
- }
23
- end
24
- end
25
-
26
- after :each do
27
- remove_all_permits
28
- end
29
-
30
- describe "Configure Rails 3 app with Cream using init devise" do
31
- before do
32
- puts "Running generator"
33
- Dir.chdir Rails.root do
34
- @generator = with_generator do |g|
35
- arguments = "--strategy role_string --init-devise --roles editor author --logfile #{LOGFILE}".args
36
- puts "arguments: #{arguments}"
37
- g.run_generator arguments
38
- end
39
- end
40
- end # before
41
-
42
- it "should generate a Devise User with only a :guest role using :role_string strategy" do
43
-
44
- # Devise User with Roles setup
45
- @generator.should generate_model :user do |clazz|
46
- clazz.should have_devise_options :defaults
47
- clazz.should use_roles :generic
48
- clazz.should include_module 'Roles::ActiveRecord'
49
- clazz.should have_call :valid_roles_are, :args => ':admin, :guest, :editor, :author'
50
- clazz.should have_call :role_strategy, :args => ":role_string"
51
- end
52
-
53
- # Gemfile
54
- @generator.should have_gems :devise, :cancan, :roles_active_record
55
-
56
- # Permissions
57
- @generator.should generate_permits :admin, :guest, :editor, :author
58
- end # it
59
- end # desc
60
- end
@@ -1,18 +0,0 @@
1
- it "should generate Permits for Guest and Admin roles"
2
- @generator.should generate_permits :guest, :admin
3
- end
4
-
5
- it "should generate Permits for Guest and Admin roles"
6
- @generator.should generate_permits :guest, :admin
7
- end
8
-
9
-
10
- it "should inject permission exception handling into controller 'application_controller'"
11
- @generator.should update_controller :application do |clazz|
12
- clazz.should match /rescue_from CanCan::AccessDenied/
13
- end
14
- end
15
-
16
- it "should generate 'cream' locale file"
17
- @generator.should generate_locale_file :cream
18
- end