tft_rails_dbc 0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (159) hide show
  1. data/.gitignore +6 -0
  2. data/.rvmrc +1 -0
  3. data/Gemfile +8 -0
  4. data/LICENSE +57 -0
  5. data/README.md +90 -0
  6. data/Rakefile +25 -0
  7. data/lib/generators/chapter07/begin/USAGE +27 -0
  8. data/lib/generators/chapter07/begin/begin_generator.rb +39 -0
  9. data/lib/generators/chapter07/begin/instructions.md +74 -0
  10. data/lib/generators/chapter07/begin/templates/app/controllers/application_controller.rb +8 -0
  11. data/lib/generators/chapter07/begin/templates/app/controllers/pages_controller.rb +11 -0
  12. data/lib/generators/chapter07/begin/templates/app/controllers/users_controller.rb +3 -0
  13. data/lib/generators/chapter07/begin/templates/app/helpers/application_helper.rb +12 -0
  14. data/lib/generators/chapter07/begin/templates/app/helpers/pages_helper.rb +2 -0
  15. data/lib/generators/chapter07/begin/templates/app/helpers/users_helper.rb +7 -0
  16. data/lib/generators/chapter07/begin/templates/app/models/user.rb +9 -0
  17. data/lib/generators/chapter07/begin/templates/app/views/layouts/_footer.html.erb +9 -0
  18. data/lib/generators/chapter07/begin/templates/app/views/layouts/_header.html.erb +10 -0
  19. data/lib/generators/chapter07/begin/templates/app/views/layouts/_stylesheets.html.erb +7 -0
  20. data/lib/generators/chapter07/begin/templates/app/views/layouts/application.html.erb +17 -0
  21. data/lib/generators/chapter07/begin/templates/app/views/pages/about.html.erb +7 -0
  22. data/lib/generators/chapter07/begin/templates/app/views/pages/contact.html.erb +5 -0
  23. data/lib/generators/chapter07/begin/templates/app/views/pages/home.html.erb +7 -0
  24. data/lib/generators/chapter07/begin/templates/app/views/users/show.html.erb +15 -0
  25. data/lib/generators/chapter07/begin/templates/config/initializers/devise.rb +194 -0
  26. data/lib/generators/chapter07/begin/templates/config/locales/devise.en.yml +50 -0
  27. data/lib/generators/chapter07/begin/templates/config/routes.rb.tt +17 -0
  28. data/lib/generators/chapter07/begin/templates/db/migrate/20110608224650_devise_create_users.rb +29 -0
  29. data/lib/generators/chapter07/begin/templates/db/schema.rb +34 -0
  30. data/lib/generators/chapter07/begin/templates/public/images/logo.png +0 -0
  31. data/lib/generators/chapter07/begin/templates/public/stylesheets/blueprint/ie.css +36 -0
  32. data/lib/generators/chapter07/begin/templates/public/stylesheets/blueprint/plugins/buttons/icons/cross.png +0 -0
  33. data/lib/generators/chapter07/begin/templates/public/stylesheets/blueprint/plugins/buttons/icons/key.png +0 -0
  34. data/lib/generators/chapter07/begin/templates/public/stylesheets/blueprint/plugins/buttons/icons/tick.png +0 -0
  35. data/lib/generators/chapter07/begin/templates/public/stylesheets/blueprint/plugins/buttons/readme.txt +32 -0
  36. data/lib/generators/chapter07/begin/templates/public/stylesheets/blueprint/plugins/buttons/screen.css +97 -0
  37. data/lib/generators/chapter07/begin/templates/public/stylesheets/blueprint/plugins/fancy-type/readme.txt +14 -0
  38. data/lib/generators/chapter07/begin/templates/public/stylesheets/blueprint/plugins/fancy-type/screen.css +71 -0
  39. data/lib/generators/chapter07/begin/templates/public/stylesheets/blueprint/plugins/link-icons/icons/doc.png +0 -0
  40. data/lib/generators/chapter07/begin/templates/public/stylesheets/blueprint/plugins/link-icons/icons/email.png +0 -0
  41. data/lib/generators/chapter07/begin/templates/public/stylesheets/blueprint/plugins/link-icons/icons/external.png +0 -0
  42. data/lib/generators/chapter07/begin/templates/public/stylesheets/blueprint/plugins/link-icons/icons/feed.png +0 -0
  43. data/lib/generators/chapter07/begin/templates/public/stylesheets/blueprint/plugins/link-icons/icons/im.png +0 -0
  44. data/lib/generators/chapter07/begin/templates/public/stylesheets/blueprint/plugins/link-icons/icons/lock.png +0 -0
  45. data/lib/generators/chapter07/begin/templates/public/stylesheets/blueprint/plugins/link-icons/icons/pdf.png +0 -0
  46. data/lib/generators/chapter07/begin/templates/public/stylesheets/blueprint/plugins/link-icons/icons/visited.png +0 -0
  47. data/lib/generators/chapter07/begin/templates/public/stylesheets/blueprint/plugins/link-icons/icons/xls.png +0 -0
  48. data/lib/generators/chapter07/begin/templates/public/stylesheets/blueprint/plugins/link-icons/readme.txt +18 -0
  49. data/lib/generators/chapter07/begin/templates/public/stylesheets/blueprint/plugins/link-icons/screen.css +42 -0
  50. data/lib/generators/chapter07/begin/templates/public/stylesheets/blueprint/plugins/rtl/readme.txt +10 -0
  51. data/lib/generators/chapter07/begin/templates/public/stylesheets/blueprint/plugins/rtl/screen.css +110 -0
  52. data/lib/generators/chapter07/begin/templates/public/stylesheets/blueprint/print.css +29 -0
  53. data/lib/generators/chapter07/begin/templates/public/stylesheets/blueprint/screen.css +265 -0
  54. data/lib/generators/chapter07/begin/templates/public/stylesheets/blueprint/src/forms.css +82 -0
  55. data/lib/generators/chapter07/begin/templates/public/stylesheets/blueprint/src/grid.css +280 -0
  56. data/lib/generators/chapter07/begin/templates/public/stylesheets/blueprint/src/grid.png +0 -0
  57. data/lib/generators/chapter07/begin/templates/public/stylesheets/blueprint/src/ie.css +79 -0
  58. data/lib/generators/chapter07/begin/templates/public/stylesheets/blueprint/src/print.css +92 -0
  59. data/lib/generators/chapter07/begin/templates/public/stylesheets/blueprint/src/reset.css +65 -0
  60. data/lib/generators/chapter07/begin/templates/public/stylesheets/blueprint/src/typography.css +123 -0
  61. data/lib/generators/chapter07/begin/templates/public/stylesheets/custom.css +137 -0
  62. data/lib/generators/chapter07/begin/templates/spec/controllers/pages_controller_07_spec.rb +48 -0
  63. data/lib/generators/chapter07/begin/templates/spec/controllers/users_controller_07_spec.rb +38 -0
  64. data/lib/generators/chapter07/begin/templates/spec/factories.rb +9 -0
  65. data/lib/generators/chapter07/begin/templates/spec/models/user_07_spec.rb +38 -0
  66. data/lib/generators/chapter07/begin/templates/spec/requests/layout_links_07_spec.rb +44 -0
  67. data/lib/generators/chapter07/begin/templates/spec/spec_helper.rb +39 -0
  68. data/lib/generators/chapter07/solutions/USAGE +21 -0
  69. data/lib/generators/chapter07/solutions/solutions_generator.rb +23 -0
  70. data/lib/generators/chapter07/solutions/templates/app/controllers/pages_controller.rb +18 -0
  71. data/lib/generators/chapter07/solutions/templates/app/controllers/users_controller.rb +8 -0
  72. data/lib/generators/chapter07/solutions/templates/app/models/user.rb +11 -0
  73. data/lib/generators/chapter07/solutions/templates/app/views/layouts/_footer.html.erb +10 -0
  74. data/lib/generators/chapter07/solutions/templates/app/views/layouts/_header.html.erb +11 -0
  75. data/lib/generators/chapter07/solutions/templates/app/views/pages/help.html.erb +4 -0
  76. data/lib/generators/chapter07/solutions/templates/app/views/pages/home.html.erb +7 -0
  77. data/lib/generators/chapter07/solutions/templates/app/views/users/show.html.erb +15 -0
  78. data/lib/generators/chapter08_09/begin/USAGE +24 -0
  79. data/lib/generators/chapter08_09/begin/begin_generator.rb +29 -0
  80. data/lib/generators/chapter08_09/begin/instructions.md +65 -0
  81. data/lib/generators/chapter08_09/begin/snippets/custom.css +49 -0
  82. data/lib/generators/chapter08_09/begin/templates/spec/controllers/devise/registrations_controller_08_spec.rb +83 -0
  83. data/lib/generators/chapter08_09/begin/templates/spec/requests/layout_links_09_spec.rb +35 -0
  84. data/lib/generators/chapter08_09/begin/templates/spec/requests/users_signup_08_spec.rb +36 -0
  85. data/lib/generators/chapter08_09/solutions/USAGE +18 -0
  86. data/lib/generators/chapter08_09/solutions/solutions_generator.rb +12 -0
  87. data/lib/generators/chapter08_09/solutions/templates/app/helpers/application_helper.rb +16 -0
  88. data/lib/generators/chapter08_09/solutions/templates/app/views/devise/passwords/edit.html.erb +16 -0
  89. data/lib/generators/chapter08_09/solutions/templates/app/views/devise/passwords/new.html.erb +12 -0
  90. data/lib/generators/chapter08_09/solutions/templates/app/views/devise/registrations/_fields.html.erb +16 -0
  91. data/lib/generators/chapter08_09/solutions/templates/app/views/devise/registrations/edit.html.erb +28 -0
  92. data/lib/generators/chapter08_09/solutions/templates/app/views/devise/registrations/new.html.erb +13 -0
  93. data/lib/generators/chapter08_09/solutions/templates/app/views/devise/sessions/new.html.erb +17 -0
  94. data/lib/generators/chapter08_09/solutions/templates/app/views/devise/shared/_links.erb +25 -0
  95. data/lib/generators/chapter08_09/solutions/templates/app/views/layouts/_header.html.erb +19 -0
  96. data/lib/generators/chapter08_09/solutions/templates/app/views/layouts/application.html.erb +20 -0
  97. data/lib/generators/chapter10/begin/USAGE +24 -0
  98. data/lib/generators/chapter10/begin/begin_generator.rb +41 -0
  99. data/lib/generators/chapter10/begin/instructions.md +47 -0
  100. data/lib/generators/chapter10/begin/snippets/custom.css +12 -0
  101. data/lib/generators/chapter10/begin/snippets/factories.rb +10 -0
  102. data/lib/generators/chapter10/begin/templates/app/views/layouts/application.html.erb +21 -0
  103. data/lib/generators/chapter10/begin/templates/lib/tasks/sample_data.rake +24 -0
  104. data/lib/generators/chapter10/begin/templates/spec/controllers/users_controller_10_spec.rb +110 -0
  105. data/lib/generators/chapter10/begin/templates/spec/models/user_10_spec.rb +24 -0
  106. data/lib/generators/chapter10/solutions/USAGE +18 -0
  107. data/lib/generators/chapter10/solutions/snippets/migration_add_admin_to_users.rb +9 -0
  108. data/lib/generators/chapter10/solutions/solutions_generator.rb +32 -0
  109. data/lib/generators/chapter10/solutions/templates/app/controllers/users_controller.rb +28 -0
  110. data/lib/generators/chapter10/solutions/templates/app/views/users/_user.html.erb +8 -0
  111. data/lib/generators/chapter10/solutions/templates/app/views/users/index.html.erb +9 -0
  112. data/lib/generators/chapter11_1/begin/USAGE +24 -0
  113. data/lib/generators/chapter11_1/begin/begin_generator.rb +24 -0
  114. data/lib/generators/chapter11_1/begin/instructions.md +39 -0
  115. data/lib/generators/chapter11_1/begin/templates/lib/tasks/sample_data.rake +29 -0
  116. data/lib/generators/chapter11_1/begin/templates/spec/models/microposts_11_1_spec.rb +45 -0
  117. data/lib/generators/chapter11_1/begin/templates/spec/models/user_11_1_spec.rb +30 -0
  118. data/lib/generators/chapter11_1/solutions/USAGE +18 -0
  119. data/lib/generators/chapter11_1/solutions/snippets/migration_create_microposts.rb +17 -0
  120. data/lib/generators/chapter11_1/solutions/solutions_generator.rb +25 -0
  121. data/lib/generators/chapter11_1/solutions/templates/app/models/micropost.rb +10 -0
  122. data/lib/generators/chapter11_1/solutions/templates/app/models/user.rb +14 -0
  123. data/lib/generators/chapter11_1/solutions/templates/spec/factories.rb +16 -0
  124. data/lib/generators/chapter11_2/begin/USAGE +24 -0
  125. data/lib/generators/chapter11_2/begin/begin_generator.rb +30 -0
  126. data/lib/generators/chapter11_2/begin/instructions.md +35 -0
  127. data/lib/generators/chapter11_2/begin/snippets/custom.css +59 -0
  128. data/lib/generators/chapter11_2/begin/templates/app/views/users/show.html.erb +23 -0
  129. data/lib/generators/chapter11_2/begin/templates/spec/controllers/users_controller_11_2_spec.rb +31 -0
  130. data/lib/generators/chapter11_2/solutions/USAGE +18 -0
  131. data/lib/generators/chapter11_2/solutions/solutions_generator.rb +12 -0
  132. data/lib/generators/chapter11_2/solutions/templates/app/controllers/users_controller.rb +29 -0
  133. data/lib/generators/chapter11_2/solutions/templates/app/views/microposts/_micropost.html.erb +8 -0
  134. data/lib/generators/chapter11_2/solutions/templates/app/views/users/show.html.erb +23 -0
  135. data/lib/generators/chapter11_3/begin/USAGE +24 -0
  136. data/lib/generators/chapter11_3/begin/begin_generator.rb +24 -0
  137. data/lib/generators/chapter11_3/begin/instructions.md +80 -0
  138. data/lib/generators/chapter11_3/begin/templates/app/views/pages/home.html.erb +24 -0
  139. data/lib/generators/chapter11_3/begin/templates/app/views/shared/_feed.html.erb +6 -0
  140. data/lib/generators/chapter11_3/begin/templates/app/views/shared/_feed_item.html.erb +14 -0
  141. data/lib/generators/chapter11_3/begin/templates/app/views/shared/_micropost_form.html.erb +9 -0
  142. data/lib/generators/chapter11_3/begin/templates/app/views/shared/_user_info.html.erb +11 -0
  143. data/lib/generators/chapter11_3/begin/templates/spec/controllers/microposts_controllers_11_3_spec.rb +103 -0
  144. data/lib/generators/chapter11_3/begin/templates/spec/controllers/pages_controller_11_3_spec.rb +14 -0
  145. data/lib/generators/chapter11_3/begin/templates/spec/models/user_11_3_spec.rb +31 -0
  146. data/lib/generators/chapter11_3/begin/templates/spec/requests/micropost_11_3_spec.rb +41 -0
  147. data/lib/generators/chapter11_3/solutions/USAGE +18 -0
  148. data/lib/generators/chapter11_3/solutions/solutions_generator.rb +30 -0
  149. data/lib/generators/chapter11_3/solutions/templates/app/controllers/microposts_controller.rb +20 -0
  150. data/lib/generators/chapter11_3/solutions/templates/app/controllers/pages_controller.rb +22 -0
  151. data/lib/generators/chapter11_3/solutions/templates/app/views/microposts/_micropost.html.erb +15 -0
  152. data/lib/generators/chapter11_3/solutions/templates/app/views/pages/home.html.erb +24 -0
  153. data/lib/generators/chapter11_3/solutions/templates/app/views/shared/_error_messages.html.erb +13 -0
  154. data/lib/generators/chapter11_3/solutions/templates/app/views/shared/_feed.html.erb +6 -0
  155. data/lib/generators/chapter11_3/solutions/templates/app/views/shared/_feed_item.html.erb +21 -0
  156. data/lib/generators/chapter11_3/solutions/templates/app/views/shared/_micropost_form.html.erb +9 -0
  157. data/lib/generators/chapter11_3/solutions/templates/app/views/shared/_user_info.html.erb +11 -0
  158. data/lib/tft_rails.rb +2 -0
  159. metadata +217 -0
