aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test
diff options
context:
space:
mode:
authorrick <rick@spacemonkey.local>2008-05-05 23:19:21 -0700
committerrick <rick@spacemonkey.local>2008-05-05 23:19:21 -0700
commit0052938ac5b8894b27fdb9f27b1ed39f0a9ea176 (patch)
treef714643a4043d9fb73b39ec2a114d18f5deeffdd /actionpack/test
parenteacb5cf0cab6447db78085c8bda6c94dd329ce6b (diff)
parent3cffe92ff066c2b35eef409547db93652c5cccfc (diff)
downloadrails-0052938ac5b8894b27fdb9f27b1ed39f0a9ea176.tar.gz
rails-0052938ac5b8894b27fdb9f27b1ed39f0a9ea176.tar.bz2
rails-0052938ac5b8894b27fdb9f27b1ed39f0a9ea176.zip
Merge commit 'core/master'
Diffstat (limited to 'actionpack/test')
-rw-r--r--actionpack/test/activerecord/render_partial_with_record_identification_test.rb31
-rw-r--r--actionpack/test/controller/assert_select_test.rb15
-rw-r--r--actionpack/test/controller/base_test.rb34
-rw-r--r--actionpack/test/controller/mime_type_test.rb7
-rw-r--r--actionpack/test/controller/render_test.rb20
-rw-r--r--actionpack/test/controller/routing_test.rb10
-rw-r--r--actionpack/test/controller/session/mem_cache_store_test.rb5
-rw-r--r--actionpack/test/fixtures/company.rb1
-rw-r--r--actionpack/test/fixtures/db_definitions/sqlite.sql6
-rw-r--r--actionpack/test/fixtures/mascot.rb3
-rw-r--r--actionpack/test/fixtures/mascots.yml4
-rw-r--r--actionpack/test/fixtures/mascots/_mascot.html.erb1
-rw-r--r--actionpack/test/fixtures/reply.rb1
-rw-r--r--actionpack/test/fixtures/shared.html.erb1
-rw-r--r--actionpack/test/fixtures/test/_raise.html.erb1
-rw-r--r--actionpack/test/template/benchmark_helper_test.rb26
-rw-r--r--actionpack/test/template/form_helper_test.rb144
-rw-r--r--actionpack/test/template/template_finder_test.rb5
-rw-r--r--actionpack/test/template/template_object_test.rb5
19 files changed, 227 insertions, 93 deletions
diff --git a/actionpack/test/activerecord/render_partial_with_record_identification_test.rb b/actionpack/test/activerecord/render_partial_with_record_identification_test.rb
index 773018d445..32b26206c3 100644
--- a/actionpack/test/activerecord/render_partial_with_record_identification_test.rb
+++ b/actionpack/test/activerecord/render_partial_with_record_identification_test.rb
@@ -1,7 +1,7 @@
require 'active_record_unit'
class RenderPartialWithRecordIdentificationTest < ActiveRecordTestCase
- fixtures :developers, :projects, :developers_projects, :topics, :replies
+ fixtures :developers, :projects, :developers_projects, :topics, :replies, :companies, :mascots
class RenderPartialWithRecordIdentificationController < ActionController::Base
def render_with_has_many_and_belongs_to_association
@@ -14,11 +14,20 @@ class RenderPartialWithRecordIdentificationTest < ActiveRecordTestCase
render :partial => @topic.replies
end
+ def render_with_named_scope
+ render :partial => Reply.base
+ end
+
def render_with_has_many_through_association
@developer = Developer.find(:first)
render :partial => @developer.topics
end
+ def render_with_has_one_association
+ @company = Company.find(1)
+ render :partial => @company.mascot
+ end
+
def render_with_belongs_to_association
@reply = Reply.find(1)
render :partial => @reply.topic
@@ -53,16 +62,9 @@ class RenderPartialWithRecordIdentificationTest < ActiveRecordTestCase
assert_template 'replies/_reply'
end
- def test_rendering_partial_with_has_many_association
- get :render_with_has_many_through_association
- assert_template 'topics/_topic'
- end
-
- def test_rendering_partial_with_belongs_to_association
- topic = Reply.find(1).topic
- get :render_with_belongs_to_association
- assert_template 'topics/_topic'
- assert_equal topic.title, @response.body
+ def test_rendering_partial_with_named_scope
+ get :render_with_named_scope
+ assert_template 'replies/_reply'
end
def test_render_with_record
@@ -74,4 +76,11 @@ class RenderPartialWithRecordIdentificationTest < ActiveRecordTestCase
get :render_with_record_collection
assert_template 'developers/_developer'
end
+
+ def test_rendering_partial_with_has_one_association
+ mascot = Company.find(1).mascot
+ get :render_with_has_one_association
+ assert_template 'mascots/_mascot'
+ assert_equal mascot.name, @response.body
+ end
end
diff --git a/actionpack/test/controller/assert_select_test.rb b/actionpack/test/controller/assert_select_test.rb
index c8ad56cbc0..5af579f3e3 100644
--- a/actionpack/test/controller/assert_select_test.rb
+++ b/actionpack/test/controller/assert_select_test.rb
@@ -345,10 +345,17 @@ class AssertSelectTest < Test::Unit::TestCase
page.replace "test", "<div id=\"1\">\343\203\201\343\202\261\343\203\203\343\203\210</div>"
end
assert_select_rjs do
- assert_select "#1", :text => "\343\203\201\343\202\261\343\203\203\343\203\210"
- assert_select "#1", "\343\203\201\343\202\261\343\203\203\343\203\210"
- assert_select "#1", Regexp.new("\343\203\201..\343\203\210",0,'U')
- assert_raises(AssertionFailedError) { assert_select "#1", Regexp.new("\343\203\201.\343\203\210",0,'U') }
+ str = "#1"
+ assert_select str, :text => "\343\203\201\343\202\261\343\203\203\343\203\210"
+ assert_select str, "\343\203\201\343\202\261\343\203\203\343\203\210"
+ if str.respond_to?(:force_encoding)
+ str.force_encoding(Encoding::UTF_8)
+ assert_select str, /\343\203\201..\343\203\210/u
+ assert_raises(AssertionFailedError) { assert_select str, /\343\203\201.\343\203\210/u }
+ else
+ assert_select str, Regexp.new("\343\203\201..\343\203\210",0,'U')
+ assert_raises(AssertionFailedError) { assert_select str, Regexp.new("\343\203\201.\343\203\210",0,'U') }
+ end
end
end
diff --git a/actionpack/test/controller/base_test.rb b/actionpack/test/controller/base_test.rb
index 1a8bd6dfe9..8416754c1e 100644
--- a/actionpack/test/controller/base_test.rb
+++ b/actionpack/test/controller/base_test.rb
@@ -48,6 +48,15 @@ protected
end
+class DefaultUrlOptionsController < ActionController::Base
+ def default_url_options_action
+ end
+
+ def default_url_options(options)
+ { :host => 'www.override.com', :action => 'new', :bacon => 'chunky' }
+ end
+end
+
class ControllerClassTests < Test::Unit::TestCase
def test_controller_path
assert_equal 'empty', EmptyController.controller_path
@@ -134,3 +143,28 @@ class PerformActionTest < Test::Unit::TestCase
assert_response 404
end
end
+
+class DefaultUrlOptionsTest < Test::Unit::TestCase
+ def setup
+ @controller = DefaultUrlOptionsController.new
+
+ @request = ActionController::TestRequest.new
+ @response = ActionController::TestResponse.new
+
+ @request.host = 'www.example.com'
+ end
+
+ def test_default_url_options_are_used_if_set
+ ActionController::Routing::Routes.draw do |map|
+ map.default_url_options 'default_url_options', :controller => 'default_url_options'
+ map.connect ':controller/:action/:id'
+ end
+
+ get :default_url_options_action # Make a dummy request so that the controller is initialized properly.
+
+ assert_equal 'http://www.override.com/default_url_options/new?bacon=chunky', @controller.url_for(:controller => 'default_url_options')
+ assert_equal 'http://www.override.com/default_url_options?bacon=chunky', @controller.send(:default_url_options_url)
+ ensure
+ ActionController::Routing::Routes.load!
+ end
+end \ No newline at end of file
diff --git a/actionpack/test/controller/mime_type_test.rb b/actionpack/test/controller/mime_type_test.rb
index 991ac04f62..03b0f8bad2 100644
--- a/actionpack/test/controller/mime_type_test.rb
+++ b/actionpack/test/controller/mime_type_test.rb
@@ -28,6 +28,13 @@ class MimeTypeTest < Test::Unit::TestCase
expect = [Mime::HTML, Mime::XML, "image/*", Mime::TEXT, Mime::ALL]
assert_equal expect, Mime::Type.parse(accept).collect { |c| c.to_s }
end
+
+ # Accept header send with user HTTP_USER_AGENT: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; InfoPath.1)
+ def test_parse_crappy_broken_acceptlines2
+ accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, , pronto/1.00.00, sslvpn/1.00.00.00, */*"
+ expect = ['image/gif', 'image/x-xbitmap', 'image/jpeg','image/pjpeg', 'application/x-shockwave-flash', 'application/vnd.ms-excel', 'application/vnd.ms-powerpoint', 'application/msword', 'pronto/1.00.00', 'sslvpn/1.00.00.00', Mime::ALL ]
+ assert_equal expect, Mime::Type.parse(accept).collect { |c| c.to_s }
+ end
def test_custom_type
Mime::Type.register("image/gif", :gif)
diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb
index 7491f16a84..066fa6acd4 100644
--- a/actionpack/test/controller/render_test.rb
+++ b/actionpack/test/controller/render_test.rb
@@ -23,6 +23,14 @@ class TestController < ActionController::Base
def render_hello_world_with_forward_slash
render :template => "/test/hello_world"
end
+
+ def render_template_in_top_directory
+ render :template => 'shared'
+ end
+
+ def render_template_in_top_directory_with_slash
+ render :template => '/shared'
+ end
def render_hello_world_from_variable
@person = "david"
@@ -243,6 +251,18 @@ class RenderTest < Test::Unit::TestCase
get :render_hello_world_with_forward_slash
assert_template "test/hello_world"
end
+
+ def test_render_in_top_directory
+ get :render_template_in_top_directory
+ assert_template "shared"
+ assert_equal "Elastica", @response.body
+ end
+
+ def test_render_in_top_directory_with_slash
+ get :render_template_in_top_directory_with_slash
+ assert_template "shared"
+ assert_equal "Elastica", @response.body
+ end
def test_render_from_variable
get :render_hello_world_from_variable
diff --git a/actionpack/test/controller/routing_test.rb b/actionpack/test/controller/routing_test.rb
index 5756c05e2e..640afd58f8 100644
--- a/actionpack/test/controller/routing_test.rb
+++ b/actionpack/test/controller/routing_test.rb
@@ -2341,11 +2341,13 @@ uses_mocha 'route loading' do
def setup
routes.instance_variable_set '@routes_last_modified', nil
silence_warnings { Object.const_set :RAILS_ROOT, '.' }
+ ActionController::Routing::Routes.configuration_file = File.join(RAILS_ROOT, 'config', 'routes.rb')
@stat = stub_everything
end
def teardown
+ ActionController::Routing::Routes.configuration_file = nil
Object.send :remove_const, :RAILS_ROOT
end
@@ -2386,6 +2388,14 @@ uses_mocha 'route loading' do
Inflector.inflections { |inflect| inflect.uncountable('equipment') }
end
+
+ def test_load_with_configuration
+ routes.configuration_file = "foobarbaz"
+ File.expects(:stat).returns(@stat)
+ routes.expects(:load).with("foobarbaz")
+
+ routes.reload
+ end
private
def routes
diff --git a/actionpack/test/controller/session/mem_cache_store_test.rb b/actionpack/test/controller/session/mem_cache_store_test.rb
index df48e6d9c5..a7d48431f8 100644
--- a/actionpack/test/controller/session/mem_cache_store_test.rb
+++ b/actionpack/test/controller/session/mem_cache_store_test.rb
@@ -62,9 +62,8 @@ class MemCacheStoreTest < Test::Unit::TestCase
assert_equal d, s.cache.get(session_key)[:test]
assert_equal d, s[:test]
end
- end
-
-
+ end
+
def test_deletion
new_session do |s|
session_key = 'session:' + s.session_id
diff --git a/actionpack/test/fixtures/company.rb b/actionpack/test/fixtures/company.rb
index 0d1c29b906..cbbd0edb14 100644
--- a/actionpack/test/fixtures/company.rb
+++ b/actionpack/test/fixtures/company.rb
@@ -1,4 +1,5 @@
class Company < ActiveRecord::Base
+ has_one :mascot
attr_protected :rating
set_sequence_name :companies_nonstd_seq
diff --git a/actionpack/test/fixtures/db_definitions/sqlite.sql b/actionpack/test/fixtures/db_definitions/sqlite.sql
index 358c2bbb04..8e1947d14a 100644
--- a/actionpack/test/fixtures/db_definitions/sqlite.sql
+++ b/actionpack/test/fixtures/db_definitions/sqlite.sql
@@ -41,3 +41,9 @@ CREATE TABLE 'developers_projects' (
'joined_on' DATE DEFAULT NULL,
'access_level' INTEGER DEFAULT 1
);
+
+CREATE TABLE 'mascots' (
+ 'id' INTEGER PRIMARY KEY NOT NULL,
+ 'company_id' INTEGER NOT NULL,
+ 'name' TEXT DEFAULT NULL
+); \ No newline at end of file
diff --git a/actionpack/test/fixtures/mascot.rb b/actionpack/test/fixtures/mascot.rb
new file mode 100644
index 0000000000..f9f1448b8f
--- /dev/null
+++ b/actionpack/test/fixtures/mascot.rb
@@ -0,0 +1,3 @@
+class Mascot < ActiveRecord::Base
+ belongs_to :company
+end \ No newline at end of file
diff --git a/actionpack/test/fixtures/mascots.yml b/actionpack/test/fixtures/mascots.yml
new file mode 100644
index 0000000000..17b7dff454
--- /dev/null
+++ b/actionpack/test/fixtures/mascots.yml
@@ -0,0 +1,4 @@
+upload_bird:
+ id: 1
+ company_id: 1
+ name: The Upload Bird \ No newline at end of file
diff --git a/actionpack/test/fixtures/mascots/_mascot.html.erb b/actionpack/test/fixtures/mascots/_mascot.html.erb
new file mode 100644
index 0000000000..432773a1da
--- /dev/null
+++ b/actionpack/test/fixtures/mascots/_mascot.html.erb
@@ -0,0 +1 @@
+<%= mascot.name %> \ No newline at end of file
diff --git a/actionpack/test/fixtures/reply.rb b/actionpack/test/fixtures/reply.rb
index 588713de1e..04598437c2 100644
--- a/actionpack/test/fixtures/reply.rb
+++ b/actionpack/test/fixtures/reply.rb
@@ -1,4 +1,5 @@
class Reply < ActiveRecord::Base
+ named_scope :base
belongs_to :topic, :include => [:replies]
belongs_to :developer
diff --git a/actionpack/test/fixtures/shared.html.erb b/actionpack/test/fixtures/shared.html.erb
new file mode 100644
index 0000000000..af262fc9f8
--- /dev/null
+++ b/actionpack/test/fixtures/shared.html.erb
@@ -0,0 +1 @@
+Elastica \ No newline at end of file
diff --git a/actionpack/test/fixtures/test/_raise.html.erb b/actionpack/test/fixtures/test/_raise.html.erb
new file mode 100644
index 0000000000..68b08181d3
--- /dev/null
+++ b/actionpack/test/fixtures/test/_raise.html.erb
@@ -0,0 +1 @@
+<%= doesnt_exist %> \ No newline at end of file
diff --git a/actionpack/test/template/benchmark_helper_test.rb b/actionpack/test/template/benchmark_helper_test.rb
index d95a3dee26..08d453c965 100644
--- a/actionpack/test/template/benchmark_helper_test.rb
+++ b/actionpack/test/template/benchmark_helper_test.rb
@@ -16,32 +16,20 @@ class BenchmarkHelperTest < ActionView::TestCase
end
end
- def setup
- @logger = MockLogger.new
- end
-
- def test_without_logger_or_block
- @logger = nil
- assert_nothing_raised { benchmark }
+ def controller
+ @controller ||= Struct.new(:logger).new(MockLogger.new)
end
def test_without_block
assert_raise(LocalJumpError) { benchmark }
- assert @logger.logged.empty?
- end
-
- def test_without_logger
- @logger = nil
- i_was_run = false
- benchmark { i_was_run = true }
- assert !i_was_run
+ assert controller.logger.logged.empty?
end
def test_defaults
i_was_run = false
benchmark { i_was_run = true }
assert i_was_run
- assert 1, @logger.logged.size
+ assert 1, controller.logger.logged.size
assert_last_logged
end
@@ -49,7 +37,7 @@ class BenchmarkHelperTest < ActionView::TestCase
i_was_run = false
benchmark('test_run') { i_was_run = true }
assert i_was_run
- assert 1, @logger.logged.size
+ assert 1, controller.logger.logged.size
assert_last_logged 'test_run'
end
@@ -57,13 +45,13 @@ class BenchmarkHelperTest < ActionView::TestCase
i_was_run = false
benchmark('debug_run', :debug) { i_was_run = true }
assert i_was_run
- assert 1, @logger.logged.size
+ assert 1, controller.logger.logged.size
assert_last_logged 'debug_run', :debug
end
private
def assert_last_logged(message = 'Benchmarking', level = :info)
- last = @logger.logged.last
+ last = controller.logger.logged.last
assert 2, last.size
assert_equal level, last.first
assert 1, last[1].size
diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb
index c48d5dfd2d..204575fd89 100644
--- a/actionpack/test/template/form_helper_test.rb
+++ b/actionpack/test/template/form_helper_test.rb
@@ -6,11 +6,11 @@ silence_warnings do
alias_method :title_before_type_cast, :title unless respond_to?(:title_before_type_cast)
alias_method :body_before_type_cast, :body unless respond_to?(:body_before_type_cast)
alias_method :author_name_before_type_cast, :author_name unless respond_to?(:author_name_before_type_cast)
-
+
def new_record=(boolean)
@new_record = boolean
end
-
+
def new_record?
@new_record
end
@@ -36,13 +36,13 @@ class FormHelperTest < ActionView::TestCase
def setup
@post = Post.new
@comment = Comment.new
- def @post.errors()
- Class.new{
- def on(field); "can't be empty" if field == "author_name"; end
- def empty?() false end
+ def @post.errors()
+ Class.new{
+ def on(field); "can't be empty" if field == "author_name"; end
+ def empty?() false end
def count() 1 end
- def full_messages() [ "Author name can't be empty" ] end
- }.new
+ def full_messages() [ "Author name can't be empty" ] end
+ }.new
end
def @post.id; 123; end
def @post.id_before_type_cast; 123; end
@@ -72,11 +72,19 @@ class FormHelperTest < ActionView::TestCase
label("post", "title", nil, :class => 'title_label')
)
end
-
+
def test_label_with_symbols
assert_dom_equal('<label for="post_title">Title</label>', label(:post, :title))
end
+ def test_label_with_for_attribute_as_symbol
+ assert_dom_equal('<label for="my_for">Title</label>', label(:post, :title, nil, :for => "my_for"))
+ end
+
+ def test_label_with_for_attribute_as_string
+ assert_dom_equal('<label for="my_for">Title</label>', label(:post, :title, nil, "for" => "my_for"))
+ end
+
def test_text_field
assert_dom_equal(
'<input id="post_title" name="post[title]" size="30" type="text" value="Hello World" />', text_field("post", "title")
@@ -96,6 +104,14 @@ class FormHelperTest < ActionView::TestCase
)
end
+ def test_text_field_with_html_entities
+ @post.title = "The HTML Entity for & is &amp;"
+ assert_dom_equal(
+ '<input id="post_title" name="post[title]" size="30" type="text" value="The HTML Entity for &amp; is &amp;amp;" />',
+ text_field("post", "title")
+ )
+ end
+
def test_text_field_with_options
expected = '<input id="post_title" name="post[title]" size="35" type="text" value="Hello World" />'
assert_dom_equal expected, text_field("post", "title", "size" => 35)
@@ -219,6 +235,14 @@ class FormHelperTest < ActionView::TestCase
)
end
+ def test_text_area_with_html_entities
+ @post.body = "The HTML Entity for & is &amp;"
+ assert_dom_equal(
+ '<textarea cols="40" id="post_body" name="post[body]" rows="20">The HTML Entity for &amp; is &amp;amp;</textarea>',
+ text_area("post", "body")
+ )
+ end
+
def test_text_area_with_size_option
assert_dom_equal(
'<textarea cols="183" id="post_body" name="post[body]" rows="820">Back to the hill and over it again!</textarea>',
@@ -303,7 +327,7 @@ class FormHelperTest < ActionView::TestCase
_erbout.concat f.submit('Create post')
end
- expected =
+ expected =
"<form action='http://www.example.com' id='create-post' method='post'>" +
"<label for='post_title'>Title</label>" +
"<input name='post[title]' size='30' type='text' id='post_title' value='Hello World' />" +
@@ -325,7 +349,7 @@ class FormHelperTest < ActionView::TestCase
_erbout.concat f.check_box(:secret)
end
- expected =
+ expected =
"<form action='http://www.example.com' id='create-post' method='post'>" +
"<div style='margin:0;padding:0'><input name='_method' type='hidden' value='put' /></div>" +
"<input name='post[title]' size='30' type='text' id='post_title' value='Hello World' />" +
@@ -346,7 +370,7 @@ class FormHelperTest < ActionView::TestCase
_erbout.concat f.check_box(:secret)
end
- expected =
+ expected =
"<form action='http://www.example.com' id='create-post' method='post'>" +
"<input name='post[title]' size='30' type='text' id='post_title' value='Hello World' />" +
"<textarea name='post[body]' id='post_body' rows='20' cols='40'>Back to the hill and over it again!</textarea>" +
@@ -367,7 +391,7 @@ class FormHelperTest < ActionView::TestCase
_erbout.concat f.check_box(:secret)
end
- expected =
+ expected =
"<form action='http://www.example.com' method='post'>" +
"<label for=\"post_123_title\">Title</label>" +
"<input name='post[123][title]' size='30' type='text' id='post_123_title' value='Hello World' />" +
@@ -423,7 +447,7 @@ class FormHelperTest < ActionView::TestCase
_erbout.concat f.check_box(:secret)
end
- expected =
+ expected =
"<input name='post[title]' size='30' type='text' id='post_title' value='Hello World' />" +
"<textarea name='post[body]' id='post_body' rows='20' cols='40'>Back to the hill and over it again!</textarea>" +
"<input name='post[secret]' checked='checked' type='checkbox' id='post_secret' value='1' />" +
@@ -494,7 +518,7 @@ class FormHelperTest < ActionView::TestCase
_erbout.concat f.check_box(:secret)
end
- expected =
+ expected =
"<input name='post[title]' size='30' type='text' id='post_title' value='Hello World' />" +
"<textarea name='post[body]' id='post_body' rows='20' cols='40'>Back to the hill and over it again!</textarea>" +
"<input name='post[secret]' checked='checked' type='checkbox' id='post_secret' value='1' />" +
@@ -511,7 +535,7 @@ class FormHelperTest < ActionView::TestCase
_erbout.concat f.check_box(:secret)
end
- expected =
+ expected =
"<input name='post[title]' size='30' type='text' id='post_title' value='Hello World' />" +
"<textarea name='post[body]' id='post_body' rows='20' cols='40'>Back to the hill and over it again!</textarea>" +
"<input name='post[secret]' checked='checked' type='checkbox' id='post_secret' value='1' />" +
@@ -532,6 +556,18 @@ class FormHelperTest < ActionView::TestCase
_erbout
end
+ def test_fields_for_object_with_bracketed_name_and_index
+ _erbout = ''
+ fields_for("author[post]", @post, :index => 1) do |f|
+ _erbout.concat f.label(:title)
+ _erbout.concat f.text_field(:title)
+ end
+
+ assert_dom_equal "<label for=\"author_post_1_title\">Title</label>" +
+ "<input name='author[post][1][title]' size='30' type='text' id='author_post_1_title' value='Hello World' />",
+ _erbout
+ end
+
def test_form_builder_does_not_have_form_for_method
assert ! ActionView::Helpers::FormBuilder.instance_methods.include?('form_for')
end
@@ -548,7 +584,7 @@ class FormHelperTest < ActionView::TestCase
end
end
- expected =
+ expected =
"<form action='http://www.example.com' id='create-post' method='post'>" +
"<input name='post[title]' size='30' type='text' id='post_title' value='Hello World' />" +
"<textarea name='post[body]' id='post_body' rows='20' cols='40'>Back to the hill and over it again!</textarea>" +
@@ -571,7 +607,7 @@ class FormHelperTest < ActionView::TestCase
end
end
- expected =
+ expected =
"<form action='http://www.example.com' id='create-post' method='post'>" +
"<input name='post[title]' size='30' type='text' id='post_title' value='Hello World' />" +
"<textarea name='post[body]' id='post_body' rows='20' cols='40'>Back to the hill and over it again!</textarea>" +
@@ -601,7 +637,7 @@ class FormHelperTest < ActionView::TestCase
_erbout.concat f.check_box(:secret)
end
- expected =
+ expected =
"<form action='http://www.example.com' method='post'>" +
"<label for='title'>Title:</label> <input name='post[title]' size='30' type='text' id='post_title' value='Hello World' /><br/>" +
"<label for='body'>Body:</label> <textarea name='post[body]' id='post_body' rows='20' cols='40'>Back to the hill and over it again!</textarea><br/>" +
@@ -623,7 +659,7 @@ class FormHelperTest < ActionView::TestCase
_erbout.concat f.check_box(:secret)
end
- expected =
+ expected =
"<form action='http://www.example.com' method='post'>" +
"<label for='title'>Title:</label> <input name='post[title]' size='30' type='text' id='post_title' value='Hello World' /><br/>" +
"<label for='body'>Body:</label> <textarea name='post[body]' id='post_body' rows='20' cols='40'>Back to the hill and over it again!</textarea><br/>" +
@@ -637,39 +673,39 @@ class FormHelperTest < ActionView::TestCase
end
def test_default_form_builder_with_active_record_helpers
-
- _erbout = ''
+
+ _erbout = ''
form_for(:post, @post) do |f|
_erbout.concat f.error_message_on('author_name')
_erbout.concat f.error_messages
- end
-
- expected = %(<form action='http://www.example.com' method='post'>) +
- %(<div class='formError'>can't be empty</div>) +
+ end
+
+ expected = %(<form action='http://www.example.com' method='post'>) +
+ %(<div class='formError'>can't be empty</div>) +
%(<div class="errorExplanation" id="errorExplanation"><h2>1 error prohibited this post from being saved</h2><p>There were problems with the following fields:</p><ul><li>Author name can't be empty</li></ul></div>) +
%(</form>)
-
+
assert_dom_equal expected, _erbout
end
-
+
def test_default_form_builder_no_instance_variable
post = @post
@post = nil
-
- _erbout = ''
+
+ _erbout = ''
form_for(:post, post) do |f|
_erbout.concat f.error_message_on('author_name')
_erbout.concat f.error_messages
- end
-
- expected = %(<form action='http://www.example.com' method='post'>) +
- %(<div class='formError'>can't be empty</div>) +
+ end
+
+ expected = %(<form action='http://www.example.com' method='post'>) +
+ %(<div class='formError'>can't be empty</div>) +
%(<div class="errorExplanation" id="errorExplanation"><h2>1 error prohibited this post from being saved</h2><p>There were problems with the following fields:</p><ul><li>Author name can't be empty</li></ul></div>) +
%(</form>)
-
+
assert_dom_equal expected, _erbout
-
+
end
# Perhaps this test should be moved to prototype helper tests.
@@ -683,7 +719,7 @@ class FormHelperTest < ActionView::TestCase
_erbout.concat f.check_box(:secret)
end
- expected =
+ expected =
%(<form action="http://www.example.com" onsubmit="new Ajax.Request('http://www.example.com', {asynchronous:true, evalScripts:true, parameters:Form.serialize(this)}); return false;" method="post">) +
"<label for='title'>Title:</label> <input name='post[title]' size='30' type='text' id='post_title' value='Hello World' /><br/>" +
"<label for='body'>Body:</label> <textarea name='post[body]' id='post_body' rows='20' cols='40'>Back to the hill and over it again!</textarea><br/>" +
@@ -693,31 +729,31 @@ class FormHelperTest < ActionView::TestCase
assert_dom_equal expected, _erbout
end
-
+
def test_fields_for_with_labelled_builder
_erbout = ''
-
+
fields_for(:post, @post, :builder => LabelledFormBuilder) do |f|
_erbout.concat f.text_field(:title)
_erbout.concat f.text_area(:body)
_erbout.concat f.check_box(:secret)
end
-
- expected =
+
+ expected =
"<label for='title'>Title:</label> <input name='post[title]' size='30' type='text' id='post_title' value='Hello World' /><br/>" +
"<label for='body'>Body:</label> <textarea name='post[body]' id='post_body' rows='20' cols='40'>Back to the hill and over it again!</textarea><br/>" +
"<label for='secret'>Secret:</label> <input name='post[secret]' checked='checked' type='checkbox' id='post_secret' value='1' />" +
"<input name='post[secret]' type='hidden' value='0' /><br/>"
-
+
assert_dom_equal expected, _erbout
end
def test_form_for_with_html_options_adds_options_to_form_tag
_erbout = ''
-
+
form_for(:post, @post, :html => {:id => 'some_form', :class => 'some_class'}) do |f| end
expected = "<form action=\"http://www.example.com\" class=\"some_class\" id=\"some_form\" method=\"post\"></form>"
-
+
assert_dom_equal expected, _erbout
end
@@ -793,16 +829,16 @@ class FormHelperTest < ActionView::TestCase
@comment.save
_erbout = ''
form_for([:admin, @post, @comment]) {}
-
+
expected = %(<form action="#{admin_comment_path(@post, @comment)}" class="edit_comment" id="edit_comment_1" method="post"><div style="margin:0;padding:0"><input name="_method" type="hidden" value="put" /></div></form>)
assert_dom_equal expected, _erbout
end
-
+
def test_form_for_with_new_object_and_namespace_in_list
@post.new_record = false
_erbout = ''
form_for([:admin, @post, @comment]) {}
-
+
expected = %(<form action="#{admin_comments_path(@post)}" class="new_comment" id="new_comment" method="post"></form>)
assert_dom_equal expected, _erbout
end
@@ -819,10 +855,10 @@ class FormHelperTest < ActionView::TestCase
def test_remote_form_for_with_html_options_adds_options_to_form_tag
self.extend ActionView::Helpers::PrototypeHelper
_erbout = ''
-
+
remote_form_for(:post, @post, :html => {:id => 'some_form', :class => 'some_class'}) do |f| end
expected = "<form action=\"http://www.example.com\" class=\"some_class\" id=\"some_form\" method=\"post\" onsubmit=\"new Ajax.Request('http://www.example.com', {asynchronous:true, evalScripts:true, parameters:Form.serialize(this)}); return false;\"></form>"
-
+
assert_dom_equal expected, _erbout
end
@@ -837,21 +873,21 @@ class FormHelperTest < ActionView::TestCase
"/posts/#{post.id}/comments/#{comment.id}"
end
alias_method :post_comment_path, :comment_path
-
+
def admin_comments_path(post)
"/admin/posts/#{post.id}/comments"
end
alias_method :admin_post_comments_path, :admin_comments_path
-
+
def admin_comment_path(post, comment)
"/admin/posts/#{post.id}/comments/#{comment.id}"
end
alias_method :admin_post_comment_path, :admin_comment_path
-
+
def posts_path
"/posts"
- end
-
+ end
+
def post_path(post)
"/posts/#{post.id}"
end
diff --git a/actionpack/test/template/template_finder_test.rb b/actionpack/test/template/template_finder_test.rb
index a162640de3..3d6baff5fb 100644
--- a/actionpack/test/template/template_finder_test.rb
+++ b/actionpack/test/template/template_finder_test.rb
@@ -21,13 +21,14 @@ class TemplateFinderTest < Test::Unit::TestCase
assert_equal ["builder", "erb", "rhtml", "rjs", "rxml", "mab"].sort,
ActionView::TemplateFinder.file_extension_cache[LOAD_PATH_ROOT].values.flatten.uniq.sort
- assert_equal Dir.glob("#{LOAD_PATH_ROOT}/**/*/*.{erb,rjs,rhtml,builder,rxml,mab}").size,
+ assert_equal (Dir.glob("#{LOAD_PATH_ROOT}/**/*/*.{erb,rjs,rhtml,builder,rxml,mab}") |
+ Dir.glob("#{LOAD_PATH_ROOT}/**.{erb,rjs,rhtml,builder,rxml,mab}")).size,
ActionView::TemplateFinder.file_extension_cache[LOAD_PATH_ROOT].keys.size
end
def test_should_cache_dir_content_properly
assert ActionView::TemplateFinder.processed_view_paths[LOAD_PATH_ROOT]
- assert_equal Dir.glob("#{LOAD_PATH_ROOT}/**/*/**").find_all {|f| !File.directory?(f) }.size,
+ assert_equal (Dir.glob("#{LOAD_PATH_ROOT}/**/*/**") | Dir.glob("#{LOAD_PATH_ROOT}/**")).find_all {|f| !File.directory?(f) }.size,
ActionView::TemplateFinder.processed_view_paths[LOAD_PATH_ROOT].size
end
diff --git a/actionpack/test/template/template_object_test.rb b/actionpack/test/template/template_object_test.rb
index 7adcde421f..afb5c5cc16 100644
--- a/actionpack/test/template/template_object_test.rb
+++ b/actionpack/test/template/template_object_test.rb
@@ -51,6 +51,11 @@ class TemplateObjectTest < Test::Unit::TestCase
assert template.locals.has_key?(:partial_only)
end
+ def test_partial_with_errors
+ template = ActionView::PartialTemplate.new(@view, 'test/raise', nil)
+ assert_raise(ActionView::TemplateError) { template.render_template }
+ end
+
uses_mocha 'Partial template preparation tests' do
def test_should_prepare_on_initialization
ActionView::PartialTemplate.any_instance.expects(:prepare!)