Permalink
Browse files

adding episode 257

  • Loading branch information...
1 parent f02fe36 commit 1947b9986bf9e483180c09548243defd3507a01c @ryanb committed Mar 14, 2011
Showing with 9,337 additions and 0 deletions.
  1. +10 −0 episode-257/README
  2. +4 −0 episode-257/todo/.gitignore
  3. +1 −0 episode-257/todo/.rspec
  4. +32 −0 episode-257/todo/Gemfile
  5. +128 −0 episode-257/todo/Gemfile.lock
  6. +7 −0 episode-257/todo/Rakefile
  7. +3 −0 episode-257/todo/app/controllers/application_controller.rb
  8. +10 −0 episode-257/todo/app/controllers/tasks_controller.rb
  9. +2 −0 episode-257/todo/app/helpers/application_helper.rb
  10. +23 −0 episode-257/todo/app/helpers/error_messages_helper.rb
  11. +22 −0 episode-257/todo/app/helpers/layout_helper.rb
  12. +2 −0 episode-257/todo/app/helpers/tasks_helper.rb
  13. +3 −0 episode-257/todo/app/models/task.rb
  14. +19 −0 episode-257/todo/app/views/layouts/application.html.erb
  15. +17 −0 episode-257/todo/app/views/tasks/index.html.erb
  16. +4 −0 episode-257/todo/config.ru
  17. +42 −0 episode-257/todo/config/application.rb
  18. +6 −0 episode-257/todo/config/boot.rb
  19. +22 −0 episode-257/todo/config/database.yml
  20. +5 −0 episode-257/todo/config/environment.rb
  21. +26 −0 episode-257/todo/config/environments/development.rb
  22. +49 −0 episode-257/todo/config/environments/production.rb
  23. +35 −0 episode-257/todo/config/environments/test.rb
  24. +7 −0 episode-257/todo/config/initializers/backtrace_silencers.rb
  25. +10 −0 episode-257/todo/config/initializers/inflections.rb
  26. +5 −0 episode-257/todo/config/initializers/mime_types.rb
  27. +7 −0 episode-257/todo/config/initializers/secret_token.rb
  28. +8 −0 episode-257/todo/config/initializers/session_store.rb
  29. +5 −0 episode-257/todo/config/locales/en.yml
  30. +4 −0 episode-257/todo/config/routes.rb
  31. +12 −0 episode-257/todo/db/migrate/20110314025647_create_tasks.rb
  32. +21 −0 episode-257/todo/db/schema.rb
  33. +7 −0 episode-257/todo/db/seeds.rb
  34. +2 −0 episode-257/todo/doc/README_FOR_APP
  35. 0 episode-257/todo/lib/tasks/.gitkeep
  36. +26 −0 episode-257/todo/public/404.html
  37. +26 −0 episode-257/todo/public/422.html
  38. +26 −0 episode-257/todo/public/500.html
  39. 0 episode-257/todo/public/favicon.ico
  40. BIN episode-257/todo/public/images/rails.png
  41. +2 −0 episode-257/todo/public/javascripts/application.js
  42. +8,316 −0 episode-257/todo/public/javascripts/jquery.js
  43. +16 −0 episode-257/todo/public/javascripts/jquery.min.js
  44. +158 −0 episode-257/todo/public/javascripts/rails.js
  45. +5 −0 episode-257/todo/public/robots.txt
  46. 0 episode-257/todo/public/stylesheets/.gitkeep
  47. +75 −0 episode-257/todo/public/stylesheets/application.css
  48. +6 −0 episode-257/todo/script/rails
  49. +27 −0 episode-257/todo/spec/requests/tasks_spec.rb
  50. +40 −0 episode-257/todo/spec/spec_helper.rb
  51. +5 −0 episode-257/todo/test/fixtures/tasks.yml
  52. +20 −0 episode-257/todo/test/functional/tasks_controller_test.rb
  53. +9 −0 episode-257/todo/test/performance/browsing_test.rb
  54. +13 −0 episode-257/todo/test/test_helper.rb
  55. +7 −0 episode-257/todo/test/unit/task_test.rb
  56. 0 episode-257/todo/vendor/plugins/.gitkeep
