aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/lib/action_controller/caching/fragments.rb2
-rw-r--r--actionpack/lib/action_controller/caching/pages.rb2
-rw-r--r--actionpack/lib/action_controller/metal/instrumentation.rb10
-rw-r--r--actionpack/lib/action_controller/test_case.rb11
-rw-r--r--actionpack/lib/action_view/helpers/form_helper.rb8
-rw-r--r--actionpack/lib/action_view/helpers/translation_helper.rb10
-rw-r--r--actionpack/lib/action_view/locale/en.yml28
-rw-r--r--actionpack/lib/action_view/render/partials.rb4
-rw-r--r--actionpack/lib/action_view/render/rendering.rb2
-rw-r--r--actionpack/lib/action_view/template.rb2
-rw-r--r--actionpack/lib/action_view/template/error.rb32
-rw-r--r--actionpack/lib/action_view/testing/resolvers.rb (renamed from actionpack/test/lib/fixture_template.rb)16
-rw-r--r--actionpack/test/abstract_unit.rb2
-rw-r--r--actionpack/test/controller/action_pack_assertions_test.rb66
-rw-r--r--actionpack/test/controller/layout_test.rb2
-rw-r--r--actionpack/test/template/form_helper_test.rb6
-rw-r--r--actionpack/test/template/testing/fixture_resolver_test.rb18
-rw-r--r--actionpack/test/template/testing/null_resolver_test.rb12
18 files changed, 139 insertions, 94 deletions
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..34499fa784 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
@@ -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/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb
index d3604925e8..6e26ae6c29 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:
#
@@ -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/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
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}'
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
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
diff --git a/actionpack/test/lib/fixture_template.rb b/actionpack/lib/action_view/testing/resolvers.rb
index b49ccd39ca..578c56c6c4 100644
--- a/actionpack/test/lib/fixture_template.rb
+++ b/actionpack/lib/action_view/testing/resolvers.rb
@@ -1,4 +1,10 @@
+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
@@ -24,6 +30,14 @@ 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 \ No newline at end of file
+
+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/action_pack_assertions_test.rb b/actionpack/test/controller/action_pack_assertions_test.rb
index 1741b58f72..765e111226 100644
--- a/actionpack/test/controller/action_pack_assertions_test.rb
+++ b/actionpack/test/controller/action_pack_assertions_test.rb
@@ -344,25 +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
- get :nothing
- assert_template nil
- end
-
- def test_assert_template_with_string
- get :hello_world
- assert_template 'hello_world'
- end
-
- def test_assert_template_with_symbol
- get :hello_world
- assert_template :hello_world
- end
# check if we were rendered by a file-based template?
def test_rendered_action
@@ -387,7 +368,6 @@ class ActionPackAssertionsControllerTest < ActionController::TestCase
assert_nil @response.redirect_url
end
-
# check server errors
def test_server_error_response_code
process :response500
@@ -538,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
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/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}'
}
}
}
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
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