From 13867a3f5f3e2248660a942956985a4eacacb283 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Fri, 30 Apr 2010 18:40:24 +0200 Subject: Use %{} syntax in I18n (faster) instead of {{}}. --- actionpack/lib/action_view/helpers/form_helper.rb | 6 ++--- actionpack/lib/action_view/locale/en.yml | 28 +++++++++++------------ 2 files changed, 17 insertions(+), 17 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb index d3604925e8..b2470edf00 100644 --- a/actionpack/lib/action_view/helpers/form_helper.rb +++ b/actionpack/lib/action_view/helpers/form_helper.rb @@ -1165,13 +1165,13 @@ module ActionView # submit button label, otherwise, it uses "Update Post". # # Those labels can be customized using I18n, under the helpers.submit key and accept - # the {{model}} as translation interpolation: + # the %{model} as translation interpolation: # # en: # helpers: # submit: - # create: "Create a {{model}}" - # update: "Confirm changes to {{model}}" + # create: "Create a %{model}" + # update: "Confirm changes to %{model}" # # It also searches for a key specific for the given object: # diff --git a/actionpack/lib/action_view/locale/en.yml b/actionpack/lib/action_view/locale/en.yml index 187e010e30..9004e52c5b 100644 --- a/actionpack/lib/action_view/locale/en.yml +++ b/actionpack/lib/action_view/locale/en.yml @@ -102,37 +102,37 @@ half_a_minute: "half a minute" less_than_x_seconds: one: "less than 1 second" - other: "less than {{count}} seconds" + other: "less than %{count} seconds" x_seconds: one: "1 second" - other: "{{count}} seconds" + other: "%{count} seconds" less_than_x_minutes: one: "less than a minute" - other: "less than {{count}} minutes" + other: "less than %{count} minutes" x_minutes: one: "1 minute" - other: "{{count}} minutes" + other: "%{count} minutes" about_x_hours: one: "about 1 hour" - other: "about {{count}} hours" + other: "about %{count} hours" x_days: one: "1 day" - other: "{{count}} days" + other: "%{count} days" about_x_months: one: "about 1 month" - other: "about {{count}} months" + other: "about %{count} months" x_months: one: "1 month" - other: "{{count}} months" + other: "%{count} months" about_x_years: one: "about 1 year" - other: "about {{count}} years" + other: "about %{count} years" over_x_years: one: "over 1 year" - other: "over {{count}} years" + other: "over %{count} years" almost_x_years: one: "almost 1 year" - other: "almost {{count}} years" + other: "almost %{count} years" prompts: year: "Year" month: "Month" @@ -148,7 +148,7 @@ # Default translation keys for submit FormHelper submit: - create: 'Create {{model}}' - update: 'Update {{model}}' - submit: 'Save {{model}}' + create: 'Create %{model}' + update: 'Update %{model}' + submit: 'Save %{model}' -- cgit v1.2.3 From a61a6d206b1d37747c3f907487db4bc0952c7b5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sat, 1 May 2010 22:38:57 +0200 Subject: Speed up I18n helpers in views and add entry to CHANGELOG. --- actionpack/lib/action_view/helpers/translation_helper.rb | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_view/helpers/translation_helper.rb b/actionpack/lib/action_view/helpers/translation_helper.rb index 89c1b4a275..086ad261c8 100644 --- a/actionpack/lib/action_view/helpers/translation_helper.rb +++ b/actionpack/lib/action_view/helpers/translation_helper.rb @@ -20,7 +20,7 @@ module ActionView options[:raise] = true translation = I18n.translate(scope_key_by_partial(key), options) translation = (translation.respond_to?(:join) ? translation.join : translation) - if html_safe_translation_key? key + if html_safe_translation_key?(key) translation.html_safe else translation @@ -53,12 +53,8 @@ module ActionView end def html_safe_translation_key?(key) - last_key = if key.is_a? Array - key.last - else - key.to_s.split('.').last - end - (last_key == "html") || (last_key.ends_with? "_html") + key = key.is_a?(Array) ? key.last : key.to_s + key =~ /(\b|_|\.)html$/ end end end -- cgit v1.2.3 From 731d4392e478ff5526b595074d9caa999da8bd0c Mon Sep 17 00:00:00 2001 From: Justin George Date: Tue, 27 Apr 2010 21:16:06 -0700 Subject: Change event namespace ordering to most-significant first [#4504 state:resolved] MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit More work still needs to be done on some of these names (render_template.action_view and render_template!.action_view particularly) but this allows (for example) /^sql/ to subscribe to all the various ORMs without further modification Signed-off-by: José Valim --- actionpack/lib/action_controller/caching/fragments.rb | 2 +- actionpack/lib/action_controller/caching/pages.rb | 2 +- actionpack/lib/action_controller/metal/instrumentation.rb | 10 +++++----- actionpack/lib/action_controller/test_case.rb | 8 ++++---- actionpack/lib/action_view/render/partials.rb | 4 ++-- actionpack/lib/action_view/render/rendering.rb | 2 +- actionpack/lib/action_view/template.rb | 2 +- 7 files changed, 15 insertions(+), 15 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_controller/caching/fragments.rb b/actionpack/lib/action_controller/caching/fragments.rb index 473a2fe214..460273dac1 100644 --- a/actionpack/lib/action_controller/caching/fragments.rb +++ b/actionpack/lib/action_controller/caching/fragments.rb @@ -99,7 +99,7 @@ module ActionController #:nodoc: end def instrument_fragment_cache(name, key) - ActiveSupport::Notifications.instrument("action_controller.#{name}", :key => key){ yield } + ActiveSupport::Notifications.instrument("#{name}.action_controller", :key => key){ yield } end end end diff --git a/actionpack/lib/action_controller/caching/pages.rb b/actionpack/lib/action_controller/caching/pages.rb index cefd1f48c0..4f7a5d3f55 100644 --- a/actionpack/lib/action_controller/caching/pages.rb +++ b/actionpack/lib/action_controller/caching/pages.rb @@ -109,7 +109,7 @@ module ActionController #:nodoc: end def instrument_page_cache(name, path) - ActiveSupport::Notifications.instrument("action_controller.#{name}", :path => path){ yield } + ActiveSupport::Notifications.instrument("#{name}.action_controller", :path => path){ yield } end end diff --git a/actionpack/lib/action_controller/metal/instrumentation.rb b/actionpack/lib/action_controller/metal/instrumentation.rb index d69de65f28..ba38b186d6 100644 --- a/actionpack/lib/action_controller/metal/instrumentation.rb +++ b/actionpack/lib/action_controller/metal/instrumentation.rb @@ -23,9 +23,9 @@ module ActionController :path => (request.fullpath rescue "unknown") } - ActiveSupport::Notifications.instrument("action_controller.start_processing", raw_payload.dup) + ActiveSupport::Notifications.instrument("start_processing.action_controller", raw_payload.dup) - ActiveSupport::Notifications.instrument("action_controller.process_action", raw_payload) do |payload| + ActiveSupport::Notifications.instrument("process_action.action_controller", raw_payload) do |payload| result = super payload[:status] = response.status append_info_to_payload(payload) @@ -42,20 +42,20 @@ module ActionController end def send_file(path, options={}) - ActiveSupport::Notifications.instrument("action_controller.send_file", + ActiveSupport::Notifications.instrument("send_file.action_controller", options.merge(:path => path)) do super end end def send_data(data, options = {}) - ActiveSupport::Notifications.instrument("action_controller.send_data", options) do + ActiveSupport::Notifications.instrument("send_data.action_controller", options) do super end end def redirect_to(*args) - ActiveSupport::Notifications.instrument("action_controller.redirect_to") do |payload| + ActiveSupport::Notifications.instrument("redirect_to.action_controller") do |payload| result = super payload[:status] = self.status payload[:location] = self.location diff --git a/actionpack/lib/action_controller/test_case.rb b/actionpack/lib/action_controller/test_case.rb index 2b9b34961e..2010d8573c 100644 --- a/actionpack/lib/action_controller/test_case.rb +++ b/actionpack/lib/action_controller/test_case.rb @@ -16,12 +16,12 @@ module ActionController @templates = Hash.new(0) @layouts = Hash.new(0) - ActiveSupport::Notifications.subscribe("action_view.render_template") do |name, start, finish, id, payload| + ActiveSupport::Notifications.subscribe("render_template.action_view") do |name, start, finish, id, payload| path = payload[:layout] @layouts[path] += 1 end - ActiveSupport::Notifications.subscribe("action_view.render_template!") do |name, start, finish, id, payload| + ActiveSupport::Notifications.subscribe("!render_template.action_view") do |name, start, finish, id, payload| path = payload[:virtual_path] next unless path partial = path =~ /^.*\/_[^\/]*$/ @@ -36,8 +36,8 @@ module ActionController end def teardown_subscriptions - ActiveSupport::Notifications.unsubscribe("action_view.render_template") - ActiveSupport::Notifications.unsubscribe("action_view.render_template!") + ActiveSupport::Notifications.unsubscribe("render_template.action_view") + ActiveSupport::Notifications.unsubscribe("!render_template.action_view") end # Asserts that the request was rendered with the appropriate template file or partials diff --git a/actionpack/lib/action_view/render/partials.rb b/actionpack/lib/action_view/render/partials.rb index 4d23d55687..974345633c 100644 --- a/actionpack/lib/action_view/render/partials.rb +++ b/actionpack/lib/action_view/render/partials.rb @@ -211,12 +211,12 @@ module ActionView identifier = ((@template = find_template) ? @template.identifier : @path) if @collection - ActiveSupport::Notifications.instrument("action_view.render_collection", + ActiveSupport::Notifications.instrument("render_collection.action_view", :identifier => identifier || "collection", :count => @collection.size) do render_collection end else - content = ActiveSupport::Notifications.instrument("action_view.render_partial", + content = ActiveSupport::Notifications.instrument("render_partial.action_view", :identifier => identifier) do render_partial end diff --git a/actionpack/lib/action_view/render/rendering.rb b/actionpack/lib/action_view/render/rendering.rb index 492326964a..4198013f57 100644 --- a/actionpack/lib/action_view/render/rendering.rb +++ b/actionpack/lib/action_view/render/rendering.rb @@ -52,7 +52,7 @@ module ActionView locals = options[:locals] || {} layout = find_layout(layout) if layout - ActiveSupport::Notifications.instrument("action_view.render_template", + ActiveSupport::Notifications.instrument("render_template.action_view", :identifier => template.identifier, :layout => layout.try(:virtual_path)) do content = template.render(self, locals) { |*name| _layout_for(*name) } diff --git a/actionpack/lib/action_view/template.rb b/actionpack/lib/action_view/template.rb index 3c0cd35359..a1a970e2d2 100644 --- a/actionpack/lib/action_view/template.rb +++ b/actionpack/lib/action_view/template.rb @@ -41,7 +41,7 @@ module ActionView def render(view, locals, &block) # Notice that we use a bang in this instrumentation because you don't want to # consume this in production. This is only slow if it's being listened to. - ActiveSupport::Notifications.instrument("action_view.render_template!", :virtual_path => @virtual_path) do + ActiveSupport::Notifications.instrument("!render_template.action_view", :virtual_path => @virtual_path) do method_name = compile(locals, view) view.send(method_name, locals, &block) end -- cgit v1.2.3 From 91125f9927ffbe1a16494910ae0e8228a4400439 Mon Sep 17 00:00:00 2001 From: David Chelimsky Date: Sun, 2 May 2010 09:20:17 -0500 Subject: move FixtureResolver to a file that is accessible outside Rails' own tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [#4522 state:resolved] Signed-off-by: José Valim --- actionpack/lib/action_view/testing/resolvers.rb | 35 +++++++++++++++++++++++++ actionpack/test/abstract_unit.rb | 2 +- actionpack/test/controller/layout_test.rb | 2 -- actionpack/test/lib/fixture_template.rb | 29 -------------------- 4 files changed, 36 insertions(+), 32 deletions(-) create mode 100644 actionpack/lib/action_view/testing/resolvers.rb delete mode 100644 actionpack/test/lib/fixture_template.rb (limited to 'actionpack') diff --git a/actionpack/lib/action_view/testing/resolvers.rb b/actionpack/lib/action_view/testing/resolvers.rb new file mode 100644 index 0000000000..f468e57c26 --- /dev/null +++ b/actionpack/lib/action_view/testing/resolvers.rb @@ -0,0 +1,35 @@ +require 'action_view/template/resolver' + +module ActionView #:nodoc: + # Use FixtureResolver in your tests to simulate the presence of files on the + # file system. This is used internally by Rails' own test suite, and is + # useful for testing extensions that have no way of knowing what the file + # system will look like at runtime. + class FixtureResolver < PathResolver + attr_reader :hash + + def initialize(hash = {}) + super() + @hash = hash + end + + private + + def query(path, exts, formats) + query = Regexp.escape(path) + exts.each do |ext| + query << '(' << ext.map {|e| e && Regexp.escape(".#{e}") }.join('|') << '|)' + end + + templates = [] + @hash.select { |k,v| k =~ /^#{query}$/ }.each do |path, source| + handler, format = extract_handler_and_format(path, formats) + templates << Template.new(source, path, handler, + :virtual_path => path, :format => format) + end + + templates.sort_by {|t| -t.identifier.match(/^#{query}$/).captures.reject(&:blank?).size } + end + end +end + diff --git a/actionpack/test/abstract_unit.rb b/actionpack/test/abstract_unit.rb index f3ff258016..89ba0990f1 100644 --- a/actionpack/test/abstract_unit.rb +++ b/actionpack/test/abstract_unit.rb @@ -16,8 +16,8 @@ require 'test/unit' require 'abstract_controller' require 'action_controller' require 'action_view' +require 'action_view/testing/resolvers' require 'action_dispatch' -require 'fixture_template' require 'active_support/dependencies' require 'active_model' diff --git a/actionpack/test/controller/layout_test.rb b/actionpack/test/controller/layout_test.rb index 48be7571ea..165c61ffad 100644 --- a/actionpack/test/controller/layout_test.rb +++ b/actionpack/test/controller/layout_test.rb @@ -10,8 +10,6 @@ ActionView::Template::register_template_handler :mab, ActionController::Base.view_paths = [ File.dirname(__FILE__) + '/../fixtures/layout_tests/' ] -require "fixture_template" - class LayoutTest < ActionController::Base def self.controller_path; 'views' end def self._implied_layout_name; to_s.underscore.gsub(/_controller$/, '') ; end diff --git a/actionpack/test/lib/fixture_template.rb b/actionpack/test/lib/fixture_template.rb deleted file mode 100644 index b49ccd39ca..0000000000 --- a/actionpack/test/lib/fixture_template.rb +++ /dev/null @@ -1,29 +0,0 @@ -module ActionView #:nodoc: - class FixtureResolver < PathResolver - attr_reader :hash - - def initialize(hash = {}) - super() - @hash = hash - end - - private - - def query(path, exts, formats) - query = Regexp.escape(path) - exts.each do |ext| - query << '(' << ext.map {|e| e && Regexp.escape(".#{e}") }.join('|') << '|)' - end - - templates = [] - @hash.select { |k,v| k =~ /^#{query}$/ }.each do |path, source| - handler, format = extract_handler_and_format(path, formats) - templates << Template.new(source, path, handler, - :virtual_path => path, :format => format) - end - - templates.sort_by {|t| -t.identifier.match(/^#{query}$/).captures.reject(&:blank?).size } - end - - end -end \ No newline at end of file -- cgit v1.2.3 From a3044967ed48e27104e8c97719c798ee2f416846 Mon Sep 17 00:00:00 2001 From: David Chelimsky Date: Sun, 2 May 2010 09:54:43 -0500 Subject: add tests for FixtureResolver MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: José Valim --- .../test/template/testing/fixture_resolver_test.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 actionpack/test/template/testing/fixture_resolver_test.rb (limited to 'actionpack') diff --git a/actionpack/test/template/testing/fixture_resolver_test.rb b/actionpack/test/template/testing/fixture_resolver_test.rb new file mode 100644 index 0000000000..de83540468 --- /dev/null +++ b/actionpack/test/template/testing/fixture_resolver_test.rb @@ -0,0 +1,18 @@ +require 'abstract_unit' + +class FixtureResolverTest < ActiveSupport::TestCase + def test_should_return_empty_list_for_unknown_path + resolver = ActionView::FixtureResolver.new() + templates = resolver.find_all("path", "arbitrary", false, {:locale => [], :formats => [:html], :handlers => []}) + assert_equal [], templates, "expected an empty list of templates" + end + + def test_should_return_template_for_declared_path + resolver = ActionView::FixtureResolver.new("arbitrary/path" => "this text") + templates = resolver.find_all("path", "arbitrary", false, {:locale => [], :formats => [:html], :handlers => []}) + assert_equal 1, templates.size, "expected one template" + assert_equal "this text", templates.first.source + assert_equal "arbitrary/path", templates.first.virtual_path + assert_equal [:html], templates.first.formats + end +end -- cgit v1.2.3 From 8672a97e11b1a3697b0147b83fd1f812395997a1 Mon Sep 17 00:00:00 2001 From: David Chelimsky Date: Sun, 2 May 2010 10:04:32 -0500 Subject: add NullResolver MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [#4523 state:resolved] Signed-off-by: José Valim --- actionpack/lib/action_view/testing/resolvers.rb | 8 ++++++++ actionpack/test/template/testing/null_resolver_test.rb | 12 ++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 actionpack/test/template/testing/null_resolver_test.rb (limited to 'actionpack') diff --git a/actionpack/lib/action_view/testing/resolvers.rb b/actionpack/lib/action_view/testing/resolvers.rb index f468e57c26..578c56c6c4 100644 --- a/actionpack/lib/action_view/testing/resolvers.rb +++ b/actionpack/lib/action_view/testing/resolvers.rb @@ -31,5 +31,13 @@ module ActionView #:nodoc: templates.sort_by {|t| -t.identifier.match(/^#{query}$/).captures.reject(&:blank?).size } end end + + class NullResolver < ActionView::PathResolver + def query(path, exts, formats) + handler, format = extract_handler_and_format(path, formats) + [ActionView::Template.new("Template generated by Null Resolver", path, handler, :virtual_path => path, :format => format)] + end + end + end diff --git a/actionpack/test/template/testing/null_resolver_test.rb b/actionpack/test/template/testing/null_resolver_test.rb new file mode 100644 index 0000000000..e142506e6a --- /dev/null +++ b/actionpack/test/template/testing/null_resolver_test.rb @@ -0,0 +1,12 @@ +require 'abstract_unit' + +class NullResolverTest < ActiveSupport::TestCase + def test_should_return_template_for_any_path + resolver = ActionView::NullResolver.new() + templates = resolver.find_all("path", "arbitrary", false, {:locale => [], :formats => [:html], :handlers => []}) + assert_equal 1, templates.size, "expected one template" + assert_equal "Template generated by Null Resolver", templates.first.source + assert_equal "arbitrary/path", templates.first.virtual_path + assert_equal [:html], templates.first.formats + end +end -- cgit v1.2.3 From 8ae9b05fa0ca579ecabcd563e6ba75ea0f44f074 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Mon, 3 May 2010 12:54:52 +0200 Subject: Make backtrace_cleaner work as expected. Prior to this patch, the Full Trace rarely showed the full trace. Also, increase performance considerably. --- actionpack/lib/action_view/template/error.rb | 32 ++++++---------------------- 1 file changed, 6 insertions(+), 26 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_view/template/error.rb b/actionpack/lib/action_view/template/error.rb index 5222ffa89c..a947d746e3 100644 --- a/actionpack/lib/action_view/template/error.rb +++ b/actionpack/lib/action_view/template/error.rb @@ -21,17 +21,18 @@ module ActionView super("Missing #{template_type} #{path} with #{details.inspect} in view paths #{display_paths}") end end + class Template # The Template::Error exception is raised when the compilation of the template fails. This exception then gathers a # bunch of intimate details and uses it to report a very precise exception message. class Error < ActionViewError #:nodoc: SOURCE_CODE_RADIUS = 3 - attr_reader :original_exception + attr_reader :original_exception, :backtrace def initialize(template, assigns, original_exception) @template, @assigns, @original_exception = template, assigns.dup, original_exception - @backtrace = compute_backtrace + @backtrace = original_exception.backtrace end def file_name @@ -42,14 +43,6 @@ module ActionView ActiveSupport::Deprecation.silence { original_exception.message } end - def clean_backtrace - if defined?(Rails) && Rails.respond_to?(:backtrace_cleaner) - Rails.backtrace_cleaner.clean(original_exception.backtrace) - else - original_exception.backtrace - end - end - def sub_template_message if @sub_templates "Trace of template inclusion: " + @@ -87,29 +80,16 @@ module ActionView @line_number ||= if file_name regexp = /#{Regexp.escape File.basename(file_name)}:(\d+)/ - - $1 if message =~ regexp or clean_backtrace.find { |line| line =~ regexp } + $1 if message =~ regexp || backtrace.find { |line| line =~ regexp } end end def to_s - "\n#{self.class} (#{message}) #{source_location}:\n" + - "#{source_extract}\n #{clean_backtrace.join("\n ")}\n\n" - end - - # don't do anything nontrivial here. Any raised exception from here becomes fatal - # (and can't be rescued). - def backtrace - @backtrace + "\n#{self.class} (#{message}) #{source_location}:\n\n" + + "#{source_extract(4)}\n #{backtrace.join("\n ")}\n\n" end private - def compute_backtrace - [ - "#{source_location.capitalize}\n\n#{source_extract(4)}\n " + - clean_backtrace.join("\n ") - ] - end def source_location if line_number -- cgit v1.2.3 From 9bd91b00b85c77bc294ae2a99beae203cc163227 Mon Sep 17 00:00:00 2001 From: Lawrence Pit Date: Mon, 3 May 2010 16:44:32 +1000 Subject: Favor %{} in all code instead of (deprecated) {{}} as interpolation syntax for I18n MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: José Valim --- actionpack/lib/action_view/helpers/form_helper.rb | 2 +- actionpack/test/template/form_helper_test.rb | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb index b2470edf00..6e26ae6c29 100644 --- a/actionpack/lib/action_view/helpers/form_helper.rb +++ b/actionpack/lib/action_view/helpers/form_helper.rb @@ -1179,7 +1179,7 @@ module ActionView # helpers: # submit: # post: - # create: "Add {{model}}" + # create: "Add %{model}" # def submit(value=nil, options={}) value, options = nil, value if value.is_a?(Hash) diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb index 47ac911540..2234fbece9 100644 --- a/actionpack/test/template/form_helper_test.rb +++ b/actionpack/test/template/form_helper_test.rb @@ -33,11 +33,11 @@ class FormHelperTest < ActionView::TestCase I18n.backend.store_translations 'submit', { :helpers => { :submit => { - :create => 'Create {{model}}', - :update => 'Confirm {{model}} changes', + :create => 'Create %{model}', + :update => 'Confirm %{model} changes', :submit => 'Save changes', :another_post => { - :update => 'Update your {{model}}' + :update => 'Update your %{model}' } } } -- cgit v1.2.3 From 849ab9294244ac94f9ce4621c8cd325a2992a382 Mon Sep 17 00:00:00 2001 From: David Chelimsky Date: Thu, 29 Apr 2010 08:18:47 -0500 Subject: Eliminate false positives when passing symbols to assert_template MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: José Valim --- actionpack/lib/action_controller/test_case.rb | 3 ++- .../test/controller/action_pack_assertions_test.rb | 29 +++++++++++++++++++--- 2 files changed, 27 insertions(+), 5 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_controller/test_case.rb b/actionpack/lib/action_controller/test_case.rb index 2010d8573c..34499fa784 100644 --- a/actionpack/lib/action_controller/test_case.rb +++ b/actionpack/lib/action_controller/test_case.rb @@ -57,7 +57,8 @@ module ActionController validate_request! case options - when NilClass, String + when NilClass, String, Symbol + options = options.to_s if Symbol === options rendered = @templates msg = build_message(message, "expecting but rendering with ", diff --git a/actionpack/test/controller/action_pack_assertions_test.rb b/actionpack/test/controller/action_pack_assertions_test.rb index 1741b58f72..eae2641dc0 100644 --- a/actionpack/test/controller/action_pack_assertions_test.rb +++ b/actionpack/test/controller/action_pack_assertions_test.rb @@ -349,21 +349,43 @@ class ActionPackAssertionsControllerTest < ActionController::TestCase assert_template :partial => '_partial' end - def test_assert_template_with_nil + def test_assert_template_with_nil_passes_when_no_template_rendered get :nothing assert_template nil end - def test_assert_template_with_string + def test_assert_template_with_nil_fails_when_template_rendered + get :hello_world + assert_raise(ActiveSupport::TestCase::Assertion) do + assert_template nil + end + end + + def test_assert_template_passes_with_correct_string get :hello_world assert_template 'hello_world' + assert_template 'test/hello_world' end - def test_assert_template_with_symbol + def test_assert_template_passes_with_correct_symbol get :hello_world assert_template :hello_world end + def test_assert_template_fails_with_incorrect_string + get :hello_world + assert_raise(ActiveSupport::TestCase::Assertion) do + assert_template 'hello_planet' + end + end + + def test_assert_template_fails_with_incorrect_symbol + get :hello_world + assert_raise(ActiveSupport::TestCase::Assertion) do + assert_template :hello_planet + end + end + # check if we were rendered by a file-based template? def test_rendered_action process :nothing @@ -387,7 +409,6 @@ class ActionPackAssertionsControllerTest < ActionController::TestCase assert_nil @response.redirect_url end - # check server errors def test_server_error_response_code process :response500 -- cgit v1.2.3 From b3dcbedc67f49ef64f33570f3e24ac00a47c0181 Mon Sep 17 00:00:00 2001 From: David Chelimsky Date: Thu, 29 Apr 2010 09:29:35 -0500 Subject: move assert_template tests to their own test case [#4501 state:resolved] MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: José Valim --- .../test/controller/action_pack_assertions_test.rb | 87 ++++++++++++---------- 1 file changed, 46 insertions(+), 41 deletions(-) (limited to 'actionpack') diff --git a/actionpack/test/controller/action_pack_assertions_test.rb b/actionpack/test/controller/action_pack_assertions_test.rb index eae2641dc0..765e111226 100644 --- a/actionpack/test/controller/action_pack_assertions_test.rb +++ b/actionpack/test/controller/action_pack_assertions_test.rb @@ -344,47 +344,6 @@ class ActionPackAssertionsControllerTest < ActionController::TestCase end end - def test_assert_template_with_partial - get :partial - assert_template :partial => '_partial' - end - - def test_assert_template_with_nil_passes_when_no_template_rendered - get :nothing - assert_template nil - end - - def test_assert_template_with_nil_fails_when_template_rendered - get :hello_world - assert_raise(ActiveSupport::TestCase::Assertion) do - assert_template nil - end - end - - def test_assert_template_passes_with_correct_string - get :hello_world - assert_template 'hello_world' - assert_template 'test/hello_world' - end - - def test_assert_template_passes_with_correct_symbol - get :hello_world - assert_template :hello_world - end - - def test_assert_template_fails_with_incorrect_string - get :hello_world - assert_raise(ActiveSupport::TestCase::Assertion) do - assert_template 'hello_planet' - end - end - - def test_assert_template_fails_with_incorrect_symbol - get :hello_world - assert_raise(ActiveSupport::TestCase::Assertion) do - assert_template :hello_planet - end - end # check if we were rendered by a file-based template? def test_rendered_action @@ -559,6 +518,52 @@ class ActionPackAssertionsControllerTest < ActionController::TestCase end end +class AssertTemplateTest < ActionController::TestCase + tests ActionPackAssertionsController + + def test_with_partial + get :partial + assert_template :partial => '_partial' + end + + def test_with_nil_passes_when_no_template_rendered + get :nothing + assert_template nil + end + + def test_with_nil_fails_when_template_rendered + get :hello_world + assert_raise(ActiveSupport::TestCase::Assertion) do + assert_template nil + end + end + + def test_passes_with_correct_string + get :hello_world + assert_template 'hello_world' + assert_template 'test/hello_world' + end + + def test_passes_with_correct_symbol + get :hello_world + assert_template :hello_world + end + + def test_fails_with_incorrect_string + get :hello_world + assert_raise(ActiveSupport::TestCase::Assertion) do + assert_template 'hello_planet' + end + end + + def test_fails_with_incorrect_symbol + get :hello_world + assert_raise(ActiveSupport::TestCase::Assertion) do + assert_template :hello_planet + end + end +end + class ActionPackHeaderTest < ActionController::TestCase tests ActionPackAssertionsController -- cgit v1.2.3