nifty-generators 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. data/CHANGELOG +11 -0
  2. data/README.rdoc +2 -2
  3. data/features/nifty_authentication.feature +2 -2
  4. data/features/nifty_scaffold.feature +15 -0
  5. data/features/step_definitions/common_steps.rb +1 -1
  6. data/features/step_definitions/rails_setup_steps.rb +1 -1
  7. data/lib/generators/nifty.rb +2 -2
  8. data/lib/generators/nifty/authentication/USAGE +15 -15
  9. data/lib/generators/nifty/authentication/authentication_generator.rb +10 -9
  10. data/lib/generators/nifty/authentication/templates/authentication.rb +9 -9
  11. data/lib/generators/nifty/authentication/templates/migration.rb +1 -1
  12. data/lib/generators/nifty/authentication/templates/sessions_controller.rb +4 -4
  13. data/lib/generators/nifty/authentication/templates/tests/rspec/sessions_controller.rb +6 -6
  14. data/lib/generators/nifty/authentication/templates/tests/rspec/user.rb +15 -15
  15. data/lib/generators/nifty/authentication/templates/tests/rspec/users_controller.rb +5 -5
  16. data/lib/generators/nifty/authentication/templates/tests/shoulda/sessions_controller.rb +3 -3
  17. data/lib/generators/nifty/authentication/templates/tests/shoulda/user.rb +15 -15
  18. data/lib/generators/nifty/authentication/templates/tests/shoulda/users_controller.rb +2 -2
  19. data/lib/generators/nifty/authentication/templates/tests/testunit/sessions_controller.rb +3 -3
  20. data/lib/generators/nifty/authentication/templates/tests/testunit/user.rb +15 -15
  21. data/lib/generators/nifty/authentication/templates/tests/testunit/users_controller.rb +2 -2
  22. data/lib/generators/nifty/authentication/templates/user.rb +7 -7
  23. data/lib/generators/nifty/authentication/templates/users_controller.rb +1 -1
  24. data/lib/generators/nifty/config/USAGE +2 -2
  25. data/lib/generators/nifty/config/config_generator.rb +3 -3
  26. data/lib/generators/nifty/layout/USAGE +2 -2
  27. data/lib/generators/nifty/layout/layout_generator.rb +4 -4
  28. data/lib/generators/nifty/layout/templates/error_messages_helper.rb +2 -2
  29. data/lib/generators/nifty/layout/templates/layout.html.erb +1 -1
  30. data/lib/generators/nifty/layout/templates/layout.html.haml +4 -4
  31. data/lib/generators/nifty/layout/templates/layout_helper.rb +3 -3
  32. data/lib/generators/nifty/layout/templates/stylesheet.sass +41 -41
  33. data/lib/generators/nifty/scaffold/USAGE +9 -9
  34. data/lib/generators/nifty/scaffold/scaffold_generator.rb +8 -6
  35. data/lib/generators/nifty/scaffold/templates/migration.rb +1 -1
  36. data/lib/generators/nifty/scaffold/templates/tests/rspec/actions/create.rb +1 -1
  37. data/lib/generators/nifty/scaffold/templates/tests/rspec/actions/update.rb +1 -1
  38. data/lib/generators/nifty/scaffold/templates/tests/rspec/controller.rb +3 -3
  39. data/lib/generators/nifty/scaffold/templates/tests/shoulda/actions/create.rb +1 -1
  40. data/lib/generators/nifty/scaffold/templates/tests/shoulda/actions/update.rb +1 -1
  41. data/lib/generators/nifty/scaffold/templates/tests/testunit/actions/create.rb +1 -1
  42. data/lib/generators/nifty/scaffold/templates/tests/testunit/actions/update.rb +1 -1
  43. data/rails_generators/nifty_authentication/USAGE +15 -15
  44. data/rails_generators/nifty_authentication/lib/insert_commands.rb +8 -8
  45. data/rails_generators/nifty_authentication/nifty_authentication_generator.rb +20 -20
  46. data/rails_generators/nifty_authentication/templates/authentication.rb +9 -9
  47. data/rails_generators/nifty_authentication/templates/migration.rb +1 -1
  48. data/rails_generators/nifty_authentication/templates/sessions_controller.rb +4 -4
  49. data/rails_generators/nifty_authentication/templates/tests/rspec/sessions_controller.rb +5 -5
  50. data/rails_generators/nifty_authentication/templates/tests/rspec/user.rb +15 -15
  51. data/rails_generators/nifty_authentication/templates/tests/rspec/users_controller.rb +4 -4
  52. data/rails_generators/nifty_authentication/templates/tests/shoulda/sessions_controller.rb +3 -3
  53. data/rails_generators/nifty_authentication/templates/tests/shoulda/user.rb +15 -15
  54. data/rails_generators/nifty_authentication/templates/tests/shoulda/users_controller.rb +2 -2
  55. data/rails_generators/nifty_authentication/templates/tests/testunit/sessions_controller.rb +3 -3
  56. data/rails_generators/nifty_authentication/templates/tests/testunit/user.rb +15 -15
  57. data/rails_generators/nifty_authentication/templates/tests/testunit/users_controller.rb +2 -2
  58. data/rails_generators/nifty_authentication/templates/user.rb +7 -7
  59. data/rails_generators/nifty_authentication/templates/users_controller.rb +1 -1
  60. data/rails_generators/nifty_config/USAGE +2 -2
  61. data/rails_generators/nifty_config/nifty_config_generator.rb +3 -3
  62. data/rails_generators/nifty_layout/USAGE +2 -2
  63. data/rails_generators/nifty_layout/nifty_layout_generator.rb +3 -3
  64. data/rails_generators/nifty_layout/templates/helper.rb +3 -3
  65. data/rails_generators/nifty_layout/templates/layout.html.erb +2 -2
  66. data/rails_generators/nifty_layout/templates/layout.html.haml +4 -4
  67. data/rails_generators/nifty_scaffold/USAGE +9 -9
  68. data/rails_generators/nifty_scaffold/nifty_scaffold_generator.rb +38 -38
  69. data/rails_generators/nifty_scaffold/templates/migration.rb +1 -1
  70. data/rails_generators/nifty_scaffold/templates/tests/rspec/actions/create.rb +1 -1
  71. data/rails_generators/nifty_scaffold/templates/tests/rspec/actions/update.rb +1 -1
  72. data/rails_generators/nifty_scaffold/templates/tests/rspec/controller.rb +2 -2
  73. data/rails_generators/nifty_scaffold/templates/tests/shoulda/actions/create.rb +1 -1
  74. data/rails_generators/nifty_scaffold/templates/tests/shoulda/actions/update.rb +1 -1
  75. data/rails_generators/nifty_scaffold/templates/tests/testunit/actions/create.rb +1 -1
  76. data/rails_generators/nifty_scaffold/templates/tests/testunit/actions/update.rb +1 -1
  77. data/test/test_helper.rb +7 -7
  78. data/test/test_nifty_authentication_generator.rb +30 -30
  79. data/test/test_nifty_config_generator.rb +4 -4
  80. data/test/test_nifty_layout_generator.rb +5 -5
  81. data/test/test_nifty_scaffold_generator.rb +93 -93
  82. metadata +6 -4
