rubycs-nifty-generators-compass 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (100) hide show
  1. data/CHANGELOG +79 -0
  2. data/LICENSE +20 -0
  3. data/README.rdoc +5 -0
  4. data/Rakefile +15 -0
  5. data/TODO +7 -0
  6. data/lib/nifty_generators.rb +3 -0
  7. data/nifty-generators-compass.gemspec +32 -0
  8. data/rails_generators/nifty_authentication/USAGE +46 -0
  9. data/rails_generators/nifty_authentication/lib/insert_commands.rb +74 -0
  10. data/rails_generators/nifty_authentication/nifty_authentication_generator.rb +118 -0
  11. data/rails_generators/nifty_authentication/templates/authentication.rb +49 -0
  12. data/rails_generators/nifty_authentication/templates/fixtures.yml +12 -0
  13. data/rails_generators/nifty_authentication/templates/migration.rb +15 -0
  14. data/rails_generators/nifty_authentication/templates/sessions_controller.rb +22 -0
  15. data/rails_generators/nifty_authentication/templates/sessions_helper.rb +2 -0
  16. data/rails_generators/nifty_authentication/templates/tests/rspec/sessions_controller.rb +25 -0
  17. data/rails_generators/nifty_authentication/templates/tests/rspec/user.rb +81 -0
  18. data/rails_generators/nifty_authentication/templates/tests/rspec/users_controller.rb +24 -0
  19. data/rails_generators/nifty_authentication/templates/tests/shoulda/sessions_controller.rb +26 -0
  20. data/rails_generators/nifty_authentication/templates/tests/shoulda/user.rb +83 -0
  21. data/rails_generators/nifty_authentication/templates/tests/shoulda/users_controller.rb +25 -0
  22. data/rails_generators/nifty_authentication/templates/tests/testunit/sessions_controller.rb +22 -0
  23. data/rails_generators/nifty_authentication/templates/tests/testunit/user.rb +86 -0
  24. data/rails_generators/nifty_authentication/templates/tests/testunit/users_controller.rb +21 -0
  25. data/rails_generators/nifty_authentication/templates/user.rb +38 -0
  26. data/rails_generators/nifty_authentication/templates/users_controller.rb +16 -0
  27. data/rails_generators/nifty_authentication/templates/users_helper.rb +2 -0
  28. data/rails_generators/nifty_authentication/templates/views/erb/login.html.erb +15 -0
  29. data/rails_generators/nifty_authentication/templates/views/erb/signup.html.erb +24 -0
  30. data/rails_generators/nifty_authentication/templates/views/haml/login.html.haml +15 -0
  31. data/rails_generators/nifty_authentication/templates/views/haml/signup.html.haml +24 -0
  32. data/rails_generators/nifty_config/USAGE +23 -0
  33. data/rails_generators/nifty_config/nifty_config_generator.rb +32 -0
  34. data/rails_generators/nifty_config/templates/config.yml +8 -0
  35. data/rails_generators/nifty_config/templates/load_config.rb +2 -0
  36. data/rails_generators/nifty_layout/USAGE +25 -0
  37. data/rails_generators/nifty_layout/nifty_layout_generator.rb +44 -0
  38. data/rails_generators/nifty_layout/templates/helper.rb +23 -0
  39. data/rails_generators/nifty_layout/templates/layout.html.erb +22 -0
  40. data/rails_generators/nifty_layout/templates/layout.html.haml +19 -0
  41. data/rails_generators/nifty_layout/templates/stylesheet.css +81 -0
  42. data/rails_generators/nifty_layout/templates/stylesheet.sass +67 -0
  43. data/rails_generators/nifty_scaffold/USAGE +51 -0
  44. data/rails_generators/nifty_scaffold/nifty_scaffold_generator.rb +232 -0
  45. data/rails_generators/nifty_scaffold/templates/actions/create.rb +9 -0
  46. data/rails_generators/nifty_scaffold/templates/actions/destroy.rb +6 -0
  47. data/rails_generators/nifty_scaffold/templates/actions/edit.rb +3 -0
  48. data/rails_generators/nifty_scaffold/templates/actions/index.rb +3 -0
  49. data/rails_generators/nifty_scaffold/templates/actions/new.rb +3 -0
  50. data/rails_generators/nifty_scaffold/templates/actions/show.rb +3 -0
  51. data/rails_generators/nifty_scaffold/templates/actions/update.rb +9 -0
  52. data/rails_generators/nifty_scaffold/templates/controller.rb +3 -0
  53. data/rails_generators/nifty_scaffold/templates/fixtures.yml +9 -0
  54. data/rails_generators/nifty_scaffold/templates/helper.rb +2 -0
  55. data/rails_generators/nifty_scaffold/templates/migration.rb +16 -0
  56. data/rails_generators/nifty_scaffold/templates/model.rb +2 -0
  57. data/rails_generators/nifty_scaffold/templates/tests/rspec/actions/create.rb +11 -0
  58. data/rails_generators/nifty_scaffold/templates/tests/rspec/actions/destroy.rb +6 -0
  59. data/rails_generators/nifty_scaffold/templates/tests/rspec/actions/edit.rb +4 -0
  60. data/rails_generators/nifty_scaffold/templates/tests/rspec/actions/index.rb +4 -0
  61. data/rails_generators/nifty_scaffold/templates/tests/rspec/actions/new.rb +4 -0
  62. data/rails_generators/nifty_scaffold/templates/tests/rspec/actions/show.rb +4 -0
  63. data/rails_generators/nifty_scaffold/templates/tests/rspec/actions/update.rb +11 -0
  64. data/rails_generators/nifty_scaffold/templates/tests/rspec/controller.rb +8 -0
  65. data/rails_generators/nifty_scaffold/templates/tests/rspec/model.rb +7 -0
  66. data/rails_generators/nifty_scaffold/templates/tests/shoulda/actions/create.rb +13 -0
  67. data/rails_generators/nifty_scaffold/templates/tests/shoulda/actions/destroy.rb +8 -0
  68. data/rails_generators/nifty_scaffold/templates/tests/shoulda/actions/edit.rb +6 -0
  69. data/rails_generators/nifty_scaffold/templates/tests/shoulda/actions/index.rb +6 -0
  70. data/rails_generators/nifty_scaffold/templates/tests/shoulda/actions/new.rb +6 -0
  71. data/rails_generators/nifty_scaffold/templates/tests/shoulda/actions/show.rb +6 -0
  72. data/rails_generators/nifty_scaffold/templates/tests/shoulda/actions/update.rb +13 -0
  73. data/rails_generators/nifty_scaffold/templates/tests/shoulda/controller.rb +5 -0
  74. data/rails_generators/nifty_scaffold/templates/tests/shoulda/model.rb +7 -0
  75. data/rails_generators/nifty_scaffold/templates/tests/testunit/actions/create.rb +11 -0
  76. data/rails_generators/nifty_scaffold/templates/tests/testunit/actions/destroy.rb +6 -0
  77. data/rails_generators/nifty_scaffold/templates/tests/testunit/actions/edit.rb +4 -0
  78. data/rails_generators/nifty_scaffold/templates/tests/testunit/actions/index.rb +4 -0
  79. data/rails_generators/nifty_scaffold/templates/tests/testunit/actions/new.rb +4 -0
  80. data/rails_generators/nifty_scaffold/templates/tests/testunit/actions/show.rb +4 -0
  81. data/rails_generators/nifty_scaffold/templates/tests/testunit/actions/update.rb +11 -0
  82. data/rails_generators/nifty_scaffold/templates/tests/testunit/controller.rb +5 -0
  83. data/rails_generators/nifty_scaffold/templates/tests/testunit/model.rb +7 -0
  84. data/rails_generators/nifty_scaffold/templates/views/erb/_form.html.erb +10 -0
  85. data/rails_generators/nifty_scaffold/templates/views/erb/edit.html.erb +14 -0
  86. data/rails_generators/nifty_scaffold/templates/views/erb/index.html.erb +29 -0
  87. data/rails_generators/nifty_scaffold/templates/views/erb/new.html.erb +7 -0
  88. data/rails_generators/nifty_scaffold/templates/views/erb/show.html.erb +20 -0
  89. data/rails_generators/nifty_scaffold/templates/views/haml/_form.html.haml +10 -0
  90. data/rails_generators/nifty_scaffold/templates/views/haml/edit.html.haml +14 -0
  91. data/rails_generators/nifty_scaffold/templates/views/haml/index.html.haml +25 -0
  92. data/rails_generators/nifty_scaffold/templates/views/haml/new.html.haml +7 -0
  93. data/rails_generators/nifty_scaffold/templates/views/haml/show.html.haml +20 -0
  94. data/tasks/deployment.rake +2 -0
  95. data/test/test_helper.rb +117 -0
  96. data/test/test_nifty_authentication_generator.rb +160 -0
  97. data/test/test_nifty_config_generator.rb +37 -0
  98. data/test/test_nifty_layout_generator.rb +42 -0
  99. data/test/test_nifty_scaffold_generator.rb +533 -0
  100. metadata +165 -0
