1
0
Fork 0
mirror of https://github.com/thoughtbot/shoulda-matchers.git synced 2022-11-09 12:01:38 -05:00

Don't test Rails 2

This commit is contained in:
Joe Ferris 2010-12-13 15:56:37 -05:00
parent 50c47f354c
commit 2320a8c539
78 changed files with 109 additions and 1356 deletions

View file

@ -45,30 +45,12 @@ end
desc "Clean files generated by rake tasks"
task :clobber => [:clobber_rdoc, :clobber_package]
namespace :cucumber do
Cucumber::Rake::Task.new(:rails2, "Run the cucumber features in Rails 2") do |t|
t.fork = true
t.cucumber_opts = ['--format', (ENV['CUCUMBER_FORMAT'] || 'progress')]
t.profile = 'rails2'
end
Cucumber::Rake::Task.new(:rails3, "Run the cucumber features in Rails 3") do |t|
t.fork = true
t.cucumber_opts = ['--format', (ENV['CUCUMBER_FORMAT'] || 'progress')]
t.profile = 'rails3'
end
end rescue nil
desc "Run the cucumber features in both Rails 2 and 3"
task :cucumber => ["cucumber:rails2", "cucumber:rails3"]
desc 'run tests for all supported versions of Rails'
task :test_all do
%w(2.3.8 3.0.0.beta4).each do |version|
system("RAILS_VERSION=#{version} rake -s test;")
end
Cucumber::Rake::Task.new do |t|
t.fork = true
t.cucumber_opts = ['--format', (ENV['CUCUMBER_FORMAT'] || 'progress')]
t.profile = 'default'
end
desc 'Default: run test and cucumber features for support versions'
task :default => [:test_all, :cucumber]
task :default => [:test, :cucumber]

View file

@ -1,2 +1 @@
rails2: -r features/support -r features/step_definitions/common_steps.rb -r features/step_definitions/rails2_steps.rb
rails3: -r features/support -r features/step_definitions/common_steps.rb -r features/step_definitions/rails3_steps.rb
default: -r features/support -r features/step_definitions/common_steps.rb -r features/step_definitions/rails3_steps.rb

View file

@ -2,7 +2,6 @@ Feature: integrate with Rails
Background:
When I generate a new rails application
And I configure the application to use "shoulda" from this project
And I save the following as "db/migrate/1_create_users.rb"
"""
class CreateUsers < ActiveRecord::Migration
@ -31,36 +30,9 @@ Feature: integrate with Rails
"""
When I configure a wildcard route
Scenario: generate a rails application and use macros in Test::Unit
When I save the following as "test/unit/user_test.rb"
"""
require 'test_helper'
class UserTest < ActiveSupport::TestCase
should_validate_presence_of :name
end
"""
When I save the following as "test/functional/examples_controller_test.rb"
"""
require 'test_helper'
class ExamplesControllerTest < ActionController::TestCase
def setup
get :show
end
should_respond_with :success
should_assign_to :example
end
"""
When I run "rake test TESTOPTS=-v"
Then I should see "1 tests, 1 assertions, 0 failures, 0 errors"
And I should see "2 tests, 2 assertions, 0 failures, 0 errors"
And I should see "User should require name to be set"
And I should see "ExamplesController should assign @example"
Scenario: generate a rails application and use matchers in Test::Unit
When I save the following as "test/unit/user_test.rb"
When I configure the application to use "shoulda" from this project
And I save the following as "test/unit/user_test.rb"
"""
require 'test_helper'
@ -89,6 +61,7 @@ Feature: integrate with Rails
Scenario: generate a rails application and use matchers in Rspec
When I configure the application to use rspec-rails
And I configure the application to use "shoulda" from this project
And I run the rspec generator
And I save the following as "spec/models/user_spec.rb"
"""

View file

@ -1,83 +0,0 @@
When /^I generate a new rails application$/ do
load_rails = <<-RUBY
gem 'rails', '2.3.8'; \
load Gem.bin_path('rails', 'rails', '2.3.8')
RUBY
@terminal.cd(TEMP_ROOT)
@terminal.run(%{ruby -rubygems -e "#{load_rails.strip!}" #{APP_NAME}})
end
When /^I configure the application to use "([^\"]+)" from this project$/ do |name|
gemspec = File.join(PROJECT_ROOT, "#{name}.gemspec")
eval("$specification = begin; #{IO.read(gemspec)}; end")
version = $specification.version
name = $specification.name
vendor_gem_root = File.join(RAILS_ROOT, 'vendor', 'gems')
vendor_gem_path = File.join(vendor_gem_root, "shoulda-#{version}")
FileUtils.mkdir_p(vendor_gem_root)
FileUtils.ln_s(PROJECT_ROOT, vendor_gem_path)
File.open(File.join(vendor_gem_path, ".specification"), "w") do |file|
file.write($specification.to_yaml)
end
insert_into_environment("config.gem '#{name}'")
end
When /^I configure the application to use rspec\-rails$/ do
# we have to unpack and copy the generator because Rails won't find the
# generators if rspec-rails 2 is installed
insert_into_environment("config.gem 'rspec-rails', :lib => false, :version => '1.2.9'")
insert_into_environment("config.gem 'rspec', :lib => false, :version => '1.2.9'")
steps %{
When I run "rake gems:unpack"
}
rspec_generator = File.join(RAILS_ROOT,
'vendor',
'gems',
'rspec-rails-1.2.9',
'generators')
FileUtils.cp_r(rspec_generator, File.join(RAILS_ROOT, 'lib'))
end
When /^I run the rspec generator$/ do
steps %{
When I run the "rspec" generator
}
end
When /^I run the "([^"]*)" generator$/ do |name|
steps %{
When I run "./script/generate #{name}"
}
end
When /^I configure a wildcard route$/ do
steps %{
When I save the following as "config/routes.rb"
"""
ActionController::Routing::Routes.draw do |map|
map.connect ':controller/:action/:id'
end
"""
}
end
module InsertionHelpers
def insert_into(path, find, replace)
contents = IO.read(path)
contents.sub!(find, replace)
File.open(path, "w") { |file| file.write(contents) }
end
def insert_into_environment(contents)
environment_file = File.join(RAILS_ROOT, 'config', 'environment.rb')
initializer = "Rails::Initializer.run do |config|"
replace = "#{initializer}\n #{contents}"
insert_into(environment_file, initializer, replace)
end
end
World(InsertionHelpers)