@@ -1,14 +1,14 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + "/lib/insert_commands.rb")
2
2
  class NiftyAuthenticationGenerator < Rails::Generator::Base
3
3
  attr_accessor :user_name, :session_name
4
-
4
+
5
5
  def initialize(runtime_args, runtime_options = {})
6
6
  super
7
-
7
+
8
8
  @user_name = @args[0] || 'user'
9
9
  @session_name = @args[1] || (options[:authlogic] ? @user_name + '_session' : 'session')
10
10
  end
11
-
11
+
12
12
  def manifest
13
13
  record do |m|
14
14
  m.directory "app/models"
@@ -16,30 +16,30 @@ class NiftyAuthenticationGenerator < Rails::Generator::Base
16
16
  m.directory "app/helpers"
17
17
  m.directory "app/views"
18
18
  m.directory "lib"
19
-
19
+
20
20
  m.directory "app/views/#{user_plural_name}"
21
21
  m.template "user.rb", "app/models/#{user_singular_name}.rb"
22
22
  m.template "authlogic_session.rb", "app/models/#{session_singular_name}.rb" if options[:authlogic]
23
23
  m.template "users_controller.rb", "app/controllers/#{user_plural_name}_controller.rb"
24
24
  m.template "users_helper.rb", "app/helpers/#{user_plural_name}_helper.rb"
