tft_rails 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +6 -0
- data/.rvmrc +1 -0
- data/Gemfile +8 -0
- data/LICENSE +57 -0
- data/README.md +72 -0
- data/Rakefile +25 -0
- data/lib/generators/chapter07/begin/USAGE +27 -0
- data/lib/generators/chapter07/begin/begin_generator.rb +32 -0
- data/lib/generators/chapter07/begin/instructions.md +74 -0
- data/lib/generators/chapter07/begin/templates/app/controllers/application_controller.rb +8 -0
- data/lib/generators/chapter07/begin/templates/app/controllers/pages_controller.rb +11 -0
- data/lib/generators/chapter07/begin/templates/app/controllers/users_controller.rb +3 -0
- data/lib/generators/chapter07/begin/templates/app/helpers/application_helper.rb +12 -0
- data/lib/generators/chapter07/begin/templates/app/helpers/pages_helper.rb +2 -0
- data/lib/generators/chapter07/begin/templates/app/helpers/users_helper.rb +7 -0
- data/lib/generators/chapter07/begin/templates/app/models/user.rb +9 -0
- data/lib/generators/chapter07/begin/templates/app/views/layouts/_footer.html.erb +9 -0
- data/lib/generators/chapter07/begin/templates/app/views/layouts/_header.html.erb +10 -0
- data/lib/generators/chapter07/begin/templates/app/views/layouts/_stylesheets.html.erb +7 -0
- data/lib/generators/chapter07/begin/templates/app/views/layouts/application.html.erb +17 -0
- data/lib/generators/chapter07/begin/templates/app/views/pages/about.html.erb +7 -0
- data/lib/generators/chapter07/begin/templates/app/views/pages/contact.html.erb +5 -0
- data/lib/generators/chapter07/begin/templates/app/views/pages/home.html.erb +7 -0
- data/lib/generators/chapter07/begin/templates/app/views/users/show.html.erb +15 -0
- data/lib/generators/chapter07/begin/templates/config/initializers/devise.rb +194 -0
- data/lib/generators/chapter07/begin/templates/config/locales/devise.en.yml +50 -0
- data/lib/generators/chapter07/begin/templates/config/routes.rb.tt +17 -0
- data/lib/generators/chapter07/begin/templates/db/migrate/20110608224650_devise_create_users.rb +29 -0
- data/lib/generators/chapter07/begin/templates/db/schema.rb +34 -0
- data/lib/generators/chapter07/begin/templates/public/images/logo.png +0 -0
- data/lib/generators/chapter07/begin/templates/public/stylesheets/blueprint/ie.css +36 -0
- data/lib/generators/chapter07/begin/templates/public/stylesheets/blueprint/plugins/buttons/icons/cross.png +0 -0
- data/lib/generators/chapter07/begin/templates/public/stylesheets/blueprint/plugins/buttons/icons/key.png +0 -0
- data/lib/generators/chapter07/begin/templates/public/stylesheets/blueprint/plugins/buttons/icons/tick.png +0 -0
- data/lib/generators/chapter07/begin/templates/public/stylesheets/blueprint/plugins/buttons/readme.txt +32 -0
- data/lib/generators/chapter07/begin/templates/public/stylesheets/blueprint/plugins/buttons/screen.css +97 -0
- data/lib/generators/chapter07/begin/templates/public/stylesheets/blueprint/plugins/fancy-type/readme.txt +14 -0
- data/lib/generators/chapter07/begin/templates/public/stylesheets/blueprint/plugins/fancy-type/screen.css +71 -0
- data/lib/generators/chapter07/begin/templates/public/stylesheets/blueprint/plugins/link-icons/icons/doc.png +0 -0
- data/lib/generators/chapter07/begin/templates/public/stylesheets/blueprint/plugins/link-icons/icons/email.png +0 -0
- data/lib/generators/chapter07/begin/templates/public/stylesheets/blueprint/plugins/link-icons/icons/external.png +0 -0
- data/lib/generators/chapter07/begin/templates/public/stylesheets/blueprint/plugins/link-icons/icons/feed.png +0 -0
- data/lib/generators/chapter07/begin/templates/public/stylesheets/blueprint/plugins/link-icons/icons/im.png +0 -0
- data/lib/generators/chapter07/begin/templates/public/stylesheets/blueprint/plugins/link-icons/icons/lock.png +0 -0
- data/lib/generators/chapter07/begin/templates/public/stylesheets/blueprint/plugins/link-icons/icons/pdf.png +0 -0
- data/lib/generators/chapter07/begin/templates/public/stylesheets/blueprint/plugins/link-icons/icons/visited.png +0 -0
- data/lib/generators/chapter07/begin/templates/public/stylesheets/blueprint/plugins/link-icons/icons/xls.png +0 -0
- data/lib/generators/chapter07/begin/templates/public/stylesheets/blueprint/plugins/link-icons/readme.txt +18 -0
- data/lib/generators/chapter07/begin/templates/public/stylesheets/blueprint/plugins/link-icons/screen.css +42 -0
- data/lib/generators/chapter07/begin/templates/public/stylesheets/blueprint/plugins/rtl/readme.txt +10 -0
- data/lib/generators/chapter07/begin/templates/public/stylesheets/blueprint/plugins/rtl/screen.css +110 -0
- data/lib/generators/chapter07/begin/templates/public/stylesheets/blueprint/print.css +29 -0
- data/lib/generators/chapter07/begin/templates/public/stylesheets/blueprint/screen.css +265 -0
- data/lib/generators/chapter07/begin/templates/public/stylesheets/blueprint/src/forms.css +82 -0
- data/lib/generators/chapter07/begin/templates/public/stylesheets/blueprint/src/grid.css +280 -0
- data/lib/generators/chapter07/begin/templates/public/stylesheets/blueprint/src/grid.png +0 -0
- data/lib/generators/chapter07/begin/templates/public/stylesheets/blueprint/src/ie.css +79 -0
- data/lib/generators/chapter07/begin/templates/public/stylesheets/blueprint/src/print.css +92 -0
- data/lib/generators/chapter07/begin/templates/public/stylesheets/blueprint/src/reset.css +65 -0
- data/lib/generators/chapter07/begin/templates/public/stylesheets/blueprint/src/typography.css +123 -0
- data/lib/generators/chapter07/begin/templates/public/stylesheets/custom.css +137 -0
- data/lib/generators/chapter07/begin/templates/spec/controllers/pages_controller_07_spec.rb +48 -0
- data/lib/generators/chapter07/begin/templates/spec/controllers/users_controller_07_spec.rb +38 -0
- data/lib/generators/chapter07/begin/templates/spec/factories.rb +7 -0
- data/lib/generators/chapter07/begin/templates/spec/models/user_07_spec.rb +38 -0
- data/lib/generators/chapter07/begin/templates/spec/requests/layout_links_07_spec.rb +44 -0
- data/lib/generators/chapter07/begin/templates/spec/spec_helper.rb +29 -0
- data/lib/generators/chapter07/solutions/USAGE +21 -0
- data/lib/generators/chapter07/solutions/solutions_generator.rb +23 -0
- data/lib/generators/chapter07/solutions/templates/app/controllers/pages_controller.rb +18 -0
- data/lib/generators/chapter07/solutions/templates/app/controllers/users_controller.rb +8 -0
- data/lib/generators/chapter07/solutions/templates/app/models/user.rb +11 -0
- data/lib/generators/chapter07/solutions/templates/app/views/layouts/_footer.html.erb +10 -0
- data/lib/generators/chapter07/solutions/templates/app/views/layouts/_header.html.erb +11 -0
- data/lib/generators/chapter07/solutions/templates/app/views/pages/help.html.erb +4 -0
- data/lib/generators/chapter07/solutions/templates/app/views/pages/home.html.erb +7 -0
- data/lib/generators/chapter07/solutions/templates/app/views/users/show.html.erb +15 -0
- data/lib/generators/chapter08_09/begin/USAGE +24 -0
- data/lib/generators/chapter08_09/begin/begin_generator.rb +29 -0
- data/lib/generators/chapter08_09/begin/instructions.md +54 -0
- data/lib/generators/chapter08_09/begin/snippets/custom.css +49 -0
- data/lib/generators/chapter08_09/begin/templates/spec/controllers/devise/registrations_controller_08_spec.rb +83 -0
- data/lib/generators/chapter08_09/begin/templates/spec/requests/layout_links_09_spec.rb +35 -0
- data/lib/generators/chapter08_09/begin/templates/spec/requests/users_signup_08_spec.rb +36 -0
- data/lib/generators/chapter08_09/solutions/USAGE +18 -0
- data/lib/generators/chapter08_09/solutions/solutions_generator.rb +12 -0
- data/lib/generators/chapter08_09/solutions/templates/app/helpers/application_helper.rb +16 -0
- data/lib/generators/chapter08_09/solutions/templates/app/views/devise/passwords/edit.html.erb +16 -0
- data/lib/generators/chapter08_09/solutions/templates/app/views/devise/passwords/new.html.erb +12 -0
- data/lib/generators/chapter08_09/solutions/templates/app/views/devise/registrations/_fields.html.erb +16 -0
- data/lib/generators/chapter08_09/solutions/templates/app/views/devise/registrations/edit.html.erb +28 -0
- data/lib/generators/chapter08_09/solutions/templates/app/views/devise/registrations/new.html.erb +13 -0
- data/lib/generators/chapter08_09/solutions/templates/app/views/devise/sessions/new.html.erb +17 -0
- data/lib/generators/chapter08_09/solutions/templates/app/views/devise/shared/_links.erb +25 -0
- data/lib/generators/chapter08_09/solutions/templates/app/views/layouts/_header.html.erb +19 -0
- data/lib/generators/chapter08_09/solutions/templates/app/views/layouts/application.html.erb +20 -0
- data/lib/tft_rails.rb +2 -0
- metadata +160 -0
data/.gitignore
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm use 1.9.2@rails3
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
Copyright 2011 Wolfram Arnold
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
22
|
+
This work was sponsored by Marakana.
|
23
|
+
|
24
|
+
|
25
|
+
License and Copyright for the original RailsTutorial sources:
|
26
|
+
|
27
|
+
Copyright (c) 2010 Michael Hartl
|
28
|
+
|
29
|
+
Permission is hereby granted, free of charge, to any person
|
30
|
+
obtaining a copy of this software and associated documentation
|
31
|
+
files (the "Software"), to deal in the Software without
|
32
|
+
restriction, including without limitation the rights to use,
|
33
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
34
|
+
copies of the Software, and to permit persons to whom the
|
35
|
+
Software is furnished to do so, subject to the following
|
36
|
+
conditions:
|
37
|
+
|
38
|
+
The above copyright notice and this permission notice shall be
|
39
|
+
included in all copies or substantial portions of the Software.
|
40
|
+
|
41
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
42
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
43
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
44
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
45
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
46
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
47
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
48
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
49
|
+
/*
|
50
|
+
* ------------------------------------------------------------
|
51
|
+
* "THE BEERWARE LICENSE" (Revision 42):
|
52
|
+
* Michael Hartl wrote this code. As long as you retain this
|
53
|
+
* notice, you can do whatever you want with this stuff. If we
|
54
|
+
* meet someday, and you think this stuff is worth it, you can
|
55
|
+
* buy me a beer in return.
|
56
|
+
* ------------------------------------------------------------
|
57
|
+
*/
|
data/README.md
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
TFT Rails
|
2
|
+
=========
|
3
|
+
|
4
|
+
This project is a series of exercises for learning Rails, based on an adaptation of Michael Hartl's [RailsTutorial],
|
5
|
+
using the [Test-First Teaching][tft] philosophy that was originally developed by [Sarah Allen and Alex Chaffee](tft_preso) and others.
|
6
|
+
This project has been sponsored by [Marakana] and was authored by Wolfram Arnold in collaboration with Alex Chaffee.
|
7
|
+
|
8
|
+
This project is a gem which provides a series of generators intended to be run on a bare-bones Rails 3 app. Each
|
9
|
+
generator provides a new set of tests (specs) corresponding to a given chapter in [RailsTutorial] and a set of
|
10
|
+
solutions.
|
11
|
+
|
12
|
+
Installation and Use
|
13
|
+
--------------------
|
14
|
+
|
15
|
+
To use, create a fresh Rails 3 project:
|
16
|
+
|
17
|
+
rails new sample_app
|
18
|
+
|
19
|
+
Add this gem to `Gemfile`:
|
20
|
+
|
21
|
+
gem 'tft_rails'
|
22
|
+
|
23
|
+
Run the first generator:
|
24
|
+
|
25
|
+
rails generate chapter07:begin
|
26
|
+
|
27
|
+
Run the specs
|
28
|
+
|
29
|
+
rake spec
|
30
|
+
|
31
|
+
Implement code to make the specs all pass. To compare to the solution, or to skip ahead, run:
|
32
|
+
|
33
|
+
rails generate chapter07:solutions
|
34
|
+
|
35
|
+
If you wrote your own code files that conflict with the solutions, you'll be prompted like so:
|
36
|
+
|
37
|
+
conflict app/controllers/application_controller.rb
|
38
|
+
Overwrite /home/wolfram/workspace/classes/ruby_rails/iterations/sample_app_tft/app/controllers/application_controller.rb? (enter "h" for help) [Ynaqdh]
|
39
|
+
|
40
|
+
Choose 'h' for a list of options, 'Y' for accepting the solution file as is, 'n' for leaving your own file in place, 'd' to view the difference between both.
|
41
|
+
|
42
|
+
As a matter of best practice, you should commit your solutions to git, then run the finish generator above, accept all conflicts with 'Y' and use git tools
|
43
|
+
to view the differences and change files selectively.
|
44
|
+
|
45
|
+
Then continue to the next chapter.
|
46
|
+
|
47
|
+
Note that chapters are not exactly sequential. This is because some chapters in RailsTutorial have been skipped due to
|
48
|
+
the adaptations, see below.
|
49
|
+
|
50
|
+
Adapted how?
|
51
|
+
------------
|
52
|
+
|
53
|
+
The project is based on an adaptation of [RailsTutorial]. The main difference is that the [Devise gem][devise] was used
|
54
|
+
instead of the home-grown solution that RailsTutorial builds up. This was done for two reasons: (1) These exercises
|
55
|
+
are designed for a 3-day course preceded by a 2-day Ruby course. There is not enough time to cover a building up an
|
56
|
+
authentication solution from scratch, and for a general-purpose Rails class, the author views it as more important
|
57
|
+
to provide a full sweep through many Rails features than to focus on the specific intricacies of building an
|
58
|
+
authentication solution. (2) Authentication is a hard problem that shouldn't be taken lightly. RailsTutorial does
|
59
|
+
a wonderful job to illustrate many concepts for teaching, but it is no replacement for an industrial strength solution
|
60
|
+
that has been peer-reviewed by many experienced developers and is in use in many commercial applications. Devise is the
|
61
|
+
current industry standard solution and was used here.
|
62
|
+
|
63
|
+
Sponsors
|
64
|
+
--------
|
65
|
+
|
66
|
+
This project has been underwritten by [Marakana] and developed by Wolfram Arnold in collaboration with Alex Chaffee.
|
67
|
+
|
68
|
+
[RailsTutorial]: http://railstutorial.org "Rails Tutorial"
|
69
|
+
[tft]: http://testfirst.org/ "Test-First Teaching"
|
70
|
+
[tft_perso]: http://www.slideshare.net/sarah.allen/test-first-teaching "TFT Presentation by Sarah Allen and Alex Chaffee"
|
71
|
+
[devise]: https://github.com/plataformatec/devise "Devise on Github"
|
72
|
+
[Marakana]: http://marakana.com "Marakana.com"
|
data/Rakefile
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'rubygems'
|
3
|
+
begin
|
4
|
+
require 'bundler/setup'
|
5
|
+
rescue LoadError
|
6
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
7
|
+
end
|
8
|
+
|
9
|
+
require 'rake'
|
10
|
+
require 'rake/rdoctask'
|
11
|
+
|
12
|
+
require 'rspec/core'
|
13
|
+
require 'rspec/core/rake_task'
|
14
|
+
|
15
|
+
RSpec::Core::RakeTask.new(:spec)
|
16
|
+
|
17
|
+
task :default => :spec
|
18
|
+
|
19
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
20
|
+
rdoc.rdoc_dir = 'rdoc'
|
21
|
+
rdoc.title = 'TftRails'
|
22
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
23
|
+
rdoc.rdoc_files.include('README.rdoc')
|
24
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
25
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
Description:
|
2
|
+
Begins Test-First Teaching exercises adapted from Chapter 07 of the RailsTutorial by Michael Hartl.
|
3
|
+
|
4
|
+
Chapter 07 is the first chapter covered, because the application built herein is an adaptation from
|
5
|
+
RailsTutorial and uses the Devise authentication gem, rather than the home-grown solution from RailsTutorial.
|
6
|
+
|
7
|
+
It is assumed that this generator is run in an freshly-created bare-bones Rails project.
|
8
|
+
|
9
|
+
Successive chapters are expected to be run sequentially. Each chapter's generators comes with a delta
|
10
|
+
to the next chapter, in two phase, the "begin" one will create tests, the "finish" one includes the solution files.
|
11
|
+
If all tests pass, the "finish" phase is optional.
|
12
|
+
|
13
|
+
Example:
|
14
|
+
rails generate chapter07:begin
|
15
|
+
|
16
|
+
This copies new tests into the project, which are failing.
|
17
|
+
The student's task is to write code to make the test pass. The material covered by the tests is consistent
|
18
|
+
with Chapter 07 of the RailsTutorial.
|
19
|
+
|
20
|
+
When you're done, and all tests pass, or you just want to skip ahead, run:
|
21
|
+
|
22
|
+
rails generate chapter07:solutions
|
23
|
+
|
24
|
+
This will copy solutions files into the application tree. If you already have a solution file,
|
25
|
+
you'll be prompted whether you want to overwrite your file, see the difference, or keep your file.
|
26
|
+
|
27
|
+
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Chapter07
|
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, :force => true)
|
8
|
+
end
|
9
|
+
|
10
|
+
def augment_gemfile
|
11
|
+
gem 'devise', '~> 1.3.4'
|
12
|
+
gem 'gravatar_image_tag', '~> 1.0.0'
|
13
|
+
gem 'rspec-rails', :version => '~> 2.6.0', :group => :development
|
14
|
+
gem 'rspec', :version => '~> 2.6.0', :group => :test
|
15
|
+
gem 'webrat', :version => '~> 0.7.3', :group => :test
|
16
|
+
gem 'factory_girl_rails', :version => '~> 1.0', :group => :test
|
17
|
+
end
|
18
|
+
|
19
|
+
def generate_instructions
|
20
|
+
require 'rdiscount'
|
21
|
+
|
22
|
+
instr_md = File.expand_path('../instructions.md',self.class.source_root)
|
23
|
+
dest = File.join(Rails.root,'doc','chapter07.html')
|
24
|
+
copy_file(instr_md, dest, :force => true) do |content|
|
25
|
+
RDiscount.new(content).to_html
|
26
|
+
end
|
27
|
+
say_status('Note',"Now open file://#{dest} in your web browser for instructions", :cyan)
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
RailsTutorial Chapter 07 Test-First Teaching Instructions
|
2
|
+
=========================================================
|
3
|
+
|
4
|
+
Running Specs
|
5
|
+
-------------
|
6
|
+
|
7
|
+
See the paragraphs below for more details on each exercise.
|
8
|
+
To run all spec files:
|
9
|
+
|
10
|
+
rake spec
|
11
|
+
|
12
|
+
To run just one file, you can also run, e.g.
|
13
|
+
|
14
|
+
rspec spec/controllers/pages_controller_spec.rb
|
15
|
+
|
16
|
+
Note: Before you run the specs for the very first time,
|
17
|
+
most likely you'll need to migrate your database with:
|
18
|
+
|
19
|
+
rake db:migrate
|
20
|
+
|
21
|
+
This will migrate the development database only. Your specs,
|
22
|
+
however, will use the test database. The `rake spec` command
|
23
|
+
automatically takes care of copying the latest schema from
|
24
|
+
the development database to the test database, thereby
|
25
|
+
migrating the test database as well.
|
26
|
+
|
27
|
+
This is not the case for the `rspec` command. You can run
|
28
|
+
`rake spec` once, or you can explicitly set up the test
|
29
|
+
database with the latest schema via: `rake db:test:prepare`
|
30
|
+
|
31
|
+
Static Pages
|
32
|
+
------------
|
33
|
+
|
34
|
+
The purpose of this section is completing the static pages,
|
35
|
+
such as About, Help, Home, etc.
|
36
|
+
|
37
|
+
The pages are currently in various stages of completion.
|
38
|
+
|
39
|
+
For some, the controller action is present, in
|
40
|
+
`PagesController`, for some it is missing. Some have
|
41
|
+
view templates in `app/views/pages`, others do not.
|
42
|
+
|
43
|
+
Some have route entries in `config/routes`, others do not.
|
44
|
+
|
45
|
+
Run the spec, `specs/controllers/pages_controller_spec.rb`
|
46
|
+
and watch carefully for the error message and look
|
47
|
+
at what each spec is asserting.
|
48
|
+
|
49
|
+
User Validation
|
50
|
+
---------------
|
51
|
+
|
52
|
+
Another purpose of this section are validations of the
|
53
|
+
User model. Run `specs/models/user_spec.rb` and
|
54
|
+
see what is failing. Review the presentation slides on
|
55
|
+
validation of inspiration.
|
56
|
+
|
57
|
+
Users Controller
|
58
|
+
----------------
|
59
|
+
|
60
|
+
This section also has tests on the `UsersController`'s
|
61
|
+
show action. It is in charge of displaying a given
|
62
|
+
user's info.
|
63
|
+
|
64
|
+
Currently, the view template exists, but contains placeholders.
|
65
|
+
Your task is to replace them with actual code such
|
66
|
+
that the tests pass.
|
67
|
+
|
68
|
+
Layouts
|
69
|
+
-------
|
70
|
+
|
71
|
+
Lastly, this section has tests against the navigation
|
72
|
+
links on the layout. This deals with the application
|
73
|
+
layout in `views/layouts/application.html.erb` and its
|
74
|
+
associated partials.
|
@@ -0,0 +1,9 @@
|
|
1
|
+
class User < ActiveRecord::Base
|
2
|
+
# Include default devise modules. Others available are:
|
3
|
+
# :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
|
4
|
+
devise :database_authenticatable, :registerable,
|
5
|
+
:recoverable, :rememberable, :trackable, :validatable
|
6
|
+
|
7
|
+
# Setup accessible (or protected) attributes for your model
|
8
|
+
attr_accessible :name, :email, :password, :password_confirmation, :remember_me
|
9
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
<header>
|
2
|
+
<% logo = image_tag("logo.png", :alt => "Sample App", :class => "round") %>
|
3
|
+
<%= link_to logo, root_path %>
|
4
|
+
<nav class="round">
|
5
|
+
<ul>
|
6
|
+
<li><%= link_to "Home", root_path %></li>
|
7
|
+
<li><%= link_to "Sign in", '#' %></li>
|
8
|
+
</ul>
|
9
|
+
</nav>
|
10
|
+
</header>
|
@@ -0,0 +1,7 @@
|
|
1
|
+
<!--[if lt IE 9]>
|
2
|
+
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
|
3
|
+
<![endif]-->
|
4
|
+
<%= stylesheet_link_tag 'blueprint/screen', :media => 'screen' %>
|
5
|
+
<%= stylesheet_link_tag 'blueprint/print', :media => 'print' %>
|
6
|
+
<!--[if lt IE 8]><%= stylesheet_link_tag 'blueprint/ie' %><![endif]-->
|
7
|
+
<%= stylesheet_link_tag 'custom', :media => 'screen' %>
|
@@ -0,0 +1,17 @@
|
|
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
|
+
<%= yield %>
|
13
|
+
</section>
|
14
|
+
<%= render 'layouts/footer' %>
|
15
|
+
</div>
|
16
|
+
</body>
|
17
|
+
</html>
|
@@ -0,0 +1,7 @@
|
|
1
|
+
<h1>About Us</h1>
|
2
|
+
<p>
|
3
|
+
<a href="http://railstutorial.org/">Ruby on Rails Tutorial</a>
|
4
|
+
is a project to make a book and screencasts to teach web development
|
5
|
+
with <a href="http://rubyonrails.org/">Ruby on Rails</a>. This
|
6
|
+
is the sample application for the tutorial.
|
7
|
+
</p>
|
@@ -0,0 +1,15 @@
|
|
1
|
+
<table class="profile" summary="Profile information">
|
2
|
+
<tr>
|
3
|
+
<td class="main">
|
4
|
+
<h1>
|
5
|
+
User's gravatar image (hint: see users_helper.rb file)
|
6
|
+
and User's name here
|
7
|
+
</h1>
|
8
|
+
</td>
|
9
|
+
<td class="sidebar round">
|
10
|
+
<strong>Name</strong> User's name here
|
11
|
+
<br/>
|
12
|
+
<strong>URL</strong> Link to this page here
|
13
|
+
</td>
|
14
|
+
</tr>
|
15
|
+
</table>
|
@@ -0,0 +1,194 @@
|
|
1
|
+
# Use this hook to configure devise mailer, warden hooks and so forth. The first
|
2
|
+
# four configuration values can also be set straight in your models.
|
3
|
+
Devise.setup do |config|
|
4
|
+
# ==> Mailer Configuration
|
5
|
+
# Configure the e-mail address which will be shown in DeviseMailer.
|
6
|
+
config.mailer_sender = "please-change-me-at-config-initializers-devise@example.com"
|
7
|
+
|
8
|
+
# Configure the class responsible to send e-mails.
|
9
|
+
# config.mailer = "Devise::Mailer"
|
10
|
+
|
11
|
+
# ==> ORM configuration
|
12
|
+
# Load and configure the ORM. Supports :active_record (default) and
|
13
|
+
# :mongoid (bson_ext recommended) by default. Other ORMs may be
|
14
|
+
# available as additional gems.
|
15
|
+
require 'devise/orm/active_record'
|
16
|
+
|
17
|
+
# ==> Configuration for any authentication mechanism
|
18
|
+
# Configure which keys are used when authenticating a user. The default is
|
19
|
+
# just :email. You can configure it to use [:username, :subdomain], so for
|
20
|
+
# authenticating a user, both parameters are required. Remember that those
|
21
|
+
# parameters are used only when authenticating and not when retrieving from
|
22
|
+
# session. If you need permissions, you should implement that in a before filter.
|
23
|
+
# You can also supply a hash where the value is a boolean determining whether
|
24
|
+
# or not authentication should be aborted when the value is not present.
|
25
|
+
# config.authentication_keys = [ :email ]
|
26
|
+
|
27
|
+
# Configure parameters from the request object used for authentication. Each entry
|
28
|
+
# given should be a request method and it will automatically be passed to the
|
29
|
+
# find_for_authentication method and considered in your model lookup. For instance,
|
30
|
+
# if you set :request_keys to [:subdomain], :subdomain will be used on authentication.
|
31
|
+
# The same considerations mentioned for authentication_keys also apply to request_keys.
|
32
|
+
# config.request_keys = []
|
33
|
+
|
34
|
+
# Configure which authentication keys should be case-insensitive.
|
35
|
+
# These keys will be downcased upon creating or modifying a user and when used
|
36
|
+
# to authenticate or find a user. Default is :email.
|
37
|
+
config.case_insensitive_keys = [ :email ]
|
38
|
+
|
39
|
+
# Tell if authentication through request.params is enabled. True by default.
|
40
|
+
# config.params_authenticatable = true
|
41
|
+
|
42
|
+
# Tell if authentication through HTTP Basic Auth is enabled. False by default.
|
43
|
+
# config.http_authenticatable = false
|
44
|
+
|
45
|
+
# If http headers should be returned for AJAX requests. True by default.
|
46
|
+
# config.http_authenticatable_on_xhr = true
|
47
|
+
|
48
|
+
# The realm used in Http Basic Authentication. "Application" by default.
|
49
|
+
# config.http_authentication_realm = "Application"
|
50
|
+
|
51
|
+
# ==> Configuration for :database_authenticatable
|
52
|
+
# For bcrypt, this is the cost for hashing the password and defaults to 10. If
|
53
|
+
# using other encryptors, it sets how many times you want the password re-encrypted.
|
54
|
+
config.stretches = 10
|
55
|
+
|
56
|
+
# Setup a pepper to generate the encrypted password.
|
57
|
+
# config.pepper = "2453d31d04ee354f4838a3e87b74ef2e12bd6ece8631c00a9b9b0e75f4fcbc05627e4e27751b10f1be93aa4994820513c105ad64790741141c354660e49de2ed"
|
58
|
+
|
59
|
+
# ==> Configuration for :confirmable
|
60
|
+
# The time you want to give your user to confirm his account. During this time
|
61
|
+
# he will be able to access your application without confirming. Default is 0.days
|
62
|
+
# When confirm_within is zero, the user won't be able to sign in without confirming.
|
63
|
+
# You can use this to let your user access some features of your application
|
64
|
+
# without confirming the account, but blocking it after a certain period
|
65
|
+
# (ie 2 days).
|
66
|
+
# config.confirm_within = 2.days
|
67
|
+
|
68
|
+
# Defines which key will be used when confirming an account
|
69
|
+
# config.confirmation_keys = [ :email ]
|
70
|
+
|
71
|
+
# ==> Configuration for :rememberable
|
72
|
+
# The time the user will be remembered without asking for credentials again.
|
73
|
+
# config.remember_for = 2.weeks
|
74
|
+
|
75
|
+
# If true, a valid remember token can be re-used between multiple browsers.
|
76
|
+
# config.remember_across_browsers = true
|
77
|
+
|
78
|
+
# If true, extends the user's remember period when remembered via cookie.
|
79
|
+
# config.extend_remember_period = false
|
80
|
+
|
81
|
+
# If true, uses the password salt as remember token. This should be turned
|
82
|
+
# to false if you are not using database authenticatable.
|
83
|
+
config.use_salt_as_remember_token = true
|
84
|
+
|
85
|
+
# Options to be passed to the created cookie. For instance, you can set
|
86
|
+
# :secure => true in order to force SSL only cookies.
|
87
|
+
# config.cookie_options = {}
|
88
|
+
|
89
|
+
# ==> Configuration for :validatable
|
90
|
+
# Range for password length. Default is 6..128.
|
91
|
+
# config.password_length = 6..128
|
92
|
+
|
93
|
+
# Regex to use to validate the email address
|
94
|
+
# config.email_regexp = /\A([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})\z/i
|
95
|
+
|
96
|
+
# ==> Configuration for :timeoutable
|
97
|
+
# The time you want to timeout the user session without activity. After this
|
98
|
+
# time the user will be asked for credentials again. Default is 30 minutes.
|
99
|
+
# config.timeout_in = 30.minutes
|
100
|
+
|
101
|
+
# ==> Configuration for :lockable
|
102
|
+
# Defines which strategy will be used to lock an account.
|
103
|
+
# :failed_attempts = Locks an account after a number of failed attempts to sign in.
|
104
|
+
# :none = No lock strategy. You should handle locking by yourself.
|
105
|
+
# config.lock_strategy = :failed_attempts
|
106
|
+
|
107
|
+
# Defines which key will be used when locking and unlocking an account
|
108
|
+
# config.unlock_keys = [ :email ]
|
109
|
+
|
110
|
+
# Defines which strategy will be used to unlock an account.
|
111
|
+
# :email = Sends an unlock link to the user email
|
112
|
+
# :time = Re-enables login after a certain amount of time (see :unlock_in below)
|
113
|
+
# :both = Enables both strategies
|
114
|
+
# :none = No unlock strategy. You should handle unlocking by yourself.
|
115
|
+
# config.unlock_strategy = :both
|
116
|
+
|
117
|
+
# Number of authentication tries before locking an account if lock_strategy
|
118
|
+
# is failed attempts.
|
119
|
+
# config.maximum_attempts = 20
|
120
|
+
|
121
|
+
# Time interval to unlock the account if :time is enabled as unlock_strategy.
|
122
|
+
# config.unlock_in = 1.hour
|
123
|
+
|
124
|
+
# ==> Configuration for :recoverable
|
125
|
+
#
|
126
|
+
# Defines which key will be used when recovering the password for an account
|
127
|
+
# config.reset_password_keys = [ :email ]
|
128
|
+
|
129
|
+
# Time interval you can reset your password with a reset password key.
|
130
|
+
# Don't put a too small interval or your users won't have the time to
|
131
|
+
# change their passwords.
|
132
|
+
config.reset_password_within = 2.hours
|
133
|
+
|
134
|
+
# ==> Configuration for :encryptable
|
135
|
+
# Allow you to use another encryption algorithm besides bcrypt (default). You can use
|
136
|
+
# :sha1, :sha512 or encryptors from others authentication tools as :clearance_sha1,
|
137
|
+
# :authlogic_sha512 (then you should set stretches above to 20 for default behavior)
|
138
|
+
# and :restful_authentication_sha1 (then you should set stretches to 10, and copy
|
139
|
+
# REST_AUTH_SITE_KEY to pepper)
|
140
|
+
# config.encryptor = :sha512
|
141
|
+
|
142
|
+
# ==> Configuration for :token_authenticatable
|
143
|
+
# Defines name of the authentication token params key
|
144
|
+
# config.token_authentication_key = :auth_token
|
145
|
+
|
146
|
+
# If true, authentication through token does not store user in session and needs
|
147
|
+
# to be supplied on each request. Useful if you are using the token as API token.
|
148
|
+
# config.stateless_token = false
|
149
|
+
|
150
|
+
# ==> Scopes configuration
|
151
|
+
# Turn scoped views on. Before rendering "sessions/new", it will first check for
|
152
|
+
# "users/sessions/new". It's turned off by default because it's slower if you
|
153
|
+
# are using only default views.
|
154
|
+
# config.scoped_views = false
|
155
|
+
|
156
|
+
# Configure the default scope given to Warden. By default it's the first
|
157
|
+
# devise role declared in your routes (usually :user).
|
158
|
+
# config.default_scope = :user
|
159
|
+
|
160
|
+
# Configure sign_out behavior.
|
161
|
+
# Sign_out action can be scoped (i.e. /users/sign_out affects only :user scope).
|
162
|
+
# The default is true, which means any logout action will sign out all active scopes.
|
163
|
+
# config.sign_out_all_scopes = true
|
164
|
+
|
165
|
+
# ==> Navigation configuration
|
166
|
+
# Lists the formats that should be treated as navigational. Formats like
|
167
|
+
# :html, should redirect to the sign in page when the user does not have
|
168
|
+
# access, but formats like :xml or :json, should return 401.
|
169
|
+
#
|
170
|
+
# If you have any extra navigational formats, like :iphone or :mobile, you
|
171
|
+
# should add them to the navigational formats lists.
|
172
|
+
#
|
173
|
+
# The :"*/*" and "*/*" formats below is required to match Internet
|
174
|
+
# Explorer requests.
|
175
|
+
# config.navigational_formats = [:"*/*", "*/*", :html]
|
176
|
+
|
177
|
+
# The default HTTP method used to sign out a resource. Default is :get.
|
178
|
+
# config.sign_out_via = :get
|
179
|
+
|
180
|
+
# ==> OmniAuth
|
181
|
+
# Add a new OmniAuth provider. Check the wiki for more information on setting
|
182
|
+
# up on your models and hooks.
|
183
|
+
# config.omniauth :github, 'APP_ID', 'APP_SECRET', :scope => 'user,public_repo'
|
184
|
+
|
185
|
+
# ==> Warden configuration
|
186
|
+
# If you want to use other strategies, that are not supported by Devise, or
|
187
|
+
# change the failure app, you can configure them inside the config.warden block.
|
188
|
+
#
|
189
|
+
# config.warden do |manager|
|
190
|
+
# manager.failure_app = AnotherApp
|
191
|
+
# manager.intercept_401 = false
|
192
|
+
# manager.default_strategies(:scope => :user).unshift :some_external_strategy
|
193
|
+
# end
|
194
|
+
end
|