aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/template
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack/test/template')
-rw-r--r--actionpack/test/template/lookup_context_test.rb4
-rw-r--r--actionpack/test/template/record_tag_helper_test.rb41
-rw-r--r--actionpack/test/template/render_test.rb7
-rw-r--r--actionpack/test/template/template_test.rb2
4 files changed, 31 insertions, 23 deletions
diff --git a/actionpack/test/template/lookup_context_test.rb b/actionpack/test/template/lookup_context_test.rb
index c65f707da0..96b14a0acd 100644
--- a/actionpack/test/template/lookup_context_test.rb
+++ b/actionpack/test/template/lookup_context_test.rb
@@ -78,9 +78,9 @@ class LookupContextTest < ActiveSupport::TestCase
end
test "found templates respects given formats if one cannot be found from template or handler" do
- ActionView::Template::Handlers::ERB.expects(:default_format).returns(nil)
+ ActionView::Template::Handlers::Builder.expects(:default_format).returns(nil)
@lookup_context.formats = [:text]
- template = @lookup_context.find("hello_world", %w(test))
+ template = @lookup_context.find("hello", %w(test))
assert_equal [:text], template.formats
end
diff --git a/actionpack/test/template/record_tag_helper_test.rb b/actionpack/test/template/record_tag_helper_test.rb
index ec777d15c4..80d6f130ed 100644
--- a/actionpack/test/template/record_tag_helper_test.rb
+++ b/actionpack/test/template/record_tag_helper_test.rb
@@ -1,15 +1,15 @@
require 'abstract_unit'
require 'controller/fake_models'
-class Post
+class RecordTagPost
extend ActiveModel::Naming
include ActiveModel::Conversion
- attr_writer :id, :body
+ attr_writer :id, :body, :persisted
def initialize
@id = nil
@body = nil
- super
+ @persisted = false
end
def id
@@ -17,8 +17,11 @@ class Post
end
def body
- super || @body || "What a wonderful world!"
+ @body || "What a wonderful world!"
end
+
+ def persisted?; @persisted end
+
end
class RecordTagHelperTest < ActionView::TestCase
@@ -28,30 +31,30 @@ class RecordTagHelperTest < ActionView::TestCase
def setup
super
- @post = Post.new
+ @post = RecordTagPost.new
@post.persisted = true
end
def test_content_tag_for
- expected = %(<li class="post bar" id="post_45"></li>)
+ expected = %(<li class="record_tag_post bar" id="record_tag_post_45"></li>)
actual = content_tag_for(:li, @post, :class => 'bar') { }
assert_dom_equal expected, actual
end
def test_content_tag_for_prefix
- expected = %(<ul class="archived_post" id="archived_post_45"></ul>)
+ expected = %(<ul class="archived_record_tag_post" id="archived_record_tag_post_45"></ul>)
actual = content_tag_for(:ul, @post, :archived) { }
assert_dom_equal expected, actual
end
def test_content_tag_for_with_extra_html_tags
- expected = %(<tr class="post bar" id="post_45" style='background-color: #f0f0f0'></tr>)
+ expected = %(<tr class="record_tag_post bar" id="record_tag_post_45" style='background-color: #f0f0f0'></tr>)
actual = content_tag_for(:tr, @post, {:class => "bar", :style => "background-color: #f0f0f0"}) { }
assert_dom_equal expected, actual
end
def test_block_not_in_erb_multiple_calls
- expected = %(<div class="post bar" id="post_45">#{@post.body}</div>)
+ expected = %(<div class="record_tag_post bar" id="record_tag_post_45">#{@post.body}</div>)
actual = div_for(@post, :class => "bar") { @post.body }
assert_dom_equal expected, actual
actual = div_for(@post, :class => "bar") { @post.body }
@@ -59,29 +62,29 @@ class RecordTagHelperTest < ActionView::TestCase
end
def test_block_works_with_content_tag_for_in_erb
- expected = %(<tr class="post" id="post_45">#{@post.body}</tr>)
+ expected = %(<tr class="record_tag_post" id="record_tag_post_45">#{@post.body}</tr>)
actual = render_erb("<%= content_tag_for(:tr, @post) do %><%= @post.body %><% end %>")
assert_dom_equal expected, actual
end
def test_div_for_in_erb
- expected = %(<div class="post bar" id="post_45">#{@post.body}</div>)
+ expected = %(<div class="record_tag_post bar" id="record_tag_post_45">#{@post.body}</div>)
actual = render_erb("<%= div_for(@post, :class => 'bar') do %><%= @post.body %><% end %>")
assert_dom_equal expected, actual
end
def test_content_tag_for_collection
- post_1 = Post.new.tap { |post| post.id = 101; post.body = "Hello!"; post.persisted = true }
- post_2 = Post.new.tap { |post| post.id = 102; post.body = "World!"; post.persisted = true }
- expected = %(<li class="post" id="post_101">Hello!</li>\n<li class="post" id="post_102">World!</li>)
+ post_1 = RecordTagPost.new.tap { |post| post.id = 101; post.body = "Hello!"; post.persisted = true }
+ post_2 = RecordTagPost.new.tap { |post| post.id = 102; post.body = "World!"; post.persisted = true }
+ expected = %(<li class="record_tag_post" id="record_tag_post_101">Hello!</li>\n<li class="record_tag_post" id="record_tag_post_102">World!</li>)
actual = content_tag_for(:li, [post_1, post_2]) { |post| concat post.body }
assert_dom_equal expected, actual
end
def test_div_for_collection
- post_1 = Post.new.tap { |post| post.id = 101; post.body = "Hello!"; post.persisted = true }
- post_2 = Post.new.tap { |post| post.id = 102; post.body = "World!"; post.persisted = true }
- expected = %(<div class="post" id="post_101">Hello!</div>\n<div class="post" id="post_102">World!</div>)
+ post_1 = RecordTagPost.new.tap { |post| post.id = 101; post.body = "Hello!"; post.persisted = true }
+ post_2 = RecordTagPost.new.tap { |post| post.id = 102; post.body = "World!"; post.persisted = true }
+ expected = %(<div class="record_tag_post" id="record_tag_post_101">Hello!</div>\n<div class="record_tag_post" id="record_tag_post_102">World!</div>)
actual = div_for([post_1, post_2]) { |post| concat post.body }
assert_dom_equal expected, actual
end
@@ -92,8 +95,8 @@ class RecordTagHelperTest < ActionView::TestCase
end
def test_content_tag_for_collection_is_html_safe
- post_1 = Post.new.tap { |post| post.id = 101; post.body = "Hello!"; post.persisted = true }
- post_2 = Post.new.tap { |post| post.id = 102; post.body = "World!"; post.persisted = true }
+ post_1 = RecordTagPost.new.tap { |post| post.id = 101; post.body = "Hello!"; post.persisted = true }
+ post_2 = RecordTagPost.new.tap { |post| post.id = 102; post.body = "World!"; post.persisted = true }
result = content_tag_for(:li, [post_1, post_2]) { |post| concat post.body }
assert result.html_safe?
end
diff --git a/actionpack/test/template/render_test.rb b/actionpack/test/template/render_test.rb
index 4eb3754a50..503bbb207e 100644
--- a/actionpack/test/template/render_test.rb
+++ b/actionpack/test/template/render_test.rb
@@ -51,9 +51,14 @@ module RenderTestCases
assert_match "<error>No Comment</error>", @view.render(:template => "comments/empty", :formats => [:xml])
end
+ def test_render_partial_implicitly_use_format_of_the_rendered_template
+ @view.lookup_context.formats = [:json]
+ assert_equal "Hello world", @view.render(:template => "test/one", :formats => [:html])
+ end
+
def test_render_template_with_a_missing_partial_of_another_format
+ @view.lookup_context.formats = [:html]
assert_raise ActionView::Template::Error, "Missing partial /missing with {:locale=>[:en], :formats=>[:json], :handlers=>[:erb, :builder]}" do
- @view.lookup_context.freeze_formats([:html])
@view.render(:template => "with_format", :formats => [:json])
end
end
diff --git a/actionpack/test/template/template_test.rb b/actionpack/test/template/template_test.rb
index 836c5c7586..dd45a08b01 100644
--- a/actionpack/test/template/template_test.rb
+++ b/actionpack/test/template/template_test.rb
@@ -12,7 +12,7 @@ class TestERBTemplate < ActiveSupport::TestCase
def find_template(*args)
end
- attr_writer :formats
+ attr_accessor :formats
end
class Context