25
25
  m.template "views/#{view_language}/signup.html.#{view_language}", "app/views/#{user_plural_name}/new.html.#{view_language}"
26
-
26
+
27
27
  m.directory "app/views/#{session_plural_name}"
28
28
  m.template "sessions_controller.rb", "app/controllers/#{session_plural_name}_controller.rb"
29
29
  m.template "sessions_helper.rb", "app/helpers/#{session_plural_name}_helper.rb"
30
30
  m.template "views/#{view_language}/login.html.#{view_language}", "app/views/#{session_plural_name}/new.html.#{view_language}"
31
-
31
+
32
32
  m.template "authentication.rb", "lib/authentication.rb"
33
33
  m.migration_template "migration.rb", "db/migrate", :migration_file_name => "create_#{user_plural_name}"
34
-
34
+
35
35
  m.route_resources user_plural_name
36
36
  m.route_resources session_plural_name
37
37
  m.route_name :login, 'login', :controller => session_plural_name, :action => 'new'
38
38
  m.route_name :logout, 'logout', :controller => session_plural_name, :action => 'destroy'
39
39
  m.route_name :signup, 'signup', :controller => user_plural_name, :action => 'new'
40
-
40
+
41
41
  m.insert_into "app/controllers/#{application_controller_name}.rb", 'include Authentication'
42
-
42
+
43
43
  if test_framework == :rspec
44
44
  m.directory "spec"
45
45
  m.directory "spec/fixtures"
@@ -61,11 +61,11 @@ class NiftyAuthenticationGenerator < Rails::Generator::Base
61
61
  end
62
62
  end
63
63
  end
64
-
64
+
65
65
  def user_singular_name
66
66
  user_name.underscore
67
67
  end
68
-
68
+
69
69
  def user_plural_name
70
70
  user_singular_name.pluralize
71
71
  end
@@ -73,15 +73,15 @@ class NiftyAuthenticationGenerator < Rails::Generator::Base
73
73
  def user_class_name
74
74
  user_name.camelize
75
75
  end
76
-
76
+
77
77
  def user_plural_class_name
78
78
  user_plural_name.camelize
79
79
  end
80
-
80
+
81
81
  def session_singular_name
82
82
  session_name.underscore
83
83
  end
84
-
84
+
85
85
  def session_plural_name
86
86
  session_singular_name.pluralize
87
87
  end
@@ -89,25 +89,25 @@ class NiftyAuthenticationGenerator < Rails::Generator::Base
89
89
  def session_class_name
90
90
  session_name.camelize
91
91
  end
92
-
92
+
93
93
  def session_plural_class_name
94
94
  session_plural_name.camelize
95
95
  end
96
-
96
+
97
97
  def application_controller_name
98
98
  Rails.version >= '2.3.0' ? 'application_controller' : 'application'
99
99
  end
100
100
 
101
101
  protected
102
-
102
+
103
103
  def view_language
104
104
  options[:haml] ? 'haml' : 'erb'
105
105
  end
106
-
106
+
107
107
  def test_framework
108
108
  options[:test_framework] ||= File.exist?(destination_path("spec")) ? :rspec : :testunit
