4 | The Ruby on Rails Tutorial
5 | is a project to make a book and screencasts to teach web development
6 | with Ruby on Rails. This
7 | is the sample application for the tutorial.
8 |
--------------------------------------------------------------------------------
/config.ru:
--------------------------------------------------------------------------------
1 | # This file is used by Rack-based servers to start the application.
2 |
3 | require ::File.expand_path('../config/environment', __FILE__)
4 | run SampleApp::Application
5 |
--------------------------------------------------------------------------------
/config/application.rb:
--------------------------------------------------------------------------------
1 | require File.expand_path('../boot', __FILE__)
2 |
3 | # Pick the frameworks you want:
4 | require "active_record/railtie"
5 | require "action_controller/railtie"
6 | require "action_mailer/railtie"
7 | require "active_resource/railtie"
8 | require "sprockets/railtie"
9 | # require "rails/test_unit/railtie"
10 |
11 | if defined?(Bundler)
12 | # If you precompile assets before deploying to production, use this line
13 | Bundler.require(*Rails.groups(:assets => %w(development test)))
14 | # If you want your assets lazily compiled in production, use this line
15 | # Bundler.require(:default, :assets, Rails.env)
16 | end
17 |
18 | module SampleApp
19 | class Application < Rails::Application
20 | # Settings in config/environments/* take precedence over those specified here.
21 | # Application configuration should go into files in config/initializers
22 | # -- all .rb files in that directory are automatically loaded.
23 |
24 | # Custom directories with classes and modules you want to be autoloadable.
25 | # config.autoload_paths += %W(#{config.root}/extras)
26 |
27 | # Only load the plugins named here, in the order given (default is alphabetical).
28 | # :all can be used as a placeholder for all plugins not explicitly named.
29 | # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
30 |
31 | # Activate observers that should always be running.
32 | # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
33 |
34 | # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
35 | # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
36 | # config.time_zone = 'Central Time (US & Canada)'
37 |
38 | # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
39 | # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
40 | # config.i18n.default_locale = :de
41 |
42 | # Configure the default encoding used in templates for Ruby 1.9.
43 | config.encoding = "utf-8"
44 |
45 | # Configure sensitive parameters which will be filtered from the log file.
46 | config.filter_parameters += [:password]
47 |
48 | # Use SQL instead of Active Record's schema dumper when creating the database.
49 | # This is necessary if your schema can't be completely dumped by the schema dumper,
50 | # like if you have constraints or database-specific column types
51 | # config.active_record.schema_format = :sql
52 |
53 | # Enforce whitelist mode for mass assignment.
54 | # This will create an empty whitelist of attributes available for mass-assignment for all models
55 | # in your app. As such, your models will need to explicitly whitelist or blacklist accessible
56 | # parameters by using an attr_accessible or attr_protected declaration.
57 | config.active_record.whitelist_attributes = true
58 |
59 | # Enable the asset pipeline
60 | config.assets.enabled = true
61 |
62 | # Version of your assets, change this if you want to expire all your assets
63 | config.assets.version = '1.0'
64 | end
65 | end
66 |
--------------------------------------------------------------------------------
/config/boot.rb:
--------------------------------------------------------------------------------
1 | require 'rubygems'
2 |
3 | # Set up gems listed in the Gemfile.
4 | ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
5 |
6 | require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
7 |
--------------------------------------------------------------------------------
/config/cucumber.yml:
--------------------------------------------------------------------------------
1 | <%
2 | rerun = File.file?('rerun.txt') ? IO.read('rerun.txt') : ""
3 | rerun_opts = rerun.to_s.strip.empty? ? "--format #{ENV['CUCUMBER_FORMAT'] || 'progress'} features" : "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} #{rerun}"
4 | std_opts = "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} --strict --tags ~@wip"
5 | %>
6 | default: <%= std_opts %> features
7 | wip: --tags @wip:3 --wip features
8 | rerun: <%= rerun_opts %> --format rerun --out rerun.txt --strict --tags ~@wip
9 |
--------------------------------------------------------------------------------
/config/database.yml.example:
--------------------------------------------------------------------------------
1 | # SQLite version 3.x
2 | # gem install sqlite3
3 | #
4 | # Ensure the SQLite 3 gem is defined in your Gemfile
5 | # gem 'sqlite3'
6 | development:
7 | adapter: sqlite3
8 | database: db/development.sqlite3
9 | pool: 5
10 | timeout: 5000
11 |
12 | # Warning: The database defined as "test" will be erased and
13 | # re-generated from your development database when you run "rake".
14 | # Do not set this db to the same as development or production.
15 | test: &test
16 | adapter: sqlite3
17 | database: db/test.sqlite3
18 | pool: 5
19 | timeout: 5000
20 |
21 | production:
22 | adapter: sqlite3
23 | database: db/production.sqlite3
24 | pool: 5
25 | timeout: 5000
26 |
27 | cucumber:
28 | <<: *test
--------------------------------------------------------------------------------
/config/environment.rb:
--------------------------------------------------------------------------------
1 | # Load the rails application
2 | require File.expand_path('../application', __FILE__)
3 |
4 | # Initialize the rails application
5 | SampleApp::Application.initialize!
6 |
--------------------------------------------------------------------------------
/config/environments/development.rb:
--------------------------------------------------------------------------------
1 | SampleApp::Application.configure do
2 | # Settings specified here will take precedence over those in config/application.rb
3 |
4 | # In the development environment your application's code is reloaded on
5 | # every request. This slows down response time but is perfect for development
6 | # since you don't have to restart the web server when you make code changes.
7 | config.cache_classes = false
8 |
9 | # Log error messages when you accidentally call methods on nil.
10 | config.whiny_nils = true
11 |
12 | # Show full error reports and disable caching
13 | config.consider_all_requests_local = true
14 | config.action_controller.perform_caching = false
15 |
16 | # Don't care if the mailer can't send
17 | config.action_mailer.raise_delivery_errors = false
18 |
19 | # Print deprecation notices to the Rails logger
20 | config.active_support.deprecation = :log
21 |
22 | # Only use best-standards-support built into browsers
23 | config.action_dispatch.best_standards_support = :builtin
24 |
25 | # Raise exception on mass assignment protection for Active Record models
26 | config.active_record.mass_assignment_sanitizer = :strict
27 |
28 | # Log the query plan for queries taking more than this (works
29 | # with SQLite, MySQL, and PostgreSQL)
30 | config.active_record.auto_explain_threshold_in_seconds = 0.5
31 |
32 | # Do not compress assets
33 | config.assets.compress = false
34 |
35 | # Expands the lines which load the assets
36 | config.assets.debug = true
37 | end
38 |
--------------------------------------------------------------------------------
/config/environments/production.rb:
--------------------------------------------------------------------------------
1 | SampleApp::Application.configure do
2 | # Settings specified here will take precedence over those in config/application.rb
3 |
4 | # Code is not reloaded between requests
5 | config.cache_classes = true
6 |
7 | # Full error reports are disabled and caching is turned on
8 | config.consider_all_requests_local = false
9 | config.action_controller.perform_caching = true
10 |
11 | # Disable Rails's static asset server (Apache or nginx will already do this)
12 | config.serve_static_assets = false
13 |
14 | # Compress JavaScripts and CSS
15 | config.assets.compress = true
16 |
17 | # Don't fallback to assets pipeline if a precompiled asset is missed
18 | config.assets.compile = false
19 |
20 | # Generate digests for assets URLs
21 | config.assets.digest = true
22 |
23 | # Defaults to Rails.root.join("public/assets")
24 | # config.assets.manifest = YOUR_PATH
25 |
26 | # Specifies the header that your server uses for sending files
27 | # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
28 | # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx
29 |
30 | # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
31 | config.force_ssl = true
32 |
33 | # See everything in the log (default is :info)
34 | # config.log_level = :debug
35 |
36 | # Prepend all log lines with the following tags
37 | # config.log_tags = [ :subdomain, :uuid ]
38 |
39 | # Use a different logger for distributed setups
40 | # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
41 |
42 | # Use a different cache store in production
43 | # config.cache_store = :mem_cache_store
44 |
45 | # Enable serving of images, stylesheets, and JavaScripts from an asset server
46 | # config.action_controller.asset_host = "http://assets.example.com"
47 |
48 | # Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
49 | # config.assets.precompile += %w( search.js )
50 |
51 | # Disable delivery errors, bad email addresses will be ignored
52 | # config.action_mailer.raise_delivery_errors = false
53 |
54 | # Enable threaded mode
55 | # config.threadsafe!
56 |
57 | # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
58 | # the I18n.default_locale when a translation can not be found)
59 | config.i18n.fallbacks = true
60 |
61 | # Send deprecation notices to registered listeners
62 | config.active_support.deprecation = :notify
63 |
64 | # Log the query plan for queries taking more than this (works
65 | # with SQLite, MySQL, and PostgreSQL)
66 | # config.active_record.auto_explain_threshold_in_seconds = 0.5
67 | end
68 |
--------------------------------------------------------------------------------
/config/environments/test.rb:
--------------------------------------------------------------------------------
1 | SampleApp::Application.configure do
2 | # Settings specified here will take precedence over those in config/application.rb
3 |
4 | # The test environment is used exclusively to run your application's
5 | # test suite. You never need to work with it otherwise. Remember that
6 | # your test database is "scratch space" for the test suite and is wiped
7 | # and recreated between test runs. Don't rely on the data there!
8 | config.cache_classes = true
9 |
10 | # Configure static asset server for tests with Cache-Control for performance
11 | config.serve_static_assets = true
12 | config.static_cache_control = "public, max-age=3600"
13 |
14 | # Log error messages when you accidentally call methods on nil
15 | config.whiny_nils = true
16 |
17 | # Show full error reports and disable caching
18 | config.consider_all_requests_local = true
19 | config.action_controller.perform_caching = false
20 |
21 | # Raise exceptions instead of rendering exception templates
22 | config.action_dispatch.show_exceptions = false
23 |
24 | # Disable request forgery protection in test environment
25 | config.action_controller.allow_forgery_protection = false
26 |
27 | # Tell Action Mailer not to deliver emails to the real world.
28 | # The :test delivery method accumulates sent emails in the
29 | # ActionMailer::Base.deliveries array.
30 | config.action_mailer.delivery_method = :test
31 |
32 | # Raise exception on mass assignment protection for Active Record models
33 | config.active_record.mass_assignment_sanitizer = :strict
34 |
35 | # Print deprecation notices to the stderr
36 | config.active_support.deprecation = :stderr
37 |
38 | require 'bcrypt'
39 | silence_warnings do
40 | BCrypt::Engine::DEFAULT_COST = BCrypt::Engine::MIN_COST
41 | end
42 | end
43 |
--------------------------------------------------------------------------------
/config/initializers/backtrace_silencers.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
4 | # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
5 |
6 | # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
7 | # Rails.backtrace_cleaner.remove_silencers!
8 |
--------------------------------------------------------------------------------
/config/initializers/inflections.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # Add new inflection rules using the following format
4 | # (all these examples are active by default):
5 | # ActiveSupport::Inflector.inflections do |inflect|
6 | # inflect.plural /^(ox)$/i, '\1en'
7 | # inflect.singular /^(ox)en/i, '\1'
8 | # inflect.irregular 'person', 'people'
9 | # inflect.uncountable %w( fish sheep )
10 | # end
11 | #
12 | # These inflection rules are supported but not enabled by default:
13 | # ActiveSupport::Inflector.inflections do |inflect|
14 | # inflect.acronym 'RESTful'
15 | # end
16 |
--------------------------------------------------------------------------------
/config/initializers/mime_types.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # Add new mime types for use in respond_to blocks:
4 | # Mime::Type.register "text/richtext", :rtf
5 | # Mime::Type.register_alias "text/html", :iphone
6 |
--------------------------------------------------------------------------------
/config/initializers/secret_token.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # Your secret key for verifying the integrity of signed cookies.
4 | # If you change this key, all old signed cookies will become invalid!
5 | # Make sure the secret is at least 30 characters and all random,
6 | # no regular words or you'll be exposed to dictionary attacks.
7 | SampleApp::Application.config.secret_token = 'ced345e01611593c1b783bae98e4e56dbaee787747e92a141565f7c61d0ab2c6f98f7396fb4b178258301e2713816e158461af58c14b695901692f91e72b6200'
8 |
--------------------------------------------------------------------------------
/config/initializers/session_store.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | SampleApp::Application.config.session_store :cookie_store, key: '_sample_app_session'
4 |
5 | # Use the database for sessions instead of the cookie-based default,
6 | # which shouldn't be used to store highly confidential information
7 | # (create the session table with "rails generate session_migration")
8 | # SampleApp::Application.config.session_store :active_record_store
9 |
--------------------------------------------------------------------------------
/config/initializers/wrap_parameters.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 | #
3 | # This file contains settings for ActionController::ParamsWrapper which
4 | # is enabled by default.
5 |
6 | # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
7 | ActiveSupport.on_load(:action_controller) do
8 | wrap_parameters format: [:json]
9 | end
10 |
11 | # Disable root element in JSON by default.
12 | ActiveSupport.on_load(:active_record) do
13 | self.include_root_in_json = false
14 | end
15 |
--------------------------------------------------------------------------------
/config/locales/en.yml:
--------------------------------------------------------------------------------
1 | # Sample localization file for English. Add more files in this directory for other locales.
2 | # See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
3 |
4 | en:
5 | hello: "Hello world"
--------------------------------------------------------------------------------
/config/routes.rb:
--------------------------------------------------------------------------------
1 | SampleApp::Application.routes.draw do
2 | resources :users do
3 | member do
4 | get :following, :followers
5 | end
6 | end
7 | resources :sessions, only: [:new, :create, :destroy]
8 | resources :microposts, only: [:create, :destroy]
9 | resources :relationships, only: [:create, :destroy]
10 |
11 | root to: 'static_pages#home'
12 |
13 | match '/signup', to: 'users#new'
14 | match '/signin', to: 'sessions#new'
15 | match '/signout', to: 'sessions#destroy', via: :delete
16 |
17 | match '/help', to: 'static_pages#help'
18 | match '/about', to: 'static_pages#about'
19 | match '/contact', to: 'static_pages#contact'
20 |
21 | # The priority is based upon order of creation:
22 | # first created -> highest priority.
23 |
24 | # Sample of regular route:
25 | # match 'products/:id' => 'catalog#view'
26 | # Keep in mind you can assign values other than :controller and :action
27 |
28 | # Sample of named route:
29 | # match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
30 | # This route can be invoked with purchase_url(:id => product.id)
31 |
32 | # Sample resource route (maps HTTP verbs to controller actions automatically):
33 | # resources :products
34 |
35 | # Sample resource route with options:
36 | # resources :products do
37 | # member do
38 | # get 'short'
39 | # post 'toggle'
40 | # end
41 | #
42 | # collection do
43 | # get 'sold'
44 | # end
45 | # end
46 |
47 | # Sample resource route with sub-resources:
48 | # resources :products do
49 | # resources :comments, :sales
50 | # resource :seller
51 | # end
52 |
53 | # Sample resource route with more complex sub-resources
54 | # resources :products do
55 | # resources :comments
56 | # resources :sales do
57 | # get 'recent', :on => :collection
58 | # end
59 | # end
60 |
61 | # Sample resource route within a namespace:
62 | # namespace :admin do
63 | # # Directs /admin/products/* to Admin::ProductsController
64 | # # (app/controllers/admin/products_controller.rb)
65 | # resources :products
66 | # end
67 |
68 | # You can have the root of your site routed with "root"
69 | # just remember to delete public/index.html.
70 | # root :to => 'welcome#index'
71 |
72 | # See how all your routes lay out with "rake routes"
73 |
74 | # This is a legacy wild controller route that's not recommended for RESTful applications.
75 | # Note: This route will make all actions in every controller accessible via GET requests.
76 | # match ':controller(/:action(/:id))(.:format)'
77 | end
78 |
--------------------------------------------------------------------------------
/db/migrate/20120308032820_create_users.rb:
--------------------------------------------------------------------------------
1 | class CreateUsers < ActiveRecord::Migration
2 | def change
3 | create_table :users do |t|
4 | t.string :name
5 | t.string :email
6 |
7 | t.timestamps
8 | end
9 | end
10 | end
11 |
--------------------------------------------------------------------------------
/db/migrate/20120308034224_add_index_to_users_email.rb:
--------------------------------------------------------------------------------
1 | class AddIndexToUsersEmail < ActiveRecord::Migration
2 | def change
3 | add_index :users, :email, unique: true
4 | end
5 | end
--------------------------------------------------------------------------------
/db/migrate/20120308034454_add_password_digest_to_users.rb:
--------------------------------------------------------------------------------
1 | class AddPasswordDigestToUsers < ActiveRecord::Migration
2 | def change
3 | add_column :users, :password_digest, :string
4 | end
5 | end
6 |
--------------------------------------------------------------------------------
/db/migrate/20120308054414_add_remember_token_to_users.rb:
--------------------------------------------------------------------------------
1 | class AddRememberTokenToUsers < ActiveRecord::Migration
2 | def change
3 | add_column :users, :remember_token, :string
4 | add_index :users, :remember_token
5 | end
6 | end
--------------------------------------------------------------------------------
/db/migrate/20120308193644_add_admin_to_users.rb:
--------------------------------------------------------------------------------
1 | class AddAdminToUsers < ActiveRecord::Migration
2 | def change
3 | add_column :users, :admin, :boolean, default: false
4 | end
5 | end
6 |
--------------------------------------------------------------------------------
/db/migrate/20120308210452_create_microposts.rb:
--------------------------------------------------------------------------------
1 | class CreateMicroposts < ActiveRecord::Migration
2 | def change
3 | create_table :microposts do |t|
4 | t.string :content
5 | t.integer :user_id
6 |
7 | t.timestamps
8 | end
9 | add_index :microposts, [:user_id, :created_at]
10 | end
11 | end
--------------------------------------------------------------------------------
/db/migrate/20120308215846_create_relationships.rb:
--------------------------------------------------------------------------------
1 | class CreateRelationships < ActiveRecord::Migration
2 | def change
3 | create_table :relationships do |t|
4 | t.integer :follower_id
5 | t.integer :followed_id
6 |
7 | t.timestamps
8 | end
9 |
10 | add_index :relationships, :follower_id
11 | add_index :relationships, :followed_id
12 | add_index :relationships, [:follower_id, :followed_id], unique: true
13 | end
14 | end
--------------------------------------------------------------------------------
/db/schema.rb:
--------------------------------------------------------------------------------
1 | # encoding: UTF-8
2 | # This file is auto-generated from the current state of the database. Instead
3 | # of editing this file, please use the migrations feature of Active Record to
4 | # incrementally modify your database, and then regenerate this schema definition.
5 | #
6 | # Note that this schema.rb definition is the authoritative source for your
7 | # database schema. If you need to create the application database on another
8 | # system, you should be using db:schema:load, not running all the migrations
9 | # from scratch. The latter is a flawed and unsustainable approach (the more migrations
10 | # you'll amass, the slower it'll run and the greater likelihood for issues).
11 | #
12 | # It's strongly recommended to check this file into your version control system.
13 |
14 | ActiveRecord::Schema.define(:version => 20120308215846) do
15 |
16 | create_table "microposts", :force => true do |t|
17 | t.string "content"
18 | t.integer "user_id"
19 | t.datetime "created_at", :null => false
20 | t.datetime "updated_at", :null => false
21 | end
22 |
23 | add_index "microposts", ["user_id", "created_at"], :name => "index_microposts_on_user_id_and_created_at"
24 |
25 | create_table "relationships", :force => true do |t|
26 | t.integer "follower_id"
27 | t.integer "followed_id"
28 | t.datetime "created_at", :null => false
29 | t.datetime "updated_at", :null => false
30 | end
31 |
32 | add_index "relationships", ["followed_id"], :name => "index_relationships_on_followed_id"
33 | add_index "relationships", ["follower_id", "followed_id"], :name => "index_relationships_on_follower_id_and_followed_id", :unique => true
34 | add_index "relationships", ["follower_id"], :name => "index_relationships_on_follower_id"
35 |
36 | create_table "users", :force => true do |t|
37 | t.string "name"
38 | t.string "email"
39 | t.datetime "created_at", :null => false
40 | t.datetime "updated_at", :null => false
41 | t.string "password_digest"
42 | t.string "remember_token"
43 | t.boolean "admin", :default => false
44 | end
45 |
46 | add_index "users", ["email"], :name => "index_users_on_email", :unique => true
47 | add_index "users", ["remember_token"], :name => "index_users_on_remember_token"
48 |
49 | end
50 |
--------------------------------------------------------------------------------
/db/seeds.rb:
--------------------------------------------------------------------------------
1 | # This file should contain all the record creation needed to seed the database with its default values.
2 | # The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
3 | #
4 | # Examples:
5 | #
6 | # cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
7 | # Mayor.create(name: 'Emanuel', city: cities.first)
8 |
--------------------------------------------------------------------------------
/doc/README_FOR_APP:
--------------------------------------------------------------------------------
1 | Use this README file to introduce your application and point to useful places in the API for learning more.
2 | Run "rake doc:app" to generate API documentation for your models, controllers, helpers, and libraries.
3 |
--------------------------------------------------------------------------------
/features/signing_in.feature:
--------------------------------------------------------------------------------
1 | Feature: Signing in
2 |
3 | Scenario: Unsuccessful signin
4 | Given a user visits the signin page
5 | When they submit invalid signin information
6 | Then they should see an error message
7 |
8 | Scenario: Successful signin
9 | Given a user visits the signin page
10 | And the user has an account
11 | When the user submits valid signin information
12 | Then they should see their profile page
13 | And they should see a signout link
--------------------------------------------------------------------------------
/features/step_definitions/authentication_steps.rb:
--------------------------------------------------------------------------------
1 | Given /^a user visits the signin page$/ do
2 | visit signin_path
3 | end
4 |
5 | When /^they submit invalid signin information$/ do
6 | click_button "Sign in"
7 | end
8 |
9 | Then /^they should see an error message$/ do
10 | page.should have_selector('div.alert.alert-error')
11 | end
12 |
13 | Given /^the user has an account$/ do
14 | @user = User.create(name: "Example User", email: "user@example.com",
15 | password: "foobar", password_confirmation: "foobar")
16 | end
17 |
18 | When /^the user submits valid signin information$/ do
19 | visit signin_path
20 | fill_in "Email", with: @user.email
21 | fill_in "Password", with: @user.password
22 | click_button "Sign in"
23 | end
24 |
25 | Then /^they should see their profile page$/ do
26 | page.should have_selector('title', text: @user.name)
27 | end
28 |
29 | Then /^they should see a signout link$/ do
30 | page.should have_link('Sign out', href: signout_path)
31 | end
--------------------------------------------------------------------------------
/features/support/env.rb:
--------------------------------------------------------------------------------
1 | # IMPORTANT: This file is generated by cucumber-rails - edit at your own peril.
2 | # It is recommended to regenerate this file in the future when you upgrade to a
3 | # newer version of cucumber-rails. Consider adding your own code to a new file
4 | # instead of editing this one. Cucumber will automatically load all features/**/*.rb
5 | # files.
6 |
7 | require 'cucumber/rails'
8 |
9 | # Capybara defaults to XPath selectors rather than Webrat's default of CSS3. In
10 | # order to ease the transition to Capybara we set the default here. If you'd
11 | # prefer to use XPath just remove this line and adjust any selectors in your
12 | # steps to use the XPath syntax.
13 | Capybara.default_selector = :css
14 |
15 | # By default, any exception happening in your Rails application will bubble up
16 | # to Cucumber so that your scenario will fail. This is a different from how
17 | # your application behaves in the production environment, where an error page will
18 | # be rendered instead.
19 | #
20 | # Sometimes we want to override this default behaviour and allow Rails to rescue
21 | # exceptions and display an error page (just like when the app is running in production).
22 | # Typical scenarios where you want to do this is when you test your error pages.
23 | # There are two ways to allow Rails to rescue exceptions:
24 | #
25 | # 1) Tag your scenario (or feature) with @allow-rescue
26 | #
27 | # 2) Set the value below to true. Beware that doing this globally is not
28 | # recommended as it will mask a lot of errors for you!
29 | #
30 | ActionController::Base.allow_rescue = false
31 |
32 | # Remove/comment out the lines below if your app doesn't have a database.
33 | # For some databases (like MongoDB and CouchDB) you may need to use :truncation instead.
34 | begin
35 | DatabaseCleaner.strategy = :transaction
36 | rescue NameError
37 | raise "You need to add database_cleaner to your Gemfile (in the :test group) if you wish to use it."
38 | end
39 |
40 | # You may also want to configure DatabaseCleaner to use different strategies for certain features and scenarios.
41 | # See the DatabaseCleaner documentation for details. Example:
42 | #
43 | # Before('@no-txn,@selenium,@culerity,@celerity,@javascript') do
44 | # DatabaseCleaner.strategy = :truncation, {:except => %w[widgets]}
45 | # end
46 | #
47 | # Before('~@no-txn', '~@selenium', '~@culerity', '~@celerity', '~@javascript') do
48 | # DatabaseCleaner.strategy = :transaction
49 | # end
50 | #
51 |
52 | # Possible values are :truncation and :transaction
53 | # The :transaction strategy is faster, but might give you threading problems.
54 | # See https://github.com/cucumber/cucumber-rails/blob/master/features/choose_javascript_database_strategy.feature
55 | Cucumber::Rails::Database.javascript_strategy = :truncation
56 |
57 |
--------------------------------------------------------------------------------
/lib/assets/.gitkeep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/railstutorial/sample_app_2nd_ed/e59c4fc43eb1763ed00ed9ff27f57a97d488434c/lib/assets/.gitkeep
--------------------------------------------------------------------------------
/lib/tasks/.gitkeep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/railstutorial/sample_app_2nd_ed/e59c4fc43eb1763ed00ed9ff27f57a97d488434c/lib/tasks/.gitkeep
--------------------------------------------------------------------------------
/lib/tasks/cucumber.rake:
--------------------------------------------------------------------------------
1 | # IMPORTANT: This file is generated by cucumber-rails - edit at your own peril.
2 | # It is recommended to regenerate this file in the future when you upgrade to a
3 | # newer version of cucumber-rails. Consider adding your own code to a new file
4 | # instead of editing this one. Cucumber will automatically load all features/**/*.rb
5 | # files.
6 |
7 |
8 | unless ARGV.any? {|a| a =~ /^gems/} # Don't load anything when running the gems:* tasks
9 |
10 | vendored_cucumber_bin = Dir["#{Rails.root}/vendor/{gems,plugins}/cucumber*/bin/cucumber"].first
11 | $LOAD_PATH.unshift(File.dirname(vendored_cucumber_bin) + '/../lib') unless vendored_cucumber_bin.nil?
12 |
13 | begin
14 | require 'cucumber/rake/task'
15 |
16 | namespace :cucumber do
17 | Cucumber::Rake::Task.new({:ok => 'db:test:prepare'}, 'Run features that should pass') do |t|
18 | t.binary = vendored_cucumber_bin # If nil, the gem's binary is used.
19 | t.fork = true # You may get faster startup if you set this to false
20 | t.profile = 'default'
21 | end
22 |
23 | Cucumber::Rake::Task.new({:wip => 'db:test:prepare'}, 'Run features that are being worked on') do |t|
24 | t.binary = vendored_cucumber_bin
25 | t.fork = true # You may get faster startup if you set this to false
26 | t.profile = 'wip'
27 | end
28 |
29 | Cucumber::Rake::Task.new({:rerun => 'db:test:prepare'}, 'Record failing features and run only them if any exist') do |t|
30 | t.binary = vendored_cucumber_bin
31 | t.fork = true # You may get faster startup if you set this to false
32 | t.profile = 'rerun'
33 | end
34 |
35 | desc 'Run all features'
36 | task :all => [:ok, :wip]
37 |
38 | task :statsetup do
39 | require 'rails/code_statistics'
40 | ::STATS_DIRECTORIES << %w(Cucumber\ features features) if File.exist?('features')
41 | ::CodeStatistics::TEST_TYPES << "Cucumber features" if File.exist?('features')
42 | end
43 | end
44 | desc 'Alias for cucumber:ok'
45 | task :cucumber => 'cucumber:ok'
46 |
47 | task :default => :cucumber
48 |
49 | task :features => :cucumber do
50 | STDERR.puts "*** The 'features' task is deprecated. See rake -T cucumber ***"
51 | end
52 |
53 | # In case we don't have ActiveRecord, append a no-op task that we can depend upon.
54 | task 'db:test:prepare' do
55 | end
56 |
57 | task :stats => 'cucumber:statsetup'
58 | rescue LoadError
59 | desc 'cucumber rake task not available (cucumber not installed)'
60 | task :cucumber do
61 | abort 'Cucumber rake task is not available. Be sure to install cucumber as a gem or plugin'
62 | end
63 | end
64 |
65 | end
66 |
--------------------------------------------------------------------------------
/lib/tasks/sample_data.rake:
--------------------------------------------------------------------------------
1 | namespace :db do
2 | desc "Fill database with sample data"
3 | task populate: :environment do
4 | make_users
5 | make_microposts
6 | make_relationships
7 | end
8 | end
9 |
10 | def make_users
11 | admin = User.create!(name: "Example User",
12 | email: "example@railstutorial.org",
13 | password: "foobar",
14 | password_confirmation: "foobar")
15 | admin.toggle!(:admin)
16 | 99.times do |n|
17 | name = Faker::Name.name
18 | email = "example-#{n+1}@railstutorial.org"
19 | password = "password"
20 | User.create!(name: name,
21 | email: email,
22 | password: password,
23 | password_confirmation: password)
24 | end
25 | end
26 |
27 | def make_microposts
28 | users = User.all(limit: 6)
29 | 50.times do
30 | content = Faker::Lorem.sentence(5)
31 | users.each { |user| user.microposts.create!(content: content) }
32 | end
33 | end
34 |
35 | def make_relationships
36 | users = User.all
37 | user = users.first
38 | followed_users = users[2..50]
39 | followers = users[3..40]
40 | followed_users.each { |followed| user.follow!(followed) }
41 | followers.each { |follower| follower.follow!(user) }
42 | end
--------------------------------------------------------------------------------
/log/.gitkeep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/railstutorial/sample_app_2nd_ed/e59c4fc43eb1763ed00ed9ff27f57a97d488434c/log/.gitkeep
--------------------------------------------------------------------------------
/public/404.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | The page you were looking for doesn't exist (404)
5 |
17 |
18 |
19 |
20 |
21 |
22 |
The page you were looking for doesn't exist.
23 |
You may have mistyped the address or the page may have moved.