focus-generator 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (197) hide show
  1. data/Gemfile +2 -0
  2. data/LICENSE +20 -0
  3. data/README.rdoc +109 -0
  4. data/Rakefile +10 -0
  5. data/features/fcus_authentication.feature +80 -0
  6. data/features/fcus_config.feature +17 -0
  7. data/features/fcus_layout.feature +20 -0
  8. data/features/fcus_scaffold.feature +80 -0
  9. data/features/step_definitions/common_steps.rb +62 -0
  10. data/features/step_definitions/rails_setup_steps.rb +6 -0
  11. data/features/support/env.rb +6 -0
  12. data/features/support/matchers.rb +7 -0
  13. data/lib/generators/fcus.rb +28 -0
  14. data/lib/generators/fcus/authentication/USAGE +50 -0
  15. data/lib/generators/fcus/authentication/authentication_generator.rb +154 -0
  16. data/lib/generators/fcus/authentication/templates/authlogic_session.rb +2 -0
  17. data/lib/generators/fcus/authentication/templates/controller_authentication.rb +60 -0
  18. data/lib/generators/fcus/authentication/templates/fixtures.yml +24 -0
  19. data/lib/generators/fcus/authentication/templates/migration.rb +20 -0
  20. data/lib/generators/fcus/authentication/templates/sessions_controller.rb +41 -0
  21. data/lib/generators/fcus/authentication/templates/sessions_helper.rb +2 -0
  22. data/lib/generators/fcus/authentication/templates/tests/rspec/sessions_controller.rb +39 -0
  23. data/lib/generators/fcus/authentication/templates/tests/rspec/user.rb +83 -0
  24. data/lib/generators/fcus/authentication/templates/tests/rspec/users_controller.rb +56 -0
  25. data/lib/generators/fcus/authentication/templates/tests/shoulda/sessions_controller.rb +40 -0
  26. data/lib/generators/fcus/authentication/templates/tests/shoulda/user.rb +85 -0
  27. data/lib/generators/fcus/authentication/templates/tests/shoulda/users_controller.rb +61 -0
  28. data/lib/generators/fcus/authentication/templates/tests/testunit/sessions_controller.rb +36 -0
  29. data/lib/generators/fcus/authentication/templates/tests/testunit/user.rb +88 -0
  30. data/lib/generators/fcus/authentication/templates/tests/testunit/users_controller.rb +53 -0
  31. data/lib/generators/fcus/authentication/templates/user.rb +38 -0
  32. data/lib/generators/fcus/authentication/templates/users_controller.rb +32 -0
  33. data/lib/generators/fcus/authentication/templates/users_helper.rb +2 -0
  34. data/lib/generators/fcus/authentication/templates/views/erb/_form.html.erb +20 -0
  35. data/lib/generators/fcus/authentication/templates/views/erb/edit.html.erb +3 -0
  36. data/lib/generators/fcus/authentication/templates/views/erb/login.html.erb +30 -0
  37. data/lib/generators/fcus/authentication/templates/views/erb/signup.html.erb +5 -0
  38. data/lib/generators/fcus/authentication/templates/views/haml/_form.html.haml +16 -0
  39. data/lib/generators/fcus/authentication/templates/views/haml/edit.html.haml +3 -0
  40. data/lib/generators/fcus/authentication/templates/views/haml/login.html.haml +26 -0
  41. data/lib/generators/fcus/authentication/templates/views/haml/signup.html.haml +5 -0
  42. data/lib/generators/fcus/config/USAGE +23 -0
  43. data/lib/generators/fcus/config/config_generator.rb +24 -0
  44. data/lib/generators/fcus/config/templates/config.yml +8 -0
  45. data/lib/generators/fcus/config/templates/load_config.rb +2 -0
  46. data/lib/generators/fcus/layout/USAGE +25 -0
  47. data/lib/generators/fcus/layout/layout_generator.rb +29 -0
  48. data/lib/generators/fcus/layout/templates/error_messages_helper.rb +23 -0
  49. data/lib/generators/fcus/layout/templates/layout.html.erb +19 -0
  50. data/lib/generators/fcus/layout/templates/layout.html.haml +21 -0
  51. data/lib/generators/fcus/layout/templates/layout_helper.rb +22 -0
  52. data/lib/generators/fcus/layout/templates/stylesheet.css +83 -0
  53. data/lib/generators/fcus/layout/templates/stylesheet.sass +73 -0
  54. data/lib/generators/fcus/scaffold/USAGE +51 -0
  55. data/lib/generators/fcus/scaffold/scaffold_generator.rb +318 -0
  56. data/lib/generators/fcus/scaffold/templates/actions/create.rb +8 -0
  57. data/lib/generators/fcus/scaffold/templates/actions/destroy.rb +5 -0
  58. data/lib/generators/fcus/scaffold/templates/actions/edit.rb +3 -0
  59. data/lib/generators/fcus/scaffold/templates/actions/index.rb +3 -0
  60. data/lib/generators/fcus/scaffold/templates/actions/new.rb +3 -0
  61. data/lib/generators/fcus/scaffold/templates/actions/show.rb +3 -0
  62. data/lib/generators/fcus/scaffold/templates/actions/update.rb +8 -0
  63. data/lib/generators/fcus/scaffold/templates/controller.rb +3 -0
  64. data/lib/generators/fcus/scaffold/templates/fixtures.yml +9 -0
  65. data/lib/generators/fcus/scaffold/templates/helper.rb +2 -0
  66. data/lib/generators/fcus/scaffold/templates/migration.rb +16 -0
  67. data/lib/generators/fcus/scaffold/templates/model.rb +4 -0
  68. data/lib/generators/fcus/scaffold/templates/tests/rspec/actions/create.rb +11 -0
  69. data/lib/generators/fcus/scaffold/templates/tests/rspec/actions/destroy.rb +6 -0
  70. data/lib/generators/fcus/scaffold/templates/tests/rspec/actions/edit.rb +4 -0
  71. data/lib/generators/fcus/scaffold/templates/tests/rspec/actions/index.rb +4 -0
  72. data/lib/generators/fcus/scaffold/templates/tests/rspec/actions/new.rb +4 -0
  73. data/lib/generators/fcus/scaffold/templates/tests/rspec/actions/show.rb +4 -0
  74. data/lib/generators/fcus/scaffold/templates/tests/rspec/actions/update.rb +11 -0
  75. data/lib/generators/fcus/scaffold/templates/tests/rspec/controller.rb +8 -0
  76. data/lib/generators/fcus/scaffold/templates/tests/rspec/model.rb +7 -0
  77. data/lib/generators/fcus/scaffold/templates/tests/shoulda/actions/create.rb +13 -0
  78. data/lib/generators/fcus/scaffold/templates/tests/shoulda/actions/destroy.rb +8 -0
  79. data/lib/generators/fcus/scaffold/templates/tests/shoulda/actions/edit.rb +6 -0
  80. data/lib/generators/fcus/scaffold/templates/tests/shoulda/actions/index.rb +6 -0
  81. data/lib/generators/fcus/scaffold/templates/tests/shoulda/actions/new.rb +6 -0
  82. data/lib/generators/fcus/scaffold/templates/tests/shoulda/actions/show.rb +6 -0
  83. data/lib/generators/fcus/scaffold/templates/tests/shoulda/actions/update.rb +13 -0
  84. data/lib/generators/fcus/scaffold/templates/tests/shoulda/controller.rb +5 -0
  85. data/lib/generators/fcus/scaffold/templates/tests/shoulda/model.rb +7 -0
  86. data/lib/generators/fcus/scaffold/templates/tests/testunit/actions/create.rb +11 -0
  87. data/lib/generators/fcus/scaffold/templates/tests/testunit/actions/destroy.rb +6 -0
  88. data/lib/generators/fcus/scaffold/templates/tests/testunit/actions/edit.rb +4 -0
  89. data/lib/generators/fcus/scaffold/templates/tests/testunit/actions/index.rb +4 -0
  90. data/lib/generators/fcus/scaffold/templates/tests/testunit/actions/new.rb +4 -0
  91. data/lib/generators/fcus/scaffold/templates/tests/testunit/actions/show.rb +4 -0
  92. data/lib/generators/fcus/scaffold/templates/tests/testunit/actions/update.rb +11 -0
  93. data/lib/generators/fcus/scaffold/templates/tests/testunit/controller.rb +5 -0
  94. data/lib/generators/fcus/scaffold/templates/tests/testunit/model.rb +7 -0
  95. data/lib/generators/fcus/scaffold/templates/views/erb/_form.html.erb +10 -0
  96. data/lib/generators/fcus/scaffold/templates/views/erb/edit.html.erb +14 -0
  97. data/lib/generators/fcus/scaffold/templates/views/erb/index.html.erb +29 -0
  98. data/lib/generators/fcus/scaffold/templates/views/erb/new.html.erb +7 -0
  99. data/lib/generators/fcus/scaffold/templates/views/erb/show.html.erb +20 -0
  100. data/lib/generators/fcus/scaffold/templates/views/haml/_form.html.haml +9 -0
  101. data/lib/generators/fcus/scaffold/templates/views/haml/edit.html.haml +14 -0
  102. data/lib/generators/fcus/scaffold/templates/views/haml/index.html.haml +25 -0
  103. data/lib/generators/fcus/scaffold/templates/views/haml/new.html.haml +7 -0
  104. data/lib/generators/fcus/scaffold/templates/views/haml/show.html.haml +20 -0
  105. data/rails_generators/fcus_authentication/USAGE +50 -0
  106. data/rails_generators/fcus_authentication/fcus_authentication_generator.rb +128 -0
  107. data/rails_generators/fcus_authentication/lib/insert_commands.rb +74 -0
  108. data/rails_generators/fcus_authentication/templates/authentication.rb +61 -0
  109. data/rails_generators/fcus_authentication/templates/authlogic_session.rb +2 -0
  110. data/rails_generators/fcus_authentication/templates/fixtures.yml +24 -0
  111. data/rails_generators/fcus_authentication/templates/migration.rb +20 -0
  112. data/rails_generators/fcus_authentication/templates/sessions_controller.rb +45 -0
  113. data/rails_generators/fcus_authentication/templates/sessions_helper.rb +2 -0
  114. data/rails_generators/fcus_authentication/templates/tests/rspec/sessions_controller.rb +39 -0
  115. data/rails_generators/fcus_authentication/templates/tests/rspec/user.rb +83 -0
  116. data/rails_generators/fcus_authentication/templates/tests/rspec/users_controller.rb +26 -0
  117. data/rails_generators/fcus_authentication/templates/tests/shoulda/sessions_controller.rb +40 -0
  118. data/rails_generators/fcus_authentication/templates/tests/shoulda/user.rb +85 -0
  119. data/rails_generators/fcus_authentication/templates/tests/shoulda/users_controller.rb +27 -0
  120. data/rails_generators/fcus_authentication/templates/tests/testunit/sessions_controller.rb +36 -0
  121. data/rails_generators/fcus_authentication/templates/tests/testunit/user.rb +88 -0
  122. data/rails_generators/fcus_authentication/templates/tests/testunit/users_controller.rb +23 -0
  123. data/rails_generators/fcus_authentication/templates/user.rb +42 -0
  124. data/rails_generators/fcus_authentication/templates/users_controller.rb +18 -0
  125. data/rails_generators/fcus_authentication/templates/users_helper.rb +2 -0
  126. data/rails_generators/fcus_authentication/templates/views/erb/login.html.erb +30 -0
  127. data/rails_generators/fcus_authentication/templates/views/erb/signup.html.erb +24 -0
  128. data/rails_generators/fcus_authentication/templates/views/haml/login.html.haml +30 -0
  129. data/rails_generators/fcus_authentication/templates/views/haml/signup.html.haml +24 -0
  130. data/rails_generators/fcus_config/USAGE +23 -0
  131. data/rails_generators/fcus_config/fcus_config_generator.rb +32 -0
  132. data/rails_generators/fcus_config/templates/config.yml +8 -0
  133. data/rails_generators/fcus_config/templates/load_config.rb +2 -0
  134. data/rails_generators/fcus_layout/USAGE +25 -0
  135. data/rails_generators/fcus_layout/fcus_layout_generator.rb +44 -0
  136. data/rails_generators/fcus_layout/templates/helper.rb +22 -0
  137. data/rails_generators/fcus_layout/templates/layout.html.erb +22 -0
  138. data/rails_generators/fcus_layout/templates/layout.html.haml +19 -0
  139. data/rails_generators/fcus_layout/templates/stylesheet.css +81 -0
  140. data/rails_generators/fcus_layout/templates/stylesheet.sass +67 -0
  141. data/rails_generators/fcus_scaffold/USAGE +51 -0
  142. data/rails_generators/fcus_scaffold/fcus_scaffold_generator.rb +232 -0
  143. data/rails_generators/fcus_scaffold/templates/actions/create.rb +9 -0
  144. data/rails_generators/fcus_scaffold/templates/actions/destroy.rb +6 -0
  145. data/rails_generators/fcus_scaffold/templates/actions/edit.rb +3 -0
  146. data/rails_generators/fcus_scaffold/templates/actions/index.rb +3 -0
  147. data/rails_generators/fcus_scaffold/templates/actions/new.rb +3 -0
  148. data/rails_generators/fcus_scaffold/templates/actions/show.rb +3 -0
  149. data/rails_generators/fcus_scaffold/templates/actions/update.rb +9 -0
  150. data/rails_generators/fcus_scaffold/templates/controller.rb +3 -0
  151. data/rails_generators/fcus_scaffold/templates/fixtures.yml +9 -0
  152. data/rails_generators/fcus_scaffold/templates/helper.rb +2 -0
  153. data/rails_generators/fcus_scaffold/templates/migration.rb +16 -0
  154. data/rails_generators/fcus_scaffold/templates/model.rb +3 -0
  155. data/rails_generators/fcus_scaffold/templates/tests/rspec/actions/create.rb +11 -0
  156. data/rails_generators/fcus_scaffold/templates/tests/rspec/actions/destroy.rb +6 -0
  157. data/rails_generators/fcus_scaffold/templates/tests/rspec/actions/edit.rb +4 -0
  158. data/rails_generators/fcus_scaffold/templates/tests/rspec/actions/index.rb +4 -0
  159. data/rails_generators/fcus_scaffold/templates/tests/rspec/actions/new.rb +4 -0
  160. data/rails_generators/fcus_scaffold/templates/tests/rspec/actions/show.rb +4 -0
  161. data/rails_generators/fcus_scaffold/templates/tests/rspec/actions/update.rb +11 -0
  162. data/rails_generators/fcus_scaffold/templates/tests/rspec/controller.rb +8 -0
  163. data/rails_generators/fcus_scaffold/templates/tests/rspec/model.rb +7 -0
  164. data/rails_generators/fcus_scaffold/templates/tests/shoulda/actions/create.rb +13 -0
  165. data/rails_generators/fcus_scaffold/templates/tests/shoulda/actions/destroy.rb +8 -0
  166. data/rails_generators/fcus_scaffold/templates/tests/shoulda/actions/edit.rb +6 -0
  167. data/rails_generators/fcus_scaffold/templates/tests/shoulda/actions/index.rb +6 -0
  168. data/rails_generators/fcus_scaffold/templates/tests/shoulda/actions/new.rb +6 -0
  169. data/rails_generators/fcus_scaffold/templates/tests/shoulda/actions/show.rb +6 -0
  170. data/rails_generators/fcus_scaffold/templates/tests/shoulda/actions/update.rb +13 -0
  171. data/rails_generators/fcus_scaffold/templates/tests/shoulda/controller.rb +5 -0
  172. data/rails_generators/fcus_scaffold/templates/tests/shoulda/model.rb +7 -0
  173. data/rails_generators/fcus_scaffold/templates/tests/testunit/actions/create.rb +11 -0
  174. data/rails_generators/fcus_scaffold/templates/tests/testunit/actions/destroy.rb +6 -0
  175. data/rails_generators/fcus_scaffold/templates/tests/testunit/actions/edit.rb +4 -0
  176. data/rails_generators/fcus_scaffold/templates/tests/testunit/actions/index.rb +4 -0
  177. data/rails_generators/fcus_scaffold/templates/tests/testunit/actions/new.rb +4 -0
  178. data/rails_generators/fcus_scaffold/templates/tests/testunit/actions/show.rb +4 -0
  179. data/rails_generators/fcus_scaffold/templates/tests/testunit/actions/update.rb +11 -0
  180. data/rails_generators/fcus_scaffold/templates/tests/testunit/controller.rb +5 -0
  181. data/rails_generators/fcus_scaffold/templates/tests/testunit/model.rb +7 -0
  182. data/rails_generators/fcus_scaffold/templates/views/erb/_form.html.erb +10 -0
  183. data/rails_generators/fcus_scaffold/templates/views/erb/edit.html.erb +14 -0
  184. data/rails_generators/fcus_scaffold/templates/views/erb/index.html.erb +29 -0
  185. data/rails_generators/fcus_scaffold/templates/views/erb/new.html.erb +7 -0
  186. data/rails_generators/fcus_scaffold/templates/views/erb/show.html.erb +20 -0
  187. data/rails_generators/fcus_scaffold/templates/views/haml/_form.html.haml +10 -0
  188. data/rails_generators/fcus_scaffold/templates/views/haml/edit.html.haml +14 -0
  189. data/rails_generators/fcus_scaffold/templates/views/haml/index.html.haml +25 -0
  190. data/rails_generators/fcus_scaffold/templates/views/haml/new.html.haml +7 -0
  191. data/rails_generators/fcus_scaffold/templates/views/haml/show.html.haml +20 -0
  192. data/test/test_fcus_authentication_generator.rb +274 -0
  193. data/test/test_fcus_config_generator.rb +37 -0
  194. data/test/test_fcus_layout_generator.rb +42 -0
  195. data/test/test_fcus_scaffold_generator.rb +534 -0
  196. data/test/test_helper.rb +119 -0
  197. metadata +314 -0
