Next step in upgrading Tracks to Rails 2.2. Some highlights:

* Ran rake rails:update
* Added old actionwebservice framework
* Updated RSpec and RSpec-Rails
* Removed asset_packager plugin (not compatible, Scott no longer maintaining), and replaced with bundle_fu. See the bundle_fu README for more info.
* Hacks to UJS and ARTS plugins, which are no longer supported. Probably should move off both UJS and RJS.
* Hack to flashobject_helper plugin (upgrade to Rails 2.2-compatible version if/when it comes out.)
* Hack to skinny-spec plugin, for Rails 2.2 compatibility. Should check for official release.
* Hacks to resource_feeder plugin, for Rails 2.2 compatibility. Should check for official release (not likely) or move off it.
* Addressed some deprecation warnings. More to come.
* My mobile mime type hackery is no longer necessary with new Rails features. Yay!
* Updated environment.rb.tmpl with changes

TODO:
* Restore view specs marked pending
* Fix failing integration tests.
* Try selenium tests.
* Investigate OpenID support.
* Address deprecation warnings.
* Consider moving parts of environment.rb to initializers
* Address annoying config.gem warning about highline gem
This commit is contained in:
Luke Melia 2008-11-29 12:00:06 -05:00
parent 6d11ebd1b0
commit 35ae5fc431
394 changed files with 15184 additions and 9936 deletions

View file

@ -6,6 +6,7 @@ class RspecGenerator < Rails::Generator::Base
Config::CONFIG['ruby_install_name'])
def initialize(runtime_args, runtime_options = {})
Dir.mkdir('lib/tasks') unless File.directory?('lib/tasks')
super
end
@ -13,12 +14,16 @@ class RspecGenerator < Rails::Generator::Base
record do |m|
script_options = { :chmod => 0755, :shebang => options[:shebang] == DEFAULT_SHEBANG ? nil : options[:shebang] }
m.directory 'spec'
m.template 'spec_helper.rb', 'spec/spec_helper.rb'
m.file 'spec.opts', 'spec/spec.opts'
m.file 'rcov.opts', 'spec/rcov.opts'
m.file 'script/spec_server', 'script/spec_server', script_options
m.file 'rspec.rake', 'lib/tasks/rspec.rake'
m.file 'script/autospec', 'script/autospec', script_options
m.file 'script/spec', 'script/spec', script_options
m.file 'script/spec_server', 'script/spec_server', script_options
m.directory 'spec'
m.file 'rcov.opts', 'spec/rcov.opts'
m.file 'spec.opts', 'spec/spec.opts'
m.template 'spec_helper.rb', 'spec/spec_helper.rb'
m.directory 'stories'
m.file 'all_stories.rb', 'stories/all.rb'

View file