@@ -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_target_or_default(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,2 @@
1
+ module <%= sessions_class_name %>Helper
2
+ 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
@@ -0,0 +1,24 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe <%= user_plural_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 model is invalid" do
13
+ <%= user_class_name %>.any_instance.stubs(:valid?).returns(false)
14
+ post :create
15
+ response.should render_template(:new)
16
+ end
17
+
18
+ it "create action should redirect when model is valid" do
19
+ <%= user_class_name %>.any_instance.stubs(:valid?).returns(true)
20
+ post :create
21
+ response.should redirect_to(root_url)
22
+ session['<%= user_singular_name %>_id'].should == assigns['<%= user_singular_name %>'].id
23
+ end
24
+ end
@@ -0,0 +1,26 @@
1
+ require 'test_helper'
2
+
3
+ class <%= sessions_class_name %>ControllerTest < ActionController::TestCase
4
+ context "new action" do
5
+ should "render new template" do
6
+ get :new
7
+ assert_template 'new'
8
+ end
9
+ end
10
+
11
+ context "create action" do
12
+ should "render new template when authentication is invalid" do
13
+ <%= user_class_name %>.stubs(:authenticate).returns(nil)
14
+ post :create
15
+ assert_template 'new'
16
+ assert_nil session['<%= user_singular_name %>_id']
17
+ end
18
+
19
+ should "redirect when authentication is valid" do
20
+ <%= user_class_name %>.stubs(:authenticate).returns(<%= user_class_name %>.first)
21
+ post :create
22
+ assert_redirected_to root_url
23
+ assert_equal <%= user_class_name %>.first.id, session['<%= user_singular_name %>_id']
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,83 @@
1
+ require 'test_helper'
2
+
3
+ class <%= user_class_name %>Test < ActiveSupport::TestCase
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_singular_name %> = <%= user_class_name %>.new(attributes)
10
+ <%= user_singular_name %>.valid? # run validations
11
+ <%= user_singular_name %>
12
+ end
13
+
14
+ def setup
15
+ <%= user_class_name %>.delete_all
16
+ end
17
+
18
+ should "be valid" do
19
+ assert new_<%= user_singular_name %>.valid?
20
+ end
21
+
22
+ should "require username" do
23
+ assert new_<%= user_singular_name %>(:username => '').errors.on(:username)
24
+ end
25
+
26
+ should "require password" do
27
+ assert new_<%= user_singular_name %>(:password => '').errors.on(:password)
28
+ end
29
+
30
+ should "require well formed email" do
31
+ assert new_<%= user_singular_name %>(:email => 'foo@bar@example.com').errors.on(:email)
32
+ end
33
+
34
+ should "validate uniqueness of email" do
35
+ new_<%= user_singular_name %>(:email => 'bar@example.com').save!
36
+ assert new_<%= user_singular_name %>(:email => 'bar@example.com').errors.on(:email)
37
+ end
38
+
39
+ should "validate uniqueness of username" do
40
+ new_<%= user_singular_name %>(:username => 'uniquename').save!
41
+ assert new_<%= user_singular_name %>(:username => 'uniquename').errors.on(:username)
42
+ end
43
+
44
+ should "not allow odd characters in username" do
45
+ assert new_<%= user_singular_name %>(:username => 'odd ^&(@)').errors.on(:username)
46
+ end
47
+
48
+ should "validate password is longer than 3 characters" do
49
+ assert new_<%= user_singular_name %>(:password => 'bad').errors.on(:password)
50
+ end
51
+
52
+ should "require matching password confirmation" do
53
+ assert new_<%= user_singular_name %>(:password_confirmation => 'nonmatching').errors.on(:password)
54
+ end
55
+
56
+ should "generate password hash and salt on create" do
57
+ <%= user_singular_name %> = new_<%= user_singular_name %>
58
+ <%= user_singular_name %>.save!
59
+ assert <%= user_singular_name %>.password_hash
60
+ assert <%= user_singular_name %>.password_salt
61
+ end
62
+
63
+ should "authenticate by username" do
64
+ <%= user_singular_name %> = new_<%= user_singular_name %>(:username => 'foobar', :password => 'secret')
65
+ <%= user_singular_name %>.save!
66
+ assert_equal <%= user_singular_name %>, <%= user_class_name %>.authenticate('foobar', 'secret')
67
+ end
68
+
69
+ should "authenticate by email" do
70
+ <%= user_singular_name %> = new_<%= user_singular_name %>(:email => 'foo@bar.com', :password => 'secret')
71
+ <%= user_singular_name %>.save!
72
+ assert_equal <%= user_singular_name %>, <%= user_class_name %>.authenticate('foo@bar.com', 'secret')
73
+ end
74
+
75
+ should "not authenticate bad username" do
76
+ assert_nil <%= user_class_name %>.authenticate('nonexisting', 'secret')
77
+ end
78
+
79
+ should "not authenticate bad password" do
80
+ new_<%= user_singular_name %>(:username => 'foobar', :password => 'secret').save!
81
+ assert_nil <%= user_class_name %>.authenticate('foobar', 'badpassword')
82
+ end
83
+ end
@@ -0,0 +1,25 @@
1
+ require 'test_helper'
2
+
3
+ class <%= user_plural_class_name %>ControllerTest < ActionController::TestCase
4
+ context "new action" do
5
+ should "render new template" do
6
+ get :new
7
+ assert_template 'new'
8
+ end
9
+ end
10
+
11
+ context "create action" do
12
+ should "render new template when model is invalid" do
13
+ <%= user_class_name %>.any_instance.stubs(:valid?).returns(false)
14
+ post :create
15
+ assert_template 'new'
16
+ end
17
+
18
+ should "redirect when model is valid" do
19
+ <%= user_class_name %>.any_instance.stubs(:valid?).returns(true)
20
+ post :create
21
+ assert_redirected_to root_url
22
+ assert_equal assigns['<%= user_singular_name %>'].id, session['<%= user_singular_name %>_id']
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,22 @@
1
+ require 'test_helper'
2
+
3
+ class <%= sessions_class_name %>ControllerTest < ActionController::TestCase
4
+ def test_new
5
+ get :new
6
+ assert_template 'new'
7
+ end
8
+
9
+ def test_create_invalid
10
+ <%= user_class_name %>.stubs(:authenticate).returns(nil)
11
+ post :create
12
+ assert_template 'new'
13
+ assert_nil session['<%= user_singular_name %>_id']
14
+ end
15
+
16
+ def test_create_valid
17
+ <%= user_class_name %>.stubs(:authenticate).returns(<%= user_class_name %>.first)
18
+ post :create
19
+ assert_redirected_to root_url
20
+ assert_equal <%= user_class_name %>.first.id, session['<%= user_singular_name %>_id']
21
+ end
22
+ end
@@ -0,0 +1,86 @@
1
+ require 'test_helper'
2
+
3
+ class <%= user_class_name %>Test < ActiveSupport::TestCase
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_singular_name %> = <%= user_class_name %>.new(attributes)
10
+ <%= user_singular_name %>.valid? # run validations
11
+ <%= user_singular_name %>
12
+ end
13
+
14
+ def setup
15
+ <%= user_class_name %>.delete_all
16
+ end
17
+
18
+ def test_valid
19
+ assert new_<%= user_singular_name %>.valid?
20
+ end
21
+
22
+ def test_require_username
23
+ assert new_<%= user_singular_name %>(:username => '').errors.on(:username)
24
+ end
25
+
26
+ def test_require_password
27
+ assert new_<%= user_singular_name %>(:password => '').errors.on(:password)
28
+ end
29
+
30
+ def test_require_well_formed_email
31
+ assert new_<%= user_singular_name %>(:email => 'foo@bar@example.com').errors.on(:email)
32
+ end
33
+
34
+ def test_validate_uniqueness_of_email
35
+ new_<%= user_singular_name %>(:email => 'bar@example.com').save!
36
+ assert new_<%= user_singular_name %>(:email => 'bar@example.com').errors.on(:email)
37
+ end
38
+
39
+ def test_validate_uniqueness_of_username
40
+ new_<%= user_singular_name %>(:username => 'uniquename').save!
41
+ assert new_<%= user_singular_name %>(:username => 'uniquename').errors.on(:username)
42
+ end
43
+
44
+ def test_validate_odd_characters_in_username
45
+ assert new_<%= user_singular_name %>(:username => 'odd ^&(@)').errors.on(:username)
46
+ end
47
+
48
+ def test_validate_password_length
49
+ assert new_<%= user_singular_name %>(:password => 'bad').errors.on(:password)
50
+ end
51
+
52
+ def test_require_matching_password_confirmation
53
+ assert new_<%= user_singular_name %>(:password_confirmation => 'nonmatching').errors.on(:password)
54
+ end
55
+
56
+ def test_generate_password_hash_and_salt_on_create
57
+ <%= user_singular_name %> = new_<%= user_singular_name %>
58
+ <%= user_singular_name %>.save!
59
+ assert <%= user_singular_name %>.password_hash
60
+ assert <%= user_singular_name %>.password_salt
61
+ end
62
+
63
+ def test_authenticate_by_username
64
+ <%= user_class_name %>.delete_all
65
+ <%= user_singular_name %> = new_<%= user_singular_name %>(:username => 'foobar', :password => 'secret')
66
+ <%= user_singular_name %>.save!
67
+ assert_equal <%= user_singular_name %>, <%= user_class_name %>.authenticate('foobar', 'secret')
68
+ end
69
+
70
+ def test_authenticate_by_email
71
+ <%= user_class_name %>.delete_all
72
+ <%= user_singular_name %> = new_<%= user_singular_name %>(:email => 'foo@bar.com', :password => 'secret')
73
+ <%= user_singular_name %>.save!
74
+ assert_equal <%= user_singular_name %>, <%= user_class_name %>.authenticate('foo@bar.com', 'secret')
75
+ end
76
+
77
+ def test_authenticate_bad_username
78
+ assert_nil <%= user_class_name %>.authenticate('nonexisting', 'secret')
79
+ end
80
+
81
+ def test_authenticate_bad_password
82
+ <%= user_class_name %>.delete_all
83
+ new_<%= user_singular_name %>(:username => 'foobar', :password => 'secret').save!
84
+ assert_nil <%= user_class_name %>.authenticate('foobar', 'badpassword')
85
+ end
86
+ end
@@ -0,0 +1,21 @@
1
+ require 'test_helper'
2
+
3
+ class <%= user_plural_class_name %>ControllerTest < ActionController::TestCase
4
+ def test_new
5
+ get :new
6
+ assert_template 'new'
7
+ end
8
+
9
+ def test_create_invalid
10
+ <%= user_class_name %>.any_instance.stubs(:valid?).returns(false)
11
+ post :create
12
+ assert_template 'new'
13
+ end
14
+
15
+ def test_create_valid
16
+ <%= user_class_name %>.any_instance.stubs(:valid?).returns(true)
17
+ post :create
18
+ assert_redirected_to root_url
19
+ assert_equal assigns['<%= user_singular_name %>'].id, session['<%= user_singular_name %>_id']
20
+ end
21
+ end