rotten-rotten-generators 0.7.12
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +5 -0
- data/LICENSE +20 -0
- data/README.rdoc +10 -0
- data/Rakefile +56 -0
- data/VERSION +1 -0
- data/cucumber.yml +1 -0
- data/features/rotten.feature +9 -0
- data/features/step_definitions/rotten_steps.rb +0 -0
- data/features/support/env.rb +4 -0
- data/lib/rotten_generators.rb +3 -0
- data/rails_generators/rotten_authentication/lib/insert_commands.rb +74 -0
- data/rails_generators/rotten_authentication/rotten_authentication_generator.rb +102 -0
- data/rails_generators/rotten_authentication/templates/authentication.rb +37 -0
- data/rails_generators/rotten_authentication/templates/fixtures.yml +12 -0
- data/rails_generators/rotten_authentication/templates/migration.rb +15 -0
- data/rails_generators/rotten_authentication/templates/sessions_controller.rb +22 -0
- data/rails_generators/rotten_authentication/templates/sessions_helper.rb +2 -0
- data/rails_generators/rotten_authentication/templates/tests/rspec/sessions_controller.rb +25 -0
- data/rails_generators/rotten_authentication/templates/tests/rspec/user.rb +81 -0
- data/rails_generators/rotten_authentication/templates/tests/rspec/users_controller.rb +24 -0
- data/rails_generators/rotten_authentication/templates/user.rb +38 -0
- data/rails_generators/rotten_authentication/templates/users_controller.rb +16 -0
- data/rails_generators/rotten_authentication/templates/users_helper.rb +2 -0
- data/rails_generators/rotten_authentication/templates/views/haml/login.html.haml +15 -0
- data/rails_generators/rotten_authentication/templates/views/haml/signup.html.haml +24 -0
- data/rails_generators/rotten_controller/rotten_controller_generator.rb +52 -0
- data/rails_generators/rotten_controller/templates/controller.rb +38 -0
- data/rails_generators/rotten_controller/templates/controller_spec.rb +25 -0
- data/rails_generators/rotten_controller/templates/helper.rb +2 -0
- data/rails_generators/rotten_controller/templates/helper_spec.rb +11 -0
- data/rails_generators/rotten_controller/templates/view.html.haml +2 -0
- data/rails_generators/rotten_controller/templates/view_spec.rb +12 -0
- data/rails_generators/rotten_layout/USAGE +1 -0
- data/rails_generators/rotten_layout/rotten_layout_generator.rb +63 -0
- data/rails_generators/rotten_layout/templates/helper.rb +30 -0
- data/rails_generators/rotten_layout/templates/js/jquery-1.3.2.min.js +19 -0
- data/rails_generators/rotten_layout/templates/js/jquery-ui-1.7.2.min.js +298 -0
- data/rails_generators/rotten_layout/templates/layout.html.haml +45 -0
- data/rails_generators/rotten_layout/templates/one_column.html.haml +11 -0
- data/rails_generators/rotten_layout/templates/sass/colour.sass +1 -0
- data/rails_generators/rotten_layout/templates/sass/form.sass +1 -0
- data/rails_generators/rotten_layout/templates/sass/handheld.sass +1 -0
- data/rails_generators/rotten_layout/templates/sass/ie.sass +1 -0
- data/rails_generators/rotten_layout/templates/sass/layout.sass +1 -0
- data/rails_generators/rotten_layout/templates/sass/print.sass +1 -0
- data/rails_generators/rotten_layout/templates/sass/reset.sass +137 -0
- data/rails_generators/rotten_layout/templates/sass/screen.sass +5 -0
- data/rails_generators/rotten_layout/templates/sass/type.sass +1 -0
- data/rails_generators/rotten_layout/templates/shared_analytics.html.haml +10 -0
- data/rails_generators/rotten_layout/templates/shared_flash_messages.html.haml +12 -0
- data/rails_generators/rotten_layout/templates/shared_footer.html.haml +15 -0
- data/rails_generators/rotten_layout/templates/shared_header.html.haml +5 -0
- data/rails_generators/rotten_layout/templates/shared_navigation.html.haml +3 -0
- data/rails_generators/rotten_layout/templates/shared_sidebar.html.haml +13 -0
- data/rails_generators/rotten_layout/templates/two_column_left.html.haml +15 -0
- data/rails_generators/rotten_layout/templates/two_column_right.html.haml +14 -0
- data/rails_generators/rotten_scaffold/USAGE +48 -0
- data/rails_generators/rotten_scaffold/rotten_scaffold_generator.rb +204 -0
- data/rails_generators/rotten_scaffold/templates/actions/create.rb +9 -0
- data/rails_generators/rotten_scaffold/templates/actions/destroy.rb +6 -0
- data/rails_generators/rotten_scaffold/templates/actions/edit.rb +3 -0
- data/rails_generators/rotten_scaffold/templates/actions/index.rb +3 -0
- data/rails_generators/rotten_scaffold/templates/actions/new.rb +3 -0
- data/rails_generators/rotten_scaffold/templates/actions/show.rb +3 -0
- data/rails_generators/rotten_scaffold/templates/actions/update.rb +9 -0
- data/rails_generators/rotten_scaffold/templates/controller.rb +3 -0
- data/rails_generators/rotten_scaffold/templates/fixtures.yml +9 -0
- data/rails_generators/rotten_scaffold/templates/helper.rb +2 -0
- data/rails_generators/rotten_scaffold/templates/migration.rb +16 -0
- data/rails_generators/rotten_scaffold/templates/model.rb +2 -0
- data/rails_generators/rotten_scaffold/templates/tests/rspec/actions/create.rb +11 -0
- data/rails_generators/rotten_scaffold/templates/tests/rspec/actions/destroy.rb +6 -0
- data/rails_generators/rotten_scaffold/templates/tests/rspec/actions/edit.rb +4 -0
- data/rails_generators/rotten_scaffold/templates/tests/rspec/actions/index.rb +4 -0
- data/rails_generators/rotten_scaffold/templates/tests/rspec/actions/new.rb +4 -0
- data/rails_generators/rotten_scaffold/templates/tests/rspec/actions/show.rb +4 -0
- data/rails_generators/rotten_scaffold/templates/tests/rspec/actions/update.rb +11 -0
- data/rails_generators/rotten_scaffold/templates/tests/rspec/controller.rb +8 -0
- data/rails_generators/rotten_scaffold/templates/tests/rspec/model.rb +7 -0
- data/rails_generators/rotten_scaffold/templates/views/haml/_form.html.haml +14 -0
- data/rails_generators/rotten_scaffold/templates/views/haml/edit.html.haml +14 -0
- data/rails_generators/rotten_scaffold/templates/views/haml/index.html.haml +25 -0
- data/rails_generators/rotten_scaffold/templates/views/haml/new.html.haml +7 -0
- data/rails_generators/rotten_scaffold/templates/views/haml/show.html.haml +20 -0
- data/rotten-generators.gemspec +126 -0
- data/spec/rotten_spec.rb +7 -0
- data/spec/spec.opts +3 -0
- data/spec/spec_helper.rb +9 -0
- metadata +143 -0
data/.document
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Peter Coulton
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "rotten-generators"
|
8
|
+
gem.summary = "Collection of rails generators"
|
9
|
+
gem.email = "peter@petercoulton.com"
|
10
|
+
gem.homepage = "http://github.com/PeterCoulton/rotten-generators"
|
11
|
+
gem.authors = ["Peter Coulton"]
|
12
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
13
|
+
end
|
14
|
+
|
15
|
+
rescue LoadError
|
16
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
17
|
+
end
|
18
|
+
|
19
|
+
require 'spec/rake/spectask'
|
20
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
21
|
+
spec.libs << 'lib' << 'spec'
|
22
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
23
|
+
end
|
24
|
+
|
25
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
26
|
+
spec.libs << 'lib' << 'spec'
|
27
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
28
|
+
spec.rcov = true
|
29
|
+
end
|
30
|
+
|
31
|
+
begin
|
32
|
+
require 'cucumber/rake/task'
|
33
|
+
Cucumber::Rake::Task.new(:features)
|
34
|
+
rescue LoadError
|
35
|
+
task :features do
|
36
|
+
abort "Cucumber is not available. In order to run features, you must: sudo gem install cucumber"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
task :default => :spec
|
41
|
+
|
42
|
+
require 'rake/rdoctask'
|
43
|
+
Rake::RDocTask.new do |rdoc|
|
44
|
+
if File.exist?('VERSION.yml')
|
45
|
+
config = YAML.load(File.read('VERSION.yml'))
|
46
|
+
version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
|
47
|
+
else
|
48
|
+
version = ""
|
49
|
+
end
|
50
|
+
|
51
|
+
rdoc.rdoc_dir = 'rdoc'
|
52
|
+
rdoc.title = "rotten-generators #{version}"
|
53
|
+
rdoc.rdoc_files.include('README*')
|
54
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
55
|
+
end
|
56
|
+
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.7.12
|
data/cucumber.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
autotest: --format pretty features
|
File without changes
|
@@ -0,0 +1,74 @@
|
|
1
|
+
Rails::Generator::Commands::Create.class_eval do
|
2
|
+
def route_resource(*resources)
|
3
|
+
resource_list = resources.map { |r| r.to_sym.inspect }.join(', ')
|
4
|
+
sentinel = 'ActionController::Routing::Routes.draw do |map|'
|
5
|
+
|
6
|
+
logger.route "map.resource #{resource_list}"
|
7
|
+
unless options[:pretend]
|
8
|
+
gsub_file 'config/routes.rb', /(#{Regexp.escape(sentinel)})/mi do |match|
|
9
|
+
"#{match}\n map.resource #{resource_list}\n"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def route_name(name, path, route_options = {})
|
15
|
+
sentinel = 'ActionController::Routing::Routes.draw do |map|'
|
16
|
+
|
17
|
+
logger.route "map.#{name} '#{path}', :controller => '#{route_options[:controller]}', :action => '#{route_options[:action]}'"
|
18
|
+
unless options[:pretend]
|
19
|
+
gsub_file 'config/routes.rb', /(#{Regexp.escape(sentinel)})/mi do |match|
|
20
|
+
"#{match}\n map.#{name} '#{path}', :controller => '#{route_options[:controller]}', :action => '#{route_options[:action]}'"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def insert_into(file, line)
|
26
|
+
logger.insert "#{line} into #{file}"
|
27
|
+
unless options[:pretend]
|
28
|
+
gsub_file file, /^(class|module) .+$/ do |match|
|
29
|
+
"#{match}\n #{line}"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
Rails::Generator::Commands::Destroy.class_eval do
|
36
|
+
def route_resource(*resources)
|
37
|
+
resource_list = resources.map { |r| r.to_sym.inspect }.join(', ')
|
38
|
+
look_for = "\n map.resource #{resource_list}\n"
|
39
|
+
logger.route "map.resource #{resource_list}"
|
40
|
+
unless options[:pretend]
|
41
|
+
gsub_file 'config/routes.rb', /(#{look_for})/mi, ''
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def route_name(name, path, route_options = {})
|
46
|
+
look_for = "\n map.#{name} '#{path}', :controller => '#{route_options[:controller]}', :action => '#{route_options[:action]}'"
|
47
|
+
logger.route "map.#{name} '#{path}', :controller => '#{route_options[:controller]}', :action => '#{route_options[:action]}'"
|
48
|
+
unless options[:pretend]
|
49
|
+
gsub_file 'config/routes.rb', /(#{look_for})/mi, ''
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def insert_into(file, line)
|
54
|
+
logger.remove "#{line} from #{file}"
|
55
|
+
unless options[:pretend]
|
56
|
+
gsub_file file, "\n #{line}", ''
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
Rails::Generator::Commands::List.class_eval do
|
62
|
+
def route_resource(*resources)
|
63
|
+
resource_list = resources.map { |r| r.to_sym.inspect }.join(', ')
|
64
|
+
logger.route "map.resource #{resource_list}"
|
65
|
+
end
|
66
|
+
|
67
|
+
def route_name(name, path, options = {})
|
68
|
+
logger.route "map.#{name} '#{path}', :controller => '{options[:controller]}', :action => '#{options[:action]}'"
|
69
|
+
end
|
70
|
+
|
71
|
+
def insert_into(file, line)
|
72
|
+
logger.insert "#{line} into #{file}"
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/lib/insert_commands.rb")
|
2
|
+
|
3
|
+
class RottenAuthenticationGenerator < Rails::Generator::Base
|
4
|
+
attr_accessor :user_name, :sessions_name
|
5
|
+
|
6
|
+
def initialize(runtime_args, runtime_options = {})
|
7
|
+
super
|
8
|
+
|
9
|
+
@user_name = @args[0] || 'user'
|
10
|
+
@sessions_name = @args[1] || 'sessions'
|
11
|
+
end
|
12
|
+
|
13
|
+
def manifest
|
14
|
+
record do |m|
|
15
|
+
m.directory "app/models"
|
16
|
+
m.directory "app/controllers"
|
17
|
+
m.directory "app/helpers"
|
18
|
+
m.directory "app/views"
|
19
|
+
m.directory "lib"
|
20
|
+
|
21
|
+
m.directory "app/views/#{user_plural_name}"
|
22
|
+
m.template "user.rb", "app/models/#{user_singular_name}.rb"
|
23
|
+
m.template "users_controller.rb", "app/controllers/#{user_plural_name}_controller.rb"
|
24
|
+
m.template "users_helper.rb", "app/helpers/#{user_plural_name}_helper.rb"
|
25
|
+
m.template "views/#{view_language}/signup.html.#{view_language}", "app/views/#{user_plural_name}/new.html.#{view_language}"
|
26
|
+
|
27
|
+
m.directory "app/views/#{sessions_underscore_name}"
|
28
|
+
m.template "sessions_controller.rb", "app/controllers/#{sessions_underscore_name}_controller.rb"
|
29
|
+
m.template "sessions_helper.rb", "app/helpers/#{sessions_underscore_name}_helper.rb"
|
30
|
+
m.template "views/#{view_language}/login.html.#{view_language}", "app/views/#{sessions_underscore_name}/new.html.#{view_language}"
|
31
|
+
|
32
|
+
m.template "authentication.rb", "lib/authentication.rb"
|
33
|
+
m.migration_template "migration.rb", "db/migrate", :migration_file_name => "create_#{user_plural_name}"
|
34
|
+
|
35
|
+
m.route_resources user_plural_name
|
36
|
+
m.route_resources sessions_underscore_name
|
37
|
+
m.route_name :login, 'login', :controller => sessions_underscore_name, :action => 'new'
|
38
|
+
m.route_name :logout, 'logout', :controller => sessions_underscore_name, :action => 'destroy'
|
39
|
+
m.route_name :signup, 'signup', :controller => user_plural_name, :action => 'new'
|
40
|
+
|
41
|
+
m.insert_into "app/controllers/#{application_controller_name}.rb", 'include Authentication'
|
42
|
+
|
43
|
+
m.directory "spec"
|
44
|
+
m.directory "spec/fixtures"
|
45
|
+
m.directory "spec/controllers"
|
46
|
+
m.directory "spec/models"
|
47
|
+
m.template "fixtures.yml", "spec/fixtures/#{user_plural_name}.yml"
|
48
|
+
m.template "tests/rspec/user.rb", "spec/models/#{user_singular_name}_spec.rb"
|
49
|
+
m.template "tests/rspec/users_controller.rb", "spec/controllers/#{user_plural_name}_controller_spec.rb"
|
50
|
+
m.template "tests/rspec/sessions_controller.rb", "spec/controllers/#{sessions_underscore_name}_controller_spec.rb"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def user_singular_name
|
55
|
+
user_name.underscore
|
56
|
+
end
|
57
|
+
|
58
|
+
def user_plural_name
|
59
|
+
user_singular_name.pluralize
|
60
|
+
end
|
61
|
+
|
62
|
+
def user_class_name
|
63
|
+
user_name.camelize
|
64
|
+
end
|
65
|
+
|
66
|
+
def user_plural_class_name
|
67
|
+
user_plural_name.camelize
|
68
|
+
end
|
69
|
+
|
70
|
+
def sessions_underscore_name
|
71
|
+
sessions_name.underscore
|
72
|
+
end
|
73
|
+
|
74
|
+
def sessions_class_name
|
75
|
+
sessions_name.camelize
|
76
|
+
end
|
77
|
+
|
78
|
+
def application_controller_name
|
79
|
+
Rails.version >= '2.3.0' ? 'application_controller' : 'application'
|
80
|
+
end
|
81
|
+
|
82
|
+
protected
|
83
|
+
|
84
|
+
def view_language
|
85
|
+
'haml'
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_framework
|
89
|
+
:rspec
|
90
|
+
end
|
91
|
+
|
92
|
+
def add_options!(opt)
|
93
|
+
end
|
94
|
+
|
95
|
+
def banner
|
96
|
+
<<-EOS
|
97
|
+
Creates user model and controllers to handle registration and authentication.
|
98
|
+
|
99
|
+
USAGE: #{$0} #{spec.name} [user_name] [sessions_controller_name]
|
100
|
+
EOS
|
101
|
+
end
|
102
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# This module is included in your application controller which makes
|
2
|
+
# several methods available to all controllers and views. Here's a
|
3
|
+
# common example you might add to your application layout file.
|
4
|
+
#
|
5
|
+
# <%% if logged_in? %>
|
6
|
+
# Welcome <%%= current_user.username %>! Not you?
|
7
|
+
# <%%= link_to "Log out", logout_path %>
|
8
|
+
# <%% else %>
|
9
|
+
# <%%= link_to "Sign up", signup_path %> or
|
10
|
+
# <%%= link_to "log in", login_path %>.
|
11
|
+
# <%% end %>
|
12
|
+
#
|
13
|
+
# You can also restrict unregistered users from accessing a controller using
|
14
|
+
# a before filter. For example.
|
15
|
+
#
|
16
|
+
# before_filter :login_required, :except => [:index, :show]
|
17
|
+
module Authentication
|
18
|
+
def self.included(controller)
|
19
|
+
controller.send :helper_method, :current_<%= user_singular_name %>, :logged_in?
|
20
|
+
controller.filter_parameter_logging :password
|
21
|
+
end
|
22
|
+
|
23
|
+
def current_<%= user_singular_name %>
|
24
|
+
@current_<%= user_singular_name %> ||= <%= user_class_name %>.find(session[:<%= user_singular_name %>_id]) if session[:<%= user_singular_name %>_id]
|
25
|
+
end
|
26
|
+
|
27
|
+
def logged_in?
|
28
|
+
current_<%= user_singular_name %>
|
29
|
+
end
|
30
|
+
|
31
|
+
def login_required
|
32
|
+
unless logged_in?
|
33
|
+
flash[:error] = "You must first log in or sign up before accessing this page."
|
34
|
+
redirect_to login_url
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# password: "secret"
|
2
|
+
one:
|
3
|
+
username: foo
|
4
|
+
email: foo@example.com
|
5
|
+
password_hash: 3488f5f7efecab14b91eb96169e5e1ee518a569f
|
6
|
+
password_salt: bef65e058905c379436d80d1a32e7374b139e7b0
|
7
|
+
|
8
|
+
two:
|
9
|
+
username: bar
|
10
|
+
email: bar@example.com
|
11
|
+
password_hash: 3488f5f7efecab14b91eb96169e5e1ee518a569f
|
12
|
+
password_salt: bef65e058905c379436d80d1a32e7374b139e7b0
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class Create<%= user_plural_class_name %> < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :<%= user_plural_name %> do |t|
|
4
|
+
t.column :username, :string
|
5
|
+
t.column :email, :string
|
6
|
+
t.column :password_hash, :string
|
7
|
+
t.column :password_salt, :string
|
8
|
+
t.timestamps
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.down
|
13
|
+
drop_table :<%= user_plural_name %>
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
class <%= sessions_class_name %>Controller < ApplicationController
|
2
|
+
def new
|
3
|
+
end
|
4
|
+
|
5
|
+
def create
|
6
|
+
<%= user_singular_name %> = <%= user_class_name %>.authenticate(params[:login], params[:password])
|
7
|
+
if <%= user_singular_name %>
|
8
|
+
session[:<%= user_singular_name %>_id] = <%= user_singular_name %>.id
|
9
|
+
flash[:notice] = "Logged in successfully."
|
10
|
+
redirect_to root_url
|
11
|
+
else
|
12
|
+
flash.now[:error] = "Invalid login or password."
|
13
|
+
render :action => 'new'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def destroy
|
18
|
+
session[:<%= user_singular_name %>_id] = nil
|
19
|
+
flash[:notice] = "You have been logged out."
|
20
|
+
redirect_to root_url
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe <%= sessions_class_name %>Controller do
|
4
|
+
fixtures :all
|
5
|
+
integrate_views
|
6
|
+
|
7
|
+
it "new action should render new template" do
|
8
|
+
get :new
|
9
|
+
response.should render_template(:new)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "create action should render new template when authentication is invalid" do
|
13
|
+
<%= user_class_name %>.stubs(:authenticate).returns(nil)
|
14
|
+
post :create
|
15
|
+
response.should render_template(:new)
|
16
|
+
session['<%= user_singular_name %>_id'].should be_nil
|
17
|
+
end
|
18
|
+
|
19
|
+
it "create action should redirect when authentication is valid" do
|
20
|
+
<%= user_class_name %>.stubs(:authenticate).returns(<%= user_class_name %>.first)
|
21
|
+
post :create
|
22
|
+
response.should redirect_to(root_url)
|
23
|
+
session['<%= user_singular_name %>_id'].should == <%= user_class_name %>.first.id
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe <%= user_class_name %> do
|
4
|
+
def new_<%= user_singular_name %>(attributes = {})
|
5
|
+
attributes[:username] ||= 'foo'
|
6
|
+
attributes[:email] ||= 'foo@example.com'
|
7
|
+
attributes[:password] ||= 'abc123'
|
8
|
+
attributes[:password_confirmation] ||= attributes[:password]
|
9
|
+
<%= user_class_name %>.new(attributes)
|
10
|
+
end
|
11
|
+
|
12
|
+
before(:each) do
|
13
|
+
<%= user_class_name %>.delete_all
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should be valid" do
|
17
|
+
new_<%= user_singular_name %>.should be_valid
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should require username" do
|
21
|
+
new_<%= user_singular_name %>(:username => '').should have(1).error_on(:username)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should require password" do
|
25
|
+
new_<%= user_singular_name %>(:password => '').should have(1).error_on(:password)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should require well formed email" do
|
29
|
+
new_<%= user_singular_name %>(:email => 'foo@bar@example.com').should have(1).error_on(:email)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should validate uniqueness of email" do
|
33
|
+
new_<%= user_singular_name %>(:email => 'bar@example.com').save!
|
34
|
+
new_<%= user_singular_name %>(:email => 'bar@example.com').should have(1).error_on(:email)
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should validate uniqueness of username" do
|
38
|
+
new_<%= user_singular_name %>(:username => 'uniquename').save!
|
39
|
+
new_<%= user_singular_name %>(:username => 'uniquename').should have(1).error_on(:username)
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should not allow odd characters in username" do
|
43
|
+
new_<%= user_singular_name %>(:username => 'odd ^&(@)').should have(1).error_on(:username)
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should validate password is longer than 3 characters" do
|
47
|
+
new_<%= user_singular_name %>(:password => 'bad').should have(1).error_on(:password)
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should require matching password confirmation" do
|
51
|
+
new_<%= user_singular_name %>(:password_confirmation => 'nonmatching').should have(1).error_on(:password)
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should generate password hash and salt on create" do
|
55
|
+
<%= user_singular_name %> = new_<%= user_singular_name %>
|
56
|
+
<%= user_singular_name %>.save!
|
57
|
+
<%= user_singular_name %>.password_hash.should_not be_nil
|
58
|
+
<%= user_singular_name %>.password_salt.should_not be_nil
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should authenticate by username" do
|
62
|
+
<%= user_singular_name %> = new_<%= user_singular_name %>(:username => 'foobar', :password => 'secret')
|
63
|
+
<%= user_singular_name %>.save!
|
64
|
+
<%= user_class_name %>.authenticate('foobar', 'secret').should == <%= user_singular_name %>
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should authenticate by email" do
|
68
|
+
<%= user_singular_name %> = new_<%= user_singular_name %>(:email => 'foo@bar.com', :password => 'secret')
|
69
|
+
<%= user_singular_name %>.save!
|
70
|
+
<%= user_class_name %>.authenticate('foo@bar.com', 'secret').should == <%= user_singular_name %>
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should not authenticate bad username" do
|
74
|
+
<%= user_class_name %>.authenticate('nonexisting', 'secret').should be_nil
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should not authenticate bad password" do
|
78
|
+
new_<%= user_singular_name %>(:username => 'foobar', :password => 'secret').save!
|
79
|
+
<%= user_class_name %>.authenticate('foobar', 'badpassword').should be_nil
|
80
|
+
end
|
81
|
+
end
|