Skip to content

Commit

Permalink
Fixed usage of jeweler... maybe.
Browse files Browse the repository at this point in the history
  • Loading branch information
technicalpickles committed Oct 12, 2008
2 parents 7e2ff34 + ab71c63 commit d582bed
Show file tree
Hide file tree
Showing 17 changed files with 78 additions and 102 deletions.
5 changes: 0 additions & 5 deletions README.textile
Expand Up @@ -121,11 +121,6 @@ h2. Routes

map.root :controller => 'sessions', :action => 'new'

map.with_options :controller => 'sessions' do |m|
m.login '/login', :action => 'new'
m.logout '/logout', :action => 'destroy'
end

end

h2. Environments
Expand Down
94 changes: 33 additions & 61 deletions Rakefile
@@ -1,85 +1,57 @@
require 'rake'
require 'rake/testtask'
require 'date'
require 'lib/clearance/version'


test_files_pattern = 'test/rails_root/test/{unit,functional,other}/**/*_test.rb'
Rake::TestTask.new do |t|
t.libs << 'lib'
t.pattern = test_files_pattern
t.verbose = false
end

desc "Run the test suite"
task :default => :test

spec = Gem::Specification.new do |s|
s.name = "clearance"

s.summary = "Simple, complete Rails authentication."
s.email = "dcroak@thoughtbot.com"
s.homepage = "http://github.com/thoughtbot/clearance"
s.description = "Simple, complete Rails authentication scheme."
s.authors = ["thoughtbot, inc.", "Dan Croak", "Josh Nichols", "Mike Breen", "Mike Burns", "Jason Morrison"]
s.files = FileList["[A-Z]*", "{generators,lib,test}/**/*"]
end

desc "Generate a gemspec file for GitHub"
task :gemspec => 'version:calculate' do
date = DateTime.now
spec.date = "#{date.year}-#{date.month}-#{date.day}"

File.open("#{spec.name}.gemspec", 'w') do |f|
f.write spec.to_ruby
end
end

desc "Displays the current version"
task :version => 'version:calculate' do
puts spec.version
end

namespace :version do
desc "Determine's the version based on Clearance::Version"
task :calculate do
spec.version ||= "#{Clearance::Version::MAJOR}.#{Clearance::Version::MINOR}.#{Clearance::Version::PATCH}"
end

namespace :bump do
def bump_gemspec(spec, major, minor, patch)
File.open("lib/clearance/version.rb", 'w') do |file|
file.write <<-END
module Clearance
module Version
MAJOR = #{major}
MINOR = #{minor}
PATCH = #{patch}
end

begin
require 'jeweler'
Jeweler.gemspec = spec
rescue LoadError
puts "Jeweler not available. Try installing technicalpickles-jeweler."
end
END
end

spec.version = "#{major}.#{minor}.#{patch}"
Rake::Task["gemspec"].invoke
puts "Gem bumped to #{spec.version}"
end

desc "Bump the gemspec a major version."
task :major do
major = Clearance::Version::MAJOR + 1
bump_gemspec(spec, major, 0, 0)
end

desc "Bump the gemspec a minor version."
task :minor do
minor = Clearance::Version::MINOR + 1
bump_gemspec(spec, Clearance::Version::MAJOR, minor, 0)

namespace :generator do
task :templates do
app_files = FileList["test/rails_root/app/{controllers,models,views}/**/*"]
app_files.reject! { |file| file.include?("test/rails_root/app/views/layouts") }
test_files = FileList["test/rails_root/test/{functional,unit}/**/*"]
test_files += ["test/rails_root/test/factories.rb"]
files = test_files + app_files
templates_path = "generators/clearance/templates"
system `rm -rf #{templates_path}`
system `mkdir #{templates_path}`
["app", "app/controllers", "app/models", "app/views",
"test", "test/functional", "test/unit"].each do |directory|
system `mkdir #{templates_path}/#{directory}`
end

desc "Bump the gemspec a patch version."
task :patch do
patch = Clearance::Version::PATCH + 1
bump_gemspec(spec, Clearance::Version::MAJOR, Clearance::Version::MINOR, patch)
files.each do |file|
template = "generators/clearance/templates/#{file.gsub("test/rails_root/", "")}"
if File.directory?(file)
system `rm -rf #{template}`
system `mkdir #{template}`
else
system `rm #{template}` if File.exists?(template)
system `cp #{file} #{template}`
end
end
end
end
end
1 change: 0 additions & 1 deletion TODO.textile
Expand Up @@ -4,7 +4,6 @@
# sessions controller test is missing some tests
# mailers should not hardcode example.com as from address
# check to make sure attr_accessible doesn't override and w/ attr_protected
# helpers and tests shouldn't depend on login/logout routes
# move shoulda macros in test_helper to shoulda_macros folder
# add shoulda and factory girl dependencies to gemspec
# refactor Mailer default_url_options[:host] to something cleaner
Expand Down
6 changes: 3 additions & 3 deletions clearance.gemspec

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion generators/clearance/clearance_generator.rb
Expand Up @@ -17,7 +17,7 @@ def manifest
end