View file

@ -13,7 +13,7 @@ end
When /^I configure the application to use "([^\"]+)" from this project$/ do |name|
append_to_gemfile "gem '#{name}', :path => '../../'"
steps %{And I run "bundle lock"}
steps %{And I run "bundle install"}
end
When /^I run the "([^"]*)" generator$/ do |name|
@ -30,7 +30,7 @@ end
When /^I configure the application to use rspec\-rails$/ do
append_to_gemfile "gem 'rspec-rails', '>= 2.0.0.beta.12'"
steps %{And I run "bundle lock"}
steps %{And I run "bundle install"}
end
When /^I configure a wildcard route$/ do

View file

@ -1,8 +1,6 @@
require 'shoulda/version'
if defined?(RSpec)
require 'shoulda/integrations/rspec2'
elsif defined?(Spec)
require 'shoulda/integrations/rspec'
else
require 'shoulda/integrations/test_unit'

View file

@ -1,13 +1,22 @@
require 'shoulda/active_record/matchers'
require 'shoulda/action_controller/matchers'
require 'shoulda/action_mailer/matchers'
require 'active_support/test_case'
# :enddoc:
module ActiveSupport
class TestCase
module RSpec
module Matchers
include Shoulda::ActiveRecord::Matchers
include Shoulda::ActionController::Matchers
include Shoulda::ActionMailer::Matchers
end
module Rails
module ControllerExampleGroup
include Shoulda::ActionController::Matchers
end
module MailerExampleGroup
include Shoulda::ActionMailer::Matchers
end
end
end

View file

@ -1,22 +0,0 @@
require 'shoulda/active_record/matchers'
require 'shoulda/action_controller/matchers'
require 'shoulda/action_mailer/matchers'
# :enddoc:
module RSpec
module Matchers
include Shoulda::ActiveRecord::Matchers
end
module Rails
module ControllerExampleGroup
include Shoulda::ActionController::Matchers
end
module MailerExampleGroup
include Shoulda::ActionMailer::Matchers
end
end
end

View file

@ -1,130 +0,0 @@
class ActiveSupport::TestCase
TMP_VIEW_PATH =
File.expand_path(File.join(File.dirname(__FILE__), 'rails2_root', 'tmp', 'views')).freeze
def create_table(table_name, &block)
connection = ActiveRecord::Base.connection
begin
connection.execute("DROP TABLE IF EXISTS #{table_name}")
connection.create_table(table_name, &block)
@created_tables ||= []
@created_tables << table_name
connection
rescue Exception => e
connection.execute("DROP TABLE IF EXISTS #{table_name}")
raise e
end
end
def define_constant(class_name, base, &block)
class_name = class_name.to_s.camelize
klass = Class.new(base)
Object.const_set(class_name, klass)
klass.class_eval(&block) if block_given?
@defined_constants ||= []
@defined_constants << class_name
klass
end
def define_model_class(class_name, &block)
define_constant(class_name, ActiveRecord::Base, &block)
end
def define_model(name, columns = {}, &block)
class_name = name.to_s.pluralize.classify
table_name = class_name.tableize
create_table(table_name) do |table|
columns.each do |name, type|
table.column name, type
end
end
define_model_class(class_name, &block)
end
def define_mailer(name, paths, &block)
class_name = name.to_s.pluralize.classify
klass = define_constant(class_name, ActionMailer::Base, &block)
paths.each {|path| create_view("#{name}/#{path}", "<%= @message %>")}
klass.template_root = TMP_VIEW_PATH
end
def define_controller(class_name, &block)
class_name = class_name.to_s
class_name << 'Controller' unless class_name =~ /Controller$/
define_constant(class_name, ActionController::Base, &block)
end
def define_routes(&block)
@replaced_routes = ActionController::Routing::Routes
new_routes = ActionController::Routing::RouteSet.new
silence_warnings do
ActionController::Routing.const_set('Routes', new_routes)
end
new_routes.draw(&block)
end
def build_response(opts = {}, &block)
action = opts[:action] || 'example'
klass = define_controller('Examples')
block ||= lambda { render :nothing => true }
klass.class_eval { define_method(action, &block) }
define_routes do |map|
map.connect 'examples', :controller => 'examples', :action => action
end
create_view("examples/#{action}.html.erb", "abc")
klass.view_paths = [TMP_VIEW_PATH]
@controller = klass.new
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
get action
@controller
end
def create_view(path, contents)
full_path = File.join(TMP_VIEW_PATH, path)
FileUtils.mkdir_p(File.dirname(full_path))
File.open(full_path, 'w') { |file| file.write(contents) }
end
def teardown_with_models
if @defined_constants
@defined_constants.each do |class_name|
Object.send(:remove_const, class_name)
end
end
if @created_tables
@created_tables.each do |table_name|
ActiveRecord::Base.
connection.
execute("DROP TABLE IF EXISTS #{table_name}")
end
end
if @replaced_routes
ActionController::Routing::Routes.clear!
silence_warnings do
ActionController::Routing.const_set('Routes', @replaced_routes)
end
@replaced_routes.reload!
end
FileUtils.rm_rf(TMP_VIEW_PATH)
teardown_without_models
end
alias_method :teardown_without_models, :teardown
alias_method :teardown, :teardown_with_models
end