109
109
  end
110
-
110
+
111
111
  def add_options!(opt)
112
112
  opt.separator ''
113
113
  opt.separator 'Options:'
@@ -117,7 +117,7 @@ protected
117
117
  opt.on("--haml", "Generate HAML views instead of ERB.") { |v| options[:haml] = true }
118
118
  opt.on("--authlogic", "Use Authlogic for authentication.") { |v| options[:authlogic] = true }
119
119
  end
120
-
120
+
121
121
  def banner
122
122
  <<-EOS
123
123
  Creates user model and controllers to handle registration and authentication.
@@ -1,7 +1,7 @@
1
1
  # This module is included in your application controller which makes
2
2
  # several methods available to all controllers and views. Here's a
3
3
  # common example you might add to your application layout file.
4
- #
4
+ #
5
5
  # <%% if logged_in? %>
6
6
  # Welcome <%%=h current_<%= user_singular_name %>.username %>! Not you?
7
7
  # <%%= link_to "Log out", logout_path %>
@@ -9,17 +9,17 @@
9
9
  # <%%= link_to "Sign up", signup_path %> or
10
10
  # <%%= link_to "log in", login_path %>.
11
11
  # <%% end %>
12
- #
12
+ #
13
13
  # You can also restrict unregistered users from accessing a controller using
14
14
  # a before filter. For example.
15
- #
15
+ #
16
16
  # before_filter :login_required, :except => [:index, :show]
17
17
  module Authentication
18
18
  def self.included(controller)
19
19
  controller.send :helper_method, :current_<%= user_singular_name %>, :logged_in?, :redirect_to_target_or_default
20
20
  controller.filter_parameter_logging :password
21
21
  end
22
-
22
+
23
23
  <%- if options[:authlogic] -%>
24
24
  def current_<%= session_singular_name %>
25
25
  return @current_<%= session_singular_name %> if defined?(@current_<%= session_singular_name %>)
@@ -35,11 +35,11 @@ module Authentication
35
35
  @current_<%= user_singular_name %> ||= <%= user_class_name %>.find(session[:<%= user_singular_name %>_id]) if session[:<%= user_singular_name %>_id]
36
36
  end
37
37
  <%- end -%>
38
-
38
+
39
39
  def logged_in?
40
40
  current_<%= user_singular_name %>
41
41
  end
42
-
42
+
43
43
  def login_required
44
44
  unless logged_in?
45
45
  flash[:error] = "You must first log in or sign up before accessing this page."
@@ -47,14 +47,14 @@ module Authentication
47
47
  redirect_to login_url
48
48
  end
49
49
  end
50
-
50
+
51
51
  def redirect_to_target_or_default(default)
52
52
  redirect_to(session[:return_to] || default)
53
53
  session[:return_to] = nil
54
54
  end
55
-
55
+
56
56
  private
57
-
57
+
58
58
  def store_target_location
59
59
  session[:return_to] = request.request_uri
60
60
  end
@@ -13,7 +13,7 @@ class Create<%= user_plural_class_name %> < ActiveRecord::Migration
13
13
  t.timestamps
14
14
  end
15
15
  end
16
-
16
+
17
17
  def self.down
18
18
  drop_table :<%= user_plural_name %>
19
19
  end
@@ -3,7 +3,7 @@ class <%= session_plural_class_name %>Controller < ApplicationController
3
3
  def new
4
4
  @<%= session_singular_name %> = <%= session_class_name %>.new
5
5
  end
6
-
6
+
7
7
  def create
8
8
  @<%= session_singular_name %> = <%= session_class_name %>.new(params[:<%= session_singular_name %>])
9
9
  if @<%= session_singular_name %>.save
@@ -13,7 +13,7 @@ class <%= session_plural_class_name %>Controller < ApplicationController
13
13
  render :action => 'new'
14
14
  end
15
15
  end