View
@@ -0,0 +1,10 @@
+Railscasts Episode #257: Request Specs and Capybara
+
+http://railscasts.com/episodes/257
+
+Commands
+
+ bundle
+ rails g rspec:install
+ rails g integration_test task
+ rake spec:requests
@@ -0,0 +1,4 @@
+.bundle
+db/*.sqlite3
+log/*.log
+tmp/
View
@@ -0,0 +1 @@
+--colour
View
@@ -0,0 +1,32 @@
+source 'http://rubygems.org'
+
+gem 'rails', '3.0.5'
+gem 'sqlite3'
+gem 'nifty-generators'
+gem 'jquery-rails'
+
+# Use unicorn as the web server
+# gem 'unicorn'
+
+# Deploy with Capistrano
+# gem 'capistrano'
+
+# To use debugger (ruby-debug for Ruby 1.8.7+, ruby-debug19 for Ruby 1.9.2+)
+# gem 'ruby-debug'
+# gem 'ruby-debug19', :require => 'ruby-debug'
+
+# Bundle the extra gems:
+# gem 'bj'
+# gem 'nokogiri'
+# gem 'sqlite3-ruby', :require => 'sqlite3'
+# gem 'aws-s3', :require => 'aws/s3'
+
+# Bundle gems for the local environment. Make sure to
+# put test-only gems in this group so their generators
+# and rake tasks are available in development mode:
+group :development, :test do
+ gem 'rspec-rails'
+ gem 'capybara', :git => 'git://github.com/jnicklas/capybara.git'
+ gem 'launchy'
+ gem 'database_cleaner'
+end
@@ -0,0 +1,128 @@
+GIT
+ remote: git://github.com/jnicklas/capybara.git
+ revision: 6f2e8c547b6d27678eefc407976ef7296bec4627
+ specs:
+ capybara (0.4.1.1)
+ mime-types (>= 1.16)
+ nokogiri (>= 1.3.3)
+ rack (>= 1.0.0)
+ rack-test (>= 0.5.4)
+ selenium-webdriver (>= 0.0.27)
+ xpath (~> 0.1.3)
+
+GEM
+ remote: http://rubygems.org/
+ specs:
+ abstract (1.0.0)
+ actionmailer (3.0.5)
+ actionpack (= 3.0.5)
+ mail (~> 2.2.15)
+ actionpack (3.0.5)
+ activemodel (= 3.0.5)
+ activesupport (= 3.0.5)
+ builder (~> 2.1.2)
+ erubis (~> 2.6.6)
+ i18n (~> 0.4)
+ rack (~> 1.2.1)
+ rack-mount (~> 0.6.13)
+ rack-test (~> 0.5.7)
+ tzinfo (~> 0.3.23)
+ activemodel (3.0.5)
+ activesupport (= 3.0.5)
+ builder (~> 2.1.2)
+ i18n (~> 0.4)
+ activerecord (3.0.5)
+ activemodel (= 3.0.5)
+ activesupport (= 3.0.5)
+ arel (~> 2.0.2)
+ tzinfo (~> 0.3.23)
+ activeresource (3.0.5)
+ activemodel (= 3.0.5)
+ activesupport (= 3.0.5)
+ activesupport (3.0.5)
+ arel (2.0.9)
+ builder (2.1.2)
+ childprocess (0.1.7)
+ ffi (~> 0.6.3)
+ configuration (1.2.0)
+ database_cleaner (0.6.5)
+ diff-lcs (1.1.2)
+ erubis (2.6.6)
+ abstract (>= 1.0.0)
+ ffi (0.6.3)
+ rake (>= 0.8.7)
+ i18n (0.5.0)
+ jquery-rails (0.2.7)
+ rails (~> 3.0)
+ thor (~> 0.14.4)
+ json_pure (1.5.1)
+ launchy (0.4.0)
+ configuration (>= 0.0.5)
+ rake (>= 0.8.1)
+ mail (2.2.15)
+ activesupport (>= 2.3.6)
+ i18n (>= 0.4.0)
+ mime-types (~> 1.16)
+ treetop (~> 1.4.8)
+ mime-types (1.16)
+ nifty-generators (0.4.5)
+ nokogiri (1.4.4)
+ polyglot (0.3.1)
+ rack (1.2.2)
+ rack-mount (0.6.13)
+ rack (>= 1.0.0)
+ rack-test (0.5.7)
+ rack (>= 1.0)
+ rails (3.0.5)
+ actionmailer (= 3.0.5)
+ actionpack (= 3.0.5)
+ activerecord (= 3.0.5)
+ activeresource (= 3.0.5)
+ activesupport (= 3.0.5)
+ bundler (~> 1.0)
+ railties (= 3.0.5)
+ railties (3.0.5)
+ actionpack (= 3.0.5)
+ activesupport (= 3.0.5)
+ rake (>= 0.8.7)
+ thor (~> 0.14.4)
+ rake (0.8.7)
+ rspec (2.5.0)
+ rspec-core (~> 2.5.0)
+ rspec-expectations (~> 2.5.0)
+ rspec-mocks (~> 2.5.0)
+ rspec-core (2.5.1)
+ rspec-expectations (2.5.0)
+ diff-lcs (~> 1.1.2)
+ rspec-mocks (2.5.0)
+ rspec-rails (2.5.0)
+ actionpack (~> 3.0)
+ activesupport (~> 3.0)
+ railties (~> 3.0)
+ rspec (~> 2.5.0)
+ rubyzip (0.9.4)
+ selenium-webdriver (0.1.3)
+ childprocess (~> 0.1.5)
+ ffi (~> 0.6.3)
+ json_pure
+ rubyzip
+ sqlite3 (1.3.3)
+ thor (0.14.6)
+ treetop (1.4.9)
+ polyglot (>= 0.3.1)
+ tzinfo (0.3.24)
+ xpath (0.1.3)
+ nokogiri (~> 1.3)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ capybara!
+ database_cleaner
+ jquery-rails
+ launchy
+ nifty-generators
+ rails (= 3.0.5)
+ rspec-rails
+ sqlite3
@@ -0,0 +1,7 @@
+# Add your own tasks in files placed in lib/tasks ending in .rake,
+# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
+
+require File.expand_path('../config/application', __FILE__)
+require 'rake'
+
+Todo::Application.load_tasks
@@ -0,0 +1,3 @@
+class ApplicationController < ActionController::Base
+ protect_from_forgery
+end
@@ -0,0 +1,10 @@
+class TasksController < ApplicationController
+ def index
+ @tasks = Task.all
+ end
+
+ def create
+ @task = Task.create!(params[:task])
+ redirect_to tasks_url, :notice => "Successfully added task."
+ end
+end
@@ -0,0 +1,2 @@
+module ApplicationHelper
+end
@@ -0,0 +1,23 @@
+module ErrorMessagesHelper
+ # Render error messages for the given objects. The :message and :header_message options are allowed.
+ def error_messages_for(*objects)
+ options = objects.extract_options!
+ options[:header_message] ||= I18n.t(:"activerecord.errors.header", :default => "Invalid Fields")
+ options[:message] ||= I18n.t(:"activerecord.errors.message", :default => "Correct the following errors and try again.")
+ messages = objects.compact.map { |o| o.errors.full_messages }.flatten
+ unless messages.empty?
+ content_tag(:div, :class => "error_messages") do
+ list_items = messages.map { |msg| content_tag(:li, msg) }
+ content_tag(:h2, options[:header_message]) + content_tag(:p, options[:message]) + content_tag(:ul, list_items.join.html_safe)
+ end
+ end
+ end
+
+ module FormBuilderAdditions
+ def error_messages(options = {})
+ @template.error_messages_for(@object, options)
+ end
+ end
+end
+
+ActionView::Helpers::FormBuilder.send(:include, ErrorMessagesHelper::FormBuilderAdditions)
@@ -0,0 +1,22 @@
+# These helper methods can be called in your template to set variables to be used in the layout
+# This module should be included in all views globally,
+# to do so you may need to add this line to your ApplicationController
+# helper :layout
+module LayoutHelper
+ def title(page_title, show_title = true)
+ content_for(:title) { h(page_title.to_s) }
+ @show_title = show_title
+ end
+
+ def show_title?
+ @show_title
+ end
+
+ def stylesheet(*args)
+ content_for(:head) { stylesheet_link_tag(*args) }
+ end
+
+ def javascript(*args)
+ content_for(:head) { javascript_include_tag(*args) }
+ end
+end
@@ -0,0 +1,2 @@
+module TasksHelper
+end
@@ -0,0 +1,3 @@
+class Task < ActiveRecord::Base
+ attr_accessible :name
+end
@@ -0,0 +1,19 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <title><%= content_for?(:title) ? yield(:title) : "Untitled" %></title>
+ <%= stylesheet_link_tag "application" %>
+ <%= javascript_include_tag :defaults %>
+ <%= csrf_meta_tag %>
+ <%= yield(:head) %>
+ </head>
+ <body>
+ <div id="container">
+ <% flash.each do |name, msg| %>
+ <%= content_tag :div, msg, :id => "flash_#{name}" %>
+ <% end %>
+ <%= content_tag :h1, yield(:title) if show_title? %>
+ <%= yield %>
+ </div>
+ </body>
+</html>
@@ -0,0 +1,17 @@
+<% title "Task List" %>
+
+<%= link_to_function "test js", '$(this).html("js works")' %>
+
+<%= form_for Task.new do |f| %>
+ <p>
+ <%= f.label :name, "New Task:" %>
+ <%= f.text_field :name %>
+ <%= f.submit "Add" %>
+ </p>
+<% end %>
+
+<ul>
+<% for task in @tasks %>
+ <li><%= task.name %></li>
+<% end %>
+</ul>
@@ -0,0 +1,4 @@
+# This file is used by Rack-based servers to start the application.
+
+require ::File.expand_path('../config/environment', __FILE__)
+run Todo::Application
@@ -0,0 +1,42 @@
+require File.expand_path('../boot', __FILE__)
+
+require 'rails/all'
+
+# If you have a Gemfile, require the gems listed there, including any gems
+# you've limited to :test, :development, or :production.
+Bundler.require(:default, Rails.env) if defined?(Bundler)
+
+module Todo
+ class Application < Rails::Application
+ # Settings in config/environments/* take precedence over those specified here.
+ # Application configuration should go into files in config/initializers
+ # -- all .rb files in that directory are automatically loaded.
+
+ # Custom directories with classes and modules you want to be autoloadable.
+ # config.autoload_paths += %W(#{config.root}/extras)
+
+ # Only load the plugins named here, in the order given (default is alphabetical).
+ # :all can be used as a placeholder for all plugins not explicitly named.
+ # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
+
+ # Activate observers that should always be running.
+ # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
+
+ # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
+ # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
+ # config.time_zone = 'Central Time (US & Canada)'
+
+ # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
+ # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
+ # config.i18n.default_locale = :de
+
+ # JavaScript files you want as :defaults (application.js is always included).
+ # config.action_view.javascript_expansions[:defaults] = %w(jquery rails)
+
+ # Configure the default encoding used in templates for Ruby 1.9.
+ config.encoding = "utf-8"
+
+ # Configure sensitive parameters which will be filtered from the log file.
+ config.filter_parameters += [:password]
+ end
+end
@@ -0,0 +1,6 @@
+require 'rubygems'
+
+# Set up gems listed in the Gemfile.
+ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
+
+require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
@@ -0,0 +1,22 @@
+# SQLite version 3.x
+# gem install sqlite3
+development:
+ adapter: sqlite3
+ database: db/development.sqlite3
+ pool: 5
+ timeout: 5000
+
+# Warning: The database defined as "test" will be erased and
+# re-generated from your development database when you run "rake".
+# Do not set this db to the same as development or production.
+test:
+ adapter: sqlite3
+ database: db/test.sqlite3
+ pool: 5
+ timeout: 5000
+
+production:
+ adapter: sqlite3
+ database: db/production.sqlite3
+ pool: 5
+ timeout: 5000
@@ -0,0 +1,5 @@
+# Load the rails application
+require File.expand_path('../application', __FILE__)
+
+# Initialize the rails application
+Todo::Application.initialize!
Oops, something went wrong.

0 comments on commit 1947b99

Please sign in to comment.