Skip to content

Commit

Permalink
automatic import from ryanb/railscasts-episodes
Browse files Browse the repository at this point in the history
  • Loading branch information
gilesbowkett committed Jul 29, 2011
0 parents commit b818954
Show file tree
Hide file tree
Showing 119 changed files with 19,195 additions and 0 deletions.
11 changes: 11 additions & 0 deletions README
@@ -0,0 +1,11 @@
Railscasts Episode #261: Testing JavaScript with Jasmine

http://railscasts.com/episodes/261

Commands

bundle
rails g jasmine:install
rake jasmine
rake jasmine:ci
curl http://cloud.github.com/downloads/velesin/jasmine-jquery/jasmine-jquery-1.2.0.js > spec/javascripts/helpers/jasmine_jquery-1.2.0.js
4 changes: 4 additions & 0 deletions checkout-after/.gitignore
@@ -0,0 +1,4 @@
.bundle
db/*.sqlite3
log/*.log
tmp/
7 changes: 7 additions & 0 deletions checkout-after/Gemfile
@@ -0,0 +1,7 @@
source 'http://rubygems.org'

gem 'rails', '3.0.5'
gem 'sqlite3'
gem 'nifty-generators'
gem 'jquery-rails'
gem 'jasmine', :group => [:development, :test]
105 changes: 105 additions & 0 deletions checkout-after/Gemfile.lock
@@ -0,0 +1,105 @@
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.8)
ffi (~> 1.0.6)
diff-lcs (1.1.2)
erubis (2.6.6)
abstract (>= 1.0.0)
ffi (1.0.7)
rake (>= 0.8.7)
i18n (0.5.0)
jasmine (1.0.2.0)
json_pure (>= 1.4.3)
rack (>= 1.1)
rspec (>= 1.3.1)
selenium-webdriver (>= 0.1.3)
jquery-rails (0.2.7)
rails (~> 3.0)
thor (~> 0.14.4)
json_pure (1.5.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.6)
polyglot (0.3.1)
rack (1.2.2)
rack-mount (0.6.14)
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)
rubyzip (0.9.4)
selenium-webdriver (0.1.4)
childprocess (>= 0.1.7)
ffi (>= 1.0.7)
json_pure
rubyzip
sqlite3 (1.3.3)
thor (0.14.6)
treetop (1.4.9)
polyglot (>= 0.3.1)
tzinfo (0.3.26)

PLATFORMS
ruby

DEPENDENCIES
jasmine
jquery-rails
nifty-generators
rails (= 3.0.5)
sqlite3
7 changes: 7 additions & 0 deletions checkout-after/Rakefile
@@ -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'

Checkout::Application.load_tasks
3 changes: 3 additions & 0 deletions checkout-after/app/controllers/application_controller.rb
@@ -0,0 +1,3 @@
class ApplicationController < ActionController::Base
protect_from_forgery
end
37 changes: 37 additions & 0 deletions checkout-after/app/controllers/orders_controller.rb
@@ -0,0 +1,37 @@
class OrdersController < ApplicationController
def index
@orders = Order.all
end

def new
@order = Order.new
end

def create
@order = Order.new(params[:order])
if @order.save
redirect_to orders_url, :notice => "Successfully created order."
else
render :action => 'new'
end
end

def edit
@order = Order.find(params[:id])
end

def update
@order = Order.find(params[:id])
if @order.update_attributes(params[:order])
redirect_to orders_url, :notice => "Successfully updated order."
else
render :action => 'edit'
end
end

def destroy
@order = Order.find(params[:id])
@order.destroy
redirect_to orders_url, :notice => "Successfully destroyed order."
end
end
2 changes: 2 additions & 0 deletions checkout-after/app/helpers/application_helper.rb
@@ -0,0 +1,2 @@
module ApplicationHelper
end
23 changes: 23 additions & 0 deletions checkout-after/app/helpers/error_messages_helper.rb
@@ -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)
22 changes: 22 additions & 0 deletions checkout-after/app/helpers/layout_helper.rb
@@ -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
2 changes: 2 additions & 0 deletions checkout-after/app/helpers/orders_helper.rb
@@ -0,0 +1,2 @@
module OrdersHelper
end
3 changes: 3 additions & 0 deletions checkout-after/app/models/order.rb
@@ -0,0 +1,3 @@
class Order < ActiveRecord::Base
attr_accessible :credit_card_number, :credit_card_expires_on
end
19 changes: 19 additions & 0 deletions checkout-after/app/views/layouts/application.html.erb
@@ -0,0 +1,19 @@
<!DOCTYPE html>
<html>
<head>
<title><%= content_for?(:title) ? yield(:title) : "Untitled" %></title>
<%= stylesheet_link_tag "application" %>
<%= javascript_include_tag :defaults, "credit_card" %>
<%= 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>
13 changes: 13 additions & 0 deletions checkout-after/app/views/orders/_form.html.erb
@@ -0,0 +1,13 @@
<%= form_for @order do |f| %>
<%= f.error_messages %>
<p>
<%= f.label :credit_card_number %><br />
<%= f.text_field :credit_card_number %>
<span id="order_credit_card_number_error"></span>
</p>
<p>
<%= f.label :credit_card_expires_on, "Credit card expiration date" %><br />
<%= f.date_select :credit_card_expires_on, :add_month_numbers => true, :start_year => Time.now.year, :order => [:month, :year] %>
</p>
<p><%= f.submit %></p>
<% end %>
4 changes: 4 additions & 0 deletions checkout-after/app/views/orders/edit.html.erb
@@ -0,0 +1,4 @@
<% title "Edit Order" %>
<%= render 'form' %>

18 changes: 18 additions & 0 deletions checkout-after/app/views/orders/index.html.erb
@@ -0,0 +1,18 @@
<% title "Orders" %>

<table>
<tr>
<th>Credit Card Number</th>
<th>Credit Card Expires On</th>
</tr>
<% for order in @orders %>
<tr>
<td><%= order.credit_card_number %></td>
<td><%= order.credit_card_expires_on %></td>
<td><%= link_to "Edit", edit_order_path(order) %></td>
<td><%= link_to "Destroy", order, :confirm => 'Are you sure?', :method => :delete %></td>
</tr>
<% end %>
</table>

<p><%= link_to "New Order", new_order_path %></p>
5 changes: 5 additions & 0 deletions checkout-after/app/views/orders/new.html.erb
@@ -0,0 +1,5 @@
<% title "New Order" %>
<%= render 'form' %>

<p><%= link_to "Back to List", orders_path %></p>
4 changes: 4 additions & 0 deletions checkout-after/config.ru
@@ -0,0 +1,4 @@
# This file is used by Rack-based servers to start the application.

require ::File.expand_path('../config/environment', __FILE__)
run Checkout::Application
42 changes: 42 additions & 0 deletions checkout-after/config/application.rb
@@ -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 Checkout
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
6 changes: 6 additions & 0 deletions checkout-after/config/boot.rb
@@ -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'])
22 changes: 22 additions & 0 deletions checkout-after/config/database.yml
@@ -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
5 changes: 5 additions & 0 deletions checkout-after/config/environment.rb
@@ -0,0 +1,5 @@
# Load the rails application
require File.expand_path('../application', __FILE__)

# Initialize the rails application
Checkout::Application.initialize!

0 comments on commit b818954

Please sign in to comment.