16
-
16
+
17
17
  def destroy
18
18
  @<%= session_singular_name %> = <%= session_class_name %>.find
19
19
  @<%= session_singular_name %>.destroy
@@ -23,7 +23,7 @@ class <%= session_plural_class_name %>Controller < ApplicationController
23
23
  <%- else -%>
24
24
  def new
25
25
  end
26
-
26
+
27
27
  def create
28
28
  <%= user_singular_name %> = <%= user_class_name %>.authenticate(params[:login], params[:password])
29
29
  if <%= user_singular_name %>
@@ -35,7 +35,7 @@ class <%= session_plural_class_name %>Controller < ApplicationController
35
35
  render :action => 'new'
36
36
  end
37
37
  end
38
-
38
+
39
39
  def destroy
40
40
  session[:<%= user_singular_name %>_id] = nil
41
41
  flash[:notice] = "You have been logged out."
@@ -1,21 +1,21 @@
1
1
  require File.dirname(__FILE__) + '/../spec_helper'
2
-
2
+
3
3
  describe <%= session_plural_class_name %>Controller do
4
4
  fixtures :all
5
5
  integrate_views
6
-
6
+
7
7
  it "new action should render new template" do
8
8
  get :new
9
9
  response.should render_template(:new)
10
10
  end
11
-
11
+
12
12
  <%- if options[:authlogic] -%>
13
13
  it "create action should render new template when authentication is invalid" do
14
14
  post :create, :<%= session_singular_name %> => { :username => "foo", :password => "badpassword" }
15
15
  response.should render_template(:new)
16
16
  <%= session_class_name %>.find.should be_nil
17
17
  end
18
-
18
+
19
19
  it "create action should redirect when authentication is valid" do
20
20
  post :create, :<%= session_singular_name %> => { :username => "foo", :password => "secret" }
21
21
  response.should redirect_to(root_url)
@@ -28,7 +28,7 @@ describe <%= session_plural_class_name %>Controller do
28
28
  response.should render_template(:new)
29
29
  session['<%= user_singular_name %>_id'].should be_nil
30
30
  end
31
-
31
+
32
32
  it "create action should redirect when authentication is valid" do
33
33
  <%= user_class_name %>.stubs(:authenticate).returns(<%= user_class_name %>.first)
34
34
  post :create
@@ -9,72 +9,72 @@ describe <%= user_class_name %> do
9
9
  attributes[:password_confirmation] ||= attributes[:password]
10
10
  <%= user_class_name %>.new(attributes)
11
11
  end
12
-
12
+
13
13
  before(:each) do
14
14
  <%= user_class_name %>.delete_all
15
15
  end
16
-
16
+
17
17
  it "should be valid" do
18
18
  new_<%= user_singular_name %>.should be_valid
19
19
  end
20
-
20
+
21
21
  it "should require username" do
22
22
  new_<%= user_singular_name %>(:username => '').should have(1).error_on(:username)
23
23
  end
24
-
24
+
25
25
  it "should require password" do
26
26
  new_<%= user_singular_name %>(:password => '').should have(1).error_on(:password)
27
27
  end
28
-
28
+
29
29
  it "should require well formed email" do
30
30
  new_<%= user_singular_name %>(:email => 'foo@bar@example.com').should have(1).error_on(:email)
31
31
  end
32
-
32
+
33
33
  it "should validate uniqueness of email" do
34
34
  new_<%= user_singular_name %>(:email => 'bar@example.com').save!
35
35
  new_<%= user_singular_name %>(:email => 'bar@example.com').should have(1).error_on(:email)
36
36
  end
37
-
37
+
38
38
  it "should validate uniqueness of username" do
39
39
  new_<%= user_singular_name %>(:username => 'uniquename').save!
40
40
  new_<%= user_singular_name %>(:username => 'uniquename').should have(1).error_on(:username)
41
41
  end
42
-
42
+
43
43
  it "should not allow odd characters in username" do
