bobby 0.0.3 → 0.0.4

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.
data/Gemfile CHANGED
@@ -1,4 +1,3 @@
1
- source :gemcutter
2
1
  source "http://rubygems.org"
3
2
 
4
3
  gem 'rails', '3.0.0.beta4'
@@ -20,6 +19,9 @@ group :development do
20
19
 
21
20
  # for development only !
22
21
  #gem "rails-footnotes" - not ready for Rails 3
22
+
23
+ # for testing gems
24
+ gem 'rubigen'
23
25
 
24
26
  end
25
27
 
@@ -39,6 +41,8 @@ group :test do
39
41
 
40
42
  end
41
43
 
44
+ # gem 'bobby'
45
+
42
46
  # database interfaces to provide
43
47
  # gem 'mysql'
44
48
  gem 'sqlite3-ruby', :require => 'sqlite3'
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.3
1
+ 0.0.4
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{bobby}
8
- s.version = "0.0.3"
8
+ s.version = "0.0.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Enrique Phillips"]
@@ -26,13 +26,27 @@ Gem::Specification.new do |s|
26
26
  "Rakefile",
27
27
  "VERSION",
28
28
  "bobby.gemspec",
29
+ "features/install_bobby.feature",
29
30
  "features/manage_posts.feature",
31
+ "features/step_definitions/common_steps.rb",
30
32
  "features/step_definitions/devise_steps.rb",
33
+ "features/step_definitions/install_bobby_steps.rb",
31
34
  "features/step_definitions/post_steps.rb",
35
+ "features/step_definitions/rails_setup_steps.rb",
32
36
  "features/step_definitions/web_steps.rb",
37
+ "features/support/common.rb",
33
38
  "features/support/env.rb",
39
+ "features/support/matchers.rb",
34
40
  "features/support/paths.rb",
35
41
  "lib/bobby.rb",
42
+ "lib/generators/bobby/USAGE",
43
+ "lib/generators/bobby/bobby/bobby_generator.rb",
44
+ "lib/generators/bobby/bobby_generator.rb",
45
+ "lib/generators/bobby/bobby_install_generator.rb",
46
+ "lib/generators/bobby/install/install_generator.rb",
47
+ "lib/generators/bobby/install/templates/README",
48
+ "lib/generators/bobby/install/templates/en.yml",
49
+ "lib/generators/bobby/install/templates/migration.rb",
36
50
  "lib/tasks/.gitkeep",
37
51
  "lib/tasks/cucumber.rake",
38
52
  "lib/tasks/jquery_setup.rake",