View file

@ -1,22 +0,0 @@
# Filters added to this controller apply to all controllers in the application.
# Likewise, all the methods added will be available for all controllers.
class ApplicationController < ActionController::Base
def ensure_logged_in
unless session[:logged_in]
respond_to do |accepts|
accepts.html do
flash[:error] = 'What do you think you\'re doing?'
redirect_to '/'
end
accepts.xml do
headers["Status"] = "Unauthorized"
headers["WWW-Authenticate"] = %(Basic realm="Web Password")
render :text => "Couldn't authenticate you", :status => '401 Unauthorized'
end
end
return false
end
return true
end
end

View file

@ -1,87 +0,0 @@
class PostsController < ApplicationController
before_filter :ensure_logged_in
before_filter :load_user
def index
@posts = @user.posts
respond_to do |format|
format.html # index.rhtml
format.xml { render :xml => @posts.to_xml }
format.rss do
headers['Content-Type'] = 'application/rss+xml'
session[:special] = '$2 off your next purchase'
session[:special_user_id] = @user.id
session[:false_var] = false
head :ok
end
end
end
def show
@post = @user.posts.find(params[:id])
@false_flag = false
respond_to do |format|
format.html { render :layout => 'wide' }
format.xml { render :xml => @post.to_xml }
end
end
def new
@post = @user.posts.build
render :layout => false
end
def edit
@post = @user.posts.find(params[:id])
end
def create
@post = @user.posts.build(params[:post])
respond_to do |format|
if @post.save
flash[:notice] = 'Post was successfully created.'
format.html { redirect_to user_post_url(@post.user, @post) }
format.xml { head :created, :location => user_post_url(@post.user, @post) }
else
format.html { render :action => "new" }
format.xml { render :xml => @post.errors.to_xml }
end
end
end
def update
@post = @user.posts.find(params[:id])
respond_to do |format|
if @post.update_attributes(params[:post])
flash[:notice] = 'Post was successfully updated.'
format.html { redirect_to user_post_url(@post.user, @post) }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @post.errors.to_xml }
end
end
end
def destroy
@post = @user.posts.find(params[:id])
@post.destroy
flash[:notice] = "Post was removed"
respond_to do |format|
format.html { redirect_to user_posts_url(@post.user) }
format.xml { head :ok }
end
end
private
def load_user
@user = User.find(params[:user_id])
end
end

View file

@ -1,84 +0,0 @@
class UsersController < ApplicationController
filter_parameter_logging :ssn
# GET /users
# GET /users.xml
def index
@users = User.find(:all)
respond_to do |format|
format.html # index.rhtml
format.xml { render :xml => @users.to_xml }
end
end
# GET /users/1
# GET /users/1.xml
def show
@user = User.find(params[:id])
respond_to do |format|
format.html # show.rhtml
format.xml { render :xml => @user.to_xml }
end
end
# GET /users/new
def new
@user = User.new
end
# GET /users/1;edit
def edit
@user = User.find(params[:id])
end
# POST /users
# POST /users.xml
def create
@user = User.new(params[:user])
respond_to do |format|
if @user.save
flash[:notice] = 'User was successfully created.'
format.html { redirect_to user_url(@user) }
format.xml { head :created, :location => user_url(@user) }
else
format.html { render :action => "new" }
format.xml { render :xml => @user.errors.to_xml }
end
end
end
# PUT /users/1
# PUT /users/1.xml
def update
@user = User.find(params[:id])
respond_to do |format|
if @user.update_attributes(params[:user])
flash[:notice] = 'User was successfully updated.'
format.html { redirect_to user_url(@user) }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @user.errors.to_xml }
end
end
end
# DELETE /users/1
# DELETE /users/1.xml
def destroy
@user = User.find(params[:id])
@user.destroy
flash[:notice] = "User was removed"
respond_to do |format|
format.html { redirect_to users_url }
format.xml { head :ok }
end
end
end

View file

@ -1,3 +0,0 @@
# Methods added to this helper will be available to all templates in the application.
module ApplicationHelper
end

View file

