Skip to content

Commit

Permalink
initial start to getting clearance working on Rails 3
Browse files Browse the repository at this point in the history
  • Loading branch information
Chad Pytel committed Jun 9, 2010
1 parent 12f3371 commit 395b589
Show file tree
Hide file tree
Showing 52 changed files with 9,213 additions and 13 deletions.
24 changes: 13 additions & 11 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace :test do
"generator:clearance"]) do |task|
task.libs << "lib"
task.libs << "test"
task.pattern = "test/**/*_test.rb"
task.pattern = "test/**/user_test.rb"
task.verbose = false
end

Expand Down Expand Up @@ -44,32 +44,34 @@ generators = %w(clearance clearance_features clearance_views)
namespace :generator do
desc "Cleans up the test app before running the generator"
task :cleanup do
FileList["test/rails_root/db/**/*"].each do |each|
FileList["test/rails3_root/db/**/*"].each do |each|
FileUtils.rm_rf(each)
end

FileUtils.rm_rf("test/rails_root/vendor/plugins/clearance")
FileUtils.rm_rf("test/rails_root/app/views/passwords")
FileUtils.rm_rf("test/rails_root/app/views/sessions")
FileUtils.rm_rf("test/rails_root/app/views/users")
FileUtils.mkdir_p("test/rails_root/vendor/plugins")
FileUtils.rm_rf("test/rails3_root/vendor/plugins/clearance")
FileUtils.rm_rf("test/rails3_root/app/views/passwords")
FileUtils.rm_rf("test/rails3_root/app/views/sessions")
FileUtils.rm_rf("test/rails3_root/app/views/users")
FileUtils.mkdir_p("test/rails3_root/vendor/plugins")
clearance_root = File.expand_path(File.dirname(__FILE__))
system("ln -s #{clearance_root} test/rails_root/vendor/plugins/clearance")
system("ln -s #{clearance_root} test/rails3_root/vendor/plugins/clearance")
end

desc "Run the clearance generator"
task :clearance do
system "cd test/rails_root && ./script/generate clearance -f && rake db:migrate db:test:prepare"
clearance_command = "cd test/rails3_root && ./script/rails generate clearance && rake db:migrate db:test:prepare"
p clearance_command
system clearance_command
end

desc "Run the clearance features generator"
task :clearance_features do
system "cd test/rails_root && ./script/generate clearance_features -f"
system "cd test/rails3_root && ./script/rails generate clearance_features"
end

desc "Run the clearance views generator"
task :clearance_views do
system "cd test/rails_root && ./script/generate clearance_views -f"
system "cd test/rails3_root && ./script/rails generate clearance_views"
end
end

Expand Down
70 changes: 70 additions & 0 deletions lib/rails/generators/clearance_generator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
require 'rails/generators/active_record'

class ClearanceGenerator < ActiveRecord::Generators::Base
desc "Setup the basic stuff needed for Clearance"

argument :name, :type => :string, :default => "migration_source_name"

def self.source_root
@_clearance_source_root ||= File.expand_path("../../../../../../../../../generators/clearance/templates", __FILE__)
end

def install
template "clearance.rb", "config/initializers/clearance.rb"

inject_into_class "app/controllers/application_controller.rb", ApplicationController do
" include Clearance::Authentication\n"
end

user_model = "app/models/user.rb"
if File.exists?(user_model)
inject_into_class user_model, User do
"include Clearance::User"
end
else
template "user.rb", user_model
end

route "Clearance::Routes.draw(map)"

template "factories.rb", "test/factories/clearance.rb"

migration_template "migrations/#{migration_source_name}.rb",
"db/migrate/clearance_#{migration_target_name}"

#readme "README"
end

private

def schema_version_constant
if upgrading_clearance_again?
"To#{schema_version.gsub('_', '')}"
end
end

def migration_source_name
if ActiveRecord::Base.connection.table_exists?(:users)
'update_users'
else
'create_users'
end
end

def migration_target_name
if upgrading_clearance_again?
"update_users_to_#{schema_version}"
else
'create_users'
end
end

def schema_version
IO.read(File.join(File.dirname(__FILE__), '..', '..', 'VERSION')).strip.gsub(/[^\d]/, '_')
end

def upgrading_clearance_again?
ActiveRecord::Base.connection.table_exists?(:users)
end

end
4 changes: 4 additions & 0 deletions test/rails3_root/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.bundle
db/*.sqlite3
log/*.log
tmp/**/*
36 changes: 36 additions & 0 deletions test/rails3_root/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
source 'http://rubygems.org'

gem 'rails', '3.0.0.beta3'

# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'

gem 'sqlite3-ruby', :require => 'sqlite3'

gem 'mocha'

gem 'formtastic', "1.0.0.beta", :git => "git://github.com/justinfrench/formtastic.git", :branch => "rails3"

gem 'shoulda', '>= 2.10.3', :git => "git://github.com/thoughtbot/shoulda.git", :branch => "master"
gem 'factory_girl', '>= 1.2.3', :git => "git://github.com/thoughtbot/factory_girl.git", :branch => "fixes_for_rails3"
gem 'nokogiri', '1.4.1'
gem 'cucumber-rails', '0.3.0'
gem 'webrat', '0.7.0'

# Use unicorn as the web server
# gem 'unicorn'

# Deploy with Capistrano
# gem 'capistrano'

# Bundle the extra gems:
# gem 'bj'
# gem 'nokogiri', '1.4.1'
# gem 'sqlite3-ruby', :require => 'sqlite3'
# gem 'aws-s3', :require => 'aws/s3'

# Bundle gems for certain environments:
# gem 'rspec', :group => :test
# group :test do
# gem 'webrat'
# end
Loading

0 comments on commit 395b589

Please sign in to comment.