@@ -0,0 +1,83 @@
1
+ require 'spec_helper'
2
+
3
+ describe Devise::RegistrationsController do
4
+ render_views
5
+
6
+ before do
7
+ # The following request parameter is necessary for testing, according to:
8
+ # https://github.com/plataformatec/devise/wiki/How-To:-Controllers-and-Views-tests-with-Rails-3-(and-rspec)
9
+ request.env["devise.mapping"] = Devise.mappings[:user]
10
+ end
11
+
12
+ describe "GET 'new'" do
13
+
14
+ it "should be successful" do
15
+ get :new
16
+ response.should be_success
17
+ end
18
+
19
+ it "should have h1 tag with Sign up" do
20
+ get :new
21
+ response.should have_selector("h1", :content => "Sign up")
22
+ end
23
+
24
+ %w(name email password password_confirmation).each do |attr|
25
+ it "should have a #{attr} field" do
26
+ get :new
27
+ response.should have_selector("input[name='user[#{attr}]']")
28
+ end
29
+ end
30
+ end
31
+
32
+
33
+ describe "POST 'create'" do
34
+
35
+ describe "failure" do
36
+
37
+ before(:each) do
38
+ @attr = { :name => "", :email => "", :password => "",
39
+ :password_confirmation => "" }
40
+ end
41
+
42
+ it "should not create a user" do
43
+ expect {
44
+ post :create, :user => @attr
45
+ }.to_not change(User, :count)
46
+ end
47
+
48
+ it "should render the 'new' page" do
49
+ post :create, :user => @attr
50
+ response.should render_template('new')
51
+ end
52
+
53
+ it "should show errors" do
54
+ post :create, :user => @attr
55
+ response.should have_selector("div#error_explanation")
56
+ end
57
+ end
58
+
59
+ describe "success" do
60
+
61
+ before(:each) do
62
+ @attr = { :name => "New User", :email => "user@example.com",
63
+ :password => "foobar", :password_confirmation => "foobar" }
64
+ end
65
+
66
+ it "should create a user" do
67
+ expect {
68
+ post :create, :user => @attr
69
+ }.to change(User, :count).by(1)
70
+ end
71
+
72
+ it "should redirect to the user show page" do
73
+ post :create, :user => @attr
74
+ response.should redirect_to(user_path(assigns(:user)))
75
+ end
76
+
77
+ it "should have a welcome message" do
78
+ post :create, :user => @attr
79
+ flash[:notice].should == "Welcome! You have signed up successfully."
80
+ end
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Layout links" do
4
+
5
+ describe "when not signed in" do
6
+ it "should have a signin link" do
7
+ visit root_path
8
+ response.should have_selector("a", :href => signin_path,
9
+ :content => "Sign in")
10
+ end
11
+ end
12
+
13
+ describe "when signed in" do
14
+
15
+ before(:each) do
16
+ @user = Factory(:user)
17
+ visit signin_path
18
+ fill_in :email, :with => @user.email
19
+ fill_in :password, :with => @user.password
20
+ click_button
21
+ end
22
+
23
+ it "should have a signout link" do
24
+ visit root_path
25
+ response.should have_selector("a", :href => signout_path,
26
+ :content => "Sign out")
27
+ end
28
+
29
+ it "should have a profile link" do
30
+ visit root_path
31
+ response.should have_selector("a", :href => user_path(@user),
32
+ :content => "Profile")
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,36 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Users" do
4
+
5
+ describe "signup" do
6
+
7
+ describe "success" do
8
+
9
+ it "should make a new user" do
10
+ expect {
11
+ visit signup_path
12
+ fill_in "Name", :with => "Example User"
13
+ fill_in "Email", :with => "user@example.com"
14
+ fill_in "Password", :with => "foobar"
15
+ fill_in "Confirmation", :with => "foobar"
16
+ click_button
17
+ response.should render_template('users/show')
18
+ }.to change(User, :count).by(1)
19
+ end
20
+
21
+ it "should print a welcome message" do
22
+ visit signup_path
23
+ fill_in "Name", :with => "Example User"
24
+ fill_in "Email", :with => "user@example.com"
25
+ fill_in "Password", :with => "foobar"
26
+ fill_in "Confirmation", :with => "foobar"
27
+ click_button
28
+ response.should have_selector("div.flash.notice",
29
+ :content => "Welcome! You have signed up successfully.")
30
+ end
31
+
32
+ end
33
+
34
+
35
+ end
36
+ end
@@ -0,0 +1,18 @@
1
+ Description:
2
+ Wraps up Test-First Teaching exercises adapted from Chapters 08, 09 of the RailsTutorial by Michael Hartl.
3
+
4
+ Example:
5
+ rails generate chapter08_09:solutions
6
+
7
+ This copies the solutions and other necessary files (e.g. images, assets, helpers, etc.) into the project
8
+ to conclude Chapters 08, 09. This should make all tests pass and bring you in sync to the application at
9
+ the end of Chapters 08, 09.
10
+
11
+ If you already have a solution file, you'll be prompted whether you want to overwrite your file,
12
+ see the difference, or keep your file.
13
+
14
+ It's a good idea to commit your changes to git, prior to running finish, in case you accidentally choose to
15
+ overwrite files you wanted to keep. Assuming your project is already git-controlled, you can commit changes with:
16
+
17
+ git add .
18
+ git commit -m "comment here explaining WHY you made the changes"
@@ -0,0 +1,12 @@
1
+ module Chapter08_09
2
+ module Generators
3
+ class SolutionsGenerator < Rails::Generators::Base
4
+ source_root File.expand_path("../templates", __FILE__)
5
+
6
+ def copy_app_tree
7
+ directory(self.class.source_root, Rails.root)
8
+ end
9
+
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,16 @@
1
+ module ApplicationHelper
2
+
3
+ def title
4
+ base_title = "Ruby on Rails Tutorial Sample App"
5
+ if @title.nil?
6
+ base_title
7
+ else
8
+ "#{base_title} | #{@title}"
9
+ end
10
+ end
11
+
12
+ def logo
13
+ image_tag("logo.png", :alt => "Sample App", :class => "round")
14
+ end
15
+
16
+ end
@@ -0,0 +1,16 @@
1
+ <h2>Change your password</h2>
2
+
3
+ <%= form_for(resource, :as => resource_name, :url => password_path(resource_name), :html => { :method => :put }) do |f| %>
4
+ <%= devise_error_messages! %>
5
+ <%= f.hidden_field :reset_password_token %>
6
+
7
+ <p><%= f.label :password, "New password" %><br />
8
+ <%= f.password_field :password %></p>
9
+
10
+ <p><%= f.label :password_confirmation, "Confirm new password" %><br />
11
+ <%= f.password_field :password_confirmation %></p>
12
+
13
+ <p><%= f.submit "Change my password" %></p>
14
+ <% end %>
15
+
16
+ <%= render :partial => "devise/shared/links" %>
@@ -0,0 +1,12 @@
1
+ <h2>Forgot your password?</h2>
2
+
3
+ <%= form_for(resource, :as => resource_name, :url => password_path(resource_name), :html => { :method => :post }) do |f| %>
4
+ <%= devise_error_messages! %>
5
+
6
+ <p><%= f.label :email %><br />
7
+ <%= f.email_field :email %></p>
8
+
9
+ <p><%= f.submit "Send me reset password instructions" %></p>
10
+ <% end %>
11
+
12
+ <%= render :partial => "devise/shared/links" %>
@@ -0,0 +1,16 @@
1
+ <div class="field">
2
+ <%= f.label :name %><br />
3
+ <%= f.text_field :name %>
4
+ </div>
5
+ <div class="field">
6
+ <%= f.label :email %><br />
7
+ <%= f.text_field :email %>
8
+ </div>
9
+ <div class="field">
10
+ <%= f.label :password %><br />
11
+ <%= f.password_field :password %>
12
+ </div>
13
+ <div class="field">
14
+ <%= f.label :password_confirmation, "Confirmation" %><br />
15
+ <%= f.password_field :password_confirmation %>
16
+ </div>
@@ -0,0 +1,28 @@
1
+ <h1>Edit user</h1>
2
+
3
+ <%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
4
+
5
+ <%= devise_error_messages! %>
6
+ <%= render 'fields', :f => f %>
7
+
8
+ <div class="field">
9
+ <%= f.label :current_password %> <i>(we need your current password to confirm your changes)</i><br />
10
+ <%= f.password_field :current_password %>
11
+ </div>
12
+
13
+ <div class="actions">
14
+ <%= f.submit "Update" %>
15
+ </div>
16
+
17
+ <% end %>
18
+
19
+ <div>
20
+ <%= gravatar_for @user %>
21
+ <a href="http://gravatar.com/emails">change</a>
22
+ </div>
23
+
24
+ <h3>Cancel my account</h3>
25
+
26
+ <p>Unhappy? <%= link_to "Cancel my account", registration_path(resource_name), :confirm => "Are you sure?", :method => :delete %>.</p>
27
+
28
+ <%= link_to "Back", :back %>
@@ -0,0 +1,13 @@
1
+ <h1>Sign up</h1>
2
+
3
+ <%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
4
+
5
+ <%= devise_error_messages! %>
6
+ <%= render 'fields', :f => f %>
7
+ <div class="actions">
8
+ <%= f.submit "Sign up" %>
9
+ </div>
10
+
11
+ <% end %>
12
+
13
+ <%= render :partial => "devise/shared/links" %>
@@ -0,0 +1,17 @@
1
+ <h2>Sign in</h2>
2
+
3
+ <%= form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |f| %>
4
+ <p><%= f.label :email %><br />
5
+ <%= f.email_field :email %></p>
6
+
7
+ <p><%= f.label :password %><br />
8
+ <%= f.password_field :password %></p>
9
+
10
+ <% if devise_mapping.rememberable? -%>
11
+ <p><%= f.check_box :remember_me %> <%= f.label :remember_me %></p>
12
+ <% end -%>
13
+
14
+ <p><%= f.submit "Sign in" %></p>
15
+ <% end %>
16
+
17
+ <%= render :partial => "devise/shared/links" %>
@@ -0,0 +1,25 @@
1
+ <%- if controller_name != 'sessions' %>
2
+ <%= link_to "Sign in", new_session_path(resource_name) %><br />
3
+ <% end -%>
4
+
5
+ <%- if devise_mapping.registerable? && controller_name != 'registrations' %>
6
+ New User? <%= link_to "Sign up", new_registration_path(resource_name) %><br />
7
+ <% end -%>
8
+
9
+ <%- if devise_mapping.recoverable? && controller_name != 'passwords' %>
10
+ <%= link_to "Forgot your password?", new_password_path(resource_name) %><br />
11
+ <% end -%>
12
+
13
+ <%- if devise_mapping.confirmable? && controller_name != 'confirmations' %>
14
+ <%= link_to "Didn't receive confirmation instructions?", new_confirmation_path(resource_name) %><br />
15
+ <% end -%>
16
+
17
+ <%- if devise_mapping.lockable? && resource_class.unlock_strategy_enabled?(:email) && controller_name != 'unlocks' %>
18
+ <%= link_to "Didn't receive unlock instructions?", new_unlock_path(resource_name) %><br />
19
+ <% end -%>
20
+
21
+ <%- if devise_mapping.omniauthable? %>
22
+ <%- resource_class.omniauth_providers.each do |provider| %>
23
+ <%= link_to "Sign in with #{provider.to_s.titleize}", omniauth_authorize_path(resource_name, provider) %><br />
24
+ <% end -%>
25
+ <% end -%>
@@ -0,0 +1,19 @@
1
+ <header>
2
+ <%= link_to logo, root_path %>
3
+ <nav class="round">
4
+ <ul>
5
+ <li><%= link_to "Home", root_path %></li>
6
+ <% if signed_in? %>
7
+ <li><%= link_to "Profile", user_path(current_user) %></li>
8
+ <li><%= link_to "Users", users_path %></li>
9
+ <li><%= link_to "Settings", edit_user_registration_path(current_user.id) %></li>
10
+ <% end %>
11
+ <li><%= link_to "Help", help_path %></li>
12
+ <% if signed_in? %>
13
+ <li><%= link_to "Sign out", signout_path %></li>
14
+ <% else %>
15
+ <li><%= link_to "Sign in", signin_path %></li>
16
+ <% end %>
17
+ </ul>
18
+ </nav>
19
+ </header>
@@ -0,0 +1,20 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title><%= title %></title>
5
+ <%= csrf_meta_tag %>
6
+ <%= render 'layouts/stylesheets' %>
7
+ </head>
8
+ <body>
9
+ <div class="container">
10
+ <%= render 'layouts/header' %>
11
+ <section class="round">
12
+ <% flash.each do |key, value| %>
13
+ <div class="flash <%= key %>"><%= value %></div>
14
+ <% end %>
15
+ <%= yield %>
16
+ </section>
17
+ <%= render 'layouts/footer' %>
18
+ </div>
19
+ </body>
20
+ </html>
@@ -0,0 +1,24 @@
1
+ Description:
2
+ Begins Test-First Teaching exercises adapted from Chapter 10 of the RailsTutorial by Michael Hartl.
3
+
4
+ It is assumed that this generator is run after the exercises for Chapter 08, 09 have been completed, and the solutions are implemented.
5
+
6
+ Successive chapters are expected to be run sequentially. Each chapter's generators comes with a delta
7
+ to the next chapter, in two phase, the "begin" one will create tests, the "finish" one includes the solution files.
8
+ If all tests pass, the "finish" phase is optional.
9
+
10
+ Example:
11
+ rails generate chapter10:begin
12
+
13
+ This copies new tests into the project, which are failing.
14
+ The student's task is to write code to make the test pass. The material covered by the tests is consistent
15
+ with Chapter 10 of the RailsTutorial, however adapted for Devise as authentication solution.
16
+
17
+ When you're done, and all tests pass, or you just want to skip ahead, run:
18
+
19
+ rails generate chapter10:solutions
20
+
21
+ This will copy solutions files into the application tree. If you already have a solution file,
22
+ you'll be prompted whether you want to overwrite your file, see the difference, or keep your file.
23
+
24
+
@@ -0,0 +1,41 @@
1
+ module Chapter10
2
+ module Generators
3
+ class BeginGenerator < Rails::Generators::Base
4
+ source_root File.expand_path("../templates", __FILE__)
5
+
6
+ def copy_app_tree
7
+ directory(self.class.source_root, Rails.root)
8
+ end
9
+
10
+ def augment_gemfile
11
+ gem 'faker', '~> 0.9.5'
12
+ gem 'will_paginate', '~> 3.0.pre2'
13
+ end
14
+
15
+ def insert_css
16
+ src = File.expand_path("../snippets/custom.css", __FILE__)
17
+ dest = File.join(Rails.root,'public','stylesheets','custom.css')
18
+ insert_into_file(dest, File.binread(src), :before => /\Z/) # insert before end
19
+ end
20
+
21
+ def insert_factories
22
+ src = File.expand_path("../snippets/factories.rb", __FILE__)
23
+ dest = File.join(Rails.root,'spec','factories.rb')
24
+ insert_into_file(dest, File.binread(src), :before => /\Z/) # insert before end
25
+ end
26
+
27
+ def generate_instructions
28
+ require 'rdiscount'
29
+
30
+ instr_md = File.expand_path('../instructions.md',self.class.source_root)
31
+ return unless File.exists?(instr_md)
32
+ dest = File.join(Rails.root,'doc','chapter10.html')
33
+ copy_file(instr_md, dest, :force => true) do |content|
34
+ RDiscount.new(content).to_html
35
+ end
36
+ say_status('Note',"Now open file://#{dest} in your web browser for instructions", :cyan)
37
+ end
38
+
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,47 @@
1
+ RailsTutorial Chapter 10 Test-First Teaching Instructions
2
+ =========================================================
3
+
4
+ These exercises are based on RailsTutorial but have been adapted
5
+ to the user of [Devise](devise) as authentication solution. Among
6
+ other things, Devise also provides controllers and views to edit
7
+ the user, so that Chapter 10.1 of RailsTutorial (editing users) is being
8
+ already taken care of. Similarly for 10.2 (access protecting of the edit
9
+ page).
10
+
11
+ Showing Users
12
+ -------------
13
+
14
+ Chapter 10.3 covers implementing an index view of users with
15
+ pagination and using partials.
16
+
17
+ It also covers restricting access to the index page to signed-in users.
18
+
19
+ Devise offers a facility similar to what RailsTutorials implements.
20
+
21
+ RailsTutorial implements an `authenticate` method, while Devise's
22
+ version is `authenticate_user!`. Either method redirects to the sign-in
23
+ page if the user isn't logged in.
24
+
25
+ Destroying users with admin privilege
26
+ -------------------------------------
27
+
28
+ Chapter 10.4 covers adding an admin flag to the users table, to
29
+ identify privileged administrative users.
30
+
31
+ Having such admin privileges, we go on to implement a `destroy` action
32
+ for users which, however, is only available to admin users.
33
+
34
+ What are the two things we have to protect?
35
+
36
+ Rails Concepts Covered
37
+ ======================
38
+
39
+ * Migrations
40
+ * Factories
41
+ * Rake Tasks
42
+ * `attr_accessible`
43
+ * before_filter
44
+ * rendering partials by collection object
45
+
46
+
47
+ [devise]: https://github.com/plataformatec/devise "Devise on github"
@@ -0,0 +1,12 @@
1
+
2
+ /**********************/
3
+ /* Through Chapter 10 */
4
+ /**********************/
5
+
6
+ ul.users {
7
+ margin-top: 1em;
8
+ }
9
+
10
+ .users li {
11
+ list-style: none;
12
+ }
@@ -0,0 +1,10 @@
1
+
2
+ #--------------------
3
+ # Added in Chapter 10
4
+ #--------------------
5
+
6
+ FactoryGirl.define do
7
+ sequence :email do |n|
8
+ "person#{n}@example.com"
9
+ end
10
+ end
@@ -0,0 +1,21 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title><%= title %></title>
5
+ <%= csrf_meta_tag %>
6
+ <%= render 'layouts/stylesheets' %>
7
+ <%= javascript_include_tag :defaults %>
8
+ </head>
9
+ <body>
10
+ <div class="container">
11
+ <%= render 'layouts/header' %>
12
+ <section class="round">
13
+ <% flash.each do |key, value| %>
14
+ <div class="flash <%= key %>"><%= value %></div>
15
+ <% end %>
16
+ <%= yield %>
17
+ </section>
18
+ <%= render 'layouts/footer' %>
19
+ </div>
20
+ </body>
21
+ </html>
@@ -0,0 +1,24 @@
1
+ namespace :db do
2
+ desc "Fill database with sample data"
3
+ task :populate => :environment do
4
+ Rake::Task['db:reset'].invoke
5
+ make_users
6
+ end
7
+ end
8
+
9
+ def make_users
10
+ admin = User.create!(:name => "Example User",
11
+ :email => "example@railstutorial.org",
12
+ :password => "password",
13
+ :password_confirmation => "password")
14
+ # admin.toggle!(:admin)
15
+ 99.times do |n|
16
+ name = Faker::Name.name
17
+ email = "example-#{n+1}@railstutorial.org"
18
+ password = "password"
19
+ User.create!(:name => name,
20
+ :email => email,
21
+ :password => password,
22
+ :password_confirmation => password)
23
+ end
24
+ end