@ -1,2 +0,0 @@
module PostsHelper
end

View file

@ -1,2 +0,0 @@
module UsersHelper
end

View file

@ -1,7 +0,0 @@
class Address < ActiveRecord::Base
belongs_to :addressable, :polymorphic => true
validates_uniqueness_of :title, :scope => [:addressable_type, :addressable_id]
validates_length_of :zip, :minimum => 5
validates_numericality_of :zip
end

View file

@ -1,11 +0,0 @@
class Flea < ActiveRecord::Base
has_and_belongs_to_many :dogs
after_create :send_notification
private
def send_notification
Notifier.deliver_the_email
end
end

View file

@ -1,4 +0,0 @@
class Friendship < ActiveRecord::Base
belongs_to :user
belongs_to :friend, :class_name => "User"
end

View file

@ -1,8 +0,0 @@
class Notifier < ActionMailer::Base
def the_email
from "do-not-reply@example.com"
recipients "myself@me.com"
subject "This is spam"
body :body => "Every email is spam."
end
end

View file

@ -1,7 +0,0 @@
module Pets
class Cat < ActiveRecord::Base
belongs_to :owner, :class_name => 'User'
belongs_to :address, :dependent => :destroy
validates_presence_of :owner_id
end
end

View file

@ -1,10 +0,0 @@
module Pets
class Dog < ActiveRecord::Base
belongs_to :user, :foreign_key => :owner_id
belongs_to :address, :dependent => :destroy
has_many :treats
has_and_belongs_to_many :fleas, :join_table => :fleas
validates_presence_of :treats, :fleas
validates_presence_of :owner_id
end
end

View file

@ -1,12 +0,0 @@
class Post < ActiveRecord::Base
belongs_to :user
belongs_to :owner, :foreign_key => :user_id, :class_name => 'User'
has_many :taggings
has_many :tags, :through => :taggings
has_many :through_tags, :through => :taggings, :source => :tag
validates_uniqueness_of :title
validates_presence_of :title
validates_presence_of :body, :message => 'Seriously, wtf'
validates_numericality_of :user_id
end

View file

@ -1,12 +0,0 @@
class Product < ActiveRecord::Base
validates_presence_of :title
validates_inclusion_of :price, :in => 0..99, :unless => :tangible
validates_format_of :size, :with => /^\d+\D+$/, :unless => :tangible
validates_presence_of :price, :if => :tangible
validates_inclusion_of :price, :in => 1..9999, :if => :tangible
validates_inclusion_of :weight, :in => 1..100, :if => :tangible
validates_format_of :size, :with => /.+x.+x.+/, :if => :tangible
validates_length_of :size, :in => 5..20, :if => :tangible
end

View file

@ -1,2 +0,0 @@
class Profile < ActiveRecord::Base
end

View file

@ -1,2 +0,0 @@
class Registration < ActiveRecord::Base
end

View file

@ -1,8 +0,0 @@
class Tag < ActiveRecord::Base
has_many :taggings, :dependent => :destroy
has_many :posts, :through => :taggings
validates_length_of :name, :minimum => 2
attr_accessible :name
end

View file

@ -1,4 +0,0 @@
class Tagging < ActiveRecord::Base
belongs_to :post
belongs_to :tag
end

View file

@ -1,3 +0,0 @@
class Treat < ActiveRecord::Base
end

View file

@ -1,32 +0,0 @@
class User < ActiveRecord::Base
has_many :posts
has_many :dogs, :foreign_key => :owner_id, :class_name => "Pets::Dog"
has_many :cats, :foreign_key => :owner_id, :class_name => "Pets::Cat"
has_many :friendships
has_many :friends, :through => :friendships
has_one :address, :as => :addressable, :dependent => :destroy
has_one :registration
has_one :profile, :through => :registration
named_scope :old, :conditions => "age > 50"
named_scope :eighteen, :conditions => { :age => 18 }
named_scope :recent, lambda {|count| { :limit => count } }
def self.recent_via_method(count)
scoped(:limit => count)
end
attr_protected :password
attr_readonly :name
validates_format_of :email, :with => /\w*@\w*.com/
validates_length_of :email, :in => 1..100
validates_numericality_of :age, :greater_than_or_equal_to => 1,
:less_than_or_equal_to => 100
validates_acceptance_of :eula
validates_uniqueness_of :email, :scope => :name, :case_sensitive => false
validates_length_of :ssn, :is => 9, :message => "Social Security Number is not the right length"
validates_numericality_of :ssn
end

View file

@ -1,19 +0,0 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
<meta name="description" content="Posts, posts and more posts" />
<meta name='keywords' content='posts' />
<title>Posts: <%= controller.action_name %></title>
<%= stylesheet_link_tag 'scaffold' %>
</head>
<body>
<p style="color: green"><%= flash[:notice] %></p>
<%= yield %>
</body>
</html>

View file

@ -1,17 +0,0 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
<title>Users: <%= controller.action_name %></title>
<%= stylesheet_link_tag 'scaffold' %>
</head>
<body>
<p style="color: green"><%= flash[:notice] %></p>
<%= yield %>
</body>
</html>

View file

@ -1 +0,0 @@
<html><%= yield %></html>

View file

@ -1 +0,0 @@
<%= @body %>

View file

