diff options
author | Pratik Naik <pratiknaik@gmail.com> | 2008-11-02 03:52:15 +0530 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2008-11-02 03:52:15 +0530 |
commit | 1147453fce0890ea229c3af5f43c909ebe53061e (patch) | |
tree | 221d816ef0c908044fd6029950ccad064866ab8f /actionpack/test | |
parent | a3aa0c17ef8594a0084511f4852be7b5dc66e5e2 (diff) | |
parent | 5a02f0bccf55191c2cfbcc69bd8165df6d7a2012 (diff) | |
download | rails-1147453fce0890ea229c3af5f43c909ebe53061e.tar.gz rails-1147453fce0890ea229c3af5f43c909ebe53061e.tar.bz2 rails-1147453fce0890ea229c3af5f43c909ebe53061e.zip |
Merge commit 'mainstream/master'
Conflicts:
railties/doc/guides/html/layouts_and_rendering.html
railties/doc/guides/source/active_record_basics.txt
railties/doc/guides/source/layouts_and_rendering.txt
Diffstat (limited to 'actionpack/test')
-rw-r--r-- | actionpack/test/controller/redirect_test.rb | 10 | ||||
-rw-r--r-- | actionpack/test/controller/render_test.rb | 20 | ||||
-rw-r--r-- | actionpack/test/fixtures/layouts/_column.html.erb | 2 | ||||
-rw-r--r-- | actionpack/test/fixtures/test/_customer.erb | 2 | ||||
-rw-r--r-- | actionpack/test/fixtures/test/nested_layout.erb | 3 | ||||
-rw-r--r-- | actionpack/test/fixtures/test/template.erb | 1 | ||||
-rw-r--r-- | actionpack/test/template/asset_tag_helper_test.rb | 8 | ||||
-rw-r--r-- | actionpack/test/template/render_test.rb | 18 | ||||
-rw-r--r-- | actionpack/test/template/translation_helper_test.rb | 4 | ||||
-rw-r--r-- | actionpack/test/template/url_helper_test.rb | 23 |
10 files changed, 88 insertions, 3 deletions
diff --git a/actionpack/test/controller/redirect_test.rb b/actionpack/test/controller/redirect_test.rb index 2f8bf7b6ee..c55307d645 100644 --- a/actionpack/test/controller/redirect_test.rb +++ b/actionpack/test/controller/redirect_test.rb @@ -73,6 +73,10 @@ class RedirectController < ActionController::Base redirect_to "http://dev.rubyonrails.org/query?status=new" end + def redirect_to_url_with_complex_scheme + redirect_to "x-test+scheme.complex:redirect" + end + def redirect_to_back redirect_to :back end @@ -198,6 +202,12 @@ class RedirectTest < Test::Unit::TestCase assert_redirected_to "http://dev.rubyonrails.org/query?status=new" end + def test_redirect_to_url_with_complex_scheme + get :redirect_to_url_with_complex_scheme + assert_response :redirect + assert_equal "x-test+scheme.complex:redirect", redirect_to_url + end + def test_redirect_to_back @request.env["HTTP_REFERER"] = "http://www.example.com/coming/from" get :redirect_to_back diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb index db2d5d885b..df9376727f 100644 --- a/actionpack/test/controller/render_test.rb +++ b/actionpack/test/controller/render_test.rb @@ -154,6 +154,10 @@ class TestController < ActionController::Base render :json => {:hello => 'world'}.to_json end + def render_json_with_render_to_string + render :json => {:hello => render_to_string(:partial => 'partial')} + end + def render_custom_code render :text => "hello world", :status => 404 end @@ -180,6 +184,10 @@ class TestController < ActionController::Base render("test/hello") end + def render_vanilla_js_hello + render :js => "alert('hello')" + end + def render_xml_hello @name = "David" render :template => "test/hello" @@ -772,6 +780,12 @@ class RenderTest < Test::Unit::TestCase assert_equal 'application/json', @response.content_type end + def test_render_json_with_render_to_string + get :render_json_with_render_to_string + assert_equal '{"hello": "partial html"}', @response.body + assert_equal 'application/json', @response.content_type + end + def test_render_custom_code get :render_custom_code assert_response 404 @@ -834,6 +848,12 @@ class RenderTest < Test::Unit::TestCase assert_equal "test", @response.body # name is explicitly set to 'test' inside the controller. end + def test_render_vanilla_js + get :render_vanilla_js_hello + assert_equal "alert('hello')", @response.body + assert_equal "text/javascript", @response.content_type + end + def test_render_xml get :render_xml_hello assert_equal "<html>\n <p>Hello David</p>\n<p>This is grand!</p>\n</html>\n", @response.body diff --git a/actionpack/test/fixtures/layouts/_column.html.erb b/actionpack/test/fixtures/layouts/_column.html.erb new file mode 100644 index 0000000000..96db002b8a --- /dev/null +++ b/actionpack/test/fixtures/layouts/_column.html.erb @@ -0,0 +1,2 @@ +<div id="column"><%= yield :column %></div> +<div id="content"><%= yield %></div>
\ No newline at end of file diff --git a/actionpack/test/fixtures/test/_customer.erb b/actionpack/test/fixtures/test/_customer.erb index 872d8c44e6..d8220afeda 100644 --- a/actionpack/test/fixtures/test/_customer.erb +++ b/actionpack/test/fixtures/test/_customer.erb @@ -1 +1 @@ -Hello: <%= customer.name %>
\ No newline at end of file +Hello: <%= customer.name rescue "Anonymous" %>
\ No newline at end of file diff --git a/actionpack/test/fixtures/test/nested_layout.erb b/actionpack/test/fixtures/test/nested_layout.erb new file mode 100644 index 0000000000..7b6dcbb6c7 --- /dev/null +++ b/actionpack/test/fixtures/test/nested_layout.erb @@ -0,0 +1,3 @@ +<% content_for :title, "title" -%> +<% content_for :column do -%>column<% end -%> +<% render :layout => 'layouts/column' do -%>content<% end -%>
\ No newline at end of file diff --git a/actionpack/test/fixtures/test/template.erb b/actionpack/test/fixtures/test/template.erb new file mode 100644 index 0000000000..785afa8f6a --- /dev/null +++ b/actionpack/test/fixtures/test/template.erb @@ -0,0 +1 @@ +<%= template.path %>
\ No newline at end of file diff --git a/actionpack/test/template/asset_tag_helper_test.rb b/actionpack/test/template/asset_tag_helper_test.rb index 6dc1225035..bade96fe17 100644 --- a/actionpack/test/template/asset_tag_helper_test.rb +++ b/actionpack/test/template/asset_tag_helper_test.rb @@ -248,6 +248,14 @@ class AssetTagHelperTest < ActionView::TestCase assert_equal %(<img alt="Rails" src="/images/rails.png?#{expected_time}" />), image_tag("rails.png") end + def test_timebased_asset_id_with_relative_url_root + ActionController::Base.relative_url_root = "/collaboration/hieraki" + expected_time = File.stat(File.expand_path(File.dirname(__FILE__) + "/../fixtures/public/images/rails.png")).mtime.to_i.to_s + assert_equal %(<img alt="Rails" src="#{ActionController::Base.relative_url_root}/images/rails.png?#{expected_time}" />), image_tag("rails.png") + ensure + ActionController::Base.relative_url_root = "" + end + def test_should_skip_asset_id_on_complete_url assert_equal %(<img alt="Rails" src="http://www.example.com/rails.png" />), image_tag("http://www.example.com/rails.png") end diff --git a/actionpack/test/template/render_test.rb b/actionpack/test/template/render_test.rb index a4ea22ddcb..476e651757 100644 --- a/actionpack/test/template/render_test.rb +++ b/actionpack/test/template/render_test.rb @@ -41,6 +41,10 @@ class ViewRenderTest < Test::Unit::TestCase assert_equal "The secret is in the sauce\n", @view.render("test/dot.directory/render_file_with_ivar") end + def test_render_has_access_current_template + assert_equal "test/template.erb", @view.render("test/template.erb") + end + def test_render_update # TODO: You should not have to stub out template because template is self! @view.instance_variable_set(:@template, @view) @@ -111,6 +115,10 @@ class ViewRenderTest < Test::Unit::TestCase assert_nil @view.render(:partial => "test/customer", :collection => nil) end + def test_render_partial_with_nil_values_in_collection + assert_equal "Hello: davidHello: Anonymous", @view.render(:partial => "test/customer", :collection => [ Customer.new("david"), nil ]) + end + def test_render_partial_with_empty_array_should_return_nil assert_nil @view.render(:partial => []) end @@ -158,4 +166,14 @@ class ViewRenderTest < Test::Unit::TestCase ActionView::Template.register_template_handler :foo, CustomHandler assert_equal 'source: "Hello, <%= name %>!"', @view.render(:inline => "Hello, <%= name %>!", :locals => { :name => "Josh" }, :type => :foo) end + + def test_render_with_layout + assert_equal %(<title></title>\nHello world!\n), + @view.render(:file => "test/hello_world.erb", :layout => "layouts/yield") + end + + def test_render_with_nested_layout + assert_equal %(<title>title</title>\n<div id="column">column</div>\n<div id="content">content</div>\n), + @view.render(:file => "test/nested_layout.erb", :layout => "layouts/yield") + end end diff --git a/actionpack/test/template/translation_helper_test.rb b/actionpack/test/template/translation_helper_test.rb index 7b94221ec0..1b28a59288 100644 --- a/actionpack/test/template/translation_helper_test.rb +++ b/actionpack/test/template/translation_helper_test.rb @@ -10,8 +10,8 @@ class TranslationHelperTest < Test::Unit::TestCase end def test_delegates_to_i18n_setting_the_raise_option - I18n.expects(:translate).with(:foo, 'en-US', :raise => true) - translate :foo, 'en-US' + I18n.expects(:translate).with(:foo, :locale => 'en-US', :raise => true) + translate :foo, :locale => 'en-US' end def test_returns_missing_translation_message_wrapped_into_span diff --git a/actionpack/test/template/url_helper_test.rb b/actionpack/test/template/url_helper_test.rb index 85e967ac1c..2f6fa134b5 100644 --- a/actionpack/test/template/url_helper_test.rb +++ b/actionpack/test/template/url_helper_test.rb @@ -258,6 +258,16 @@ class UrlHelperTest < ActionView::TestCase assert_equal "Showing", link_to_unless_current("Showing", { :action => "show", :controller => "weblog" }) assert_equal "Showing", link_to_unless_current("Showing", "http://www.example.com/weblog/show") + @controller.request = RequestMock.new("http://www.example.com/weblog/show?order=desc") + @controller.url = "http://www.example.com/weblog/show" + assert_equal "Showing", link_to_unless_current("Showing", { :action => "show", :controller => "weblog" }) + assert_equal "Showing", link_to_unless_current("Showing", "http://www.example.com/weblog/show") + + @controller.request = RequestMock.new("http://www.example.com/weblog/show?order=desc") + @controller.url = "http://www.example.com/weblog/show?order=asc" + assert_equal "<a href=\"http://www.example.com/weblog/show?order=asc\">Showing</a>", link_to_unless_current("Showing", { :action => "show", :controller => "weblog" }) + assert_equal "<a href=\"http://www.example.com/weblog/show?order=asc\">Showing</a>", link_to_unless_current("Showing", "http://www.example.com/weblog/show?order=asc") + @controller.request = RequestMock.new("http://www.example.com/weblog/show") @controller.url = "http://www.example.com/weblog/list" assert_equal "<a href=\"http://www.example.com/weblog/list\">Listing</a>", @@ -366,6 +376,19 @@ class UrlHelperWithControllerTest < ActionView::TestCase assert_equal '/url_helper_with_controller/nil_url_for', @response.body end + def test_named_route_should_show_host_and_path_using_controller_default_url_options + class << @controller + def default_url_options(options = nil) + {:host => 'testtwo.host'} + end + end + + with_url_helper_routing do + get :show_named_route, :kind => 'url' + assert_equal 'http://testtwo.host/url_helper_with_controller/show_named_route', @response.body + end + end + protected def with_url_helper_routing with_routing do |set| |