@ -0,0 +1,132 @@
raise "To avoid rake task loading problems: run 'rake clobber' in vendor/plugins/rspec" if File.directory?(File.join(File.dirname(__FILE__), *%w[.. .. vendor plugins rspec pkg]))
raise "To avoid rake task loading problems: run 'rake clobber' in vendor/plugins/rspec-rails" if File.directory?(File.join(File.dirname(__FILE__), *%w[.. .. vendor plugins rspec-rails pkg]))
# In rails 1.2, plugins aren't available in the path until they're loaded.
# Check to see if the rspec plugin is installed first and require
# it if it is. If not, use the gem version.
rspec_base = File.expand_path(File.dirname(__FILE__) + '/../../vendor/plugins/rspec/lib')
$LOAD_PATH.unshift(rspec_base) if File.exist?(rspec_base)
require 'spec/rake/spectask'
spec_prereq = File.exist?(File.join(RAILS_ROOT, 'config', 'database.yml')) ? "db:test:prepare" : :noop
task :noop do
end
task :default => :spec
task :stats => "spec:statsetup"
desc "Run all specs in spec directory (excluding plugin specs)"
Spec::Rake::SpecTask.new(:spec => spec_prereq) do |t|
t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""]
t.spec_files = FileList['spec/**/*_spec.rb']
end
namespace :spec do
desc "Run all specs in spec directory with RCov (excluding plugin specs)"
Spec::Rake::SpecTask.new(:rcov) do |t|
t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""]
t.spec_files = FileList['spec/**/*_spec.rb']
t.rcov = true
t.rcov_opts = lambda do
IO.readlines("#{RAILS_ROOT}/spec/rcov.opts").map {|l| l.chomp.split " "}.flatten
end
end
desc "Print Specdoc for all specs (excluding plugin specs)"
Spec::Rake::SpecTask.new(:doc) do |t|
t.spec_opts = ["--format", "specdoc", "--dry-run"]
t.spec_files = FileList['spec/**/*_spec.rb']
end
desc "Print Specdoc for all plugin specs"
Spec::Rake::SpecTask.new(:plugin_doc) do |t|
t.spec_opts = ["--format", "specdoc", "--dry-run"]
t.spec_files = FileList['vendor/plugins/**/spec/**/*_spec.rb'].exclude('vendor/plugins/rspec/*')
end
[:models, :controllers, :views, :helpers, :lib].each do |sub|
desc "Run the specs under spec/#{sub}"
Spec::Rake::SpecTask.new(sub => spec_prereq) do |t|
t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""]
t.spec_files = FileList["spec/#{sub}/**/*_spec.rb"]
end
end
desc "Run the specs under vendor/plugins (except RSpec's own)"
Spec::Rake::SpecTask.new(:plugins => spec_prereq) do |t|
t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""]
t.spec_files = FileList['vendor/plugins/**/spec/**/*_spec.rb'].exclude('vendor/plugins/rspec/*').exclude("vendor/plugins/rspec-rails/*")
end
namespace :plugins do
desc "Runs the examples for rspec_on_rails"
Spec::Rake::SpecTask.new(:rspec_on_rails) do |t|
t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""]
t.spec_files = FileList['vendor/plugins/rspec-rails/spec/**/*_spec.rb']
end
end
# Setup specs for stats
task :statsetup do
require 'code_statistics'
::STATS_DIRECTORIES << %w(Model\ specs spec/models) if File.exist?('spec/models')
::STATS_DIRECTORIES << %w(View\ specs spec/views) if File.exist?('spec/views')
::STATS_DIRECTORIES << %w(Controller\ specs spec/controllers) if File.exist?('spec/controllers')
::STATS_DIRECTORIES << %w(Helper\ specs spec/helpers) if File.exist?('spec/helpers')
::STATS_DIRECTORIES << %w(Library\ specs spec/lib) if File.exist?('spec/lib')
::CodeStatistics::TEST_TYPES << "Model specs" if File.exist?('spec/models')
::CodeStatistics::TEST_TYPES << "View specs" if File.exist?('spec/views')
::CodeStatistics::TEST_TYPES << "Controller specs" if File.exist?('spec/controllers')
::CodeStatistics::TEST_TYPES << "Helper specs" if File.exist?('spec/helpers')
::CodeStatistics::TEST_TYPES << "Library specs" if File.exist?('spec/lib')
::STATS_DIRECTORIES.delete_if {|a| a[0] =~ /test/}
end
namespace :db do
namespace :fixtures do
desc "Load fixtures (from spec/fixtures) into the current environment's database. Load specific fixtures using FIXTURES=x,y"
task :load => :environment do
require 'active_record/fixtures'
ActiveRecord::Base.establish_connection(RAILS_ENV.to_sym)
(ENV['FIXTURES'] ? ENV['FIXTURES'].split(/,/) : Dir.glob(File.join(RAILS_ROOT, 'spec', 'fixtures', '*.{yml,csv}'))).each do |fixture_file|
Fixtures.create_fixtures('spec/fixtures', File.basename(fixture_file, '.*'))
end
end
end
end
namespace :server do
daemonized_server_pid = File.expand_path("spec_server.pid", RAILS_ROOT + "/tmp")
desc "start spec_server."
task :start do
if File.exist?(daemonized_server_pid)
$stderr.puts "spec_server is already running."
else
$stderr.puts "Starting up spec server."
system("ruby", "script/spec_server", "--daemon", "--pid", daemonized_server_pid)
end
end
desc "stop spec_server."
task :stop do
unless File.exist?(daemonized_server_pid)
$stderr.puts "No server running."
else
$stderr.puts "Shutting down spec_server."
system("kill", "-s", "TERM", File.read(daemonized_server_pid).strip) &&
File.delete(daemonized_server_pid)
end
end
desc "reload spec_server."
task :restart do
unless File.exist?(daemonized_server_pid)
$stderr.puts "No server running."
else
$stderr.puts "Reloading down spec_server."
system("kill", "-s", "USR2", File.read(daemonized_server_pid).strip)
end
end
end
end