44
44
  new_<%= user_singular_name %>(:username => 'odd ^&(@)').should have(1).error_on(:username)
45
45
  end
46
-
46
+
47
47
  it "should validate password is longer than 3 characters" do
48
48
  new_<%= user_singular_name %>(:password => 'bad').should have(1).error_on(:password)
49
49
  end
50
-
50
+
51
51
  it "should require matching password confirmation" do
52
52
  new_<%= user_singular_name %>(:password_confirmation => 'nonmatching').should have(1).error_on(:password)
53
53
  end
54
-
54
+
55
55
  it "should generate password hash and salt on create" do
56
56
  <%= user_singular_name %> = new_<%= user_singular_name %>
57
57
  <%= user_singular_name %>.save!
58
58
  <%= user_singular_name %>.password_hash.should_not be_nil
59
59
  <%= user_singular_name %>.password_salt.should_not be_nil
60
60
  end
61
-
61
+
62
62
  it "should authenticate by username" do
63
63
  <%= user_singular_name %> = new_<%= user_singular_name %>(:username => 'foobar', :password => 'secret')
64
64
  <%= user_singular_name %>.save!
65
65
  <%= user_class_name %>.authenticate('foobar', 'secret').should == <%= user_singular_name %>
66
66
  end
67
-
67
+
68
68
  it "should authenticate by email" do
69
69
  <%= user_singular_name %> = new_<%= user_singular_name %>(:email => 'foo@bar.com', :password => 'secret')
70
70
  <%= user_singular_name %>.save!
71
71
  <%= user_class_name %>.authenticate('foo@bar.com', 'secret').should == <%= user_singular_name %>
72
72
  end
73
-
73
+
74
74
  it "should not authenticate bad username" do
75
75
  <%= user_class_name %>.authenticate('nonexisting', 'secret').should be_nil
76
76
  end
77
-
77
+
78
78
  it "should not authenticate bad password" do
79
79
  new_<%= user_singular_name %>(:username => 'foobar', :password => 'secret').save!
80
80
  <%= user_class_name %>.authenticate('foobar', 'badpassword').should be_nil
@@ -1,20 +1,20 @@
1
1
  require File.dirname(__FILE__) + '/../spec_helper'
2
-
2
+
3
3
  describe <%= user_plural_class_name %>Controller do
4
4
  fixtures :all
5
5
  integrate_views
6
-
6
+
7
7
  it "new action should render new template" do
8
8
  get :new
9
9
  response.should render_template(:new)
10
10
  end
11
-
11
+
12
12
  it "create action should render new template when model is invalid" do
13
13
  <%= user_class_name %>.any_instance.stubs(:valid?).returns(false)
14
14
  post :create
15
15
  response.should render_template(:new)
16
16
  end
17
-
17
+
18
18
  it "create action should redirect when model is valid" do
19
19
  <%= user_class_name %>.any_instance.stubs(:valid?).returns(true)
20
20
  post :create
@@ -7,7 +7,7 @@ class <%= session_plural_class_name %>ControllerTest < ActionController::TestCas
7
7
  assert_template 'new'
8
8
  end
9
9
  end
10
-
10
+
11
11
  context "create action" do
12
12
  <%- if options[:authlogic] -%>
13
13
  should "render new template when authentication is invalid" do
@@ -15,7 +15,7 @@ class <%= session_plural_class_name %>ControllerTest < ActionController::TestCas
15
15
  assert_template 'new'
16
16
  assert_nil <%= session_class_name %>.find
17
17
  end
18
-
18
+
19
19
  should "redirect when authentication is valid" do
20
20
  post :create, :<%= session_singular_name %> => { :username => "foo", :password => "secret" }
21
21
  assert_redirected_to root_url
@@ -28,7 +28,7 @@ class <%= session_plural_class_name %>ControllerTest < ActionController::TestCas
28
28
  assert_template 'new'
