kellyfelkins-clearance 0.5.6
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.textile +84 -0
- data/LICENSE +21 -0
- data/README.textile +76 -0
- data/Rakefile +73 -0
- data/generators/clearance/USAGE +1 -0
- data/generators/clearance/clearance_generator.rb +96 -0
- data/generators/clearance/lib/insert_commands.rb +103 -0
- data/generators/clearance/lib/rake_commands.rb +22 -0
- data/generators/clearance/templates/README +45 -0
- data/generators/clearance/templates/app/controllers/application.rb +5 -0
- data/generators/clearance/templates/app/controllers/confirmations_controller.rb +3 -0
- data/generators/clearance/templates/app/controllers/passwords_controller.rb +3 -0
- data/generators/clearance/templates/app/controllers/sessions_controller.rb +3 -0
- data/generators/clearance/templates/app/controllers/users_controller.rb +3 -0
- data/generators/clearance/templates/app/models/clearance_mailer.rb +5 -0
- data/generators/clearance/templates/app/models/user.rb +3 -0
- data/generators/clearance/templates/app/views/clearance_mailer/change_password.html.erb +7 -0
- data/generators/clearance/templates/app/views/clearance_mailer/confirmation.html.erb +2 -0
- data/generators/clearance/templates/app/views/passwords/edit.html.erb +23 -0
- data/generators/clearance/templates/app/views/passwords/new.html.erb +15 -0
- data/generators/clearance/templates/app/views/sessions/new.html.erb +28 -0
- data/generators/clearance/templates/app/views/users/_form.html.erb +13 -0
- data/generators/clearance/templates/app/views/users/edit.html.erb +6 -0
- data/generators/clearance/templates/app/views/users/new.html.erb +6 -0
- data/generators/clearance/templates/db/migrate/create_users_with_clearance_columns.rb +20 -0
- data/generators/clearance/templates/db/migrate/update_users_with_clearance_columns.rb +41 -0
- data/generators/clearance/templates/test/factories/clearance.rb +16 -0
- data/generators/clearance/templates/test/functional/confirmations_controller_test.rb +5 -0
- data/generators/clearance/templates/test/functional/passwords_controller_test.rb +5 -0
- data/generators/clearance/templates/test/functional/sessions_controller_test.rb +5 -0
- data/generators/clearance/templates/test/functional/users_controller_test.rb +5 -0
- data/generators/clearance/templates/test/unit/clearance_mailer_test.rb +6 -0
- data/generators/clearance/templates/test/unit/user_test.rb +5 -0
- data/generators/clearance_features/USAGE +1 -0
- data/generators/clearance_features/clearance_features_generator.rb +20 -0
- data/generators/clearance_features/templates/features/password_reset.feature +31 -0
- data/generators/clearance_features/templates/features/sign_in.feature +41 -0
- data/generators/clearance_features/templates/features/sign_out.feature +22 -0
- data/generators/clearance_features/templates/features/sign_up.feature +30 -0
- data/generators/clearance_features/templates/features/step_definitions/clearance_steps.rb +110 -0
- data/generators/clearance_features/templates/features/step_definitions/factory_girl_steps.rb +5 -0
- data/generators/clearance_features/templates/features/support/paths.rb +25 -0
- data/lib/clearance.rb +15 -0
- data/lib/clearance/app/controllers/application_controller.rb +84 -0
- data/lib/clearance/app/controllers/confirmations_controller.rb +63 -0
- data/lib/clearance/app/controllers/passwords_controller.rb +79 -0
- data/lib/clearance/app/controllers/sessions_controller.rb +74 -0
- data/lib/clearance/app/controllers/users_controller.rb +45 -0
- data/lib/clearance/app/models/clearance_mailer.rb +23 -0
- data/lib/clearance/app/models/user.rb +119 -0
- data/lib/clearance/lib/extensions/errors.rb +4 -0
- data/lib/clearance/lib/extensions/rescue.rb +1 -0
- data/lib/clearance/test/functional/confirmations_controller_test.rb +72 -0
- data/lib/clearance/test/functional/passwords_controller_test.rb +180 -0
- data/lib/clearance/test/functional/sessions_controller_test.rb +187 -0
- data/lib/clearance/test/functional/users_controller_test.rb +60 -0
- data/lib/clearance/test/unit/clearance_mailer_test.rb +65 -0
- data/lib/clearance/test/unit/user_test.rb +243 -0
- data/rails/init.rb +1 -0
- data/shoulda_macros/clearance.rb +241 -0
- metadata +157 -0
data/CHANGELOG.textile
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
h1. 0.5.5 (3/23/2009)
|
2
|
+
|
3
|
+
* Removing duplicate test to get rid of warning. (Nick Quaranto)
|
4
|
+
|
5
|
+
h1. 0.5.4 (3/21/2009)
|
6
|
+
|
7
|
+
* When users fail logging in, redirect them instead of rendering. (Matt
|
8
|
+
Jankowski)
|
9
|
+
|
10
|
+
h1. 0.5.3 (3/5/2009)
|
11
|
+
|
12
|
+
* Clearance now works with (and requires) Shoulda 2.10.0. (Mark Cornick, Joe
|
13
|
+
Ferris, Dan Croak)
|
14
|
+
* Prefer flat over nested contexts in sessions_controller_test. (Joe Ferris,
|
15
|
+
Dan Croak)
|
16
|
+
|
17
|
+
h1. 0.5.2 (3/2/2009)
|
18
|
+
|
19
|
+
* Fixed last remaining errors in Rails 2.3 tests. Now fully compatible. (Joe
|
20
|
+
Ferris, Dan Croak)
|
21
|
+
|
22
|
+
h1. 0.5.1 (2/27/2009)
|
23
|
+
|
24
|
+
* [#46] A user with unconfirmed email who resets password now confirms email.
|
25
|
+
(Marcel Görner)
|
26
|
+
* Refactored user_from_cookie, user_from_session, User#authenticate to use
|
27
|
+
more direct return code instead of ugly, harder to read ternary. (Dan Croak)
|
28
|
+
* Switch order of cookies and sessions to take advantage of Rails 2.3's "Rack-based lazy-loaded sessions":http://is.gd/i23E. (Dan Croak)
|
29
|
+
* Altered generator to interact with application_controller.rb instead of
|
30
|
+
application.rb in Rails 2.3 apps. (Dan Croak)
|
31
|
+
* [#42] Bug fix. Rack-based session change altered how to test remember me
|
32
|
+
cookie. (Mihai Anca)
|
33
|
+
|
34
|
+
h2. 0.5.0 (2/27/2009)
|
35
|
+
|
36
|
+
* Fixed problem with Cucumber features. (Dan Croak)
|
37
|
+
* Fixed mising HTTP fluency use case. (Dan Croak)
|
38
|
+
* Refactored User#update_password to take just parameters it needs. (Dan
|
39
|
+
Croak)
|
40
|
+
* Refactored User unit tests to be more readable. (Dan Croak)
|
41
|
+
|
42
|
+
h2. 0.4.9 (2/20/2009)
|
43
|
+
|
44
|
+
* Protect passwords & confirmations actions with forbidden filters. (Dan Croak)
|
45
|
+
* Return 403 Forbidden status code in those cases. (Tim Pope)
|
46
|
+
* Test 403 Forbidden status code in Cucumber feature. (Dan Croak, Joe Ferris)
|
47
|
+
* Raise custom ActionController::Forbidden error internally. (Joe Ferris, Mike Burns, Jason Morrison)
|
48
|
+
* Test ActionController::Forbidden error is raised in functional test. (Joe Ferris, Mike Burns, Dan Croak)
|
49
|
+
* [#45] Fixed bug that allowed anyone to edit another user's password (Marcel Görner)
|
50
|
+
* Required Factory Girl >= 1.2.0. (Dan Croak)
|
51
|
+
|
52
|
+
h2. 0.4.8 (2/16/2009)
|
53
|
+
|
54
|
+
* Added support paths for Cucumber. (Ben Mabey)
|
55
|
+
* Added documentation for the flash. (Ben Mabey)
|
56
|
+
* Generators require "test_helper" instead of File.join. for rr compatibility. (Joe Ferris)
|
57
|
+
* Removed interpolated email address from flash message to make i18n easier. (Bence Nagy)
|
58
|
+
* Standardized flash messages that refer to email delivery. (Dan Croak)
|
59
|
+
|
60
|
+
h2. 0.4.7 (2/12/2009)
|
61
|
+
|
62
|
+
* Removed Clearance::Test::TestHelper so there is one less setup step. (Dan Croak)
|
63
|
+
* All test helpers now in shoulda_macros. (Dan Croak)
|
64
|
+
|
65
|
+
h2. 0.4.6 (2/11/2009)
|
66
|
+
|
67
|
+
* Made the modules behave like mixins again. (hat-tip Eloy Duran)
|
68
|
+
* Created Actions and PrivateMethods modules on controllers for future RDoc reasons. (Dan Croak, Joe Ferris)
|
69
|
+
|
70
|
+
h2. 0.4.5 (2/9/2009)
|
71
|
+
|
72
|
+
* [#43] Removed email downcasing because local-part is case sensitive per RFC5321. (Dan Croak)
|
73
|
+
* [#42] Removed dependency on Mocha. (Dan Croak)
|
74
|
+
* Required Shoulda >= 2.9.1. (Dan Croak)
|
75
|
+
* Added password reset feature to clearance_features generator. (Eugene Bolshakov, Dan Croak)
|
76
|
+
* Removed unnecessary session[:salt]. (Dan Croak)
|
77
|
+
* [#41] Only store location for session[:return_to] for GET requests. (Dan Croak)
|
78
|
+
* Audited "sign up" naming convention. "Register" had slipped in a few places. (Dan Croak)
|
79
|
+
* Switched to SHA1 encryption. Cypher doesn't matter much for email confirmation, password reset. Better to have shorter hashes in the emails for clients who line break on 72 chars. (Dan Croak)
|
80
|
+
|
81
|
+
h2. 0.4.4 (2/2/2009)
|
82
|
+
|
83
|
+
* Added a generator for Cucumber features. (Joe Ferris, Dan Croak)
|
84
|
+
* Standarized naming for "Sign up," "Sign in," and "Sign out". (Dan Croak)
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2008 thoughtbot, inc.
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.textile
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
h1. Clearance
|
2
|
+
|
3
|
+
Rails authentication for developers who write tests.
|
4
|
+
|
5
|
+
"We have clearance, Clarence.":http://www.youtube.com/v/mNRXJEE3Nz8
|
6
|
+
|
7
|
+
h2. Wiki
|
8
|
+
|
9
|
+
Most information regarding Clearance is on the "Github Wiki":http://wiki.github.com/thoughtbot/clearance.
|
10
|
+
|
11
|
+
h2. Integration with Suspenders
|
12
|
+
|
13
|
+
Clearance is based on the same conventions and tools as "Suspenders":http://github.com/thoughtbot/suspenders If you use it, you already have some configuration mentioned below.
|
14
|
+
|
15
|
+
h2. Gem installation (Rails 2.1+)
|
16
|
+
|
17
|
+
In config/environment.rb:
|
18
|
+
|
19
|
+
config.gem "thoughtbot-clearance",
|
20
|
+
:lib => 'clearance',
|
21
|
+
:source => 'http://gems.github.com',
|
22
|
+
:version => '0.5.3'
|
23
|
+
|
24
|
+
In config/environments/test.rb:
|
25
|
+
|
26
|
+
config.gem 'thoughtbot-shoulda',
|
27
|
+
:lib => 'shoulda',
|
28
|
+
:source => "http://gems.github.com",
|
29
|
+
:version => '2.10.0'
|
30
|
+
config.gem 'thoughtbot-factory_girl',
|
31
|
+
:lib => 'factory_girl',
|
32
|
+
:source => "http://gems.github.com",
|
33
|
+
:version => '1.2.0'
|
34
|
+
|
35
|
+
Then:
|
36
|
+
|
37
|
+
rake gems:install
|
38
|
+
rake gems:unpack
|
39
|
+
rake gems:install RAILS_ENV=test
|
40
|
+
rake gems:unpack RAILS_ENV=test
|
41
|
+
|
42
|
+
h2. The generator
|
43
|
+
|
44
|
+
Make sure the development database exists and run the generator:
|
45
|
+
|
46
|
+
script/generate clearance
|
47
|
+
|
48
|
+
A number of files will be created and instructions will be printed.
|
49
|
+
|
50
|
+
You may already have some of these files. Don't worry. You'll be asked if you want to overwrite them.
|
51
|
+
|
52
|
+
h2. Features
|
53
|
+
|
54
|
+
If you are using Cucumber on your application Clearance comes with a feature generator:
|
55
|
+
|
56
|
+
script/generate clearance_features
|
57
|
+
|
58
|
+
All of the files generated should be new with the exception of the features/support/paths.rb file. If you have not modified your paths.rb then you will be okay to replace it with this one. If you need to keep your paths.rb file then you will need to add these locations in your paths.rb manually:
|
59
|
+
|
60
|
+
def path_to(page_name)
|
61
|
+
case page_name
|
62
|
+
...
|
63
|
+
when /the sign up page/i
|
64
|
+
new_user_path
|
65
|
+
when /the sign in page/i
|
66
|
+
new_session_path
|
67
|
+
when /the password reset request page/i
|
68
|
+
new_password_path
|
69
|
+
...
|
70
|
+
end
|
71
|
+
|
72
|
+
h2. Authors
|
73
|
+
|
74
|
+
Clearance was extracted out of "Hoptoad":http://hoptoadapp.com. We merged the authentication code from two of thoughtbot's client's Rails apps. The following people have made significant contributions, suggestions, and generally improved the library. Thank you!
|
75
|
+
|
76
|
+
Dan Croak, Mike Burns, Jason Morrison, Joe Ferris, Eugene Bolshakov, Josh Nichols, Mike Breen, Marcel Görner, Bence Nagy, Ben Mabey, Eloy Duran, Tim Pope, Mihai Anca, & Mark Cornick.
|
data/Rakefile
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/testtask'
|
3
|
+
require 'cucumber/rake/task'
|
4
|
+
|
5
|
+
test_files_pattern = 'test/rails_root/test/{unit,functional,other}/**/*_test.rb'
|
6
|
+
|
7
|
+
namespace :test do
|
8
|
+
Rake::TestTask.new(:all => ['generator:cleanup',
|
9
|
+
'generator:generate']) do |task|
|
10
|
+
task.libs << 'lib'
|
11
|
+
task.libs << File.join(File.dirname(__FILE__), "test/rails_root/test")
|
12
|
+
task.pattern = test_files_pattern
|
13
|
+
task.verbose = false
|
14
|
+
end
|
15
|
+
|
16
|
+
Cucumber::Rake::Task.new(:features) do |t|
|
17
|
+
t.cucumber_opts = "--format pretty"
|
18
|
+
t.feature_pattern = 'test/rails_root/features/*.feature'
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
generators = %w(clearance clearance_features)
|
23
|
+
|
24
|
+
namespace :generator do
|
25
|
+
desc "Cleans up the test app before running the generator"
|
26
|
+
task :cleanup do
|
27
|
+
generators.each do |generator|
|
28
|
+
FileList["generators/#{generator}/templates/**/*.*"].each do |each|
|
29
|
+
file = "test/rails_root/#{each.gsub("generators/#{generator}/templates/",'')}"
|
30
|
+
File.delete(file) if File.exists?(file)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
FileList["test/rails_root/db/**/*"].each do |each|
|
35
|
+
FileUtils.rm_rf(each)
|
36
|
+
end
|
37
|
+
FileUtils.rm_rf("test/rails_root/vendor/plugins/clearance")
|
38
|
+
system "mkdir -p test/rails_root/vendor/plugins/clearance"
|
39
|
+
system "cp -R generators test/rails_root/vendor/plugins/clearance"
|
40
|
+
end
|
41
|
+
|
42
|
+
desc "Run the generator on the tests"
|
43
|
+
task :generate do
|
44
|
+
generators.each do |generator|
|
45
|
+
system "cd test/rails_root && ./script/generate #{generator}"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
desc "Run the test suite"
|
51
|
+
task :default => ['test:all', 'test:features']
|
52
|
+
|
53
|
+
gem_spec = Gem::Specification.new do |gem_spec|
|
54
|
+
gem_spec.name = "clearance"
|
55
|
+
gem_spec.version = "0.5.3"
|
56
|
+
gem_spec.summary = "Rails authentication for developers who write tests."
|
57
|
+
gem_spec.email = "support@thoughtbot.com"
|
58
|
+
gem_spec.homepage = "http://github.com/thoughtbot/clearance"
|
59
|
+
gem_spec.description = "Simple, complete Rails authentication scheme."
|
60
|
+
gem_spec.authors = ["thoughtbot, inc.", "Dan Croak", "Mike Burns",
|
61
|
+
"Jason Morrison", "Eugene Bolshakov", "Josh Nichols",
|
62
|
+
"Mike Breen", "Joe Ferris", "Bence Nagy",
|
63
|
+
"Marcel Görner", "Ben Mabey", "Tim Pope",
|
64
|
+
"Eloy Duran", "Mihai Anca", "Mark Cornick"]
|
65
|
+
gem_spec.files = FileList["[A-Z]*", "{generators,lib,shoulda_macros,rails}/**/*"]
|
66
|
+
end
|
67
|
+
|
68
|
+
desc "Generate a gemspec file"
|
69
|
+
task :gemspec do
|
70
|
+
File.open("#{gem_spec.name}.gemspec", 'w') do |f|
|
71
|
+
f.write gem_spec.to_yaml
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
script/generate clearance
|
@@ -0,0 +1,96 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/lib/insert_commands.rb")
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + "/lib/rake_commands.rb")
|
3
|
+
require 'factory_girl'
|
4
|
+
|
5
|
+
class ClearanceGenerator < Rails::Generator::Base
|
6
|
+
|
7
|
+
def manifest
|
8
|
+
record do |m|
|
9
|
+
m.directory File.join("app", "controllers")
|
10
|
+
if Rails.version >= "2.3.0"
|
11
|
+
file = "app/controllers/application_controller.rb"
|
12
|
+
else
|
13
|
+
file = "app/controllers/application.rb"
|
14
|
+
end
|
15
|
+
if File.exists?(file)
|
16
|
+
m.insert_into file, "include Clearance::App::Controllers::ApplicationController"
|
17
|
+
else
|
18
|
+
m.file file, file
|
19
|
+
end
|
20
|
+
|
21
|
+
["app/controllers/confirmations_controller.rb",
|
22
|
+
"app/controllers/passwords_controller.rb",
|
23
|
+
"app/controllers/sessions_controller.rb",
|
24
|
+
"app/controllers/users_controller.rb"].each do |file|
|
25
|
+
m.file file, file
|
26
|
+
end
|
27
|
+
|
28
|
+
m.directory File.join("app", "models")
|
29
|
+
["app/models/user.rb", "app/models/clearance_mailer.rb"].each do |file|
|
30
|
+
m.file file, file
|
31
|
+
end
|
32
|
+
|
33
|
+
m.directory File.join("app", "views")
|
34
|
+
|
35
|
+
m.directory File.join("app", "views", "passwords")
|
36
|
+
["app/views/passwords/new.html.erb",
|
37
|
+
"app/views/passwords/edit.html.erb"].each do |file|
|
38
|
+
m.file file, file
|
39
|
+
end
|
40
|
+
|
41
|
+
m.directory File.join("app", "views", "sessions")
|
42
|
+
["app/views/sessions/new.html.erb"].each do |file|
|
43
|
+
m.file file, file
|
44
|
+
end
|
45
|
+
|
46
|
+
m.directory File.join("app", "views", "clearance_mailer")
|
47
|
+
["app/views/clearance_mailer/change_password.html.erb",
|
48
|
+
"app/views/clearance_mailer/confirmation.html.erb"].each do |file|
|
49
|
+
m.file file, file
|
50
|
+
end
|
51
|
+
|
52
|
+
m.directory File.join("app", "views", "users")
|
53
|
+
["app/views/users/_form.html.erb",
|
54
|
+
"app/views/users/edit.html.erb",
|
55
|
+
"app/views/users/new.html.erb"].each do |file|
|
56
|
+
m.file file, file
|
57
|
+
end
|
58
|
+
|
59
|
+
m.directory File.join("test", "functional")
|
60
|
+
["test/functional/confirmations_controller_test.rb",
|
61
|
+
"test/functional/passwords_controller_test.rb",
|
62
|
+
"test/functional/sessions_controller_test.rb",
|
63
|
+
"test/functional/users_controller_test.rb"].each do |file|
|
64
|
+
m.file file, file
|
65
|
+
end
|
66
|
+
|
67
|
+
m.directory File.join("test", "unit")
|
68
|
+
["test/unit/clearance_mailer_test.rb",
|
69
|
+
"test/unit/user_test.rb"].each do |file|
|
70
|
+
m.file file, file
|
71
|
+
end
|
72
|
+
|
73
|
+
m.directory File.join("test", "factories")
|
74
|
+
["test/factories/clearance.rb"].each do |file|
|
75
|
+
m.file file, file
|
76
|
+
end
|
77
|
+
|
78
|
+
m.route_resources ':passwords'
|
79
|
+
m.route_resource ':session'
|
80
|
+
m.route_resources ':users, :has_one => [:password, :confirmation]'
|
81
|
+
|
82
|
+
if ActiveRecord::Base.connection.table_exists?(:users)
|
83
|
+
m.migration_template 'db/migrate/update_users_with_clearance_columns.rb',
|
84
|
+
'db/migrate', :migration_file_name => 'create_or_update_users_with_clearance_columns'
|
85
|
+
else
|
86
|
+
m.migration_template 'db/migrate/create_users_with_clearance_columns.rb',
|
87
|
+
'db/migrate', :migration_file_name => 'create_or_update_users_with_clearance_columns'
|
88
|
+
end
|
89
|
+
|
90
|
+
m.rake_db_migrate
|
91
|
+
|
92
|
+
m.readme "README"
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
# Mostly pinched from http://github.com/ryanb/nifty-generators/tree/master
|
2
|
+
|
3
|
+
Rails::Generator::Commands::Base.class_eval do
|
4
|
+
def file_contains?(relative_destination, line)
|
5
|
+
File.read(destination_path(relative_destination)).include?(line)
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
Rails::Generator::Commands::Create.class_eval do
|
10
|
+
|
11
|
+
def route_resources(resource_list)
|
12
|
+
sentinel = 'ActionController::Routing::Routes.draw do |map|'
|
13
|
+
|
14
|
+
logger.route "map.resources #{resource_list}"
|
15
|
+
unless options[:pretend] || file_contains?('config/routes.rb', resource_list)
|
16
|
+
gsub_file 'config/routes.rb', /(#{Regexp.escape(sentinel)})/mi do |match|
|
17
|
+
"#{match}\n map.resources #{resource_list}"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def route_resource(resource_list)
|
23
|
+
sentinel = 'ActionController::Routing::Routes.draw do |map|'
|
24
|
+
|
25
|
+
logger.route "map.resource #{resource_list}"
|
26
|
+
unless options[:pretend] || file_contains?('config/routes.rb', resource_list)
|
27
|
+
gsub_file 'config/routes.rb', /(#{Regexp.escape(sentinel)})/mi do |match|
|
28
|
+
"#{match}\n map.resource #{resource_list}"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def route_name(name, path, route_options = {})
|
34
|
+
sentinel = 'ActionController::Routing::Routes.draw do |map|'
|
35
|
+
|
36
|
+
logger.route "map.#{name} '#{path}', :controller => '#{route_options[:controller]}', :action => '#{route_options[:action]}'"
|
37
|
+
unless options[:pretend]
|
38
|
+
gsub_file_once 'config/routes.rb', /(#{Regexp.escape(sentinel)})/mi do |match|
|
39
|
+
"#{match}\n map.#{name} '#{path}', :controller => '#{route_options[:controller]}', :action => '#{route_options[:action]}'"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def insert_into(file, line)
|
45
|
+
logger.insert "#{line} into #{file}"
|
46
|
+
unless options[:pretend] || file_contains?(file, line)
|
47
|
+
gsub_file file, /^(class|module) .+$/ do |match|
|
48
|
+
"#{match}\n #{line}"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
Rails::Generator::Commands::Destroy.class_eval do
|
55
|
+
def route_resource(resource_list)
|
56
|
+
look_for = " map.resource #{resource_list}\n".gsub(/[\[\]]/, '\\\\\0')
|
57
|
+
logger.route "map.resource #{resource_list} #{look_for}"
|
58
|
+
unless options[:pretend]
|
59
|
+
gsub_file 'config/routes.rb', /(#{look_for})/mi, ''
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def route_resources(resource_list)
|
64
|
+
look_for = " map.resources #{resource_list}\n".gsub(/[\[\]]/, '\\\\\0')
|
65
|
+
logger.route "map.resources #{resource_list} #{look_for}"
|
66
|
+
unless options[:pretend]
|
67
|
+
gsub_file 'config/routes.rb', /(#{look_for})/mi, ''
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def route_name(name, path, route_options = {})
|
72
|
+
look_for = "\n map.#{name} '#{path}', :controller => '#{route_options[:controller]}', :action => '#{route_options[:action]}'"
|
73
|
+
logger.route "map.#{name} '#{path}', :controller => '#{route_options[:controller]}', :action => '#{route_options[:action]}'"
|
74
|
+
unless options[:pretend]
|
75
|
+
gsub_file 'config/routes.rb', /(#{look_for})/mi, ''
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def insert_into(file, line)
|
80
|
+
logger.remove "#{line} from #{file}"
|
81
|
+
unless options[:pretend]
|
82
|
+
gsub_file file, "\n #{line}", ''
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
Rails::Generator::Commands::List.class_eval do
|
88
|
+
def route_resource(resources_list)
|
89
|
+
logger.route "map.resource #{resource_list}"
|
90
|
+
end
|
91
|
+
|
92
|
+
def route_resources(resources_list)
|
93
|
+
logger.route "map.resource #{resource_list}"
|
94
|
+
end
|
95
|
+
|
96
|
+
def route_name(name, path, options = {})
|
97
|
+
logger.route "map.#{name} '#{path}', :controller => '{options[:controller]}', :action => '#{options[:action]}'"
|
98
|
+
end
|
99
|
+
|
100
|
+
def insert_into(file, line)
|
101
|
+
logger.insert "#{line} into #{file}"
|
102
|
+
end
|
103
|
+
end
|