mirror of
https://github.com/haml/haml-rails.git
synced 2022-11-09 12:34:15 -05:00
Pull in Haml tests from rails3-generators
This commit is contained in:
parent
1d6a59aee2
commit
c7025ae5bf
8 changed files with 192 additions and 3 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -1 +1,2 @@
|
|||
*.gem
|
||||
*.gem
|
||||
tmp/
|
|
@ -12,4 +12,4 @@ Once you've done that, any time you generate a controller or scaffold, you'll ge
|
|||
|
||||
### Contributors
|
||||
|
||||
Haml generators originally from [rails3-generators](http://github.com/indirect/rails3-generators), and written by Paul Barry, Anuj Dutta, Louis T, and Chris Rhoden.
|
||||
Haml generators originally from [rails3-generators](http://github.com/indirect/rails3-generators), and written by Paul Barry, Anuj Dutta, Louis T, and Chris Rhoden. Tests originally written by Louis T.
|
11
Rakefile
11
Rakefile
|
@ -1,2 +1,11 @@
|
|||
require 'bundler'
|
||||
Bundler::GemHelper.install_tasks
|
||||
Bundler::GemHelper.install_tasks
|
||||
|
||||
require 'rake/testtask'
|
||||
Rake::TestTask.new(:test) do |test|
|
||||
test.libs << 'lib' << 'test'
|
||||
test.pattern = 'test/**/*_test.rb'
|
||||
test.verbose = true
|
||||
end
|
||||
|
||||
task :default => :test
|
||||
|
|
58
test/fixtures/routes.rb
vendored
Normal file
58
test/fixtures/routes.rb
vendored
Normal file
|
@ -0,0 +1,58 @@
|
|||
TestApp.routes.draw do |map|
|
||||
# The priority is based upon order of creation:
|
||||
# first created -> highest priority.
|
||||
|
||||
# Sample of regular route:
|
||||
# match 'products/:id' => 'catalog#view'
|
||||
# Keep in mind you can assign values other than :controller and :action
|
||||
|
||||
# Sample of named route:
|
||||
# match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
|
||||
# This route can be invoked with purchase_url(:id => product.id)
|
||||
|
||||
# Sample resource route (maps HTTP verbs to controller actions automatically):
|
||||
# resources :products
|
||||
|
||||
# Sample resource route with options:
|
||||
# resources :products do
|
||||
# member do
|
||||
# get :short
|
||||
# post :toggle
|
||||
# end
|
||||
#
|
||||
# collection do
|
||||
# get :sold
|
||||
# end
|
||||
# end
|
||||
|
||||
# Sample resource route with sub-resources:
|
||||
# resources :products do
|
||||
# resources :comments, :sales
|
||||
# resource :seller
|
||||
# end
|
||||
|
||||
# Sample resource route with more complex sub-resources
|
||||
# resources :products do
|
||||
# resources :comments
|
||||
# resources :sales do
|
||||
# get :recent, :on => :collection
|
||||
# end
|
||||
# end
|
||||
|
||||
# Sample resource route within a namespace:
|
||||
# namespace :admin do
|
||||
# # Directs /admin/products/* to Admin::ProductsController
|
||||
# # (app/controllers/admin/products_controller.rb)
|
||||
# resources :products
|
||||
# end
|
||||
|
||||
# You can have the root of your site routed with "root"
|
||||
# just remember to delete public/index.html.
|
||||
# root :to => "welcome#index"
|
||||
|
||||
# See how all your routes lay out with "rake routes"
|
||||
|
||||
# This is a legacy wild controller route that's not recommended for RESTful applications.
|
||||
# Note: This route will make all actions in every controller accessible via GET requests.
|
||||
# match ':controller(/:action(/:id(.:format)))'
|
||||
end
|
17
test/lib/generators/haml/controller_generator_test.rb
Normal file
17
test/lib/generators/haml/controller_generator_test.rb
Normal file
|
@ -0,0 +1,17 @@
|
|||
require 'test_helper'
|
||||
require 'lib/generators/haml/testing_helper'
|
||||
|
||||
class Haml::Generators::ControllerGeneratorTest < Rails::Generators::TestCase
|
||||
destination File.join(Rails.root)
|
||||
tests Rails::Generators::ControllerGenerator
|
||||
arguments %w(Account foo bar --template-engine haml)
|
||||
|
||||
setup :prepare_destination
|
||||
setup :copy_routes
|
||||
|
||||
test "should invoke template engine" do
|
||||
run_generator
|
||||
assert_file "app/views/account/foo.html.haml", %r(app/views/account/foo\.html\.haml)
|
||||
assert_file "app/views/account/bar.html.haml", %r(app/views/account/bar\.html\.haml)
|
||||
end
|
||||
end
|
31
test/lib/generators/haml/scaffold_generator_test.rb
Normal file
31
test/lib/generators/haml/scaffold_generator_test.rb
Normal file
|
@ -0,0 +1,31 @@
|
|||
require 'test_helper'
|
||||
require 'lib/generators/haml/testing_helper'
|
||||
|
||||
class Haml::Generators::ScaffoldGeneratorTest < Rails::Generators::TestCase
|
||||
destination File.join(Rails.root)
|
||||
tests Rails::Generators::ScaffoldGenerator
|
||||
arguments %w(product_line title:string price:integer --template-engine haml)
|
||||
|
||||
setup :prepare_destination
|
||||
setup :copy_routes
|
||||
|
||||
test "should invoke template engine" do
|
||||
run_generator
|
||||
|
||||
%w(index edit new show _form).each { |view| assert_file "app/views/product_lines/#{view}.html.haml" }
|
||||
assert_no_file "app/views/layouts/product_lines.html.haml"
|
||||
end
|
||||
|
||||
test "should revoke template engine" do
|
||||
run_generator
|
||||
run_generator ["product_line"], :behavior => :revoke
|
||||
|
||||
assert_no_file "app/views/product_lines"
|
||||
assert_no_file "app/views/layouts/product_lines.html.haml"
|
||||
end
|
||||
|
||||
test "should invoke form builder" do
|
||||
run_generator %w(product_line title:string price:integer --template-engine haml --form-builder some-form-builder)
|
||||
assert_no_file "app/views/product_lines/_form.html.haml"
|
||||
end
|
||||
end
|
1
test/lib/generators/haml/testing_helper.rb
Normal file
1
test/lib/generators/haml/testing_helper.rb
Normal file
|
@ -0,0 +1 @@
|
|||
require_generators :haml => ['scaffold', 'controller']
|
72
test/test_helper.rb
Normal file
72
test/test_helper.rb
Normal file
|
@ -0,0 +1,72 @@
|
|||
require 'rubygems'
|
||||
gem 'test-unit'
|
||||
require 'test/unit'
|
||||
require 'rails/all'
|
||||
require 'rails/generators'
|
||||
require 'rails/generators/test_case'
|
||||
|
||||
class TestApp < Rails::Application
|
||||
config.root = File.dirname(__FILE__)
|
||||
end
|
||||
Rails.application = TestApp
|
||||
|
||||
module Rails
|
||||
def self.root
|
||||
@root ||= File.expand_path(File.join(File.dirname(__FILE__), '..', 'tmp', 'rails'))
|
||||
end
|
||||
end
|
||||
Rails.application.config.root = Rails.root
|
||||
|
||||
# Call configure to load the settings from
|
||||
# Rails.application.config.generators to Rails::Generators
|
||||
Rails::Generators.configure!
|
||||
|
||||
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
||||
|
||||
def copy_routes
|
||||
routes = File.expand_path(File.join(File.dirname(__FILE__), 'fixtures', 'routes.rb'))
|
||||
destination = File.join(Rails.root, "config")
|
||||
FileUtils.mkdir_p(destination)
|
||||
FileUtils.cp File.expand_path(routes), destination
|
||||
end
|
||||
|
||||
# Asserts the given class exists in the given content. When a block is given,
|
||||
# it yields the content of the class.
|
||||
#
|
||||
# assert_file "test/functional/accounts_controller_test.rb" do |controller_test|
|
||||
# assert_class "AccountsControllerTest", controller_test do |klass|
|
||||
# assert_match /context "index action"/, klass
|
||||
# end
|
||||
# end
|
||||
#
|
||||
def assert_class(klass, content)
|
||||
assert content =~ /class #{klass}(\(.+\))?(.*?)\nend/m, "Expected to have class #{klass}"
|
||||
yield $2.strip if block_given?
|
||||
end
|
||||
|
||||
def generator_list
|
||||
{
|
||||
:rails => ['scaffold', 'controller'],
|
||||
:haml => ['scaffold', 'controller']
|
||||
}
|
||||
end
|
||||
|
||||
def path_prefix(name)
|
||||
case name
|
||||
when :rails
|
||||
'rails/generators'
|
||||
else
|
||||
'generators'
|
||||
end
|
||||
end
|
||||
|
||||
def require_generators(generator_list)
|
||||
generator_list.each do |name, generators|
|
||||
generators.each do |generator_name|
|
||||
require File.join(path_prefix(name), name.to_s, generator_name.to_s, "#{generator_name}_generator")
|
||||
end
|
||||
end
|
||||
end
|
||||
alias :require_generator :require_generators
|
||||
|
||||
require_generators generator_list
|
Loading…
Add table
Add a link
Reference in a new issue