29
29
  assert_nil session['<%= user_singular_name %>_id']
30
30
  end
31
-
31
+
32
32
  should "redirect when authentication is valid" do
33
33
  <%= user_class_name %>.stubs(:authenticate).returns(<%= user_class_name %>.first)
34
34
  post :create
@@ -11,72 +11,72 @@ class <%= user_class_name %>Test < ActiveSupport::TestCase
11
11
  <%= user_singular_name %>.valid? # run validations
12
12
  <%= user_singular_name %>
13
13
  end
14
-
14
+
15
15
  def setup
16
16
  <%= user_class_name %>.delete_all
17
17
  end
18
-
18
+
19
19
  should "be valid" do
20
20
  assert new_<%= user_singular_name %>.valid?
21
21
  end
22
-
22
+
23
23
  should "require username" do
24
24
  assert new_<%= user_singular_name %>(:username => '').errors.on(:username)
25
25
  end
26
-
26
+
27
27
  should "require password" do
28
28
  assert new_<%= user_singular_name %>(:password => '').errors.on(:password)
29
29
  end
30
-
30
+
31
31
  should "require well formed email" do
32
32
  assert new_<%= user_singular_name %>(:email => 'foo@bar@example.com').errors.on(:email)
33
33
  end
34
-
34
+
35
35
  should "validate uniqueness of email" do
36
36
  new_<%= user_singular_name %>(:email => 'bar@example.com').save!
37
37
  assert new_<%= user_singular_name %>(:email => 'bar@example.com').errors.on(:email)
38
38
  end
39
-
39
+
40
40
  should "validate uniqueness of username" do
41
41
  new_<%= user_singular_name %>(:username => 'uniquename').save!
42
42
  assert new_<%= user_singular_name %>(:username => 'uniquename').errors.on(:username)
43
43
  end
44
-
44
+
45
45
  should "not allow odd characters in username" do
46
46
  assert new_<%= user_singular_name %>(:username => 'odd ^&(@)').errors.on(:username)
47
47
  end
48
-
48
+
49
49
  should "validate password is longer than 3 characters" do
50
50
  assert new_<%= user_singular_name %>(:password => 'bad').errors.on(:password)
51
51
  end
52
-
52
+
53
53
  should "require matching password confirmation" do
54
54
  assert new_<%= user_singular_name %>(:password_confirmation => 'nonmatching').errors.on(:password)
55
55
  end
56
-
56
+
57
57
  should "generate password hash and salt on create" do
58
58
  <%= user_singular_name %> = new_<%= user_singular_name %>
59
59
  <%= user_singular_name %>.save!
60
60
  assert <%= user_singular_name %>.password_hash
61
61
  assert <%= user_singular_name %>.password_salt
62
62
  end
63
-
63
+
64
64
  should "authenticate by username" do
65
65
  <%= user_singular_name %> = new_<%= user_singular_name %>(:username => 'foobar', :password => 'secret')
66
66
  <%= user_singular_name %>.save!
67
67
  assert_equal <%= user_singular_name %>, <%= user_class_name %>.authenticate('foobar', 'secret')
68
68
  end
69
-
69
+
70
70
  should "authenticate by email" do
71
71
  <%= user_singular_name %> = new_<%= user_singular_name %>(:email => 'foo@bar.com', :password => 'secret')
72
72
  <%= user_singular_name %>.save!
73
73
  assert_equal <%= user_singular_name %>, <%= user_class_name %>.authenticate('foo@bar.com', 'secret')
74
74
  end
75
-
75
+
76
76
  should "not authenticate bad username" do
77
77
  assert_nil <%= user_class_name %>.authenticate('nonexisting', 'secret')
78
78
  end
79
-
79
+
80
80
  should "not authenticate bad password" do
81
81
  new_<%= user_singular_name %>(:username => 'foobar', :password => 'secret').save!
82
82
  assert_nil <%= user_class_name %>.authenticate('foobar', 'badpassword')