Create a simple test application; run the provided functional tests.
ruby -rubygems /home/rubys/git/rails/bin/rails new testapp
create
create README
create Rakefile
create config.ru
create .gitignore
create Gemfile
create app
create app/controllers/application_controller.rb
create app/views/layouts/application.html.erb
create app/helpers/application_helper.rb
create app/models
create config
create config/routes.rb
create config/application.rb
create config/environment.rb
create config/environments
create config/environments/test.rb
create config/environments/production.rb
create config/environments/development.rb
create config/initializers
create config/initializers/backtrace_silencers.rb
create config/initializers/secret_token.rb
create config/initializers/mime_types.rb
create config/initializers/inflections.rb
create config/initializers/session_store.rb
create config/locales
create config/locales/en.yml
create config/boot.rb
create config/database.yml
create db
create db/seeds.rb
create doc
create doc/README_FOR_APP
create lib
create lib/tasks
create lib/tasks/.gitkeep
create log
create log/server.log
create log/production.log
create log/development.log
create log/test.log
create public
create public/422.html
create public/404.html
create public/robots.txt
create public/500.html
create public/index.html
create public/favicon.ico
create public/images
create public/images/rails.png
create public/stylesheets
create public/stylesheets/.gitkeep
create public/javascripts
create public/javascripts/controls.js
create public/javascripts/rails.js
create public/javascripts/application.js
create public/javascripts/prototype.js
create public/javascripts/effects.js
create public/javascripts/dragdrop.js
create script
create script/rails
create test
create test/performance/browsing_test.rb
create test/test_helper.rb
create test/unit
create test/fixtures
create test/functional
create test/integration
create tmp
create tmp/sessions
create tmp/sockets
create tmp/cache
create tmp/pids
create vendor/plugins
create vendor/plugins/.gitkeep
bundle install
Using rake (0.8.7) from bundler gems
Using abstract (1.0.0) from bundler gems
Using activesupport (3.0.0.beta3) from source code at /home/rubys/git/rails
Using builder (2.1.2) from bundler gems
Using i18n (0.4.1) from bundler gems
Using activemodel (3.0.0.beta3) from source code at /home/rubys/git/rails
Using erubis (2.6.5) from bundler gems
Using rack (1.1.0) from bundler gems
Using rack-mount (0.6.3) from bundler gems
Using rack-test (0.5.4) from bundler gems
Using tzinfo (0.3.22) from bundler gems
Using actionpack (3.0.0.beta3) from source code at /home/rubys/git/rails
Using mime-types (1.16) from bundler gems
Using polyglot (0.3.1) from bundler gems
Using treetop (1.4.8) from bundler gems
Using mail (2.2.1) from bundler gems
Using actionmailer (3.0.0.beta3) from source code at /home/rubys/git/rails
Using arel (0.3.3) from bundler gems
Using activerecord (3.0.0.beta3) from source code at /home/rubys/git/rails
Using activeresource (3.0.0.beta3) from source code at /home/rubys/git/rails
Using bundler (0.9.25) from bundler gems
Using thor (0.13.6) from bundler gems
Using railties (3.0.0.beta3) from source code at /home/rubys/git/rails
Using rails (3.0.0.beta3) from source code at /home/rubys/git/rails
Using sqlite3-ruby (1.2.5) from bundler gems Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.
rails generate scaffold product title:string
invoke active_record
create db/migrate/20100606173038_create_products.rb
create app/models/product.rb
invoke test_unit
create test/unit/product_test.rb
create test/fixtures/products.yml
route resources :products
invoke scaffold_controller
create app/controllers/products_controller.rb
invoke erb
create app/views/products
create app/views/products/index.html.erb
create app/views/products/edit.html.erb
create app/views/products/show.html.erb
create app/views/products/new.html.erb
create app/views/products/_form.html.erb
invoke test_unit
create test/functional/products_controller_test.rb
invoke helper
create app/helpers/products_helper.rb
invoke test_unit
create test/unit/helpers/products_helper_test.rb
invoke stylesheets
create public/stylesheets/scaffold.css
rake db:migrate
mv 20100606173038_create_products.rb 20100301000001_create_products.rb
(in /home/rubys/tmp/work/testapp)
== CreateProducts: migrating =================================================
-- create_table(:products)
-> 0.0029s
== CreateProducts: migrated (0.0031s) ========================================
rake test:functionals
(in /home/rubys/tmp/work/testapp)
Loaded suite /home/rubys/.rvm/gems/ruby-1.8.7-p174/gems/rake-0.8.7/lib/rake/rake_test_loader
Started
.......
Finished in 0.356161 seconds.
7 tests, 10 assertions, 0 failures, 0 errors
Create a test using XHR
edit test/functional/products_controller_test.rb
require 'test_helper'
class ProductsControllerTest < ActionController::TestCase
setup do
@product = products(:one)
end
test "should get index" do
get :index
assert_response :success
assert_not_nil assigns(:products)
end
test "should get new" do
get :new
assert_response :success
end
test "should create product" do
assert_difference('Product.count') do
post :create, :product => @product.attributes
end
assert_redirected_to product_path(assigns(:product))
end
test "should show product" do
get :show, :id => @product.to_param
assert_response :success
end
test "should get edit" do
get :edit, :id => @product.to_param
assert_response :success
end
test "should update product" do
put :update, :id => @product.to_param, :product => @product.attributes
assert_redirected_to product_path(assigns(:product))
end
test "should destroy product" do
assert_difference('Product.count', -1) do
delete :destroy, :id => @product.to_param
end
assert_redirected_to products_path
end
test "should create line_item via XHR" do
assert_difference('Product.count', +1) do
xhr :post, :create, :product_title => 'Lorem Ipsum'
end
end
end
Rerun the tests
rake test:functionals
(in /home/rubys/tmp/work/testapp)
Loaded suite /home/rubys/.rvm/gems/ruby-1.8.7-p174/gems/rake-0.8.7/lib/rake/rake_test_loader
Started
........
Finished in 0.386938 seconds.
8 tests, 11 assertions, 0 failures, 0 errors
Add js to the response formats for create
edit app/controllers/products_controller.rb
class ProductsController < ApplicationController
# GET /products
# GET /products.xml
def index
@products = Product.all
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @products }
end
end
# GET /products/1
# GET /products/1.xml
def show
@product = Product.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @product }
end
end
# GET /products/new
# GET /products/new.xml
def new
@product = Product.new
respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @product }
end
end
# GET /products/1/edit
def edit
@product = Product.find(params[:id])
end
# POST /products
# POST /products.xml
def create
@product = Product.new(params[:product])
respond_to do |format|
if @product.save
format.html { redirect_to(@product, :notice => 'Product was successfully created.') }
format.js
format.xml { render :xml => @product, :status => :created, :location => @product }
else
format.html { render :action => "new" }
format.xml { render :xml => @product.errors, :status => :unprocessable_entity }
end
end
end
# PUT /products/1
# PUT /products/1.xml
def update
@product = Product.find(params[:id])
respond_to do |format|
if @product.update_attributes(params[:product])
format.html { redirect_to(@product, :notice => 'Product was successfully updated.') }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @product.errors, :status => :unprocessable_entity }
end
end
end
# DELETE /products/1
# DELETE /products/1.xml
def destroy
@product = Product.find(params[:id])
@product.destroy
respond_to do |format|
format.html { redirect_to(products_url) }
format.xml { head :ok }
end
end
end
Create an empty rjs file
edit app/views/products/create.js.rjs
# this space intentionally left blank
Rerun functional tests
rake test:functionals
(in /home/rubys/tmp/work/testapp)
Loaded suite /home/rubys/.rvm/gems/ruby-1.8.7-p174/gems/rake-0.8.7/lib/rake/rake_test_loader
Started
E.......
Finished in 0.589985 seconds.
1) Error:
test_should_create_line_item_via_XHR(ProductsControllerTest):
NoMethodError: undefined method `size' for :js:Symbol
app/controllers/products_controller.rb:45:in `create'
/test/functional/products_controller_test.rb:52:in `test_should_create_line_item_via_XHR'
/test/functional/products_controller_test.rb:51:in `test_should_create_line_item_via_XHR'
8 tests, 10 assertions, 0 failures, 1 errors
rake aborted!
Command failed with status (1): [/home/rubys/.rvm/rubies/ruby-1.8.7-p174/bi...]
(See full trace by running task with --trace)
</8 tests, 11 assertions, 0 failures, 0 errors/> expected but was <"(in /home/rubys/tmp/work/testapp)">. Traceback: /home/rubys/tmp/rjs_functional_test.rb:50 /home/rubys/git/gorp/lib/gorp/test.rb:148:in `call' /home/rubys/git/gorp/lib/gorp/test.rb:148:in `rake' /home/rubys/tmp/rjs_functional_test.rb:49
Sun, 06 Jun 2010 17:30:59 GMT
/home/rubys/.rvm/rubies/ruby-1.8.7-p174/bin/ruby -v
ruby 1.8.7 (2009-06-12 patchlevel 174) [x86_64-linux]
gem -v
1.3.7
bundle show
Gems included by the bundle:
* abstract (1.0.0)
* actionmailer (3.0.0.beta3)
* actionpack (3.0.0.beta3)
* activemodel (3.0.0.beta3)
* activerecord (3.0.0.beta3)
* activeresource (3.0.0.beta3)
* activesupport (3.0.0.beta3)
* arel (0.3.3)
* builder (2.1.2)
* bundler (0.9.25)
* erubis (2.6.5)
* i18n (0.4.1)
* mail (2.2.1)
* mime-types (1.16)
* polyglot (0.3.1)
* rack (1.1.0)
* rack-mount (0.6.3)
* rack-test (0.5.4)
* rails (3.0.0.beta3 509f3d)
* railties (3.0.0.beta3)
* rake (0.8.7)
* sqlite3-ruby (1.2.5)
* thor (0.13.6)
* treetop (1.4.8)
* tzinfo (0.3.22)
rake about
(in /home/rubys/tmp/work/testapp)
About your application's environment
Ruby version 1.8.7 (x86_64-linux)
RubyGems version 1.3.7
Rack version 1.1
Rails version 3.0.0.beta3
Active Record version 3.0.0.beta3
Action Pack version 3.0.0.beta3
Active Resource version 3.0.0.beta3
Action Mailer version 3.0.0.beta3
Active Support version 3.0.0.beta3
Application root /home/rubys/tmp/work/testapp
Environment development
git log -1
commit 509f3d7d2f346b83dfd22aec681feffbd2d25803
Author: Jeremy Kemper <jeremy@bitsweat.net>
Date: Sat Jun 5 20:34:30 2010 -0700
Simplify middleware stack lazy compares using named const references