diff options
Diffstat (limited to 'actionpack')
23 files changed, 317 insertions, 69 deletions
diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md index 2e7b3190fc..815a46a3ca 100644 --- a/actionpack/CHANGELOG.md +++ b/actionpack/CHANGELOG.md @@ -1,5 +1,29 @@ ## Rails 4.0.0 (unreleased) ## +* Allow to use mounted_helpers (helpers for accessing mounted engines) in ActionView::TestCase. *Piotr Sarnacki* + +* Include mounted_helpers (helpers for accessing mounted engines) in ActionDispatch::IntegrationTest by default. *Piotr Sarnacki* + +* Extracted redirect logic from `ActionController::ForceSSL::ClassMethods.force_ssl` into `ActionController::ForceSSL#force_ssl_redirect` + + *Jeremy Friesen* + +* Make possible to use a block in button_to helper if button text is hard + to fit into the name parameter, e.g.: + + <%= button_to [:make_happy, @user] do %> + Make happy <strong><%= @user.name %></strong> + <% end %> + # => "<form method="post" action="/users/1/make_happy" class="button_to"> + # <div> + # <button type="submit"> + # Make happy <strong>Name</strong> + # </button> + # </div> + # </form>" + + *Sergey Nartimov* + * change a way of ordering helpers from several directories. Previously, when loading helpers from multiple paths, all of the helpers files were gathered into one array an then they were sorted. Helpers from different @@ -217,6 +241,38 @@ HTML5 `mark` element. *Brian Cardarella* +## Rails 3.2.5 (Jun 1, 2012) ## + +* No changes. + + +## Rails 3.2.4 (May 31, 2012) ## + +* Deprecate old APIs for highlight, excerpt and word_wrap *Jeremy Walker* + +* Deprecate `:disable_with` in favor of `'data-disable-with'` option for `button_to`, `button_tag` and `submit_tag` helpers. + + *Carlos Galdino + Rafael Mendonça França* + +* Deprecate `:mouseover` option for `image_tag` helper. *Rafael Mendonça França* + +* Deprecate `button_to_function` and `link_to_function` helpers. *Rafael Mendonça França* + +* Don't break Haml with textarea newline fix. GH #393, #4000, #5190, #5191 + +* Fix options handling on labels. GH #2492, #5614 + +* Added config.action_view.embed_authenticity_token_in_remote_forms to deal + with regression from 16ee611fa + +* Set rendered_format when doing render :inline. GH #5632 + +* Fix the redirect when it receive blocks with arity of 1. Closes #5677 + +* Strip [nil] from parameters hash. Thanks to Ben Murphy for + reporting this! CVE-2012-2660 + + ## Rails 3.2.3 (March 30, 2012) ## * Add `config.action_view.embed_authenticity_token_in_remote_forms` (defaults to true) which allows to set if authenticity token will be included by default in remote forms. If you change it to false, you can still force authenticity token by passing `:authenticity_token => true` in form options *Piotr Sarnacki* diff --git a/actionpack/lib/abstract_controller/collector.rb b/actionpack/lib/abstract_controller/collector.rb index 81fb514770..492329c401 100644 --- a/actionpack/lib/abstract_controller/collector.rb +++ b/actionpack/lib/abstract_controller/collector.rb @@ -4,7 +4,7 @@ module AbstractController module Collector def self.generate_method_for_mime(mime) sym = mime.is_a?(Symbol) ? mime : mime.to_sym - const = sym.to_s.upcase + const = sym.upcase class_eval <<-RUBY, __FILE__, __LINE__ + 1 def #{sym}(*args, &block) # def html(*args, &block) custom(Mime::#{const}, *args, &block) # custom(Mime::HTML, *args, &block) @@ -19,7 +19,7 @@ module AbstractController protected def method_missing(symbol, &block) - mime_constant = Mime.const_get(symbol.to_s.upcase) + mime_constant = Mime.const_get(symbol.upcase) if Mime::SET.include?(mime_constant) AbstractController::Collector.generate_method_for_mime(mime_constant) @@ -29,4 +29,4 @@ module AbstractController end end end -end
\ No newline at end of file +end diff --git a/actionpack/lib/action_controller/caching/pages.rb b/actionpack/lib/action_controller/caching/pages.rb index dd4eddbe9a..73b8cd383c 100644 --- a/actionpack/lib/action_controller/caching/pages.rb +++ b/actionpack/lib/action_controller/caching/pages.rb @@ -110,7 +110,7 @@ module ActionController #:nodoc: gzip_level = options.fetch(:gzip, page_cache_compression) gzip_level = case gzip_level when Symbol - Zlib.const_get(gzip_level.to_s.upcase) + Zlib.const_get(gzip_level.upcase) when Fixnum gzip_level when false diff --git a/actionpack/lib/action_controller/metal/force_ssl.rb b/actionpack/lib/action_controller/metal/force_ssl.rb index ac12cbb625..77d799a38a 100644 --- a/actionpack/lib/action_controller/metal/force_ssl.rb +++ b/actionpack/lib/action_controller/metal/force_ssl.rb @@ -40,15 +40,23 @@ module ActionController def force_ssl(options = {}) host = options.delete(:host) before_filter(options) do - unless request.ssl? - redirect_options = {:protocol => 'https://', :status => :moved_permanently} - redirect_options.merge!(:host => host) if host - redirect_options.merge!(:params => request.query_parameters) - flash.keep if respond_to?(:flash) - redirect_to redirect_options - end + force_ssl_redirect(host) end end end + + # Redirect the existing request to use the HTTPS protocol. + # + # ==== Parameters + # * <tt>host</tt> - Redirect to a different host name + def force_ssl_redirect(host = nil) + unless request.ssl? + redirect_options = {:protocol => 'https://', :status => :moved_permanently} + redirect_options.merge!(:host => host) if host + redirect_options.merge!(:params => request.query_parameters) + flash.keep if respond_to?(:flash) + redirect_to redirect_options + end + end end end diff --git a/actionpack/lib/action_dispatch/http/request.rb b/actionpack/lib/action_dispatch/http/request.rb index aa5ba3e8a5..6757a53bd1 100644 --- a/actionpack/lib/action_dispatch/http/request.rb +++ b/actionpack/lib/action_dispatch/http/request.rb @@ -263,6 +263,28 @@ module ActionDispatch LOCALHOST =~ remote_addr && LOCALHOST =~ remote_ip end + protected + + # Remove nils from the params hash + def deep_munge(hash) + hash.each_value do |v| + case v + when Array + v.grep(Hash) { |x| deep_munge(x) } + when Hash + deep_munge(v) + end + end + + keys = hash.keys.find_all { |k| hash[k] == [nil] } + keys.each { |k| hash[k] = nil } + hash + end + + def parse_query(qs) + deep_munge(super) + end + private def check_method(name) diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index e43e897783..25d099d83e 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -1327,7 +1327,7 @@ module ActionDispatch msg += @draw_paths.map { |_path| " * #{_path}" }.join("\n") raise ArgumentError, msg end - + route_path = "#{path}/#{name}.rb" instance_eval(File.read(route_path), route_path.to_s) end diff --git a/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb b/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb index 8fde667108..86ce7a83b9 100644 --- a/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb +++ b/actionpack/lib/action_dispatch/routing/polymorphic_routes.rb @@ -95,7 +95,7 @@ module ActionDispatch end record = extract_record(record_or_hash_or_array) - record = record.to_model if record.respond_to?(:to_model) + record = convert_to_model(record) args = Array === record_or_hash_or_array ? record_or_hash_or_array.dup : @@ -122,6 +122,8 @@ module ActionDispatch args.last.kind_of?(Hash) ? args.last.merge!(url_options) : args << url_options end + args.collect! { |a| convert_to_model(a) } + (proxy || self).send(named_route, *args) end @@ -152,6 +154,10 @@ module ActionDispatch options[:action] ? "#{options[:action]}_" : '' end + def convert_to_model(object) + object.respond_to?(:to_model) ? object.to_model : object + end + def routing_type(options) options[:routing_type] || :url end diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb index 7872f4007e..64b1d58ae9 100644 --- a/actionpack/lib/action_dispatch/routing/route_set.rb +++ b/actionpack/lib/action_dispatch/routing/route_set.rb @@ -252,15 +252,11 @@ module ActionDispatch self.draw_paths = [] self.request_class = request_class - @valid_conditions = {} - + @valid_conditions = { :controller => true, :action => true } request_class.public_instance_methods.each { |m| - @valid_conditions[m.to_sym] = true + @valid_conditions[m] = true } - @valid_conditions[:controller] = true - @valid_conditions[:action] = true - - self.valid_conditions.delete(:id) + @valid_conditions.delete(:id) @append = [] @prepend = [] diff --git a/actionpack/lib/action_dispatch/testing/integration.rb b/actionpack/lib/action_dispatch/testing/integration.rb index 3fdc6688c2..50ca28395b 100644 --- a/actionpack/lib/action_dispatch/testing/integration.rb +++ b/actionpack/lib/action_dispatch/testing/integration.rb @@ -193,8 +193,11 @@ module ActionDispatch # If the app is a Rails app, make url_helpers available on the session # This makes app.url_for and app.foo_path available in the console - if app.respond_to?(:routes) && app.routes.respond_to?(:url_helpers) - singleton_class.class_eval { include app.routes.url_helpers } + if app.respond_to?(:routes) + singleton_class.class_eval do + include app.routes.url_helpers if app.routes.respond_to?(:url_helpers) + include app.routes.mounted_helpers if app.routes.respond_to?(:mounted_helpers) + end end reset! diff --git a/actionpack/lib/action_view/helpers/controller_helper.rb b/actionpack/lib/action_view/helpers/controller_helper.rb index 1a583e62ae..74ef25f7c1 100644 --- a/actionpack/lib/action_view/helpers/controller_helper.rb +++ b/actionpack/lib/action_view/helpers/controller_helper.rb @@ -10,14 +10,16 @@ module ActionView delegate :request_forgery_protection_token, :params, :session, :cookies, :response, :headers, :flash, :action_name, :controller_name, :controller_path, :to => :controller - delegate :logger, :to => :controller, :allow_nil => true - def assign_controller(controller) if @_controller = controller @_request = controller.request if controller.respond_to?(:request) @_config = controller.config.inheritable_copy if controller.respond_to?(:config) end end + + def logger + controller.logger if controller.respond_to?(:logger) + end end end end diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb index ac150882b1..7dd35f7357 100644 --- a/actionpack/lib/action_view/helpers/form_helper.rb +++ b/actionpack/lib/action_view/helpers/form_helper.rb @@ -1311,10 +1311,21 @@ module ActionView # post: # create: "Add %{model}" # - def button(value=nil, options={}) + # ==== Examples + # button("Create a post") + # # => <button name='button' type='submit'>Create post</button> + # + # button do + # content_tag(:strong, 'Ask me!') + # end + # # => <button name='button' type='submit'> + # # <strong>Ask me!</strong> + # # </button> + # + def button(value = nil, options = {}, &block) value, options = nil, value if value.is_a?(Hash) value ||= submit_default_value - @template.button_tag(value, options) + @template.button_tag(value, options, &block) end def emitted_hidden_id? diff --git a/actionpack/lib/action_view/helpers/url_helper.rb b/actionpack/lib/action_view/helpers/url_helper.rb index 7e69547dab..7f5b3c8a0f 100644 --- a/actionpack/lib/action_view/helpers/url_helper.rb +++ b/actionpack/lib/action_view/helpers/url_helper.rb @@ -233,25 +233,15 @@ module ActionView # # link_to("Destroy", "http://www.example.com", :method => :delete, :confirm => "Are you sure?") # # => <a href='http://www.example.com' rel="nofollow" data-method="delete" data-confirm="Are you sure?">Destroy</a> - def link_to(*args, &block) - if block_given? - options = args.first || {} - html_options = args.second - link_to(capture(&block), options, html_options) - else - name = args[0] - options = args[1] || {} - html_options = args[2] - - html_options = convert_options_to_data_attributes(options, html_options) - url = url_for(options) + def link_to(name = nil, options = nil, html_options = nil, &block) + html_options, options = options, name if block_given? + options ||= {} + url = url_for(options) - href = html_options['href'] - tag_options = tag_options(html_options) + html_options = convert_options_to_data_attributes(options, html_options) + html_options['href'] ||= url - href_attr = "href=\"#{ERB::Util.html_escape(url)}\"" unless href - "<a #{href_attr}#{tag_options}>#{ERB::Util.html_escape(name || url)}</a>".html_safe - end + content_tag(:a, name || url, html_options, &block) end # Generates a form containing a single button that submits to the URL created @@ -294,6 +284,16 @@ module ActionView # # <div><input value="New" type="submit" /></div> # # </form>" # + # <%= button_to [:make_happy, @user] do %> + # Make happy <strong><%= @user.name %></strong> + # <% end %> + # # => "<form method="post" action="/users/1/make_happy" class="button_to"> + # # <div> + # # <button type="submit"> + # # Make happy <strong><%= @user.name %></strong> + # # </button> + # # </div> + # # </form>" # # <%= button_to "New", :action => "new", :form_class => "new-thing" %> # # => "<form method="post" action="/controller/new" class="new-thing"> @@ -331,7 +331,11 @@ module ActionView # # </div> # # </form>" # # - def button_to(name, options = {}, html_options = {}) + def button_to(name = nil, options = nil, html_options = nil, &block) + html_options, options = options, name if block_given? + options ||= {} + html_options ||= {} + html_options = html_options.stringify_keys convert_boolean_attributes!(html_options, %w(disabled)) @@ -350,9 +354,16 @@ module ActionView request_token_tag = form_method == 'post' ? token_tag : '' html_options = convert_options_to_data_attributes(options, html_options) - html_options.merge!("type" => "submit", "value" => name || url) + html_options['type'] = 'submit' + + button = if block_given? + content_tag('button', html_options, &block) + else + html_options['value'] = name || url + tag('input', html_options) + end - inner_tags = method_tag.safe_concat tag('input', html_options).safe_concat request_token_tag + inner_tags = method_tag.safe_concat(button).safe_concat(request_token_tag) content_tag('form', content_tag('div', inner_tags), form_options) end diff --git a/actionpack/lib/action_view/test_case.rb b/actionpack/lib/action_view/test_case.rb index fece499c94..53bde48e4d 100644 --- a/actionpack/lib/action_view/test_case.rb +++ b/actionpack/lib/action_view/test_case.rb @@ -229,7 +229,8 @@ module ActionView def method_missing(selector, *args) if @controller.respond_to?(:_routes) && - @controller._routes.named_routes.helpers.include?(selector) + ( @controller._routes.named_routes.helpers.include?(selector) || + @controller._routes.mounted_helpers.method_defined?(selector) ) @controller.__send__(selector, *args) else super diff --git a/actionpack/test/abstract_unit.rb b/actionpack/test/abstract_unit.rb index ba06bcae51..37deb9c98a 100644 --- a/actionpack/test/abstract_unit.rb +++ b/actionpack/test/abstract_unit.rb @@ -277,6 +277,7 @@ module ActionController include ActionController::Testing # This stub emulates the Railtie including the URL helpers from a Rails application include SharedTestRoutes.url_helpers + include SharedTestRoutes.mounted_helpers self.view_paths = FIXTURE_LOAD_PATH diff --git a/actionpack/test/activerecord/polymorphic_routes_test.rb b/actionpack/test/activerecord/polymorphic_routes_test.rb index 90e7f4ae59..afb714484b 100644 --- a/actionpack/test/activerecord/polymorphic_routes_test.rb +++ b/actionpack/test/activerecord/polymorphic_routes_test.rb @@ -25,6 +25,24 @@ class Series < ActiveRecord::Base self.table_name = 'projects' end +class ModelDelegator < ActiveRecord::Base + self.table_name = 'projects' + + def to_model + ModelDelegate.new + end +end + +class ModelDelegate + def self.model_name + ActiveModel::Name.new(self) + end + + def to_param + 'overridden' + end +end + module Blog class Post < ActiveRecord::Base self.table_name = 'projects' @@ -50,6 +68,7 @@ class PolymorphicRoutesTest < ActionController::TestCase @bid = Bid.new @tax = Tax.new @fax = Fax.new + @delegator = ModelDelegator.new @series = Series.new @blog_post = Blog::Post.new @blog_blog = Blog::Blog.new @@ -439,6 +458,13 @@ class PolymorphicRoutesTest < ActionController::TestCase end end + def test_routing_a_to_model_delegate + with_test_routes do + @delegator.save + assert_equal "http://example.com/model_delegates/overridden", polymorphic_url(@delegator) + end + end + def with_namespaced_routes(name) with_routing do |set| set.draw do @@ -469,6 +495,7 @@ class PolymorphicRoutesTest < ActionController::TestCase resource :bid end resources :series + resources :model_delegates end self.class.send(:include, @routes.url_helpers) @@ -516,5 +543,4 @@ class PolymorphicRoutesTest < ActionController::TestCase yield end end - end diff --git a/actionpack/test/controller/force_ssl_test.rb b/actionpack/test/controller/force_ssl_test.rb index 5b423c8151..6758668b7a 100644 --- a/actionpack/test/controller/force_ssl_test.rb +++ b/actionpack/test/controller/force_ssl_test.rb @@ -49,6 +49,15 @@ class ForceSSLFlash < ForceSSLController end end +class RedirectToSSL < ForceSSLController + def banana + force_ssl_redirect || render(:text => 'monkey') + end + def cheeseburger + force_ssl_redirect('secure.cheeseburger.host') || render(:text => 'ihaz') + end +end + class ForceSSLControllerLevelTest < ActionController::TestCase tests ForceSSLControllerLevel @@ -149,3 +158,25 @@ class ForceSSLFlashTest < ActionController::TestCase assert_equal "hello", assigns["flashy"] end end + +class RedirectToSSLTest < ActionController::TestCase + tests RedirectToSSL + def test_banana_redirects_to_https_if_not_https + get :banana + assert_response 301 + assert_equal "https://test.host/redirect_to_ssl/banana", redirect_to_url + end + + def test_cheeseburgers_redirects_to_https_with_new_host_if_not_https + get :cheeseburger + assert_response 301 + assert_equal "https://secure.cheeseburger.host/redirect_to_ssl/cheeseburger", redirect_to_url + end + + def test_banana_does_not_redirect_if_already_https + request.env['HTTPS'] = 'on' + get :cheeseburger + assert_response 200 + assert_equal 'ihaz', response.body + end +end
\ No newline at end of file diff --git a/actionpack/test/controller/helper_test.rb b/actionpack/test/controller/helper_test.rb index deb234b04f..248c81193e 100644 --- a/actionpack/test/controller/helper_test.rb +++ b/actionpack/test/controller/helper_test.rb @@ -109,13 +109,13 @@ class HelperTest < ActiveSupport::TestCase def test_helper_method assert_nothing_raised { @controller_class.helper_method :delegate_method } - assert master_helper_methods.include?('delegate_method') + assert master_helper_methods.include?(:delegate_method) end def test_helper_attr assert_nothing_raised { @controller_class.helper_attr :delegate_attr } - assert master_helper_methods.include?('delegate_attr') - assert master_helper_methods.include?('delegate_attr=') + assert master_helper_methods.include?(:delegate_attr) + assert master_helper_methods.include?(:delegate_attr=) end def call_controller(klass, action) @@ -160,16 +160,16 @@ class HelperTest < ActiveSupport::TestCase end def test_all_helpers - methods = AllHelpersController._helpers.instance_methods.map {|m| m.to_s} + methods = AllHelpersController._helpers.instance_methods # abc_helper.rb - assert methods.include?('bare_a') + assert methods.include?(:bare_a) # fun/games_helper.rb - assert methods.include?('stratego') + assert methods.include?(:stratego) # fun/pdf_helper.rb - assert methods.include?('foobar') + assert methods.include?(:foobar) end def test_all_helpers_with_alternate_helper_dir @@ -180,35 +180,35 @@ class HelperTest < ActiveSupport::TestCase @controller_class.helper :all # helpers/abc_helper.rb should not be included - assert !master_helper_methods.include?('bare_a') + assert !master_helper_methods.include?(:bare_a) # alternate_helpers/foo_helper.rb - assert master_helper_methods.include?('baz') + assert master_helper_methods.include?(:baz) end def test_helper_proxy - methods = AllHelpersController.helpers.methods.map(&:to_s) + methods = AllHelpersController.helpers.methods # Action View - assert methods.include?('pluralize') + assert methods.include?(:pluralize) # abc_helper.rb - assert methods.include?('bare_a') + assert methods.include?(:bare_a) # fun/games_helper.rb - assert methods.include?('stratego') + assert methods.include?(:stratego) # fun/pdf_helper.rb - assert methods.include?('foobar') + assert methods.include?(:foobar) end private def expected_helper_methods - TestHelper.instance_methods.map {|m| m.to_s } + TestHelper.instance_methods end def master_helper_methods - @controller_class._helpers.instance_methods.map {|m| m.to_s } + @controller_class._helpers.instance_methods end def missing_methods diff --git a/actionpack/test/controller/integration_test.rb b/actionpack/test/controller/integration_test.rb index fb41dcb33a..f18bf33969 100644 --- a/actionpack/test/controller/integration_test.rb +++ b/actionpack/test/controller/integration_test.rb @@ -538,11 +538,26 @@ class ApplicationIntegrationTest < ActionDispatch::IntegrationTest @routes ||= ActionDispatch::Routing::RouteSet.new end + class MountedApp + def self.routes + @routes ||= ActionDispatch::Routing::RouteSet.new + end + + routes.draw do + get 'baz', :to => 'application_integration_test/test#index', :as => :baz + end + + def self.call(*) + end + end + routes.draw do get '', :to => 'application_integration_test/test#index', :as => :empty_string get 'foo', :to => 'application_integration_test/test#index', :as => :foo get 'bar', :to => 'application_integration_test/test#index', :as => :bar + + mount MountedApp => '/mounted', :as => "mounted" end def app @@ -555,6 +570,10 @@ class ApplicationIntegrationTest < ActionDispatch::IntegrationTest assert_equal '/bar', bar_path end + test "includes mounted helpers" do + assert_equal '/mounted/baz', mounted.baz_path + end + test "route helpers after controller access" do get '/' assert_equal '/', empty_string_path diff --git a/actionpack/test/controller/request_forgery_protection_test.rb b/actionpack/test/controller/request_forgery_protection_test.rb index 066cd523be..0289f4070b 100644 --- a/actionpack/test/controller/request_forgery_protection_test.rb +++ b/actionpack/test/controller/request_forgery_protection_test.rb @@ -9,7 +9,7 @@ module RequestForgeryProtectionActions end def show_button - render :inline => "<%= button_to('New', '/') {} %>" + render :inline => "<%= button_to('New', '/') %>" end def external_form @@ -79,7 +79,7 @@ class FreeCookieController < RequestForgeryProtectionController end def show_button - render :inline => "<%= button_to('New', '/') {} %>" + render :inline => "<%= button_to('New', '/') %>" end end diff --git a/actionpack/test/dispatch/request/query_string_parsing_test.rb b/actionpack/test/dispatch/request/query_string_parsing_test.rb index c3f009ab15..6ea66f9d32 100644 --- a/actionpack/test/dispatch/request/query_string_parsing_test.rb +++ b/actionpack/test/dispatch/request/query_string_parsing_test.rb @@ -81,7 +81,12 @@ class QueryStringParsingTest < ActionDispatch::IntegrationTest end test "query string without equal" do - assert_parses({ "action" => nil }, "action") + assert_parses({"action" => nil}, "action") + assert_parses({"action" => {"foo" => nil}}, "action[foo]") + assert_parses({"action" => {"foo" => { "bar" => nil }}}, "action[foo][bar]") + assert_parses({"action" => {"foo" => { "bar" => nil }}}, "action[foo][bar][]") + assert_parses({"action" => {"foo" => nil}}, "action[foo][]") + assert_parses({"action"=>{"foo"=>[{"bar"=>nil}]}}, "action[foo][][bar]") end test "query string with empty key" do diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb index c9b39ed18f..7da293ce23 100644 --- a/actionpack/test/template/form_helper_test.rb +++ b/actionpack/test/template/form_helper_test.rb @@ -1054,6 +1054,9 @@ class FormHelperTest < ActionView::TestCase concat f.check_box(:secret) concat f.submit('Create post') concat f.button('Create post') + concat f.button { + concat content_tag(:span, 'Create post') + } end expected = whole_form("/posts/123", "create-post" , "edit_post", :method => 'patch') do @@ -1063,7 +1066,8 @@ class FormHelperTest < ActionView::TestCase "<input name='post[secret]' type='hidden' value='0' />" + "<input name='post[secret]' checked='checked' type='checkbox' id='post_secret' value='1' />" + "<input name='commit' type='submit' value='Create post' />" + - "<button name='button' type='submit'>Create post</button>" + "<button name='button' type='submit'>Create post</button>" + + "<button name='button' type='submit'><span>Create post</span></button>" end assert_dom_equal expected, output_buffer @@ -2359,7 +2363,7 @@ class FormHelperTest < ActionView::TestCase end def test_form_builder_does_not_have_form_for_method - assert ! ActionView::Helpers::FormBuilder.instance_methods.include?('form_for') + assert !ActionView::Helpers::FormBuilder.instance_methods.include?(:form_for) end def test_form_for_and_fields_for diff --git a/actionpack/test/template/test_case_test.rb b/actionpack/test/template/test_case_test.rb index f2ed2ec609..c005f040eb 100644 --- a/actionpack/test/template/test_case_test.rb +++ b/actionpack/test/template/test_case_test.rb @@ -222,6 +222,25 @@ module ActionView end end + test "is able to use mounted routes" do + with_routing do |set| + app = Class.new do + def self.routes + @routes ||= ActionDispatch::Routing::RouteSet.new + end + + routes.draw { get "bar", :to => lambda {} } + + def self.call(*) + end + end + + set.draw { mount app => "/foo", :as => "foo_app" } + + assert_equal '/foo/bar', foo_app.bar_path + end + end + test "named routes can be used from helper included in view" do with_routing do |set| set.draw { resources :contents } diff --git a/actionpack/test/template/url_helper_test.rb b/actionpack/test/template/url_helper_test.rb index fb5b35bac6..62608a727f 100644 --- a/actionpack/test/template/url_helper_test.rb +++ b/actionpack/test/template/url_helper_test.rb @@ -144,6 +144,13 @@ class UrlHelperTest < ActiveSupport::TestCase ) end + def test_button_to_with_block + assert_dom_equal( + "<form method=\"post\" action=\"http://www.example.com\" class=\"button_to\"><div><button type=\"submit\"><span>Hello</span></button></div></form>", + button_to("http://www.example.com") { content_tag(:span, 'Hello') } + ) + end + def test_link_tag_with_straight_url assert_dom_equal "<a href=\"http://www.example.com\">Hello</a>", link_to("Hello", "http://www.example.com") end @@ -270,6 +277,16 @@ class UrlHelperTest < ActiveSupport::TestCase ) end + def test_link_tag_with_block + assert_dom_equal '<a href="/"><span>Example site</span></a>', + link_to('/') { content_tag(:span, 'Example site') } + end + + def test_link_tag_with_block_and_html_options + assert_dom_equal '<a class="special" href="/"><span>Example site</span></a>', + link_to('/', :class => "special") { content_tag(:span, 'Example site') } + end + def test_link_tag_using_block_in_erb out = render_erb %{<%= link_to('/') do %>Example site<% end %>} assert_equal '<a href="/">Example site</a>', out @@ -282,6 +299,16 @@ class UrlHelperTest < ActiveSupport::TestCase ) end + def test_link_tag_escapes_content + assert_dom_equal '<a href="/">Malicious <script>content</script></a>', + link_to("Malicious <script>content</script>", "/") + end + + def test_link_tag_does_not_escape_html_safe_content + assert_dom_equal '<a href="/">Malicious <script>content</script></a>', + link_to("Malicious <script>content</script>".html_safe, "/") + end + def test_link_to_unless assert_equal "Showing", link_to_unless(true, "Showing", url_hash) |