@@ -0,0 +1,14 @@
1
+ Feature: Installing Bobby
2
+ In order to control access to actions on controllers and instances of models
3
+ As a humble corners-cutting Rails/JavaScript developer
4
+ I want to install bobby into my Rails app
5
+
6
+ Background:
7
+ Given a Rails app
8
+ And I have the generator in "lib/generators/bobby"
9
+
10
+ Scenario: Setup the Bobby
11
+ Given I have bobby installed
12
+ When I invoke "bobby:install" generator
13
+ And I invoke task "rake db:migrate"
14
+ Then I can instanciate the models "Authorisation GroupUser GroupUsersUsers Permission PermissionsRoles Role"
@@ -0,0 +1,178 @@
1
+ Given /^this project is active project folder/ do
2
+ @active_project_folder = File.expand_path(File.dirname(__FILE__) + "/../..")
3
+ end
4
+
5
+ Given /^env variable \$([\w_]+) set to "(.*)"/ do |env_var, value|
6
+ ENV[env_var] = value
7
+ end
8
+
9
+ Given /I delete (folder|file) "([^\"]*)"/ do |type, folder|
10
+ in_project_folder { FileUtils.rm_rf folder }
11
+ end
12
+
13
+ When /^I invoke "(.*)" generator with arguments "(.*)"$/ do |generator, arguments|
14
+ @stdout = StringIO.new
15
+
16
+ # in_project_folder do
17
+ # if Object.const_defined?("APP_ROOT")
18
+ # APP_ROOT.replace(FileUtils.pwd)
19
+ # else
20
+ # APP_ROOT = FileUtils.pwd
21
+ # end
22
+ # run_generator(generator, arguments.split(' '), SOURCES, :stdout => @stdout)
23
+ # end
24
+
25
+ f = open("|rails generate #{generator} #{arguments}")
26
+ foo = f.read()
27
+ f.close
28
+
29
+ foo.should include('fisk')
30
+ end
31
+
32
+ When /^I run executable "(.*)" with arguments "(.*)"/ do |executable, arguments|
33
+ @stdout = File.expand_path(File.join(@tmp_root, "executable.out"))
34
+ in_project_folder do
35
+ system "#{executable} #{arguments} > #{@stdout} 2> #{@stdout}"
36
+ end
37
+ end
38
+
39
+ When /^I run project executable "(.*)" with arguments "(.*)"/ do |executable, arguments|
40
+ @stdout = File.expand_path(File.join(@tmp_root, "executable.out"))
41
+ in_project_folder do
42
+ system "ruby #{executable} #{arguments} > #{@stdout} 2> #{@stdout}"
43
+ end
44
+ end
45
+
46
+ When /^I run local executable "(.*)" with arguments "(.*)"/ do |executable, arguments|
47
+ @stdout = File.expand_path(File.join(@tmp_root, "executable.out"))
48
+ executable = File.expand_path(File.join(File.dirname(__FILE__), "/../../bin", executable))
49
+ in_project_folder do
50
+ system "ruby #{executable} #{arguments} > #{@stdout} 2> #{@stdout}"
51
+ end
52
+ end
53
+
54
+ When /^I invoke task "rake (.*)"/ do |task|
55
+ @stdout = File.expand_path(File.join(@tmp_root, "rake.out"))
56
+ @stderr = File.expand_path(File.join(@tmp_root, "rake.err"))
57
+ in_project_folder do
58
+ system "rake #{task} --trace > #{@stdout} 2> #{@stderr}"
59
+ end
60
+ File.read(@stderr).should_not =~ /rake aborted!/
61
+ end
62
+
63
+ Then /^folder "(.*)" (is|is not) created/ do |folder, is|
64
+ in_project_folder do
65
+ File.exists?(folder).should(is == 'is' ? be_true : be_false)
66
+ end
67
+ end
68
+
69
+ Then /^file "(.*)" (is|is not) created/ do |file, is|
70
+ in_project_folder do
71
+ File.exists?(file).should(is == 'is' ? be_true : be_false)
72
+ end
73
+ end
74
+
75
+ Then /^file with name matching "(.*)" is created/ do |pattern|
76
+ in_project_folder do
77
+ Dir[pattern].should_not be_empty
78
+ end
79
+ end
80
+
81
+ Then /^file "(.*)" contents (does|does not) match \/(.*)\// do |file, does, regex|
82
+ in_project_folder do
83
+ actual_output = File.read(file)
84
+ (does == 'does') ?
85
+ actual_output.should(match(/#{regex}/)) :
86
+ actual_output.should_not(match(/#{regex}/))
87
+ end
88
+ end
89
+
90
+ Then /gem file "(.*)" and generated file "(.*)" should be the same/ do |gem_file, project_file|
91
+ File.exists?(gem_file).should be_true
92
+ File.exists?(project_file).should be_true
93
+ gem_file_contents = File.read(File.dirname(__FILE__) + "/../../#{gem_file}")
94
+ project_file_contents = File.read(File.join(@active_project_folder, project_file))
95
+ project_file_contents.should == gem_file_contents
96
+ end
97
+
98
+ Then /^(does|does not) invoke generator "(.*)"$/ do |does_invoke, generator|
99
+ actual_output = File.read(@stdout)
100
+ does_invoke == "does" ?
101
+ actual_output.should(match(/dependency\s+#{generator}/)) :
102
+ actual_output.should_not(match(/dependency\s+#{generator}/))
103
+ end
104
+
105
+ Then /help options "(.*)" and "(.*)" are displayed/ do |opt1, opt2|
106
+ actual_output = File.read(@stdout)
107
+ actual_output.should match(/#{opt1}/)
108
+ actual_output.should match(/#{opt2}/)
109
+ end
110
+
111
+ Then /^file should contain "([^\"]*)"$/ do |text|
112
+ actual_output = File.read(@stdout)
113
+ actual_output.should contain(text)
114
+ end
115
+
116
+ Then /^file should not contain "([^\"]*)"$/ do |text|
117
+ actual_output = File.read(@stdout)
118
+ actual_output.should_not contain(text)
119
+ end
120
+
121
+ Then /^file should contain$/ do |text|
122
+ actual_output = File.read(@stdout)
123
+ actual_output.should contain(text)
124
+ end
125
+
126
+ Then /^file should not contain$/ do |text|
127
+ actual_output = File.read(@stdout)
128
+ actual_output.should_not contain(text)
129
+ end
130
+
131
+ Then /^file should contain exactly$/ do |text|
132
+ actual_output = File.read(@stdout)
133
+ actual_output.should == text
134
+ end
135
+
136
+ Then /^I should see all (\d+) tests pass/ do |expected_test_count|
137
+ expected = %r{^#{expected_test_count} tests, \d+ assertions, 0 failures, 0 errors}
138
+ actual_output = File.read(@stdout)
139
+ actual_output.should match(expected)
140
+ end
141
+
142
+ Then /^I should see all (\d+) examples pass/ do |expected_test_count|
143
+ expected = %r{^#{expected_test_count} examples?, 0 failures}
144
+ actual_output = File.read(@stdout)
145
+ actual_output.should match(expected)
146
+ end
147
+
148
+ Then /^yaml file "(.*)" contains (\{.*\})/ do |file, yaml|
149
+ in_project_folder do
150
+ yaml = eval yaml
151
+ YAML.load(File.read(file)).should == yaml
152
+ end
153
+ end
154
+
155
+ Then /^Rakefile can display tasks successfully/ do
156
+ @stdout = File.expand_path(File.join(@tmp_root, "rakefile.out"))
157
+ in_project_folder do
158
+ system "rake -T > #{@stdout} 2> #{@stdout}"
159
+ end
160
+ actual_output = File.read(@stdout)
161
+ actual_output.should match(/^rake\s+\w+\s+#\s.*/)
162
+ end
163
+
164
+ Then /^task "rake (.*)" is executed successfully/ do |task|
165
+ @stdout.should_not be_nil
166
+ actual_output = File.read(@stdout)
167
+ actual_output.should_not match(/^Don't know how to build task '#{task}'/)
168
+ actual_output.should_not match(/Error/i)
169
+ end
170
+
171
+ Then /^gem spec key "(.*)" contains \/(.*)\// do |key, regex|
172
+ in_project_folder do
173
+ gem_file = Dir["pkg/*.gem"].first
174
+ gem_spec = Gem::Specification.from_yaml(`gem spec #{gem_file}`)
175
+ spec_value = gem_spec.send(key.to_sym)
176
+ spec_value.to_s.should match(/#{regex}/)
177
+ end
178
+ end
@@ -0,0 +1,33 @@
1
+ Given /^a Rails app$/ do
2
+ %w{ app app/controllers app/models app/views }.each do |pattern|
3
+ Dir[pattern].should_not be_empty
4
+ end
5
+ end
6
+
7
+ Given /^I have the generator in "([^"]*)"$/ do |folder|
8
+ folder = File.expand_path(File.join(Rails.root, folder))
9
+ File.exists?(folder+"/USAGE").should be_true
10
+ end
11
+
12
+ Then /^I can instanciate the models "([^"]*)"$/ do |models|
13
+ models.split(" ").each do |model|
14
+ puts model
15
+ #(model.constantize).table_name.should == model.underscore.pluralize
16
+ end
17
+ end
18
+
19
+ Given /^I have bobby installed$/ do
20
+ actual_output = File.read('Gemfile')
21
+ actual_output.should(match(/bobby/))
22
+ end
23
+
24
+ When /^I invoke "([^"]*)" generator$/ do |generator|
25
+ f = open("|rails generate #{generator}")
26
+ foo = f.read()
27
+ f.close
28
+
29
+ foo.should include('bobby_create_tables')
30
+ foo.should include('roles')
31
+ foo.should include('permissions')
32
+ foo.should include('group_users')
33
+ end
@@ -0,0 +1,26 @@
1
+ # Given /^a Rails app$/ do
2
+ # FileUtils.chdir(@tmp_root) do
3
+ # `rails new test_project`
4
+ # end
5
+ # @active_project_folder = File.expand_path(File.join(@tmp_root, "test_project"))
6
+ # end
7
+
8
+ # Given /^I copy the project generators into "([^\"]*)"$/ do |target_folder|
9
+ # in_project_folder do
10
+ # FileUtils.mkdir_p(target_folder)
11
+ # end
12
+ # `cp -rf #{File.dirname(__FILE__) + "/../../rails_generators/*"} #{File.join(@active_project_folder, target_folder)}`
13
+ # end
14
+ #
15
+ # When /^I add a feature file to test Rails index.html default file$/ do
16
+ # sample_feature = File.expand_path(File.dirname(__FILE__) + "/../fixtures/sample_feature")
17
+ # in_project_folder do
18
+ # `cp -rf #{sample_feature} features/sample.feature`
19
+ # end
20
+ # end
21
+ #
22
+ # After do
23
+ # in_project_folder do
24
+ # Given 'I invoke task "rake culerity:rails:stop"'
25
+ # end
26
+ # end
@@ -0,0 +1,32 @@
1
+ module CommonHelpers
2
+ def in_tmp_folder(&block)
3
+ FileUtils.chdir(@tmp_root, &block)
4
+ end
5
+
6
+ def in_project_folder(&block)
7
+ project_folder = @active_project_folder || @tmp_root
8
+ FileUtils.chdir(project_folder, &block)
9
+ end
10
+
11
+ def in_home_folder(&block)
12
+ FileUtils.chdir(@home_path, &block)
13
+ end
14
+
15
+ def force_local_lib_override(options = {})
16
+ target_path = options[:target_path] || options[:target_file] || options[:target] || 'Rakefile'
17
+ in_project_folder do
18
+ contents = File.read(target_path)
19
+ File.open(target_path, "w+") do |f|
20
+ f << "$:.unshift('#{@lib_path}')\n"
21
+ f << contents
22
+ end
23
+ end
24
+ end
25
+
26
+ def setup_active_project_folder project_name
27
+ @active_project_folder = File.join(@tmp_root, project_name)
28
+ @project_name = project_name
29
+ end
30
+ end
31
+
32
+ World(CommonHelpers)
@@ -16,7 +16,32 @@ require 'cucumber/web/tableish'
16
16
  require 'capybara/rails'
17
17
  require 'capybara/cucumber'
18
18
  require 'capybara/session'
19
- require 'cucumber/rails/capybara_javascript_emulation' # Lets you click links with onclick javascript handlers without using @culerity or @javascript
19
+ require 'cucumber/rails/capybara_javascript_emulation'
20
+
21
+ #require File.dirname(__FILE__) + "/../../lib/bobby"
22
+
23
+ # gem 'rspec'
24
+ # require 'spec'
25
+
26
+ Before do
27
+ @tmp_root = File.dirname(__FILE__) + "/../../tmp"
28
+ @home_path = File.expand_path(File.join(@tmp_root, "home"))
29
+ @lib_path = File.expand_path(File.dirname(__FILE__) + "/../../lib")
30
+ FileUtils.rm_rf @tmp_root
31
+ FileUtils.mkdir_p @home_path
32
+ ENV['HOME'] = @home_path
33
+ end
34
+
35
+ # require 'rubigen'
36
+ # require 'rubigen/helpers/generator_test_helper'
37
+ # include RubiGen::GeneratorTestHelper
38
+ #require 'rails_generator'
39
+
40
+ # SOURCES = Dir[File.dirname(__FILE__) + "/../../generators"].map do |f|
41
+ # RubiGen::PathSource.new(:test, File.expand_path(f))
42
+ # end
43
+
44
+ # Lets you click links with onclick javascript handlers without using @culerity or @javascript
20
45
  # Capybara defaults to XPath selectors rather than Webrat's default of CSS3. In
21
46
  # order to ease the transition to Capybara we set the default here. If you'd
22
47
  # prefer to use XPath just remove this line and adjust any selectors in your
@@ -0,0 +1,11 @@
1
+ module Matchers
2
+ # def contain(expected)
3
+ # simple_matcher("contain #{expected.inspect}") do |given, matcher|
4
+ # matcher.failure_message = "expected #{given.inspect} to contain #{expected.inspect}"
5
+ # matcher.negative_failure_message = "expected #{given.inspect} not to contain #{expected.inspect}"
6
+ # given.index expected
7
+ # end
8
+ # end
9
+ end
10
+
11
+ World(Matchers)
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Explain the generator
3
+
4
+ Example:
5
+ rails generate bobby Thing
6
+
7
+ This will create:
8
+ what/will/it/create
@@ -0,0 +1,88 @@
1
+ require 'rails/generators/migration'
2
+
3
+ module Devise
4
+ module Generators
5
+ class DeviseGenerator < Rails::Generators::NamedBase
6
+ include Rails::Generators::Migration
7
+
8
+ source_root File.expand_path("../templates", __FILE__)
9
+ #namespace "bobby"
10
+
11
+ desc "Generates models with the given NAME (if one does not exist) with bobby " <<
12
+ "configuration plus a migration file and bobby routes."
13
+
14
+ def self.orm_has_migration?
15
+ Rails::Generators.options[:rails][:orm] == :active_record
16
+ end
17
+
18
+ def self.next_migration_number(path)
19
+ Time.now.utc.strftime("%Y%m%d%H%M%S")
20
+ end
21
+
22
+ class_option :orm
23
+ class_option :migration, :type => :boolean, :default => orm_has_migration?
24
+
25
+ def invoke_orm_model
26
+ return unless behavior == :invoke
27
+
28
+ if model_exists?
29
+ say "* Model already exists. Adding Devise behavior."
30
+ elsif options[:orm].present?
31
+ invoke "model", [name], :migration => false, :orm => options[:orm]
32
+
33
+ unless model_exists?
34
+ abort "Tried to invoke the model generator for '#{options[:orm]}' but could not find it.\n" <<
35
+ "Please create your model by hand before calling `rails g devise #{name}`."
36
+ end
37
+ else
38
+ abort "Cannot create a devise model because config.generators.orm is blank.\n" <<
39
+ "Please create your model by hand or configure your generators orm before calling `rails g devise #{name}`."
40
+ end
41
+ end
42
+
43
+ def inject_devise_config_into_model
44
+ devise_class_setup = <<-CONTENT
45
+
46
+ # Include default devise modules. Others available are:
47
+ # :token_authenticatable, :confirmable, :lockable and :timeoutable
48
+ devise :database_authenticatable, :registerable,
49
+ :recoverable, :rememberable, :trackable, :validatable
50
+
51
+ CONTENT
52
+
53
+ case options[:orm].to_s
54
+ when "mongoid"
55
+ inject_into_file model_path, devise_class_setup, :after => "include Mongoid::Document\n"
56
+ when "data_mapper"
57
+ inject_into_file model_path, devise_class_setup, :after => "include DataMapper::Resource\n"
58
+ when "active_record"
59
+ inject_into_class model_path, class_name, devise_class_setup + <<-CONTENT
60
+ # Setup accessible (or protected) attributes for your model
61
+ attr_accessible :email, :password, :password_confirmation
62
+ CONTENT
63
+ end
64
+ end
65
+
66
+ def copy_migration_template
67
+ return unless options.migration?
68
+ migration_template "migration.rb", "db/migrate/bobby_create_tables"
69
+ end
70
+
71
+ def add_bobby_routes
72
+ route "ressources :roles"
73
+ route "ressources :permissions"
74
+ route "ressources :group_users"
75
+ end
76
+
77
+ protected
78
+
79
+ def model_exists?
80
+ File.exists?(File.join(destination_root, model_path))
81
+ end
82
+
83
+ def model_path
84
+ @model_path ||= File.join("app", "models", "#{file_path}.rb")
85
+ end
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,2 @@
1
+ # Remove this file on next rails release
2
+ require "generators/bobby/bobby/bobby_generator"
@@ -0,0 +1,4 @@
1
+ # Remove this file after deprecation -
2
+ if caller.none? { |l| l =~ %r{lib/rails/generators\.rb:(\d+):in `lookup!'$} }
3
+ warn "[WARNING] `rails g bobby_install` is deprecated, please use `rails g devise:install` instead."
4
+ end
@@ -0,0 +1,103 @@
1
+ require 'active_support/secure_random'
2
+ require 'rails/generators/migration'
3
+
4
+
5
+ module Bobby
6
+ module Generators
7
+ class InstallGenerator < Rails::Generators::Base
8
+ include Rails::Generators::Migration
9
+
10
+ source_root File.expand_path("../templates", __FILE__)
11
+
12
+ desc "Generates models with the given NAME (if one does not exist) with bobby " <<
13
+ "configuration plus a migration file, bobby routes and copy locale files to your application."
14
+
15
+ class_option :orm
16
+
17
+ # def copy_initializer
18
+ # template "bobby.rb", "config/initializers/bobby.rb"
19
+ # end
20
+
21
+ def self.orm_has_migration?
22
+ Rails::Generators.options[:rails][:orm] == :active_record
23
+ end
24
+
25
+ def self.next_migration_number(path)
26
+ Time.now.utc.strftime("%Y%m%d%H%M%S")
27
+ end
28
+
29
+ class_option :migration, :type => :boolean, :default => orm_has_migration?
30
+
31
+ # def invoke_orm_model
32
+ # return unless behavior == :invoke
33
+ #
34
+ # if model_exists?
35
+ # say "* Model already exists. Adding Bobby behavior."
36
+ # elsif options[:orm].present?
37
+ # invoke "model", [name], :migration => false, :orm => options[:orm]
38
+ #
39
+ # unless model_exists?
40
+ # abort "Tried to invoke the model generator for '#{options[:orm]}' but could not find it.\n" <<
41
+ # "Please create your model by hand before calling `rails g bobby #{name}`."
42
+ # end
43
+ # else
44
+ # abort "Cannot create a devise model because config.generators.orm is blank.\n" <<
45
+ # "Please create your model by hand or configure your generators orm before calling `rails g devise #{name}`."
46
+ # end
47
+ # end
48
+
49
+ # def inject_devise_config_into_model
50
+ # devise_class_setup = <<-CONTENT
51
+ #
52
+ # # Include default devise modules. Others available are:
53
+ # # :token_authenticatable, :confirmable, :lockable and :timeoutable
54
+ # devise :database_authenticatable, :registerable,
55
+ # :recoverable, :rememberable, :trackable, :validatable
56
+ #
57
+ # CONTENT
58
+ #
59
+ # case options[:orm].to_s
60
+ # when "mongoid"
61
+ # inject_into_file model_path, devise_class_setup, :after => "include Mongoid::Document\n"
62
+ # when "data_mapper"
63
+ # inject_into_file model_path, devise_class_setup, :after => "include DataMapper::Resource\n"
64
+ # when "active_record"
65
+ # inject_into_class model_path, class_name, devise_class_setup + <<-CONTENT
66
+ # # Setup accessible (or protected) attributes for your model
67
+ # attr_accessible :email, :password, :password_confirmation
68
+ # CONTENT
69
+ # end
70
+ # end
71
+
72
+ def copy_migration_template
73
+ return unless options.migration?
74
+ migration_template "migration.rb", "db/migrate/bobby_create_tables"
75
+ end
76
+
77
+ def add_bobby_routes
78
+ route "resources :roles"
79
+ route "resources :permissions"
80
+ route "resources :group_users"
81
+ end
82
+
83
+ protected
84
+
85
+ def model_exists?
86
+ File.exists?(File.join(destination_root, model_path))
87
+ end
88
+
89
+ def model_path
90
+ @model_path ||= File.join("app", "models", "#{file_path}.rb")
91
+ end
92
+
93
+ def copy_locale
94
+ copy_file "en.yml", "config/locales/bobby.en.yml"
95
+ end
96
+
97
+ def show_readme
98
+ readme "README"
99
+ end
100
+
101
+ end
102
+ end
103
+ end
@@ -0,0 +1,29 @@
1
+
2
+ ===============================================================================
3
+
4
+ Some setup you must do manually:
5
+
6
+ 1. add a filter to your ApplicationController
7
+
8
+ before_filter :access_authorized?
9
+
10
+ or add the filter to select controllers
11
+
12
+ if controllers follows particular patterns like the Presenter Pattern
13
+ add the table(s) as arguments to the filter
14
+
15
+ before_filter :access_authorized? :posts, :comments
16
+
17
+ 2. add a default_scope to your models
18
+
19
+ default_scope :instances_authorized
20
+
21
+ 3. build access control structures using the Role, Permission and GroupUser views,
22
+ like
23
+
24
+ /roles
25
+ /permissions
26
+ /group_users
27
+
28
+
29
+ ===============================================================================
@@ -0,0 +1,49 @@
1
+ class BobbyCreateTables < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :permissions do |t|
4
+ t.string :name
5
+ t.string :actions_allowed
6
+ t.text :on_tables
7
+
8
+ t.timestamps
9
+ end
10
+ create_table :roles do |t|
11
+ t.string :name
12
+
13
+ t.timestamps
14
+ end
15
+ create_table :authorisations do |t|
16
+ t.references :authorisable, :polymorphic => true
17
+ t.integer :role_id
18
+
19
+ t.timestamps
20
+ end
21
+ create_table :permissions_roles, :id => false do |t|
22
+ t.integer :permission_id
23
+ t.integer :role_id
24
+
25
+ t.timestamps
26
+ end
27
+ create_table :group_users do |t|
28
+ t.string :name
29
+
30
+ t.timestamps
31
+ end
32
+ create_table :group_users_users, :id => false do |t|
33
+ t.integer :group_user_id
34
+ t.integer :user_id
35
+
36
+ t.timestamps
37
+ end
38
+
39
+ end
40
+
41
+ def self.down
42
+ drop_table :group_users_users
43
+ drop_table :group_users
44
+ drop_table :permissions_roles
45
+ drop_table :authorisations
46
+ drop_table :roles
47
+ drop_table :permissions
48
+ end
49
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bobby
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 3
10
- version: 0.0.3
9
+ - 4
10
+ version: 0.0.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Enrique Phillips
@@ -68,13 +68,27 @@ files:
68
68
  - Rakefile
69
69
  - VERSION
70
70
  - bobby.gemspec
71
+ - features/install_bobby.feature
71
72
  - features/manage_posts.feature
73
+ - features/step_definitions/common_steps.rb
72
74
  - features/step_definitions/devise_steps.rb
75
+ - features/step_definitions/install_bobby_steps.rb
73
76
  - features/step_definitions/post_steps.rb
77
+ - features/step_definitions/rails_setup_steps.rb
74
78
  - features/step_definitions/web_steps.rb
79
+ - features/support/common.rb
75
80
  - features/support/env.rb
81
+ - features/support/matchers.rb
76
82
  - features/support/paths.rb
77
83
  - lib/bobby.rb
84
+ - lib/generators/bobby/USAGE
85
+ - lib/generators/bobby/bobby/bobby_generator.rb
86
+ - lib/generators/bobby/bobby_generator.rb
87
+ - lib/generators/bobby/bobby_install_generator.rb
88
+ - lib/generators/bobby/install/install_generator.rb
89
+ - lib/generators/bobby/install/templates/README
90
+ - lib/generators/bobby/install/templates/en.yml
91
+ - lib/generators/bobby/install/templates/migration.rb
78
92
  - lib/tasks/.gitkeep
79
93
  - lib/tasks/cucumber.rake
80
94
  - lib/tasks/jquery_setup.rake