View file

@ -0,0 +1,4 @@
#!/usr/bin/env ruby
ENV['RSPEC'] = 'true' # allows autotest to discover rspec
ENV['AUTOTEST'] = 'true' # allows autotest to run w/ color on linux
system (RUBY_PLATFORM =~ /mswin|mingw/ ? 'autotest.bat' : 'autotest'), *ARGV

View file

@ -1,4 +1,5 @@
#!/usr/bin/env ruby
$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + "/../vendor/plugins/rspec/lib"))
require 'rubygems'
require 'spec'
exit ::Spec::Runner::CommandLine.run(::Spec::Runner::OptionParser.parse(ARGV, STDERR, STDOUT))

View file

@ -0,0 +1,19 @@
module Rails
module Generator
class GeneratedAttribute
def default_value
@default_value ||= case type
when :int, :integer then "\"1\""
when :float then "\"1.5\""
when :decimal then "\"9.99\""
when :datetime, :timestamp, :time then "Time.now"
when :date then "Date.today"
when :string, :text then "\"value for #{@name}\""
when :boolean then "false"
else
""
end
end
end
end
end

View file

@ -1,4 +1,5 @@
require 'rails_generator/generators/components/model/model_generator'
require File.dirname(__FILE__) + '/../rspec_default_values'
class RspecModelGenerator < ModelGenerator
@ -11,12 +12,16 @@ class RspecModelGenerator < ModelGenerator
# Model, spec, and fixture directories.
m.directory File.join('app/models', class_path)
m.directory File.join('spec/models', class_path)
m.directory File.join('spec/fixtures', class_path)
unless options[:skip_fixture]
m.directory File.join('spec/fixtures', class_path)
end
# Model class, spec and fixtures.
m.template 'model:model.rb', File.join('app/models', class_path, "#{file_name}.rb")
m.template 'model:fixtures.yml', File.join('spec/fixtures', class_path, "#{table_name}.yml")
m.template 'model_spec.rb', File.join('spec/models', class_path, "#{file_name}_spec.rb")
unless options[:skip_fixture]
m.template 'model:fixtures.yml', File.join('spec/fixtures', "#{table_name}.yml")
end
unless options[:skip_migration]
m.migration_template 'model:migration.rb', 'db/migrate', :assigns => {

View file

@ -2,10 +2,14 @@ require File.expand_path(File.dirname(__FILE__) + '<%= '/..' * class_nesting_dep
describe <%= class_name %> do
before(:each) do
@<%= file_name %> = <%= class_name %>.new
@valid_attributes = {
<% attributes.each_with_index do |attribute, attribute_index| -%>
:<%= attribute.name %> => <%= attribute.default_value %><%= attribute_index == attributes.length - 1 ? '' : ','%>
<% end -%>
}
end
it "should be valid" do
@<%= file_name %>.should be_valid
it "should create a new instance given valid attributes" do
<%= class_name %>.create!(@valid_attributes)
end
end

View file

@ -1,3 +1,5 @@
require File.dirname(__FILE__) + '/../rspec_default_values'
class RspecScaffoldGenerator < Rails::Generator::NamedBase
default_options :skip_migration => false
@ -140,21 +142,6 @@ end
module Rails
module Generator
class GeneratedAttribute
def default_value
@default_value ||= case type
when :int, :integer then "\"1\""
when :float then "\"1.5\""
when :decimal then "\"9.99\""
when :datetime, :timestamp, :time then "Time.now"
when :date then "Date.today"
when :string then "\"MyString\""
when :text then "\"MyText\""
when :boolean then "false"
else
""
end
end
def input_type
@input_type ||= case type
when :text then "textarea"

View file

@ -1,313 +1,173 @@
require File.expand_path(File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../spec_helper')
describe <%= controller_class_name %>Controller do
describe "handling GET /<%= table_name %>" do
before(:each) do
@<%= file_name %> = mock_model(<%= class_name %>)
<%= class_name %>.stub!(:find).and_return([@<%= file_name %>])
end
def mock_<%= file_name %>(stubs={})
@mock_<%= file_name %> ||= mock_model(<%= class_name %>, stubs)
end
def do_get
describe "responding to GET index" do
it "should expose all <%= table_name.pluralize %> as @<%= table_name.pluralize %>" do
<%= class_name %>.should_receive(:find).with(:all).and_return([mock_<%= file_name %>])
get :index
end
it "should be successful" do
do_get
response.should be_success
assigns[:<%= table_name %>].should == [mock_<%= file_name %>]
end
it "should render index template" do
do_get
response.should render_template('index')
end
describe "with mime type of xml" do
it "should find all <%= table_name %>" do
<%= class_name %>.should_receive(:find).with(:all).and_return([@<%= file_name %>])
do_get
end
it "should assign the found <%= table_name %> for the view" do
do_get
assigns[:<%= table_name %>].should == [@<%= file_name %>]
it "should render all <%= table_name.pluralize %> as xml" do
request.env["HTTP_ACCEPT"] = "application/xml"
<%= class_name %>.should_receive(:find).with(:all).and_return(<%= file_name.pluralize %> = mock("Array of <%= class_name.pluralize %>"))
<%= file_name.pluralize %>.should_receive(:to_xml).and_return("generated XML")
get :index
response.body.should == "generated XML"
end
end
end
describe "handling GET /<%= table_name %>.xml" do
describe "responding to GET show" do
before(:each) do
@<%= file_name.pluralize %> = mock("Array of <%= class_name.pluralize %>", :to_xml => "XML")
<%= class_name %>.stub!(:find).and_return(@<%= file_name.pluralize %>)
end
def do_get
@request.env["HTTP_ACCEPT"] = "application/xml"
get :index
end
it "should be successful" do
do_get
response.should be_success
end
it "should find all <%= table_name %>" do
<%= class_name %>.should_receive(:find).with(:all).and_return(@<%= file_name.pluralize %>)
do_get
end
it "should render the found <%= table_name %> as xml" do
@<%= file_name.pluralize %>.should_receive(:to_xml).and_return("XML")
do_get
response.body.should == "XML"
end
end
describe "handling GET /<%= table_name %>/1" do
before(:each) do
@<%= file_name %> = mock_model(<%= class_name %>)
<%= class_name %>.stub!(:find).and_return(@<%= file_name %>)
end
def do_get
get :show, :id => "1"
end
it "should be successful" do
do_get
response.should be_success
end
it "should render show template" do
do_get
response.should render_template('show')
end
it "should find the <%= file_name %> requested" do
<%= class_name %>.should_receive(:find).with("1").and_return(@<%= file_name %>)
do_get
end
it "should assign the found <%= file_name %> for the view" do
do_get
assigns[:<%= file_name %>].should equal(@<%= file_name %>)
end
end
describe "handling GET /<%= table_name %>/1.xml" do
before(:each) do
@<%= file_name %> = mock_model(<%= class_name %>, :to_xml => "XML")
<%= class_name %>.stub!(:find).and_return(@<%= file_name %>)
end
def do_get
@request.env["HTTP_ACCEPT"] = "application/xml"
get :show, :id => "1"
end
it "should be successful" do
do_get
response.should be_success
end
it "should find the <%= file_name %> requested" do
<%= class_name %>.should_receive(:find).with("1").and_return(@<%= file_name %>)
do_get
end
it "should render the found <%= file_name %> as xml" do
@<%= file_name %>.should_receive(:to_xml).and_return("XML")
do_get
response.body.should == "XML"
end
end
describe "handling GET /<%= table_name %>/new" do
before(:each) do
@<%= file_name %> = mock_model(<%= class_name %>)
<%= class_name %>.stub!(:new).and_return(@<%= file_name %>)
end
def do_get
get :new
end
it "should be successful" do
do_get
response.should be_success
end
it "should render new template" do
do_get
response.should render_template('new')
end
it "should create an new <%= file_name %>" do
<%= class_name %>.should_receive(:new).and_return(@<%= file_name %>)
do_get
end
it "should not save the new <%= file_name %>" do
@<%= file_name %>.should_not_receive(:save)
do_get
end
it "should assign the new <%= file_name %> for the view" do
do_get
assigns[:<%= file_name %>].should equal(@<%= file_name %>)
end
end
describe "handling GET /<%= table_name %>/1/edit" do
before(:each) do
@<%= file_name %> = mock_model(<%= class_name %>)
<%= class_name %>.stub!(:find).and_return(@<%= file_name %>)
end
def do_get
get :edit, :id => "1"
end
it "should be successful" do
do_get
response.should be_success
end
it "should render edit template" do
do_get
response.should render_template('edit')
end
it "should find the <%= file_name %> requested" do
<%= class_name %>.should_receive(:find).and_return(@<%= file_name %>)
do_get
end
it "should assign the found <%= class_name %> for the view" do
do_get
assigns[:<%= file_name %>].should equal(@<%= file_name %>)
end
end
describe "handling POST /<%= table_name %>" do
before(:each) do
@<%= file_name %> = mock_model(<%= class_name %>, :to_param => "1")
<%= class_name %>.stub!(:new).and_return(@<%= file_name %>)
it "should expose the requested <%= file_name %> as @<%= file_name %>" do
<%= class_name %>.should_receive(:find).with("37").and_return(mock_<%= file_name %>)
get :show, :id => "37"
assigns[:<%= file_name %>].should equal(mock_<%= file_name %>)
end
describe "with successful save" do
def do_post
@<%= file_name %>.should_receive(:save).and_return(true)
post :create, :<%= file_name %> => {}
end
it "should create a new <%= file_name %>" do
<%= class_name %>.should_receive(:new).with({}).and_return(@<%= file_name %>)
do_post
describe "with mime type of xml" do
it "should render the requested <%= file_name %> as xml" do
request.env["HTTP_ACCEPT"] = "application/xml"
<%= class_name %>.should_receive(:find).with("37").and_return(mock_<%= file_name %>)
mock_<%= file_name %>.should_receive(:to_xml).and_return("generated XML")
get :show, :id => "37"
response.body.should == "generated XML"
end
it "should redirect to the new <%= file_name %>" do
do_post
response.should redirect_to(<%= table_name.singularize %>_url("1"))
end
end
describe "responding to GET new" do
it "should expose a new <%= file_name %> as @<%= file_name %>" do
<%= class_name %>.should_receive(:new).and_return(mock_<%= file_name %>)
get :new
assigns[:<%= file_name %>].should equal(mock_<%= file_name %>)
end
end
describe "responding to GET edit" do
it "should expose the requested <%= file_name %> as @<%= file_name %>" do
<%= class_name %>.should_receive(:find).with("37").and_return(mock_<%= file_name %>)
get :edit, :id => "37"
assigns[:<%= file_name %>].should equal(mock_<%= file_name %>)
end
end
describe "responding to POST create" do
describe "with valid params" do
it "should expose a newly created <%= file_name %> as @<%= file_name %>" do
<%= class_name %>.should_receive(:new).with({'these' => 'params'}).and_return(mock_<%= file_name %>(:save => true))
post :create, :<%= file_name %> => {:these => 'params'}
assigns(:<%= file_name %>).should equal(mock_<%= file_name %>)
end
it "should redirect to the created <%= file_name %>" do
<%= class_name %>.stub!(:new).and_return(mock_<%= file_name %>(:save => true))
post :create, :<%= file_name %> => {}
response.should redirect_to(<%= table_name.singularize %>_url(mock_<%= file_name %>))
end
end
describe "with failed save" do
describe "with invalid params" do
def do_post
@<%= file_name %>.should_receive(:save).and_return(false)
post :create, :<%= file_name %> => {}
it "should expose a newly created but unsaved <%= file_name %> as @<%= file_name %>" do
<%= class_name %>.stub!(:new).with({'these' => 'params'}).and_return(mock_<%= file_name %>(:save => false))
post :create, :<%= file_name %> => {:these => 'params'}
assigns(:<%= file_name %>).should equal(mock_<%= file_name %>)
end
it "should re-render 'new'" do
do_post
it "should re-render the 'new' template" do
<%= class_name %>.stub!(:new).and_return(mock_<%= file_name %>(:save => false))
post :create, :<%= file_name %> => {}
response.should render_template('new')
end
end
end
describe "handling PUT /<%= table_name %>/1" do
describe "responding to PUT udpate" do
before(:each) do
@<%= file_name %> = mock_model(<%= class_name %>, :to_param => "1")
<%= class_name %>.stub!(:find).and_return(@<%= file_name %>)
end
describe "with successful update" do
describe "with valid params" do
def do_put
@<%= file_name %>.should_receive(:update_attributes).and_return(true)
it "should update the requested <%= file_name %>" do
<%= class_name %>.should_receive(:find).with("37").and_return(mock_<%= file_name %>)
mock_<%= file_name %>.should_receive(:update_attributes).with({'these' => 'params'})
put :update, :id => "37", :<%= file_name %> => {:these => 'params'}
end
it "should expose the requested <%= file_name %> as @<%= file_name %>" do
<%= class_name %>.stub!(:find).and_return(mock_<%= file_name %>(:update_attributes => true))
put :update, :id => "1"
end
it "should find the <%= file_name %> requested" do
<%= class_name %>.should_receive(:find).with("1").and_return(@<%= file_name %>)
do_put
end
it "should update the found <%= file_name %>" do
do_put
assigns(:<%= file_name %>).should equal(@<%= file_name %>)
end
it "should assign the found <%= file_name %> for the view" do
do_put
assigns(:<%= file_name %>).should equal(@<%= file_name %>)
assigns(:<%= file_name %>).should equal(mock_<%= file_name %>)
end
it "should redirect to the <%= file_name %>" do
do_put
response.should redirect_to(<%= table_name.singularize %>_url("1"))
<%= class_name %>.stub!(:find).and_return(mock_<%= file_name %>(:update_attributes => true))
put :update, :id => "1"
response.should redirect_to(<%= table_name.singularize %>_url(mock_<%= file_name %>))
end
end
describe "with failed update" do
describe "with invalid params" do
def do_put
@<%= file_name %>.should_receive(:update_attributes).and_return(false)
put :update, :id => "1"
it "should update the requested <%= file_name %>" do
<%= class_name %>.should_receive(:find).with("37").and_return(mock_<%= file_name %>)
mock_<%= file_name %>.should_receive(:update_attributes).with({'these' => 'params'})
put :update, :id => "37", :<%= file_name %> => {:these => 'params'}
end
it "should re-render 'edit'" do
do_put
it "should expose the <%= file_name %> as @<%= file_name %>" do
<%= class_name %>.stub!(:find).and_return(mock_<%= file_name %>(:update_attributes => false))
put :update, :id => "1"
assigns(:<%= file_name %>).should equal(mock_<%= file_name %>)
end
it "should re-render the 'edit' template" do
<%= class_name %>.stub!(:find).and_return(mock_<%= file_name %>(:update_attributes => false))
put :update, :id => "1"
response.should render_template('edit')
end
end
end
describe "handling DELETE /<%= table_name %>/1" do
describe "responding to DELETE destroy" do
before(:each) do
@<%= file_name %> = mock_model(<%= class_name %>, :destroy => true)
<%= class_name %>.stub!(:find).and_return(@<%= file_name %>)
end
def do_delete
delete :destroy, :id => "1"
end
it "should find the <%= file_name %> requested" do
<%= class_name %>.should_receive(:find).with("1").and_return(@<%= file_name %>)
do_delete
end
it "should call destroy on the found <%= file_name %>" do
@<%= file_name %>.should_receive(:destroy)
do_delete
it "should destroy the requested <%= file_name %>" do
<%= class_name %>.should_receive(:find).with("37").and_return(mock_<%= file_name %>)
mock_<%= file_name %>.should_receive(:destroy)
delete :destroy, :id => "37"
end
it "should redirect to the <%= table_name %> list" do
do_delete
<%= class_name %>.stub!(:find).and_return(mock_<%= file_name %>(:destroy => true))
delete :destroy, :id => "1"
response.should redirect_to(<%= table_name %>_url)
end
end
end

View file

@ -3,12 +3,13 @@ require File.expand_path(File.dirname(__FILE__) + '<%= '/..' * class_nesting_dep
describe "/<%= table_name %>/edit.<%= default_file_extension %>" do
include <%= controller_class_name %>Helper
before do
@<%= file_name %> = mock_model(<%= class_name %>)
<% for attribute in attributes -%>
@<%= file_name %>.stub!(:<%= attribute.name %>).and_return(<%= attribute.default_value %>)
<% end -%>
assigns[:<%= file_name %>] = @<%= file_name %>
before(:each) do
assigns[:<%= file_name %>] = @<%= file_name %> = stub_model(<%= class_name %>,
:new_record? => false<%= attributes.empty? ? '' : ',' %>
<% attributes.each_with_index do |attribute, attribute_index| -%><% unless attribute.name =~ /_id/ || [:datetime, :timestamp, :time, :date].index(attribute.type) -%>
:<%= attribute.name %> => <%= attribute.default_value %><%= attribute_index == attributes.length - 1 ? '' : ','%>
<% end -%><% end -%>
)
end
it "should render edit form" do

View file

@ -4,12 +4,17 @@ describe "/<%= table_name %>/index.<%= default_file_extension %>" do
include <%= controller_class_name %>Helper
before(:each) do
<% [98,99].each do |id| -%>
<%= file_name %>_<%= id %> = mock_model(<%= class_name %>)
<% for attribute in attributes -%>
<%= file_name %>_<%= id %>.should_receive(:<%= attribute.name %>).and_return(<%= attribute.default_value %>)
<% end -%><% end %>
assigns[:<%= table_name %>] = [<%= file_name %>_98, <%= file_name %>_99]
assigns[:<%= table_name %>] = [
<% [1,2].each_with_index do |id, model_index| -%>
stub_model(<%= class_name %><%= attributes.empty? ? (model_index == 1 ? ')' : '),') : ',' %>
<% attributes.each_with_index do |attribute, attribute_index| -%><% unless attribute.name =~ /_id/ || [:datetime, :timestamp, :time, :date].index(attribute.type) -%>
:<%= attribute.name %> => <%= attribute.default_value %><%= attribute_index == attributes.length - 1 ? '' : ','%>
<% end -%><% end -%>
<% if !attributes.empty? -%>
<%= model_index == 1 ? ')' : '),' %>
<% end -%>
<% end -%>
]
end
it "should render list of <%= table_name %>" do

View file

@ -4,12 +4,12 @@ describe "/<%= table_name %>/new.<%= default_file_extension %>" do
include <%= controller_class_name %>Helper
before(:each) do
@<%= file_name %> = mock_model(<%= class_name %>)
@<%= file_name %>.stub!(:new_record?).and_return(true)
<% for attribute in attributes -%>
@<%= file_name %>.stub!(:<%= attribute.name %>).and_return(<%= attribute.default_value %>)
<% end -%>
assigns[:<%= file_name %>] = @<%= file_name %>
assigns[:<%= file_name %>] = stub_model(<%= class_name %>,
:new_record? => true<%= attributes.empty? ? '' : ',' %>
<% attributes.each_with_index do |attribute, attribute_index| -%><% unless attribute.name =~ /_id/ || [:datetime, :timestamp, :time, :date].index(attribute.type) -%>
:<%= attribute.name %> => <%= attribute.default_value %><%= attribute_index == attributes.length - 1 ? '' : ','%>
<% end -%><% end -%>
)
end
it "should render new form" do

View file

@ -2,59 +2,57 @@ require File.expand_path(File.dirname(__FILE__) + '<%= '/..' * class_nesting_dep
describe <%= controller_class_name %>Controller do
describe "route generation" do
it "should map { :controller => '<%= table_name %>', :action => 'index' } to /<%= table_name %>" do
it "should map #index" do
route_for(:controller => "<%= table_name %>", :action => "index").should == "/<%= table_name %>"
end
it "should map { :controller => '<%= table_name %>', :action => 'new' } to /<%= table_name %>/new" do
it "should map #new" do
route_for(:controller => "<%= table_name %>", :action => "new").should == "/<%= table_name %>/new"
end
it "should map { :controller => '<%= table_name %>', :action => 'show', :id => 1 } to /<%= table_name %>/1" do
it "should map #show" do
route_for(:controller => "<%= table_name %>", :action => "show", :id => 1).should == "/<%= table_name %>/1"
end
it "should map { :controller => '<%= table_name %>', :action => 'edit', :id => 1 } to /<%= table_name %>/1<%= resource_edit_path %>" do
it "should map #edit" do
route_for(:controller => "<%= table_name %>", :action => "edit", :id => 1).should == "/<%= table_name %>/1<%= resource_edit_path %>"
end
it "should map { :controller => '<%= table_name %>', :action => 'update', :id => 1} to /<%= table_name %>/1" do
it "should map #update" do
route_for(:controller => "<%= table_name %>", :action => "update", :id => 1).should == "/<%= table_name %>/1"
end
it "should map { :controller => '<%= table_name %>', :action => 'destroy', :id => 1} to /<%= table_name %>/1" do
it "should map #destroy" do
route_for(:controller => "<%= table_name %>", :action => "destroy", :id => 1).should == "/<%= table_name %>/1"
end
end
describe "route recognition" do
it "should generate params { :controller => '<%= table_name %>', action => 'index' } from GET /<%= table_name %>" do
it "should generate params for #index" do
params_from(:get, "/<%= table_name %>").should == {:controller => "<%= table_name %>", :action => "index"}
end
it "should generate params { :controller => '<%= table_name %>', action => 'new' } from GET /<%= table_name %>/new" do
it "should generate params for #new" do
params_from(:get, "/<%= table_name %>/new").should == {:controller => "<%= table_name %>", :action => "new"}
end
it "should generate params { :controller => '<%= table_name %>', action => 'create' } from POST /<%= table_name %>" do
it "should generate params for #create" do
params_from(:post, "/<%= table_name %>").should == {:controller => "<%= table_name %>", :action => "create"}
end
it "should generate params { :controller => '<%= table_name %>', action => 'show', id => '1' } from GET /<%= table_name %>/1" do
it "should generate params for #show" do
params_from(:get, "/<%= table_name %>/1").should == {:controller => "<%= table_name %>", :action => "show", :id => "1"}
end
it "should generate params { :controller => '<%= table_name %>', action => 'edit', id => '1' } from GET /<%= table_name %>/1;edit" do
it "should generate params for #edit" do
params_from(:get, "/<%= table_name %>/1<%= resource_edit_path %>").should == {:controller => "<%= table_name %>", :action => "edit", :id => "1"}
end
it "should generate params { :controller => '<%= table_name %>', action => 'update', id => '1' } from PUT /<%= table_name %>/1" do
it "should generate params for #update" do
params_from(:put, "/<%= table_name %>/1").should == {:controller => "<%= table_name %>", :action => "update", :id => "1"}
end
it "should generate params { :controller => '<%= table_name %>', action => 'destroy', id => '1' } from DELETE /<%= table_name %>/1" do
it "should generate params for #destroy" do
params_from(:delete, "/<%= table_name %>/1").should == {:controller => "<%= table_name %>", :action => "destroy", :id => "1"}
end
end

View file

@ -4,12 +4,13 @@ describe "/<%= table_name %>/show.<%= default_file_extension %>" do
include <%= controller_class_name %>Helper
before(:each) do
@<%= file_name %> = mock_model(<%= class_name %>)
<% for attribute in attributes -%>
@<%= file_name %>.stub!(:<%= attribute.name %>).and_return(<%= attribute.default_value %>)
assigns[:<%= file_name %>] = @<%= file_name %> = stub_model(<%= class_name %><%= attributes.empty? ? ')' : ',' %>
<% attributes.each_with_index do |attribute, attribute_index| -%><% unless attribute.name =~ /_id/ || [:datetime, :timestamp, :time, :date].index(attribute.type) -%>
:<%= attribute.name %> => <%= attribute.default_value %><%= attribute_index == attributes.length - 1 ? '' : ','%>
<% end -%><% end -%>
<% if !attributes.empty? -%>
)
<% end -%>
assigns[:<%= file_name %>] = @<%= file_name %>
end
it "should render attributes in <p>" do