@ -1,27 +0,0 @@
<h1>Editing post</h1>
<%= error_messages_for :post %>
<% form_for(:post, :url => user_post_path(@post.user, @post), :html => { :method => :put }) do |f| %>
<p>
<b>User</b><br />
<%= f.text_field :user_id %>
</p>
<p>
<b>Title</b><br />
<%= f.text_field :title %>
</p>
<p>
<b>Body</b><br />
<%= f.text_area :body %>
</p>
<p>
<%= submit_tag "Update" %>
</p>
<% end %>
<%= link_to 'Show', user_post_path(@post.user, @post) %> |
<%= link_to 'Back', user_posts_path(@post.user) %>

View file

@ -1,25 +0,0 @@
<h1>Listing posts</h1>
<table>
<tr>
<th>User</th>
<th>Title</th>
<th>Body</th>
</tr>
<% for post in @posts %>
<tr>
<td><%=h post.user_id %></td>
<td><%=h post.title %></td>
<td><%=h post.body %></td>
<td><%= link_to 'Show', user_post_path(post.user, post) %></td>
<td><%= link_to 'Edit', edit_user_post_path(post.user, post) %></td>
<td><%= link_to 'Destroy', user_post_path(post.user, post), :confirm => 'Are you sure?',
:method => :delete %></td>
</tr>
<% end %>
</table>
<br />
<%= link_to 'New post', new_user_post_path(post.user) %>

View file

@ -1,26 +0,0 @@
<h1>New post</h1>
<%= error_messages_for :post %>
<% form_for(:post, :url => user_posts_path(@user)) do |f| %>
<p>
<b>User</b><br />
<%= f.text_field :user_id %>
</p>
<p>
<b>Title</b><br />
<%= f.text_field :title %>
</p>
<p>
<b>Body</b><br />
<%= f.text_area :body %>
</p>
<p>
<%= submit_tag "Create" %>
</p>
<% end %>
<%= link_to 'Back', user_posts_path(@user) %>

View file

@ -1,18 +0,0 @@
<p>
<b>User:</b>
<%=h @post.user_id %>
</p>
<p>
<b>Title:</b>
<%=h @post.title %>
</p>
<p>
<b>Body:</b>
<%=h @post.body %>
</p>
<%= link_to 'Edit', edit_user_post_path(@post.user, @post) %> |
<%= link_to 'Back', user_posts_path(@post.user) %>

View file

@ -1,22 +0,0 @@
<h1>Editing user</h1>
<%= error_messages_for :user %>
<% form_for(:user, :url => user_path(@user), :html => { :method => :put }) do |f| %>
<p>
<b>Email</b><br />
<%= f.text_field :email %>
</p>
<p>
<b>Age</b><br />
<%= f.text_field :age %>
</p>
<p>
<%= submit_tag "Update" %>
</p>
<% end %>
<%= link_to 'Show', user_path(@user) %> |
<%= link_to 'Back', users_path %>

View file

@ -1,22 +0,0 @@
<h1>Listing users</h1>
<table>
<tr>
<th>Email</th>
<th>Age</th>
</tr>
<% for user in @users %>
<tr>
<td><%=h user.email %></td>
<td><%=h user.age %></td>
<td><%= link_to 'Show', user_path(user) %></td>
<td><%= link_to 'Edit', edit_user_path(user) %></td>
<td><%= link_to 'Destroy', user_path(user), :confirm => 'Are you sure?', :method => :delete %></td>
</tr>
<% end %>
</table>
<br />
<%= link_to 'New user', new_user_path %>

View file

@ -1,21 +0,0 @@
<h1>New user</h1>
<%= error_messages_for :user %>
<% form_for(:user, :url => users_path) do |f| %>
<p>
<b>Email</b><br />
<%= f.text_field :email %>
</p>
<p>
<b>Age</b><br />
<%= f.text_field :age %>
</p>
<p>
<%= submit_tag "Create" %>
</p>
<% end %>
<%= link_to 'Back', users_path %>

View file

@ -1,13 +0,0 @@
<p>
<b>Email:</b>
<%=h @user.email %>
</p>
<p>
<b>Age:</b>
<%=h @user.age %>
</p>
<%= link_to 'Edit', edit_user_path(@user) %> |
<%= link_to 'Back', users_path %>

View file