@@ -0,0 +1,2 @@
1
+ module <%= session_plural_class_name %>Helper
2
+ end
@@ -0,0 +1,39 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe <%= session_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
+ <%- if options[:authlogic] -%>
13
+ it "create action should render new template when authentication is invalid" do
14
+ post :create, :<%= session_singular_name %> => { :username => "foo", :password => "badpassword" }
15
+ response.should render_template(:new)
16
+ <%= session_class_name %>.find.should be_nil
17
+ end
18
+
19
+ it "create action should redirect when authentication is valid" do
20
+ post :create, :<%= session_singular_name %> => { :username => "foo", :password => "secret" }
21
+ response.should redirect_to(root_url)
22
+ <%= session_class_name %>.find.<%= user_singular_name %>.should == <%= user_plural_name %>(:foo)
23
+ end
24
+ <%- else -%>
25
+ it "create action should render new template when authentication is invalid" do
26
+ <%= user_class_name %>.stubs(:authenticate).returns(nil)
27
+ post :create
28
+ response.should render_template(:new)
29
+ session['<%= user_singular_name %>_id'].should be_nil
30
+ end
31
+
32
+ it "create action should redirect when authentication is valid" do
33
+ <%= user_class_name %>.stubs(:authenticate).returns(<%= user_class_name %>.first)
34
+ post :create
35
+ response.should redirect_to(root_url)
36
+ session['<%= user_singular_name %>_id'].should == <%= user_class_name %>.first.id
37
+ end
38
+ <%- end -%>
39
+ end
@@ -0,0 +1,83 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe <%= user_class_name %> do
4
+ <%- unless options[:authlogic] -%>
5
+ def new_<%= user_singular_name %>(attributes = {})
6
+ attributes[:username] ||= 'foo'
7
+ attributes[:email] ||= 'foo@example.com'
8
+ attributes[:password] ||= 'abc123'
9
+ attributes[:password_confirmation] ||= attributes[:password]
10
+ <%= user_class_name %>.new(attributes)
11
+ end
12
+
13
+ before(:each) do
14
+ <%= user_class_name %>.delete_all
15
+ end
16
+
17
+ it "should be valid" do
18
+ new_<%= user_singular_name %>.should be_valid
19
+ end
20
+
21
+ it "should require username" do
22
+ new_<%= user_singular_name %>(:username => '').should have(1).error_on(:username)
23
+ end
24
+
25
+ it "should require password" do
26
+ new_<%= user_singular_name %>(:password => '').should have(1).error_on(:password)
27
+ end
28
+
29
+ it "should require well formed email" do
30
+ new_<%= user_singular_name %>(:email => 'foo@bar@example.com').should have(1).error_on(:email)
31
+ end
32
+
33
+ it "should validate uniqueness of email" do
34
+ new_<%= user_singular_name %>(:email => 'bar@example.com').save!
35
+ new_<%= user_singular_name %>(:email => 'bar@example.com').should have(1).error_on(:email)
36
+ end
37
+
38
+ it "should validate uniqueness of username" do
39
+ new_<%= user_singular_name %>(:username => 'uniquename').save!
40
+ new_<%= user_singular_name %>(:username => 'uniquename').should have(1).error_on(:username)
41
+ end
42
+
43
+ it "should not allow odd characters in username" do
44
+ new_<%= user_singular_name %>(:username => 'odd ^&(@)').should have(1).error_on(:username)
45
+ end
46
+
47
+ it "should validate password is longer than 3 characters" do
48
+ new_<%= user_singular_name %>(:password => 'bad').should have(1).error_on(:password)
49
+ end
50
+
51
+ it "should require matching password confirmation" do
52
+ new_<%= user_singular_name %>(:password_confirmation => 'nonmatching').should have(1).error_on(:password)
53
+ end
54
+
55
+ it "should generate password hash and salt on create" do
56
+ <%= user_singular_name %> = new_<%= user_singular_name %>
57
+ <%= user_singular_name %>.save!
58
+ <%= user_singular_name %>.password_hash.should_not be_nil
59
+ <%= user_singular_name %>.password_salt.should_not be_nil
60
+ end
61
+
62
+ it "should authenticate by username" do
63
+ <%= user_singular_name %> = new_<%= user_singular_name %>(:username => 'foobar', :password => 'secret')
64
+ <%= user_singular_name %>.save!
65
+ <%= user_class_name %>.authenticate('foobar', 'secret').should == <%= user_singular_name %>
66
+ end
67
+
68
+ it "should authenticate by email" do
69
+ <%= user_singular_name %> = new_<%= user_singular_name %>(:email => 'foo@bar.com', :password => 'secret')
70
+ <%= user_singular_name %>.save!
71
+ <%= user_class_name %>.authenticate('foo@bar.com', 'secret').should == <%= user_singular_name %>
72
+ end
73
+
74
+ it "should not authenticate bad username" do
75
+ <%= user_class_name %>.authenticate('nonexisting', 'secret').should be_nil
76
+ end
77
+
78
+ it "should not authenticate bad password" do
79
+ new_<%= user_singular_name %>(:username => 'foobar', :password => 'secret').save!
80
+ <%= user_class_name %>.authenticate('foobar', 'badpassword').should be_nil
81
+ end
82
+ <%- end -%>
83
+ end
@@ -0,0 +1,26 @@
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
+ <%- unless options[:authlogic] -%>
23
+ session['<%= user_singular_name %>_id'].should == assigns['<%= user_singular_name %>'].id
24
+ <%- end -%>
25
+ end
26
+ end
@@ -0,0 +1,40 @@
1
+ require 'test_helper'
2
+
3
+ class <%= session_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
+ <%- if options[:authlogic] -%>
13
+ should "render new template when authentication is invalid" do
14
+ post :create, :<%= session_singular_name %> => { :username => "foo", :password => "badpassword" }
15
+ assert_template 'new'
16
+ assert_nil <%= session_class_name %>.find
17
+ end
18
+
19
+ should "redirect when authentication is valid" do
20
+ post :create, :<%= session_singular_name %> => { :username => "foo", :password => "secret" }
21
+ assert_redirected_to root_url
22
+ assert_equal <%= user_plural_name %>(:foo), <%= session_class_name %>.find.<%= user_singular_name %>
23
+ end
24
+ <%- else -%>
25
+ should "render new template when authentication is invalid" do
26
+ <%= user_class_name %>.stubs(:authenticate).returns(nil)
27
+ post :create
28
+ assert_template 'new'
29
+ assert_nil session['<%= user_singular_name %>_id']
30
+ end
31
+
32
+ should "redirect when authentication is valid" do
33
+ <%= user_class_name %>.stubs(:authenticate).returns(<%= user_class_name %>.first)
34
+ post :create
35
+ assert_redirected_to root_url
36
+ assert_equal <%= user_class_name %>.first.id, session['<%= user_singular_name %>_id']
37
+ end
38
+ <%- end -%>
39
+ end
40
+ end
@@ -0,0 +1,85 @@
1
+ require 'test_helper'
2
+
3
+ class <%= user_class_name %>Test < ActiveSupport::TestCase
4
+ <%- unless options[:authlogic] -%>
5
+ def new_<%= user_singular_name %>(attributes = {})
6
+ attributes[:username] ||= 'foo'
7
+ attributes[:email] ||= 'foo@example.com'
8
+ attributes[:password] ||= 'abc123'
9
+ attributes[:password_confirmation] ||= attributes[:password]
10
+ <%= user_singular_name %> = <%= user_class_name %>.new(attributes)
11
+ <%= user_singular_name %>.valid? # run validations
12
+ <%= user_singular_name %>
13
+ end
14
+
15
+ def setup
16
+ <%= user_class_name %>.delete_all
17
+ end
18
+
19
+ should "be valid" do
20
+ assert new_<%= user_singular_name %>.valid?
21
+ end
22
+
23
+ should "require username" do
24
+ assert new_<%= user_singular_name %>(:username => '').errors.on(:username)
25
+ end
26
+
27
+ should "require password" do
28
+ assert new_<%= user_singular_name %>(:password => '').errors.on(:password)
29
+ end
30
+
31
+ should "require well formed email" do
32
+ assert new_<%= user_singular_name %>(:email => 'foo@bar@example.com').errors.on(:email)
33
+ end
34
+
35
+ should "validate uniqueness of email" do
36
+ new_<%= user_singular_name %>(:email => 'bar@example.com').save!
37
+ assert new_<%= user_singular_name %>(:email => 'bar@example.com').errors.on(:email)
38
+ end
39
+
40
+ should "validate uniqueness of username" do
41
+ new_<%= user_singular_name %>(:username => 'uniquename').save!
42
+ assert new_<%= user_singular_name %>(:username => 'uniquename').errors.on(:username)
43
+ end
44
+
45
+ should "not allow odd characters in username" do
46
+ assert new_<%= user_singular_name %>(:username => 'odd ^&(@)').errors.on(:username)
47
+ end
48
+
49
+ should "validate password is longer than 3 characters" do
50
+ assert new_<%= user_singular_name %>(:password => 'bad').errors.on(:password)
51
+ end
52
+
53
+ should "require matching password confirmation" do
54
+ assert new_<%= user_singular_name %>(:password_confirmation => 'nonmatching').errors.on(:password)
55
+ end
56
+
57
+ should "generate password hash and salt on create" do
58
+ <%= user_singular_name %> = new_<%= user_singular_name %>
59
+ <%= user_singular_name %>.save!
60
+ assert <%= user_singular_name %>.password_hash
61
+ assert <%= user_singular_name %>.password_salt
62
+ end
63
+
64
+ should "authenticate by username" do
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
+ should "authenticate by email" do
71
+ <%= user_singular_name %> = new_<%= user_singular_name %>(:email => 'foo@bar.com', :password => 'secret')
72
+ <%= user_singular_name %>.save!
73
+ assert_equal <%= user_singular_name %>, <%= user_class_name %>.authenticate('foo@bar.com', 'secret')
74
+ end
75
+
76
+ should "not authenticate bad username" do
77
+ assert_nil <%= user_class_name %>.authenticate('nonexisting', 'secret')
78
+ end
79
+
80
+ should "not authenticate bad password" do
81
+ new_<%= user_singular_name %>(:username => 'foobar', :password => 'secret').save!
82
+ assert_nil <%= user_class_name %>.authenticate('foobar', 'badpassword')
83
+ end
84
+ <%- end -%>
85
+ end
@@ -0,0 +1,27 @@
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
+ <%- unless options[:authlogic] -%>
23
+ assert_equal assigns['<%= user_singular_name %>'].id, session['<%= user_singular_name %>_id']
24
+ <%- end -%>
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,36 @@
1
+ require 'test_helper'
2
+
3
+ class <%= session_plural_class_name %>ControllerTest < ActionController::TestCase
4
+ def test_new
5
+ get :new
6
+ assert_template 'new'
7
+ end
8
+
9
+ <%- if options[:authlogic] -%>
10
+ def test_create_invalid
11
+ post :create, :<%= session_singular_name %> => { :username => "foo", :password => "badpassword" }
12
+ assert_template 'new'
13
+ assert_nil <%= session_class_name %>.find
14
+ end
15
+
16
+ def test_create_valid
17
+ post :create, :<%= session_singular_name %> => { :username => "foo", :password => "secret" }
18
+ assert_redirected_to root_url
19
+ assert_equal <%= user_plural_name %>(:foo), <%= session_class_name %>.find.<%= user_singular_name %>
20
+ end
21
+ <%- else -%>
22
+ def test_create_invalid
23
+ <%= user_class_name %>.stubs(:authenticate).returns(nil)
24
+ post :create
25
+ assert_template 'new'
26
+ assert_nil session['<%= user_singular_name %>_id']
27
+ end
28
+
29
+ def test_create_valid
30
+ <%= user_class_name %>.stubs(:authenticate).returns(<%= user_class_name %>.first)
31
+ post :create
32
+ assert_redirected_to root_url
33
+ assert_equal <%= user_class_name %>.first.id, session['<%= user_singular_name %>_id']
34
+ end
35
+ <%- end -%>
36
+ end
@@ -0,0 +1,88 @@
1
+ require 'test_helper'
2
+
3
+ class <%= user_class_name %>Test < ActiveSupport::TestCase
4
+ <%- unless options[:authlogic] -%>
5
+ def new_<%= user_singular_name %>(attributes = {})
6
+ attributes[:username] ||= 'foo'
7
+ attributes[:email] ||= 'foo@example.com'
8
+ attributes[:password] ||= 'abc123'
9
+ attributes[:password_confirmation] ||= attributes[:password]
10
+ <%= user_singular_name %> = <%= user_class_name %>.new(attributes)
11
+ <%= user_singular_name %>.valid? # run validations
12
+ <%= user_singular_name %>
13
+ end
14
+
15
+ def setup
16
+ <%= user_class_name %>.delete_all
17
+ end
18
+
19
+ def test_valid
20
+ assert new_<%= user_singular_name %>.valid?
21
+ end
22
+
23
+ def test_require_username
24
+ assert new_<%= user_singular_name %>(:username => '').errors.on(:username)
25
+ end
26
+
27
+ def test_require_password
28
+ assert new_<%= user_singular_name %>(:password => '').errors.on(:password)
29
+ end
30
+
31
+ def test_require_well_formed_email
32
+ assert new_<%= user_singular_name %>(:email => 'foo@bar@example.com').errors.on(:email)
33
+ end
34
+
35
+ def test_validate_uniqueness_of_email
36
+ new_<%= user_singular_name %>(:email => 'bar@example.com').save!
37
+ assert new_<%= user_singular_name %>(:email => 'bar@example.com').errors.on(:email)
38
+ end
39
+
40
+ def test_validate_uniqueness_of_username
41
+ new_<%= user_singular_name %>(:username => 'uniquename').save!
42
+ assert new_<%= user_singular_name %>(:username => 'uniquename').errors.on(:username)
43
+ end
44
+
45
+ def test_validate_odd_characters_in_username
46
+ assert new_<%= user_singular_name %>(:username => 'odd ^&(@)').errors.on(:username)
47
+ end
48
+
49
+ def test_validate_password_length
50
+ assert new_<%= user_singular_name %>(:password => 'bad').errors.on(:password)
51
+ end
52
+
53
+ def test_require_matching_password_confirmation
54
+ assert new_<%= user_singular_name %>(:password_confirmation => 'nonmatching').errors.on(:password)
55
+ end
56
+
57
+ def test_generate_password_hash_and_salt_on_create
58
+ <%= user_singular_name %> = new_<%= user_singular_name %>
59
+ <%= user_singular_name %>.save!
60
+ assert <%= user_singular_name %>.password_hash
61
+ assert <%= user_singular_name %>.password_salt
62
+ end
63
+
64
+ def test_authenticate_by_username
65
+ <%= user_class_name %>.delete_all
66
+ <%= user_singular_name %> = new_<%= user_singular_name %>(:username => 'foobar', :password => 'secret')
67
+ <%= user_singular_name %>.save!
68
+ assert_equal <%= user_singular_name %>, <%= user_class_name %>.authenticate('foobar', 'secret')
69
+ end
70
+
71
+ def test_authenticate_by_email
72
+ <%= user_class_name %>.delete_all
73
+ <%= user_singular_name %> = new_<%= user_singular_name %>(:email => 'foo@bar.com', :password => 'secret')
74
+ <%= user_singular_name %>.save!
75
+ assert_equal <%= user_singular_name %>, <%= user_class_name %>.authenticate('foo@bar.com', 'secret')
76
+ end
77
+
78
+ def test_authenticate_bad_username
79
+ assert_nil <%= user_class_name %>.authenticate('nonexisting', 'secret')
80
+ end
81
+
82
+ def test_authenticate_bad_password
83
+ <%= user_class_name %>.delete_all
84
+ new_<%= user_singular_name %>(:username => 'foobar', :password => 'secret').save!
85
+ assert_nil <%= user_class_name %>.authenticate('foobar', 'badpassword')
86
+ end
87
+ <%- end -%>
88
+ end
@@ -0,0 +1,23 @@
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
+ <%- unless options[:authlogic] -%>
20
+ assert_equal assigns['<%= user_singular_name %>'].id, session['<%= user_singular_name %>_id']
21
+ <%- end -%>
22
+ end
23
+ end