m.directory File.join("app", "views")
system `mkdir app/views/confirmations`
m.directory File.join("app", "views", "confirmations")
["app/views/confirmations/new.html.erb"].each do |file|
m.file file, file
end
Expand Down
5 changes: 5 additions & 0 deletions generators/clearance/templates/app/controllers/application.rb
@@ -0,0 +1,5 @@
class ApplicationController < ActionController::Base
helper :all
protect_from_forgery
include Clearance::ApplicationController
end
Expand Up @@ -14,4 +14,7 @@
<div class="group buttons">
<%= form.submit 'Login', :disable_with => 'Please wait...' %>
</div>
<% end %>
<% end %>

<p><%= link_to "Sign up", new_user_path %></p>
<p><%= link_to "Forgot My Password", new_password_path %></p>
2 changes: 1 addition & 1 deletion generators/clearance/templates/test/factories.rb
Expand Up @@ -6,4 +6,4 @@
user.email { Factory.next :email }
user.password "password"
user.password_confirmation "password"
end
end
5 changes: 5 additions & 0 deletions generators/clearance/templates/test/unit/user_test.rb
@@ -0,0 +1,5 @@
require File.dirname(__FILE__) + '/../test_helper'

class UserTest < Test::Unit::TestCase
include Clearance::UserTest
end
2 changes: 1 addition & 1 deletion lib/clearance/app/controllers/application_controller.rb
Expand Up @@ -60,7 +60,7 @@ def store_location
end

def deny_access(flash_message = nil, opts = {})
opts[:redirect] ||= login_url
opts[:redirect] ||= new_session_url
store_location
flash[:error] = flash_message if flash_message
redirect_to opts[:redirect]
Expand Down
2 changes: 1 addition & 1 deletion lib/clearance/app/controllers/passwords_controller.rb
Expand Up @@ -22,7 +22,7 @@ def create
render :action => :new
else
UserMailer.deliver_change_password user
redirect_to login_path
redirect_to new_session_url
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/clearance/app/controllers/sessions_controller.rb
Expand Up @@ -66,7 +66,7 @@ def url_after_create
end

def url_after_destroy
login_url
new_session_url
end
end
end
Expand Down
8 changes: 4 additions & 4 deletions lib/clearance/app/controllers/users_controller.rb
Expand Up @@ -22,9 +22,9 @@ def new
def create
@user = user_model.new params[:user]
if @user.save
current_user = @user
flash[:notice] = "User created and logged in."
redirect_back_or root_url
UserMailer.deliver_confirmation @user
flash[:notice] = "You will receive an email within the next few minutes. It contains instructions to confirm your account."
redirect_to new_session_url
else
render :action => "new"
end
Expand All @@ -34,7 +34,7 @@ def create
module PrivateInstanceMethods

def url_after_create
root_url
new_session_url
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/clearance/test/functionals/users_controller_test.rb
Expand Up @@ -38,7 +38,7 @@ def self.included(base)
}
end

should_set_the_flash_to /created/i
should_set_the_flash_to /confirm/i
should_redirect_to "@controller.send(:url_after_create)"
should_assign_to :user
should_change 'User.count', :by => 1
Expand Down
2 changes: 1 addition & 1 deletion lib/clearance/version.rb
Expand Up @@ -2,6 +2,6 @@ module Clearance
module Version
MAJOR = 0
MINOR = 2
PATCH = 3
PATCH = 6
end
end
5 changes: 4 additions & 1 deletion test/rails_root/app/views/sessions/new.html.erb
Expand Up @@ -14,4 +14,7 @@
<div class="group buttons">
<%= form.submit 'Login', :disable_with => 'Please wait...' %>
</div>
<% end %>
<% end %>

<p><%= link_to "Sign up", new_user_path %></p>
<p><%= link_to "Forgot My Password", new_password_path %></p>
32 changes: 13 additions & 19 deletions test/rails_root/config/routes.rb
@@ -1,19 +1,13 @@
ActionController::Routing::Routes.draw do |map|

map.resources :users
map.resource :session

map.resources :users, :has_one => :password
map.resources :users, :has_one => :confirmation

map.resources :passwords

map.root :controller => 'sessions', :action => 'new'

map.with_options :controller => 'sessions' do |m|
m.login '/login', :action => 'new'
m.logout '/logout', :action => 'destroy'
end

end

ActionController::Routing::Routes.draw do |map|

map.resources :users
map.resource :session

map.resources :users, :has_one => :password
map.resources :users, :has_one => :confirmation

map.resources :passwords

map.root :controller => 'sessions', :action => 'new'

end

0 comments on commit d582bed

Please sign in to comment.