@ -1,110 +0,0 @@
# Don't change this file!
# Configure your app in config/environment.rb and config/environments/*.rb
RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT)
module Rails
class << self
def boot!
unless booted?
preinitialize
pick_boot.run
end
end
def booted?
defined? Rails::Initializer
end
def pick_boot
(vendor_rails? ? VendorBoot : GemBoot).new
end
def vendor_rails?
File.exist?("#{RAILS_ROOT}/vendor/rails")
end
def preinitialize
load(preinitializer_path) if File.exist?(preinitializer_path)
end
def preinitializer_path
"#{RAILS_ROOT}/config/preinitializer.rb"
end
end
class Boot
def run
load_initializer
Rails::Initializer.run(:set_load_path)
end
end
class VendorBoot < Boot
def load_initializer
require "#{RAILS_ROOT}/vendor/rails/railties/lib/initializer"
Rails::Initializer.run(:install_gem_spec_stubs)
Rails::GemDependency.add_frozen_gem_path
end
end
class GemBoot < Boot
def load_initializer
self.class.load_rubygems
load_rails_gem
require 'initializer'
end
def load_rails_gem
if version = self.class.gem_version
gem 'rails', version
else
gem 'rails'
end
rescue Gem::LoadError => load_error
$stderr.puts %(Missing the Rails #{version} gem. Please `gem install -v=#{version} rails`, update your RAILS_GEM_VERSION setting in config/environment.rb for the Rails version you do have installed, or comment out RAILS_GEM_VERSION to use the latest version installed.)
exit 1
end
class << self
def rubygems_version
Gem::RubyGemsVersion rescue nil
end
def gem_version
if defined? RAILS_GEM_VERSION
RAILS_GEM_VERSION
elsif ENV.include?('RAILS_GEM_VERSION')
ENV['RAILS_GEM_VERSION']
else
parse_gem_version(read_environment_rb)
end
end
def load_rubygems
require 'rubygems'
min_version = '1.3.1'
unless rubygems_version >= min_version
$stderr.puts %Q(Rails requires RubyGems >= #{min_version} (you have #{rubygems_version}). Please `gem update --system` and try again.)
exit 1
end
rescue LoadError
$stderr.puts %Q(Rails requires RubyGems >= #{min_version}. Please install RubyGems and try again: http://rubygems.rubyforge.org)
exit 1
end
def parse_gem_version(text)
$1 if text =~ /^[^#]*RAILS_GEM_VERSION\s*=\s*["']([!~<>=]*\s*[\d.]+)["']/
end
private
def read_environment_rb
File.read("#{RAILS_ROOT}/config/environment.rb")
end
end
end
end
# All that for this:
Rails.boot!

View file

@ -1,4 +0,0 @@
test:
:adapter: sqlite3
# :dbfile: db/sqlite3.db
:database: ":memory:"

View file

@ -1,17 +0,0 @@
# Specifies gem version of Rails to use when vendor/rails is not present
old_verbose, $VERBOSE = $VERBOSE, nil
$VERBOSE = old_verbose
require File.join(File.dirname(__FILE__), 'boot')
Rails::Initializer.run do |config|
config.log_level = :debug
config.cache_classes = false
config.whiny_nils = true
config.action_controller.session = {
:key => 'shoulda_session',
:secret => 'ceae6058a816b1446e09ce90d8372511'
}
end
# Dependencies.log_activity = true

View file

@ -1,23 +0,0 @@
# Settings specified here will take precedence over those in config/environment.rb
# The test environment is used exclusively to run your application's
# test suite. You never need to work with it otherwise. Remember that
# your test database is "scratch space" for the test suite and is wiped
# and recreated between test runs. Don't rely on the data there!
config.cache_classes = true
# Log error messages when you accidentally call methods on nil.
config.whiny_nils = true
# Show full error reports and disable caching
config.action_controller.consider_all_requests_local = true
config.action_controller.perform_caching = false
config.action_view.cache_template_loading = true
# Disable request forgery protection in test environment
config.action_controller.allow_forgery_protection = false
# Tell Action Mailer not to deliver emails to the real world.
# The :test delivery method accumulates sent emails in the
# ActionMailer::Base.deliveries array.
config.action_mailer.delivery_method = :test

View file

@ -1,15 +0,0 @@
# These settings change the behavior of Rails 2 apps and will be defaults
# for Rails 3. You can remove this initializer when Rails 3 is released.
# Include Active Record class name as root for JSON serialized output.
ActiveRecord::Base.include_root_in_json = true
# Store the full class name (including module namespace) in STI type column.
ActiveRecord::Base.store_full_sti_class = true
# Use ISO 8601 format for JSON serialized times and dates.
ActiveSupport.use_standard_json_time_format = true
# Don't escape HTML entities in JSON, leave that for the #json_escape helper.
# if you're including raw json in an HTML page.
ActiveSupport.escape_html_entities_in_json = false

View file

@ -1,8 +0,0 @@
# This simulates loading the shoulda plugin, but without relying on
# vendor/plugins
shoulda_path = File.join(File.dirname(__FILE__), *%w(.. .. .. ..))
shoulda_lib_path = File.join(shoulda_path, "lib")
$LOAD_PATH.unshift(shoulda_lib_path)
load File.join(shoulda_path, "init.rb")

View file

@ -1,6 +0,0 @@
ActionController::Routing::Routes.draw do |map|
map.resources :posts
map.resources :users, :has_many => :posts
end

View file

@ -1,19 +0,0 @@
class CreateUsers < ActiveRecord::Migration
def self.up
create_table :users do |t|
t.column :name, :string
t.column :email, :string
t.column :age, :integer
t.column :ssn, :string
t.column :phone, :string
end
add_index :users, :email, :unique => true
add_index :users, :name
add_index :users, :age
add_index :users, [:email, :name], :unique => true
end
def self.down
drop_table :users
end
end

View file

@ -1,13 +0,0 @@
class CreatePosts < ActiveRecord::Migration
def self.up
create_table :posts do |t|
t.column :user_id, :integer
t.column :title, :string
t.column :body, :text
end
end
def self.down
drop_table :posts
end
end

View file

@ -1,12 +0,0 @@
class CreateTaggings < ActiveRecord::Migration
def self.up
create_table :taggings do |t|
t.column :post_id, :integer
t.column :tag_id, :integer
end
end
def self.down
drop_table :taggings
end
end

View file

@ -1,11 +0,0 @@
class CreateTags < ActiveRecord::Migration
def self.up
create_table :tags do |t|
t.column :name, :string
end
end
def self.down
drop_table :tags
end
end

View file

@ -1,12 +0,0 @@
class CreateDogs < ActiveRecord::Migration
def self.up
create_table :dogs do |t|
t.column :owner_id, :integer
t.column :address_id, :integer
end
end
def self.down
drop_table :dogs
end
end

View file

@ -1,14 +0,0 @@
class CreateAddresses < ActiveRecord::Migration
def self.up
create_table :addresses do |t|
t.column :title, :string
t.column :addressable_id, :integer
t.column :addressable_type, :string
t.column :zip, :string
end
end
def self.down
drop_table :addresses
end
end

View file

@ -1,11 +0,0 @@
class CreateFleas < ActiveRecord::Migration
def self.up
create_table :fleas do |t|
t.string :name
end
end
def self.down
drop_table :fleas
end
end

View file

@ -1,12 +0,0 @@
class CreateDogsFleas < ActiveRecord::Migration
def self.up
create_table :dogs_fleas do |t|
t.integer :dog_id
t.integer :flea_id
end
end
def self.down
drop_table :dogs_fleas
end
end

View file

@ -1,17 +0,0 @@
class CreateProducts < ActiveRecord::Migration
def self.up
create_table :products do |t|
t.string :title
t.integer :price
t.integer :weight
t.string :size
t.boolean :tangible
t.timestamps
end
end
def self.down
drop_table :products
end
end

View file

@ -1,14 +0,0 @@
class CreateFriendships < ActiveRecord::Migration
def self.up
create_table :friendships do |t|
t.integer :user_id
t.integer :friend_id
t.timestamps
end
end
def self.down
drop_table :friendships
end
end

View file

@ -1,12 +0,0 @@
class CreateTreats < ActiveRecord::Migration
def self.up
create_table :treats do |t|
t.integer :dog_id
t.timestamps
end
end
def self.down
drop_table :treats
end
end

View file

@ -1,12 +0,0 @@
class CreateProfiles < ActiveRecord::Migration
def self.up
create_table :profiles do |t|
t.timestamps
end
end
def self.down
drop_table :profiles
end
end

View file

@ -1,14 +0,0 @@
class CreateRegistrations < ActiveRecord::Migration
def self.up
create_table :registrations do |t|
t.integer :user_id
t.integer :profile_id
t.timestamps
end
end
def self.down
drop_table :registrations
end
end

View file

@ -1,12 +0,0 @@
class CreateCats < ActiveRecord::Migration
def self.up
create_table :cats do |t|
t.column :owner_id, :integer
t.column :address_id, :integer
end
end
def self.down
drop_table :cats
end
end

View file

@ -1,40 +0,0 @@
# General Apache options
AddHandler fastcgi-script .fcgi
AddHandler cgi-script .cgi
Options +FollowSymLinks +ExecCGI
# If you don't want Rails to look in certain directories,
# use the following rewrite rules so that Apache won't rewrite certain requests
#
# Example:
# RewriteCond %{REQUEST_URI} ^/notrails.*
# RewriteRule .* - [L]
# Redirect all requests not available on the filesystem to Rails
# By default the cgi dispatcher is used which is very slow
#
# For better performance replace the dispatcher with the fastcgi one
#
# Example:
# RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
RewriteEngine On
# If your Rails application is accessed via an Alias directive,
# then you MUST also set the RewriteBase in this htaccess file.
#
# Example:
# Alias /myrailsapp /path/to/myrailsapp/public
# RewriteBase /myrailsapp
RewriteRule ^$ index.html [QSA]
RewriteRule ^([^.]+)$ $1.html [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ dispatch.cgi [QSA,L]
# In case Rails experiences terminal errors
# Instead of displaying this message you can supply a file here which will be rendered instead
#
# Example:
# ErrorDocument 500 /500.html
ErrorDocument 500 "<h2>Application error</h2>Rails application failed to start properly"

View file

@ -1,30 +0,0 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title>The page you were looking for doesn't exist (404)</title>
<style type="text/css">
body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
div.dialog {
width: 25em;
padding: 0 4em;
margin: 4em auto 0 auto;
border: 1px solid #ccc;
border-right-color: #999;
border-bottom-color: #999;
}
h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
</style>
</head>
<body>
<!-- This file lives in public/404.html -->
<div class="dialog">
<h1>The page you were looking for doesn't exist.</h1>
<p>You may have mistyped the address or the page may have moved.</p>
</div>
</body>
</html>

View file

@ -1,30 +0,0 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title>The change you wanted was rejected (422)</title>
<style type="text/css">
body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
div.dialog {
width: 25em;
padding: 0 4em;
margin: 4em auto 0 auto;
border: 1px solid #ccc;
border-right-color: #999;
border-bottom-color: #999;
}
h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
</style>
</head>
<body>
<!-- This file lives in public/422.html -->
<div class="dialog">
<h1>The change you wanted was rejected.</h1>
<p>Maybe you tried to change something you didn't have access to.</p>
</div>
</body>
</html>

View file

@ -1,30 +0,0 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title>We're sorry, but something went wrong (500)</title>
<style type="text/css">
body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
div.dialog {
width: 25em;
padding: 0 4em;
margin: 4em auto 0 auto;
border: 1px solid #ccc;
border-right-color: #999;
border-bottom-color: #999;
}
h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
</style>
</head>
<body>
<!-- This file lives in public/500.html -->
<div class="dialog">
<h1>We're sorry, but something went wrong.</h1>
<p>We've been notified about this issue and we'll take a look at it shortly.</p>
</div>
</body>
</html>

View file

@ -1,3 +0,0 @@
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/boot'
require 'commands/console'

View file

@ -1,3 +0,0 @@
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/boot'
require 'commands/generate'

View file

@ -1,6 +0,0 @@
rails_root = File.dirname(__FILE__) + '/rails2_root'
require "#{rails_root}/config/environment.rb"
require 'test_help'
require 'test/rails2_model_builder'
silence_warnings { RAILS_ENV = ENV['RAILS_ENV'] }

View file

@ -0,0 +1,77 @@
GEM
remote: http://rubygems.org/
specs:
abstract (1.0.0)
actionmailer (3.0.0.beta4)
actionpack (= 3.0.0.beta4)
mail (~> 2.2.3)
actionpack (3.0.0.beta4)
activemodel (= 3.0.0.beta4)
activesupport (= 3.0.0.beta4)
builder (~> 2.1.2)
erubis (~> 2.6.5)
i18n (~> 0.4.1)
rack (~> 1.1.0)
rack-mount (~> 0.6.3)
rack-test (~> 0.5.4)
tzinfo (~> 0.3.16)
activemodel (3.0.0.beta4)
activesupport (= 3.0.0.beta4)
builder (~> 2.1.2)
i18n (~> 0.4.1)
activerecord (3.0.0.beta4)
activemodel (= 3.0.0.beta4)
activesupport (= 3.0.0.beta4)
arel (~> 0.4.0)
tzinfo (~> 0.3.16)
activeresource (3.0.0.beta4)
activemodel (= 3.0.0.beta4)
activesupport (= 3.0.0.beta4)
activesupport (3.0.0.beta4)
arel (0.4.0)
activesupport (>= 3.0.0.beta)
builder (2.1.2)
erubis (2.6.6)
abstract (>= 1.0.0)
i18n (0.4.1)
mail (2.2.12)
activesupport (>= 2.3.6)
i18n (>= 0.4.0)
mime-types (~> 1.16)
treetop (~> 1.4.8)
mime-types (1.16)
mocha (0.9.10)
rake
polyglot (0.3.1)
rack (1.1.0)
rack-mount (0.6.13)
rack (>= 1.0.0)
rack-test (0.5.6)
rack (>= 1.0)
rails (3.0.0.beta4)
actionmailer (= 3.0.0.beta4)
actionpack (= 3.0.0.beta4)
activerecord (= 3.0.0.beta4)
activeresource (= 3.0.0.beta4)
activesupport (= 3.0.0.beta4)
bundler (>= 0.9.26)
railties (= 3.0.0.beta4)
railties (3.0.0.beta4)
actionpack (= 3.0.0.beta4)
activesupport (= 3.0.0.beta4)
rake (>= 0.8.3)
thor (~> 0.13.6)
rake (0.8.7)
sqlite3-ruby (1.3.2)
thor (0.13.8)
treetop (1.4.9)
polyglot (>= 0.3.1)
tzinfo (0.3.23)
PLATFORMS
ruby
DEPENDENCIES
mocha
rails (= 3.0.0.beta4)
sqlite3-ruby

View file

@ -1,6 +0,0 @@
rails_root = File.dirname(__FILE__) + '/rails3_root'
ENV['BUNDLE_GEMFILE'] = rails_root + '/Gemfile'
require "#{rails_root}/config/environment.rb"
require 'test/rails3_model_builder'
require 'rails/test_help'

View file

@ -3,14 +3,14 @@ require 'test/unit'
ENV['RAILS_ENV'] = 'test'
ENV['RAILS_VERSION'] ||= '2.3.8'
ENV['RAILS_VERSION'] ||= '3.0.0.beta4'
RAILS_GEM_VERSION = ENV['RAILS_VERSION']
if ENV['RAILS_VERSION'].to_s =~ /^2/
require 'test/rails2_test_helper'
else
require 'test/rails3_test_helper'
end
rails_root = File.dirname(__FILE__) + '/rails3_root'
ENV['BUNDLE_GEMFILE'] = rails_root + '/Gemfile'
require "#{rails_root}/config/environment.rb"
require 'test/rails3_model_builder'
require 'rails/test_help'
shoulda_path = File.join(File.dirname(__FILE__), '..', 'lib')
$LOAD_PATH << shoulda_path
@ -29,6 +29,6 @@ class ActiveSupport::TestCase #:nodoc:
self.use_instantiated_fixtures = false
end
Shoulda.autoload_macros File.join(File.dirname(__FILE__), 'rails2_root'),
Shoulda.autoload_macros File.join(File.dirname(__FILE__), 'rails3_root'),
File.join("vendor", "{plugins,gems}", "*")