mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-18 00:00:12 +01:00
Added Rspec and Webrat plugins and started porting Selenium on Rails tests to Rspec Plain Text Stories driving Webrat driving Selenium.
This commit is contained in:
parent
0600756bbf
commit
0f7d6f7a1d
602 changed files with 47788 additions and 29 deletions
1
vendor/plugins/rspec-rails/generators/rspec/CHANGES
vendored
Normal file
1
vendor/plugins/rspec-rails/generators/rspec/CHANGES
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
Please refer to the CHANGES file for RSpec's core
|
||||
35
vendor/plugins/rspec-rails/generators/rspec/rspec_generator.rb
vendored
Normal file
35
vendor/plugins/rspec-rails/generators/rspec/rspec_generator.rb
vendored
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
require 'rbconfig'
|
||||
|
||||
# This generator bootstraps a Rails project for use with RSpec
|
||||
class RspecGenerator < Rails::Generator::Base
|
||||
DEFAULT_SHEBANG = File.join(Config::CONFIG['bindir'],
|
||||
Config::CONFIG['ruby_install_name'])
|
||||
|
||||
def initialize(runtime_args, runtime_options = {})
|
||||
super
|
||||
end
|
||||
|
||||
def manifest
|
||||
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 'script/spec', 'script/spec', script_options
|
||||
|
||||
m.directory 'stories'
|
||||
m.file 'all_stories.rb', 'stories/all.rb'
|
||||
m.file 'stories_helper.rb', 'stories/helper.rb'
|
||||
end
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def banner
|
||||
"Usage: #{$0} rspec"
|
||||
end
|
||||
|
||||
end
|
||||
4
vendor/plugins/rspec-rails/generators/rspec/templates/all_stories.rb
vendored
Normal file
4
vendor/plugins/rspec-rails/generators/rspec/templates/all_stories.rb
vendored
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
dir = File.dirname(__FILE__)
|
||||
Dir[File.expand_path("#{dir}/**/*.rb")].uniq.each do |file|
|
||||
require file
|
||||
end
|
||||
0
vendor/plugins/rspec-rails/generators/rspec/templates/previous_failures.txt
vendored
Normal file
0
vendor/plugins/rspec-rails/generators/rspec/templates/previous_failures.txt
vendored
Normal file
2
vendor/plugins/rspec-rails/generators/rspec/templates/rcov.opts
vendored
Normal file
2
vendor/plugins/rspec-rails/generators/rspec/templates/rcov.opts
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
--exclude "spec/*,gems/*"
|
||||
--rails
|
||||
4
vendor/plugins/rspec-rails/generators/rspec/templates/script/spec
vendored
Normal file
4
vendor/plugins/rspec-rails/generators/rspec/templates/script/spec
vendored
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
#!/usr/bin/env ruby
|
||||
$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + "/../vendor/plugins/rspec/lib"))
|
||||
require 'spec'
|
||||
exit ::Spec::Runner::CommandLine.run(::Spec::Runner::OptionParser.parse(ARGV, STDERR, STDOUT))
|
||||
116
vendor/plugins/rspec-rails/generators/rspec/templates/script/spec_server
vendored
Normal file
116
vendor/plugins/rspec-rails/generators/rspec/templates/script/spec_server
vendored
Normal file
|
|
@ -0,0 +1,116 @@
|
|||
#!/usr/bin/env ruby
|
||||
$LOAD_PATH.unshift File.dirname(__FILE__) + '/../vendor/plugins/rspec/lib' # For rspec installed as plugin
|
||||
require 'rubygems'
|
||||
require 'drb/drb'
|
||||
require 'rbconfig'
|
||||
require 'spec'
|
||||
require 'optparse'
|
||||
|
||||
# This is based on Florian Weber's TDDMate
|
||||
module Spec
|
||||
module Runner
|
||||
class RailsSpecServer
|
||||
def run(argv, stderr, stdout)
|
||||
$stdout = stdout
|
||||
$stderr = stderr
|
||||
|
||||
base = ActiveRecord::Base
|
||||
def base.clear_reloadable_connections!
|
||||
active_connections.each do |name, conn|
|
||||
if conn.requires_reloading?
|
||||
conn.disconnect!
|
||||
active_connections.delete(name)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if ActionController.const_defined?(:Dispatcher)
|
||||
dispatcher = ::ActionController::Dispatcher.new($stdout)
|
||||
dispatcher.cleanup_application
|
||||
elsif ::Dispatcher.respond_to?(:reset_application!)
|
||||
::Dispatcher.reset_application!
|
||||
else
|
||||
raise "Application reloading failed"
|
||||
end
|
||||
if Object.const_defined?(:Fixtures) && Fixtures.respond_to?(:reset_cache)
|
||||
Fixtures.reset_cache
|
||||
end
|
||||
|
||||
::Dependencies.mechanism = :load
|
||||
require_dependency('application.rb') unless Object.const_defined?(:ApplicationController)
|
||||
load File.dirname(__FILE__) + '/../spec/spec_helper.rb'
|
||||
|
||||
if in_memory_database?
|
||||
load "#{RAILS_ROOT}/db/schema.rb" # use db agnostic schema by default
|
||||
ActiveRecord::Migrator.up('db/migrate') # use migrations
|
||||
end
|
||||
|
||||
::Spec::Runner::CommandLine.run(
|
||||
::Spec::Runner::OptionParser.parse(
|
||||
argv,
|
||||
$stderr,
|
||||
$stdout
|
||||
)
|
||||
)
|
||||
end
|
||||
|
||||
def in_memory_database?
|
||||
ENV["RAILS_ENV"] == "test" and
|
||||
::ActiveRecord::Base.connection.class.to_s == "ActiveRecord::ConnectionAdapters::SQLite3Adapter" and
|
||||
::Rails::Configuration.new.database_configuration['test']['database'] == ':memory:'
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
puts "Loading Rails environment"
|
||||
|
||||
ENV["RAILS_ENV"] = "test"
|
||||
require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
|
||||
require 'dispatcher'
|
||||
|
||||
def restart_test_server
|
||||
puts "restarting"
|
||||
config = ::Config::CONFIG
|
||||
ruby = File::join(config['bindir'], config['ruby_install_name']) + config['EXEEXT']
|
||||
command_line = [ruby, $0, ARGV].flatten.join(' ')
|
||||
exec(command_line)
|
||||
end
|
||||
|
||||
def daemonize(pid_file = nil)
|
||||
return yield if $DEBUG
|
||||
pid = Process.fork{
|
||||
Process.setsid
|
||||
Dir.chdir(RAILS_ROOT)
|
||||
trap("SIGINT"){ exit! 0 }
|
||||
trap("SIGTERM"){ exit! 0 }
|
||||
trap("SIGHUP"){ restart_test_server }
|
||||
File.open("/dev/null"){|f|
|
||||
STDERR.reopen f
|
||||
STDIN.reopen f
|
||||
STDOUT.reopen f
|
||||
}
|
||||
yield
|
||||
}
|
||||
puts "spec_server launched. (PID: %d)" % pid
|
||||
File.open(pid_file,"w"){|f| f.puts pid } if pid_file
|
||||
exit! 0
|
||||
end
|
||||
|
||||
options = Hash.new
|
||||
opts = OptionParser.new
|
||||
opts.on("-d", "--daemon"){|v| options[:daemon] = true }
|
||||
opts.on("-p", "--pid PIDFILE"){|v| options[:pid] = v }
|
||||
opts.parse!(ARGV)
|
||||
|
||||
puts "Ready"
|
||||
exec_server = lambda {
|
||||
trap("USR2") { restart_test_server } if Signal.list.has_key?("USR2")
|
||||
DRb.start_service("druby://127.0.0.1:8989", Spec::Runner::RailsSpecServer.new)
|
||||
DRb.thread.join
|
||||
}
|
||||
|
||||
if options[:daemon]
|
||||
daemonize(options[:pid], &exec_server)
|
||||
else
|
||||
exec_server.call
|
||||
end
|
||||
4
vendor/plugins/rspec-rails/generators/rspec/templates/spec.opts
vendored
Normal file
4
vendor/plugins/rspec-rails/generators/rspec/templates/spec.opts
vendored
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
--colour
|
||||
--format progress
|
||||
--loadby mtime
|
||||
--reverse
|
||||
47
vendor/plugins/rspec-rails/generators/rspec/templates/spec_helper.rb
vendored
Normal file
47
vendor/plugins/rspec-rails/generators/rspec/templates/spec_helper.rb
vendored
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
# This file is copied to ~/spec when you run 'ruby script/generate rspec'
|
||||
# from the project root directory.
|
||||
ENV["RAILS_ENV"] = "test"
|
||||
require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
|
||||
require 'spec'
|
||||
require 'spec/rails'
|
||||
|
||||
Spec::Runner.configure do |config|
|
||||
# If you're not using ActiveRecord you should remove these
|
||||
# lines, delete config/database.yml and disable :active_record
|
||||
# in your config/boot.rb
|
||||
config.use_transactional_fixtures = true
|
||||
config.use_instantiated_fixtures = false
|
||||
config.fixture_path = RAILS_ROOT + '/spec/fixtures/'
|
||||
|
||||
# == Fixtures
|
||||
#
|
||||
# You can declare fixtures for each example_group like this:
|
||||
# describe "...." do
|
||||
# fixtures :table_a, :table_b
|
||||
#
|
||||
# Alternatively, if you prefer to declare them only once, you can
|
||||
# do so right here. Just uncomment the next line and replace the fixture
|
||||
# names with your fixtures.
|
||||
#
|
||||
# config.global_fixtures = :table_a, :table_b
|
||||
#
|
||||
# If you declare global fixtures, be aware that they will be declared
|
||||
# for all of your examples, even those that don't use them.
|
||||
#
|
||||
# You can also declare which fixtures to use (for example fixtures for test/fixtures):
|
||||
#
|
||||
# config.fixture_path = RAILS_ROOT + '/spec/fixtures/'
|
||||
#
|
||||
# == Mock Framework
|
||||
#
|
||||
# RSpec uses it's own mocking framework by default. If you prefer to
|
||||
# use mocha, flexmock or RR, uncomment the appropriate line:
|
||||
#
|
||||
# config.mock_with :mocha
|
||||
# config.mock_with :flexmock
|
||||
# config.mock_with :rr
|
||||
#
|
||||
# == Notes
|
||||
#
|
||||
# For more information take a look at Spec::Example::Configuration and Spec::Runner
|
||||
end
|
||||
3
vendor/plugins/rspec-rails/generators/rspec/templates/stories_helper.rb
vendored
Normal file
3
vendor/plugins/rspec-rails/generators/rspec/templates/stories_helper.rb
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
ENV["RAILS_ENV"] = "test"
|
||||
require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
|
||||
require 'spec/rails/story_adapter'
|
||||
33
vendor/plugins/rspec-rails/generators/rspec_controller/USAGE
vendored
Executable file
33
vendor/plugins/rspec-rails/generators/rspec_controller/USAGE
vendored
Executable file
|
|
@ -0,0 +1,33 @@
|
|||
Description:
|
||||
The rspec_controller generator creates stub specs and files for a new
|
||||
controller and its views.
|
||||
|
||||
The generator takes a controller name and a list of views as arguments.
|
||||
The controller name may be given in CamelCase or under_score and should
|
||||
not be suffixed with 'Controller'. To create a controller within a
|
||||
module, specify the controller name as 'module/controller'.
|
||||
|
||||
The generator creates stubs for a controller (and spec), a view (and spec)
|
||||
for each view in the argument list, plus a helper.
|
||||
|
||||
Example:
|
||||
./script/generate rspec_controller dog bark fetch
|
||||
...
|
||||
create spec/controllers/dog_controller_spec.rb
|
||||
create app/controllers/dog_controller.rb
|
||||
create app/helpers/dog_helper.rb
|
||||
create spec/views/dog/bark_view_spec.rb
|
||||
create app/views/dog/bark.rhtml
|
||||
create spec/views/dog/fetch_view_spec.rb
|
||||
create app/views/dog/fetch.rhtml
|
||||
|
||||
Modules Example:
|
||||
./script/generate rspec_controller 'pets/dog' bark fetch
|
||||
...
|
||||
create spec/controllers/pets/dog_controller_spec.rb
|
||||
create app/controllers/pets/dog_controller.rb
|
||||
create app/helpers/pets/dog_helper.rb
|
||||
create spec/views/pets/dog/bark_view_spec.rb
|
||||
create app/views/pets/dog/bark.rhtml
|
||||
create spec/views/pets/dog/fetch_view_spec.rb
|
||||
create app/views/pets/dog/fetch.rhtml
|
||||
49
vendor/plugins/rspec-rails/generators/rspec_controller/rspec_controller_generator.rb
vendored
Executable file
49
vendor/plugins/rspec-rails/generators/rspec_controller/rspec_controller_generator.rb
vendored
Executable file
|
|
@ -0,0 +1,49 @@
|
|||
require 'rails_generator/generators/components/controller/controller_generator'
|
||||
|
||||
class RspecControllerGenerator < ControllerGenerator
|
||||
|
||||
def manifest
|
||||
record do |m|
|
||||
# Check for class naming collisions.
|
||||
m.class_collisions class_path, "#{class_name}Controller", "#{class_name}Helper"
|
||||
|
||||
# Controller, helper, views, and spec directories.
|
||||
m.directory File.join('app/controllers', class_path)
|
||||
m.directory File.join('app/helpers', class_path)
|
||||
m.directory File.join('app/views', class_path, file_name)
|
||||
m.directory File.join('spec/controllers', class_path)
|
||||
m.directory File.join('spec/helpers', class_path)
|
||||
m.directory File.join('spec/views', class_path, file_name)
|
||||
|
||||
if Rails::VERSION::STRING < "2.0.0"
|
||||
@default_file_extension = "rhtml"
|
||||
else
|
||||
@default_file_extension = "html.erb"
|
||||
end
|
||||
|
||||
# Controller spec, class, and helper.
|
||||
m.template 'controller_spec.rb',
|
||||
File.join('spec/controllers', class_path, "#{file_name}_controller_spec.rb")
|
||||
|
||||
m.template 'helper_spec.rb',
|
||||
File.join('spec/helpers', class_path, "#{file_name}_helper_spec.rb")
|
||||
|
||||
m.template 'controller:controller.rb',
|
||||
File.join('app/controllers', class_path, "#{file_name}_controller.rb")
|
||||
|
||||
m.template 'controller:helper.rb',
|
||||
File.join('app/helpers', class_path, "#{file_name}_helper.rb")
|
||||
|
||||
# Spec and view template for each action.
|
||||
actions.each do |action|
|
||||
m.template 'view_spec.rb',
|
||||
File.join('spec/views', class_path, file_name, "#{action}.#{@default_file_extension}_spec.rb"),
|
||||
:assigns => { :action => action, :model => file_name }
|
||||
path = File.join('app/views', class_path, file_name, "#{action}.#{@default_file_extension}")
|
||||
m.template "controller:view.#{@default_file_extension}",
|
||||
path,
|
||||
:assigns => { :action => action, :path => path }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
25
vendor/plugins/rspec-rails/generators/rspec_controller/templates/controller_spec.rb
vendored
Executable file
25
vendor/plugins/rspec-rails/generators/rspec_controller/templates/controller_spec.rb
vendored
Executable file
|
|
@ -0,0 +1,25 @@
|
|||
require File.expand_path(File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../spec_helper')
|
||||
|
||||
describe <%= class_name %>Controller do
|
||||
|
||||
<% if actions.empty? -%>
|
||||
#Delete this example and add some real ones
|
||||
<% else -%>
|
||||
#Delete these examples and add some real ones
|
||||
<% end -%>
|
||||
it "should use <%= class_name %>Controller" do
|
||||
controller.should be_an_instance_of(<%= class_name %>Controller)
|
||||
end
|
||||
|
||||
<% unless actions.empty? -%>
|
||||
<% for action in actions -%>
|
||||
|
||||
describe "GET '<%= action %>'" do
|
||||
it "should be successful" do
|
||||
get '<%= action %>'
|
||||
response.should be_success
|
||||
end
|
||||
end
|
||||
<% end -%>
|
||||
<% end -%>
|
||||
end
|
||||
11
vendor/plugins/rspec-rails/generators/rspec_controller/templates/helper_spec.rb
vendored
Normal file
11
vendor/plugins/rspec-rails/generators/rspec_controller/templates/helper_spec.rb
vendored
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
require File.expand_path(File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../spec_helper')
|
||||
|
||||
describe <%= class_name %>Helper do
|
||||
|
||||
#Delete this example and add some real ones or delete this file
|
||||
it "should be included in the object returned by #helper" do
|
||||
included_modules = (class << helper; self; end).send :included_modules
|
||||
included_modules.should include(<%= class_name %>Helper)
|
||||
end
|
||||
|
||||
end
|
||||
12
vendor/plugins/rspec-rails/generators/rspec_controller/templates/view_spec.rb
vendored
Normal file
12
vendor/plugins/rspec-rails/generators/rspec_controller/templates/view_spec.rb
vendored
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
require File.expand_path(File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../../spec_helper')
|
||||
|
||||
describe "/<%= class_name.underscore %>/<%= action %>" do
|
||||
before(:each) do
|
||||
render '<%= class_name.underscore %>/<%= action %>'
|
||||
end
|
||||
|
||||
#Delete this example and add some real ones or delete this file
|
||||
it "should tell you where to find the file" do
|
||||
response.should have_tag('p', %r[Find me in app/views/<%= class_name.underscore %>/<%= action %>])
|
||||
end
|
||||
end
|
||||
18
vendor/plugins/rspec-rails/generators/rspec_model/USAGE
vendored
Executable file
18
vendor/plugins/rspec-rails/generators/rspec_model/USAGE
vendored
Executable file
|
|
@ -0,0 +1,18 @@
|
|||
Description:
|
||||
The rspec_model generator creates stubs for a new model.
|
||||
|
||||
The generator takes a model name as its argument. The model name may be
|
||||
given in CamelCase or under_score and should not be suffixed with 'Model'.
|
||||
|
||||
The generator creates a model class in app/models, an RSpec spec in
|
||||
spec/models, database fixtures in spec/fixtures/plural_name.yml, and a migration
|
||||
in db/migrate.
|
||||
|
||||
Example:
|
||||
./script/generate rspec_model Account
|
||||
|
||||
This will create an Account model:
|
||||
Model: app/models/account.rb
|
||||
Spec: spec/models/account_spec.rb
|
||||
Fixtures: spec/fixtures/accounts.yml
|
||||
Migration: db/migrate/XXX_add_accounts.rb
|
||||
30
vendor/plugins/rspec-rails/generators/rspec_model/rspec_model_generator.rb
vendored
Executable file
30
vendor/plugins/rspec-rails/generators/rspec_model/rspec_model_generator.rb
vendored
Executable file
|
|
@ -0,0 +1,30 @@
|
|||
require 'rails_generator/generators/components/model/model_generator'
|
||||
|
||||
class RspecModelGenerator < ModelGenerator
|
||||
|
||||
def manifest
|
||||
|
||||
record do |m|
|
||||
# Check for class naming collisions.
|
||||
m.class_collisions class_path, class_name
|
||||
|
||||
# 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)
|
||||
|
||||
# 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_migration]
|
||||
m.migration_template 'model:migration.rb', 'db/migrate', :assigns => {
|
||||
:migration_name => "Create#{class_name.pluralize.gsub(/::/, '')}"
|
||||
}, :migration_file_name => "create_#{file_path.gsub(/\//, '_').pluralize}"
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
11
vendor/plugins/rspec-rails/generators/rspec_model/templates/model_spec.rb
vendored
Executable file
11
vendor/plugins/rspec-rails/generators/rspec_model/templates/model_spec.rb
vendored
Executable file
|
|
@ -0,0 +1,11 @@
|
|||
require File.expand_path(File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../spec_helper')
|
||||
|
||||
describe <%= class_name %> do
|
||||
before(:each) do
|
||||
@<%= file_name %> = <%= class_name %>.new
|
||||
end
|
||||
|
||||
it "should be valid" do
|
||||
@<%= file_name %>.should be_valid
|
||||
end
|
||||
end
|
||||
167
vendor/plugins/rspec-rails/generators/rspec_scaffold/rspec_scaffold_generator.rb
vendored
Normal file
167
vendor/plugins/rspec-rails/generators/rspec_scaffold/rspec_scaffold_generator.rb
vendored
Normal file
|
|
@ -0,0 +1,167 @@
|
|||
class RspecScaffoldGenerator < Rails::Generator::NamedBase
|
||||
default_options :skip_migration => false
|
||||
|
||||
attr_reader :controller_name,
|
||||
:controller_class_path,
|
||||
:controller_file_path,
|
||||
:controller_class_nesting,
|
||||
:controller_class_nesting_depth,
|
||||
:controller_class_name,
|
||||
:controller_singular_name,
|
||||
:controller_plural_name,
|
||||
:resource_edit_path,
|
||||
:default_file_extension
|
||||
alias_method :controller_file_name, :controller_singular_name
|
||||
alias_method :controller_table_name, :controller_plural_name
|
||||
|
||||
def initialize(runtime_args, runtime_options = {})
|
||||
super
|
||||
|
||||
@controller_name = @name.pluralize
|
||||
|
||||
base_name, @controller_class_path, @controller_file_path, @controller_class_nesting, @controller_class_nesting_depth = extract_modules(@controller_name)
|
||||
@controller_class_name_without_nesting, @controller_singular_name, @controller_plural_name = inflect_names(base_name)
|
||||
|
||||
if @controller_class_nesting.empty?
|
||||
@controller_class_name = @controller_class_name_without_nesting
|
||||
else
|
||||
@controller_class_name = "#{@controller_class_nesting}::#{@controller_class_name_without_nesting}"
|
||||
end
|
||||
|
||||
if Rails::VERSION::STRING < "2.0.0"
|
||||
@resource_generator = "scaffold_resource"
|
||||
@default_file_extension = "rhtml"
|
||||
else
|
||||
@resource_generator = "scaffold"
|
||||
@default_file_extension = "html.erb"
|
||||
end
|
||||
|
||||
if ActionController::Base.respond_to?(:resource_action_separator)
|
||||
@resource_edit_path = "/edit"
|
||||
else
|
||||
@resource_edit_path = ";edit"
|
||||
end
|
||||
end
|
||||
|
||||
def manifest
|
||||
record do |m|
|
||||
|
||||
# Check for class naming collisions.
|
||||
m.class_collisions(controller_class_path, "#{controller_class_name}Controller", "#{controller_class_name}Helper")
|
||||
m.class_collisions(class_path, "#{class_name}")
|
||||
|
||||
# Controller, helper, views, and spec directories.
|
||||
m.directory(File.join('app/models', class_path))
|
||||
m.directory(File.join('app/controllers', controller_class_path))
|
||||
m.directory(File.join('app/helpers', controller_class_path))
|
||||
m.directory(File.join('app/views', controller_class_path, controller_file_name))
|
||||
m.directory(File.join('spec/controllers', controller_class_path))
|
||||
m.directory(File.join('spec/models', class_path))
|
||||
m.directory(File.join('spec/helpers', class_path))
|
||||
m.directory File.join('spec/fixtures', class_path)
|
||||
m.directory File.join('spec/views', controller_class_path, controller_file_name)
|
||||
|
||||
# Controller spec, class, and helper.
|
||||
m.template 'rspec_scaffold:routing_spec.rb',
|
||||
File.join('spec/controllers', controller_class_path, "#{controller_file_name}_routing_spec.rb")
|
||||
|
||||
m.template 'rspec_scaffold:controller_spec.rb',
|
||||
File.join('spec/controllers', controller_class_path, "#{controller_file_name}_controller_spec.rb")
|
||||
|
||||
m.template "#{@resource_generator}:controller.rb",
|
||||
File.join('app/controllers', controller_class_path, "#{controller_file_name}_controller.rb")
|
||||
|
||||
m.template 'rspec_scaffold:helper_spec.rb',
|
||||
File.join('spec/helpers', class_path, "#{controller_file_name}_helper_spec.rb")
|
||||
|
||||
m.template "#{@resource_generator}:helper.rb",
|
||||
File.join('app/helpers', controller_class_path, "#{controller_file_name}_helper.rb")
|
||||
|
||||
for action in scaffold_views
|
||||
m.template(
|
||||
"#{@resource_generator}:view_#{action}.#{@default_file_extension}",
|
||||
File.join('app/views', controller_class_path, controller_file_name, "#{action}.#{default_file_extension}")
|
||||
)
|
||||
end
|
||||
|
||||
# Model class, unit test, 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 'rspec_model:model_spec.rb', File.join('spec/models', class_path, "#{file_name}_spec.rb")
|
||||
|
||||
# View specs
|
||||
m.template "rspec_scaffold:edit_erb_spec.rb",
|
||||
File.join('spec/views', controller_class_path, controller_file_name, "edit.#{default_file_extension}_spec.rb")
|
||||
m.template "rspec_scaffold:index_erb_spec.rb",
|
||||
File.join('spec/views', controller_class_path, controller_file_name, "index.#{default_file_extension}_spec.rb")
|
||||
m.template "rspec_scaffold:new_erb_spec.rb",
|
||||
File.join('spec/views', controller_class_path, controller_file_name, "new.#{default_file_extension}_spec.rb")
|
||||
m.template "rspec_scaffold:show_erb_spec.rb",
|
||||
File.join('spec/views', controller_class_path, controller_file_name, "show.#{default_file_extension}_spec.rb")
|
||||
|
||||
unless options[:skip_migration]
|
||||
m.migration_template(
|
||||
'model:migration.rb', 'db/migrate',
|
||||
:assigns => {
|
||||
:migration_name => "Create#{class_name.pluralize.gsub(/::/, '')}",
|
||||
:attributes => attributes
|
||||
},
|
||||
:migration_file_name => "create_#{file_path.gsub(/\//, '_').pluralize}"
|
||||
)
|
||||
end
|
||||
|
||||
m.route_resources controller_file_name
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
protected
|
||||
# Override with your own usage banner.
|
||||
def banner
|
||||
"Usage: #{$0} rspec_scaffold ModelName [field:type field:type]"
|
||||
end
|
||||
|
||||
def add_options!(opt)
|
||||
opt.separator ''
|
||||
opt.separator 'Options:'
|
||||
opt.on("--skip-migration",
|
||||
"Don't generate a migration file for this model") { |v| options[:skip_migration] = v }
|
||||
end
|
||||
|
||||
def scaffold_views
|
||||
%w[ index show new edit ]
|
||||
end
|
||||
|
||||
def model_name
|
||||
class_name.demodulize
|
||||
end
|
||||
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"
|
||||
else
|
||||
"input"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
313
vendor/plugins/rspec-rails/generators/rspec_scaffold/templates/controller_spec.rb
vendored
Executable file
313
vendor/plugins/rspec-rails/generators/rspec_scaffold/templates/controller_spec.rb
vendored
Executable file
|
|
@ -0,0 +1,313 @@
|
|||
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 do_get
|
||||
get :index
|
||||
end
|
||||
|
||||
it "should be successful" do
|
||||
do_get
|
||||
response.should be_success
|
||||
end
|
||||
|
||||
it "should render index template" do
|
||||
do_get
|
||||
response.should render_template('index')
|
||||
end
|
||||
|
||||
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 %>]
|
||||
end
|
||||
end
|
||||
|
||||
describe "handling GET /<%= table_name %>.xml" 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 %>)
|
||||
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
|
||||
end
|
||||
|
||||
it "should redirect to the new <%= file_name %>" do
|
||||
do_post
|
||||
response.should redirect_to(<%= table_name.singularize %>_url("1"))
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "with failed save" do
|
||||
|
||||
def do_post
|
||||
@<%= file_name %>.should_receive(:save).and_return(false)
|
||||
post :create, :<%= file_name %> => {}
|
||||
end
|
||||
|
||||
it "should re-render 'new'" do
|
||||
do_post
|
||||
response.should render_template('new')
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
describe "handling PUT /<%= table_name %>/1" 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
|
||||
|
||||
def do_put
|
||||
@<%= file_name %>.should_receive(:update_attributes).and_return(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 %>)
|
||||
end
|
||||
|
||||
it "should redirect to the <%= file_name %>" do
|
||||
do_put
|
||||
response.should redirect_to(<%= table_name.singularize %>_url("1"))
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "with failed update" do
|
||||
|
||||
def do_put
|
||||
@<%= file_name %>.should_receive(:update_attributes).and_return(false)
|
||||
put :update, :id => "1"
|
||||
end
|
||||
|
||||
it "should re-render 'edit'" do
|
||||
do_put
|
||||
response.should render_template('edit')
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
describe "handling DELETE /<%= table_name %>/1" 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
|
||||
end
|
||||
|
||||
it "should redirect to the <%= table_name %> list" do
|
||||
do_delete
|
||||
response.should redirect_to(<%= table_name %>_url)
|
||||
end
|
||||
end
|
||||
end
|
||||
25
vendor/plugins/rspec-rails/generators/rspec_scaffold/templates/edit_erb_spec.rb
vendored
Normal file
25
vendor/plugins/rspec-rails/generators/rspec_scaffold/templates/edit_erb_spec.rb
vendored
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
require File.expand_path(File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../../spec_helper')
|
||||
|
||||
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 %>
|
||||
end
|
||||
|
||||
it "should render edit form" do
|
||||
render "/<%= table_name %>/edit.<%= default_file_extension %>"
|
||||
|
||||
response.should have_tag("form[action=#{<%= file_name %>_path(@<%= file_name %>)}][method=post]") do
|
||||
<% for attribute in attributes -%><% unless attribute.name =~ /_id/ || [:datetime, :timestamp, :time, :date].index(attribute.type) -%>
|
||||
with_tag('<%= attribute.input_type -%>#<%= file_name %>_<%= attribute.name %>[name=?]', "<%= file_name %>[<%= attribute.name %>]")
|
||||
<% end -%><% end -%>
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
11
vendor/plugins/rspec-rails/generators/rspec_scaffold/templates/helper_spec.rb
vendored
Normal file
11
vendor/plugins/rspec-rails/generators/rspec_scaffold/templates/helper_spec.rb
vendored
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
require File.expand_path(File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../spec_helper')
|
||||
|
||||
describe <%= controller_class_name %>Helper do
|
||||
|
||||
#Delete this example and add some real ones or delete this file
|
||||
it "should be included in the object returned by #helper" do
|
||||
included_modules = (class << helper; self; end).send :included_modules
|
||||
included_modules.should include(<%= controller_class_name %>Helper)
|
||||
end
|
||||
|
||||
end
|
||||
22
vendor/plugins/rspec-rails/generators/rspec_scaffold/templates/index_erb_spec.rb
vendored
Normal file
22
vendor/plugins/rspec-rails/generators/rspec_scaffold/templates/index_erb_spec.rb
vendored
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
require File.expand_path(File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../../spec_helper')
|
||||
|
||||
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]
|
||||
end
|
||||
|
||||
it "should render list of <%= table_name %>" do
|
||||
render "/<%= table_name %>/index.<%= default_file_extension %>"
|
||||
<% for attribute in attributes -%><% unless attribute.name =~ /_id/ || [:datetime, :timestamp, :time, :date].index(attribute.type) -%>
|
||||
response.should have_tag("tr>td", <%= attribute.default_value %>, 2)
|
||||
<% end -%><% end -%>
|
||||
end
|
||||
end
|
||||
|
||||
26
vendor/plugins/rspec-rails/generators/rspec_scaffold/templates/new_erb_spec.rb
vendored
Normal file
26
vendor/plugins/rspec-rails/generators/rspec_scaffold/templates/new_erb_spec.rb
vendored
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
require File.expand_path(File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../../spec_helper')
|
||||
|
||||
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 %>
|
||||
end
|
||||
|
||||
it "should render new form" do
|
||||
render "/<%= table_name %>/new.<%= default_file_extension %>"
|
||||
|
||||
response.should have_tag("form[action=?][method=post]", <%= table_name %>_path) do
|
||||
<% for attribute in attributes -%><% unless attribute.name =~ /_id/ || [:datetime, :timestamp, :time, :date].index(attribute.type) -%>
|
||||
with_tag("<%= attribute.input_type -%>#<%= file_name %>_<%= attribute.name %>[name=?]", "<%= file_name %>[<%= attribute.name %>]")
|
||||
<% end -%><% end -%>
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
61
vendor/plugins/rspec-rails/generators/rspec_scaffold/templates/routing_spec.rb
vendored
Normal file
61
vendor/plugins/rspec-rails/generators/rspec_scaffold/templates/routing_spec.rb
vendored
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
require File.expand_path(File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../spec_helper')
|
||||
|
||||
describe <%= controller_class_name %>Controller do
|
||||
describe "route generation" do
|
||||
|
||||
it "should map { :controller => '<%= table_name %>', :action => 'index' } to /<%= table_name %>" 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
|
||||
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
|
||||
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
|
||||
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
|
||||
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
|
||||
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
|
||||
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
|
||||
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
|
||||
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
|
||||
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
|
||||
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
|
||||
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
|
||||
params_from(:delete, "/<%= table_name %>/1").should == {:controller => "<%= table_name %>", :action => "destroy", :id => "1"}
|
||||
end
|
||||
end
|
||||
end
|
||||
22
vendor/plugins/rspec-rails/generators/rspec_scaffold/templates/show_erb_spec.rb
vendored
Normal file
22
vendor/plugins/rspec-rails/generators/rspec_scaffold/templates/show_erb_spec.rb
vendored
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
require File.expand_path(File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../../spec_helper')
|
||||
|
||||
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 %>)
|
||||
<% end -%>
|
||||
|
||||
assigns[:<%= file_name %>] = @<%= file_name %>
|
||||
end
|
||||
|
||||
it "should render attributes in <p>" do
|
||||
render "/<%= table_name %>/show.<%= default_file_extension %>"
|
||||
<% for attribute in attributes -%><% unless attribute.name =~ /_id/ || [:datetime, :timestamp, :time, :date].index(attribute.type) -%>
|
||||
response.should have_text(/<%= Regexp.escape(attribute.default_value)[1..-2]%>/)
|
||||
<% end -%><% end -%>
|
||||
end
|
||||
end
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue