diff options
Diffstat (limited to 'actionpack/test')
-rwxr-xr-x | actionpack/test/controller/redirect_test.rb | 40 | ||||
-rw-r--r-- | actionpack/test/template/active_record_helper_test.rb | 2 | ||||
-rw-r--r-- | actionpack/test/template/asset_tag_helper_test.rb | 2 | ||||
-rw-r--r-- | actionpack/test/template/form_helper_test.rb | 20 | ||||
-rw-r--r-- | actionpack/test/template/form_tag_helper_test.rb | 6 | ||||
-rw-r--r-- | actionpack/test/template/java_script_macros_helper_test.rb | 2 | ||||
-rw-r--r-- | actionpack/test/template/prototype_helper_test.rb | 2 | ||||
-rw-r--r-- | actionpack/test/template/scriptaculous_helper_test.rb | 2 | ||||
-rw-r--r-- | actionpack/test/template/url_helper_test.rb | 73 |
9 files changed, 136 insertions, 13 deletions
diff --git a/actionpack/test/controller/redirect_test.rb b/actionpack/test/controller/redirect_test.rb index df037ec28d..c7e4c19a0a 100755 --- a/actionpack/test/controller/redirect_test.rb +++ b/actionpack/test/controller/redirect_test.rb @@ -1,5 +1,24 @@ require File.dirname(__FILE__) + '/../abstract_unit' +class WorkshopsController < ActionController::Base +end + +class Workshop + attr_accessor :id, :new_record + + def initialize(id, new_record) + @id, @new_record = id, new_record + end + + def new_record? + @new_record + end + + def to_s + id.to_s + end +end + class RedirectController < ActionController::Base def simple_redirect redirect_to :action => "hello_world" @@ -22,6 +41,14 @@ class RedirectController < ActionController::Base redirect_to :back end + def redirect_to_existing_record + redirect_to Workshop.new(5, false) + end + + def redirect_to_new_record + redirect_to Workshop.new(5, true) + end + def rescue_errors(e) raise e end def rescue_action(e) raise end @@ -97,6 +124,19 @@ class RedirectTest < Test::Unit::TestCase get :redirect_to_back } end + + def test_redirect_to_record + ActionController::Routing::Routes.draw do |map| + map.resources :workshops + map.connect ':controller/:action/:id' + end + + get :redirect_to_existing_record + assert_equal "http://test.host/workshops/5", redirect_to_url + + get :redirect_to_new_record + assert_equal "http://test.host/workshops", redirect_to_url + end end module ModuleTest diff --git a/actionpack/test/template/active_record_helper_test.rb b/actionpack/test/template/active_record_helper_test.rb index c1dc73990d..5eab1c8525 100644 --- a/actionpack/test/template/active_record_helper_test.rb +++ b/actionpack/test/template/active_record_helper_test.rb @@ -83,7 +83,7 @@ class ActiveRecordHelperTest < Test::Unit::TestCase setup_user @controller = Object.new - def @controller.url_for(options, *parameters_for_method_reference) + def @controller.url_for(options) options = options.symbolize_keys [options[:action], options[:id].to_param].compact.join('/') diff --git a/actionpack/test/template/asset_tag_helper_test.rb b/actionpack/test/template/asset_tag_helper_test.rb index 71378584fa..cd4b56a2a0 100644 --- a/actionpack/test/template/asset_tag_helper_test.rb +++ b/actionpack/test/template/asset_tag_helper_test.rb @@ -303,7 +303,7 @@ class AssetTagHelperNonVhostTest < Test::Unit::TestCase @controller = Class.new do attr_accessor :request - def url_for(options, *parameters_for_method_reference) + def url_for(options) "http://www.example.com/collaboration/hieraki" end end.new diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb index c5e7505a36..a7336c5b08 100644 --- a/actionpack/test/template/form_helper_test.rb +++ b/actionpack/test/template/form_helper_test.rb @@ -38,7 +38,7 @@ class FormHelperTest < Test::Unit::TestCase @controller = Class.new do attr_reader :url_for_options - def url_for(options, *parameters_for_method_reference) + def url_for(options) @url_for_options = options "http://www.example.com" end @@ -528,7 +528,7 @@ class FormHelperTest < Test::Unit::TestCase form_for(:post, @post, :url => 'http://www.otherdomain.com') do |f| end - assert_equal 'http://www.otherdomain.com', @controller.url_for_options + assert_equal '<form action="http://www.otherdomain.com" method="post"></form>', _erbout end def test_form_for_with_hash_url_option @@ -540,6 +540,14 @@ class FormHelperTest < Test::Unit::TestCase assert_equal 'action', @controller.url_for_options[:action] end + def test_form_for_with_record_url_option + _erbout = '' + + form_for(:post, @post, :url => @post) do |f| end + + expected = "<form action=\"/posts/123\" method=\"post\"></form>" + end + def test_remote_form_for_with_html_options_adds_options_to_form_tag self.extend ActionView::Helpers::PrototypeHelper _erbout = '' @@ -549,4 +557,10 @@ class FormHelperTest < Test::Unit::TestCase assert_dom_equal expected, _erbout end -end + + + protected + def polymorphic_path(record, url_writer) + "/posts/#{record.id}" + end +end
\ No newline at end of file diff --git a/actionpack/test/template/form_tag_helper_test.rb b/actionpack/test/template/form_tag_helper_test.rb index 8b5d09d2a6..2390edff86 100644 --- a/actionpack/test/template/form_tag_helper_test.rb +++ b/actionpack/test/template/form_tag_helper_test.rb @@ -9,7 +9,7 @@ class FormTagHelperTest < Test::Unit::TestCase def setup @controller = Class.new do - def url_for(options, *parameters_for_method_reference) + def url_for(options) "http://www.example.com" end end @@ -44,7 +44,7 @@ class FormTagHelperTest < Test::Unit::TestCase _erbout = '' form_tag("http://example.com") { _erbout.concat "Hello world!" } - expected = %(<form action="http://www.example.com" method="post">Hello world!</form>) + expected = %(<form action="http://example.com" method="post">Hello world!</form>) assert_dom_equal expected, _erbout end @@ -52,7 +52,7 @@ class FormTagHelperTest < Test::Unit::TestCase _erbout = '' form_tag("http://example.com", :method => :put) { _erbout.concat "Hello world!" } - expected = %(<form action="http://www.example.com" method="post"><div style='margin:0;padding:0'><input type="hidden" name="_method" value="put" /></div>Hello world!</form>) + expected = %(<form action="http://example.com" method="post"><div style='margin:0;padding:0'><input type="hidden" name="_method" value="put" /></div>Hello world!</form>) assert_dom_equal expected, _erbout end diff --git a/actionpack/test/template/java_script_macros_helper_test.rb b/actionpack/test/template/java_script_macros_helper_test.rb index 10d77558f7..13318958c8 100644 --- a/actionpack/test/template/java_script_macros_helper_test.rb +++ b/actionpack/test/template/java_script_macros_helper_test.rb @@ -12,7 +12,7 @@ class JavaScriptMacrosHelperTest < Test::Unit::TestCase def setup @controller = Class.new do - def url_for(options, *parameters_for_method_reference) + def url_for(options) url = "http://www.example.com/" url << options[:action].to_s if options and options[:action] url diff --git a/actionpack/test/template/prototype_helper_test.rb b/actionpack/test/template/prototype_helper_test.rb index ef658517ff..cd098f2a47 100644 --- a/actionpack/test/template/prototype_helper_test.rb +++ b/actionpack/test/template/prototype_helper_test.rb @@ -17,7 +17,7 @@ module BaseTest def setup @template = nil @controller = Class.new do - def url_for(options, *parameters_for_method_reference) + def url_for(options) if options.is_a?(String) options else diff --git a/actionpack/test/template/scriptaculous_helper_test.rb b/actionpack/test/template/scriptaculous_helper_test.rb index cb1171a640..e40debc0f9 100644 --- a/actionpack/test/template/scriptaculous_helper_test.rb +++ b/actionpack/test/template/scriptaculous_helper_test.rb @@ -13,7 +13,7 @@ class ScriptaculousHelperTest < Test::Unit::TestCase def setup @controller = Class.new do - def url_for(options, *parameters_for_method_reference) + def url_for(options) url = "http://www.example.com/" url << options[:action].to_s if options and options[:action] url diff --git a/actionpack/test/template/url_helper_test.rb b/actionpack/test/template/url_helper_test.rb index 9ecbc77a4e..1762015d9d 100644 --- a/actionpack/test/template/url_helper_test.rb +++ b/actionpack/test/template/url_helper_test.rb @@ -10,7 +10,7 @@ class UrlHelperTest < Test::Unit::TestCase def setup @controller = Class.new do attr_accessor :url, :request - def url_for(options, *parameters_for_method_reference) + def url_for(options) url end end @@ -168,7 +168,7 @@ class UrlHelperTest < Test::Unit::TestCase assert_equal "Showing", link_to_unless(true, "Showing", :action => "show", :controller => "weblog") assert_dom_equal "<a href=\"http://www.example.com\">Listing</a>", link_to_unless(false, "Listing", :action => "list", :controller => "weblog") assert_equal "Showing", link_to_unless(true, "Showing", :action => "show", :controller => "weblog", :id => 1) - assert_equal "<strong>Showing</strong>", link_to_unless(true, "Showing", :action => "show", :controller => "weblog", :id => 1) { |name, options, html_options, *parameters_for_method_reference| + assert_equal "<strong>Showing</strong>", link_to_unless(true, "Showing", :action => "show", :controller => "weblog", :id => 1) { |name, options, html_options| "<strong>#{name}</strong>" } assert_equal "<strong>Showing</strong>", link_to_unless(true, "Showing", :action => "show", :controller => "weblog", :id => 1) { |name| @@ -352,3 +352,72 @@ class LinkToUnlessCurrentWithControllerTest < Test::Unit::TestCase end end end + + +class Workshop + attr_accessor :id, :new_record + + def initialize(id, new_record) + @id, @new_record = id, new_record + end + + def new_record? + @new_record + end + + def to_s + id.to_s + end +end + +class PolymorphicControllerTest < Test::Unit::TestCase + class WorkshopsController < ActionController::Base + self.view_paths = ["#{File.dirname(__FILE__)}/../fixtures/"] + + def self.controller_path; 'workshops' end + + def index + @workshop = Workshop.new(1, true) + render :inline => "<%= url_for(@workshop) %>\n<%= link_to('Workshop', @workshop) %>" + end + + def show + @workshop = Workshop.new(params[:id], false) + render :inline => "<%= url_for(@workshop) %>\n<%= link_to('Workshop', @workshop) %>" + end + + def rescue_action(e) raise e end + end + + include ActionView::Helpers::UrlHelper + + def setup + @request = ActionController::TestRequest.new + @response = ActionController::TestResponse.new + @controller = WorkshopsController.new + end + + def test_new_resource + with_restful_routing do + get :index + assert_equal "/workshops\n<a href=\"/workshops\">Workshop</a>", @response.body + end + end + + def test_existing_resource + with_restful_routing do + get :show, :id => 1 + assert_equal "/workshops/1\n<a href=\"/workshops/1\">Workshop</a>", @response.body + end + end + + protected + def with_restful_routing + with_routing do |set| + set.draw do |map| + map.resources :workshops + end + yield + end + end +end
\ No newline at end of file |