aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorDmitry Polushkin <dmitry.polushkin@gmail.com>2011-10-01 20:49:14 +0100
committerDmitry Polushkin <dmitry.polushkin@gmail.com>2011-10-01 20:49:14 +0100
commit19965402b2f868c79d78269ca17cb6282f271382 (patch)
tree8635415f386595650c27469d6b6d04335121d070 /actionpack
parent9d54f8994d09db5435d6c234430ae13333928fb9 (diff)
parentec53b802dab9b676dcc9b53e542bcd840983b7a2 (diff)
downloadrails-19965402b2f868c79d78269ca17cb6282f271382.tar.gz
rails-19965402b2f868c79d78269ca17cb6282f271382.tar.bz2
rails-19965402b2f868c79d78269ca17cb6282f271382.zip
Merge branch 'master' of git://github.com/rails/rails
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/CHANGELOG48
-rwxr-xr-xactionpack/Rakefile5
-rw-r--r--actionpack/lib/action_controller/metal/params_wrapper.rb9
-rw-r--r--actionpack/lib/action_controller/vendor/html-scanner/html/sanitizer.rb1
-rw-r--r--actionpack/lib/action_dispatch/http/mime_type.rb4
-rw-r--r--actionpack/lib/action_dispatch/middleware/show_exceptions.rb4
-rw-r--r--actionpack/lib/action_dispatch/routing/route_set.rb7
-rw-r--r--actionpack/lib/action_dispatch/testing/integration.rb8
-rw-r--r--actionpack/lib/action_view/helpers/asset_tag_helpers/stylesheet_tag_helpers.rb2
-rw-r--r--actionpack/lib/action_view/helpers/url_helper.rb20
-rw-r--r--actionpack/lib/action_view/lookup_context.rb227
-rw-r--r--actionpack/lib/action_view/renderer/abstract_renderer.rb27
-rw-r--r--actionpack/lib/action_view/renderer/partial_renderer.rb23
-rw-r--r--actionpack/lib/action_view/renderer/template_renderer.rb24
-rw-r--r--actionpack/lib/action_view/test_case.rb4
-rw-r--r--actionpack/lib/sprockets/assets.rake67
-rw-r--r--actionpack/lib/sprockets/bootstrap.rb37
-rw-r--r--actionpack/lib/sprockets/compressors.rb46
-rw-r--r--actionpack/lib/sprockets/helpers/rails_helper.rb24
-rw-r--r--actionpack/lib/sprockets/railtie.rb61
-rw-r--r--actionpack/lib/sprockets/static_compiler.rb52
-rw-r--r--actionpack/test/abstract/abstract_controller_test.rb6
-rw-r--r--actionpack/test/controller/caching_test.rb2
-rw-r--r--actionpack/test/controller/integration_test.rb11
-rw-r--r--actionpack/test/controller/layout_test.rb4
-rw-r--r--actionpack/test/controller/new_base/render_file_test.rb10
-rw-r--r--actionpack/test/controller/new_base/render_partial_test.rb10
-rw-r--r--actionpack/test/controller/new_base/render_template_test.rb6
-rw-r--r--actionpack/test/controller/render_test.rb32
-rw-r--r--actionpack/test/dispatch/mime_type_test.rb2
-rw-r--r--actionpack/test/dispatch/routing_test.rb11
-rw-r--r--actionpack/test/dispatch/session/cookie_store_test.rb2
-rw-r--r--actionpack/test/fixtures/comments/empty.de.html.erb1
-rw-r--r--actionpack/test/fixtures/comments/empty.html.builder1
-rw-r--r--actionpack/test/fixtures/comments/empty.html.erb1
-rw-r--r--actionpack/test/fixtures/comments/empty.xml.erb1
-rw-r--r--actionpack/test/fixtures/test/_layout_with_partial_and_yield.html.erb2
-rw-r--r--actionpack/test/template/asset_tag_helper_test.rb4
-rw-r--r--actionpack/test/template/compiled_templates_test.rb16
-rw-r--r--actionpack/test/template/compressors_test.rb29
-rw-r--r--actionpack/test/template/log_subscriber_test.rb2
-rw-r--r--actionpack/test/template/lookup_context_test.rb10
-rw-r--r--actionpack/test/template/render_test.rb79
-rw-r--r--actionpack/test/template/sprockets_helper_test.rb50
-rw-r--r--actionpack/test/template/streaming_render_test.rb16
-rw-r--r--actionpack/test/template/url_helper_test.rb4
46 files changed, 645 insertions, 367 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG
index 5ee14dbdf1..e8c619723f 100644
--- a/actionpack/CHANGELOG
+++ b/actionpack/CHANGELOG
@@ -1,5 +1,13 @@
*Rails 3.2.0 (unreleased)*
+* Passing formats or handlers to render :template and friends is deprecated. For example: [Nick Sutterer & José Valim]
+
+ render :template => "foo.html.erb"
+
+ Instead, you can provide :handlers and :formats directly as option:
+
+ render :template => "foo", :formats => [:html, :js], :handlers => :erb
+
* Changed log level of warning for missing CSRF token from :debug to :warn. [Mike Dillon]
* content_tag_for and div_for can now take the collection of records. It will also yield the record as the first argument if you set a receiving argument in your block [Prem Sichanugrist]
@@ -48,6 +56,46 @@
*Rails 3.1.1 (unreleased)*
+* javascript_path and stylesheet_path now refer to /assets if asset pipelining
+is on. [Santiago Pastorino]
+
+* button_to support form option. Now you're able to pass for example
+'data-type' => 'json'. [ihower]
+
+* image_path and image_tag should use /assets if asset pipelining is turned
+on. Closes #3126 [Santiago Pastorino and christos]
+
+* Avoid use of existing precompiled assets during rake assets:precompile run.
+Closes #3119 [Guillermo Iguaran]
+
+* Copy assets to nondigested filenames too [Santiago Pastorino]
+
+* Give precedence to `config.digest = false` over the existence of
+manifest.yml asset digests [christos]
+
+* escape options for the stylesheet_link_tag method [Alexey Vakhov]
+
+* Re-launch assets:precompile task using (Rake.)ruby instead of Kernel.exec so
+it works on Windows [cablegram]
+
+* env var passed to process shouldn't be modified in process method. [Santiago
+Pastorino]
+
+* `rake assets:precompile` loads the application but does not initialize
+it.
+
+ To the app developer, this means configuration add in
+ config/initializers/* will not be executed.
+
+ Plugins developers need to special case their initializers that are
+ meant to be run in the assets group by adding :group => :assets. [José Valim]
+
+* Sprockets uses config.assets.prefix for asset_path [asee]
+
+* FileStore key_file_path properly limit filenames to 255 characters. [phuibonhoa]
+
+* Fix Hash#to_query edge case with html_safe strings. [brainopia]
+
* Allow asset tag helper methods to accept :digest => false option in order to completely avoid the digest generation.
Useful for linking assets from static html files or from emails when the user
could probably look at an older html email with an older asset. [Santiago Pastorino]
diff --git a/actionpack/Rakefile b/actionpack/Rakefile
index 66dd88f0c6..d9e3e56fcc 100755
--- a/actionpack/Rakefile
+++ b/actionpack/Rakefile
@@ -26,6 +26,11 @@ namespace :test do
Rake::TestTask.new(:isolated) do |t|
t.pattern = 'test/ts_isolated.rb'
end
+
+ Rake::TestTask.new(:template) do |t|
+ t.libs << 'test'
+ t.pattern = 'test/template/**/*.rb'
+ end
end
desc 'ActiveRecord Integration Tests'
diff --git a/actionpack/lib/action_controller/metal/params_wrapper.rb b/actionpack/lib/action_controller/metal/params_wrapper.rb
index 6acbb23907..e0d8e1c992 100644
--- a/actionpack/lib/action_controller/metal/params_wrapper.rb
+++ b/actionpack/lib/action_controller/metal/params_wrapper.rb
@@ -141,19 +141,16 @@ module ActionController
# try to find Foo::Bar::User, Foo::User and finally User.
def _default_wrap_model #:nodoc:
return nil if self.anonymous?
-
model_name = self.name.sub(/Controller$/, '').singularize
begin
- model_klass = model_name.constantize
- rescue NameError, ArgumentError => e
- if e.message =~ /is not missing constant|uninitialized constant #{model_name}/
+ if model_klass = model_name.safe_constantize
+ model_klass
+ else
namespaces = model_name.split("::")
namespaces.delete_at(-2)
break if namespaces.last == model_name
model_name = namespaces.join("::")
- else
- raise
end
end until model_klass
diff --git a/actionpack/lib/action_controller/vendor/html-scanner/html/sanitizer.rb b/actionpack/lib/action_controller/vendor/html-scanner/html/sanitizer.rb
index eaefdc0f15..af06bffa16 100644
--- a/actionpack/lib/action_controller/vendor/html-scanner/html/sanitizer.rb
+++ b/actionpack/lib/action_controller/vendor/html-scanner/html/sanitizer.rb
@@ -1,4 +1,5 @@
require 'set'
+require 'cgi'
require 'active_support/core_ext/class/attribute'
module HTML
diff --git a/actionpack/lib/action_dispatch/http/mime_type.rb b/actionpack/lib/action_dispatch/http/mime_type.rb
index fa2948c8db..8a9f9c4315 100644
--- a/actionpack/lib/action_dispatch/http/mime_type.rb
+++ b/actionpack/lib/action_dispatch/http/mime_type.rb
@@ -256,6 +256,10 @@ module Mime
@@html_types.include?(to_sym) || @string =~ /html/
end
+ def respond_to?(method, include_private = false) #:nodoc:
+ super || method.to_s =~ /(\w+)\?$/
+ end
+
private
def method_missing(method, *args)
if method.to_s =~ /(\w+)\?$/
diff --git a/actionpack/lib/action_dispatch/middleware/show_exceptions.rb b/actionpack/lib/action_dispatch/middleware/show_exceptions.rb
index a765c23dae..2fa68c64c5 100644
--- a/actionpack/lib/action_dispatch/middleware/show_exceptions.rb
+++ b/actionpack/lib/action_dispatch/middleware/show_exceptions.rb
@@ -86,8 +86,8 @@ module ActionDispatch
:framework_trace => framework_trace(exception),
:full_trace => full_trace(exception)
)
- file = "rescues/#{@@rescue_templates[exception.class.name]}.erb"
- body = template.render(:file => file, :layout => 'rescues/layout.erb')
+ file = "rescues/#{@@rescue_templates[exception.class.name]}"
+ body = template.render(:template => file, :layout => 'rescues/layout')
render(status_code(exception), body)
end
diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb
index 46a68a32ae..e921269331 100644
--- a/actionpack/lib/action_dispatch/routing/route_set.rb
+++ b/actionpack/lib/action_dispatch/routing/route_set.rb
@@ -165,13 +165,14 @@ module ActionDispatch
remove_possible_method :#{selector}
def #{selector}(*args)
options = args.extract_options!
+ result = #{options.inspect}
if args.any?
- options[:_positional_args] = args
- options[:_positional_keys] = #{route.segment_keys.inspect}
+ result[:_positional_args] = args
+ result[:_positional_keys] = #{route.segment_keys.inspect}
end
- options ? #{options.inspect}.merge(options) : #{options.inspect}
+ result.merge(options)
end
protected :#{selector}
END_EVAL
diff --git a/actionpack/lib/action_dispatch/testing/integration.rb b/actionpack/lib/action_dispatch/testing/integration.rb
index aae5752c93..0f1bb9f260 100644
--- a/actionpack/lib/action_dispatch/testing/integration.rb
+++ b/actionpack/lib/action_dispatch/testing/integration.rb
@@ -241,8 +241,8 @@ module ActionDispatch
end
# Performs the actual request.
- def process(method, path, parameters = nil, env = nil)
- env ||= {}
+ def process(method, path, parameters = nil, rack_env = nil)
+ rack_env ||= {}
if path =~ %r{://}
location = URI.parse(path)
https! URI::HTTPS === location if location.scheme
@@ -258,7 +258,7 @@ module ActionDispatch
hostname, port = host.split(':')
- default_env = {
+ env = {
:method => method,
:params => parameters,
@@ -276,7 +276,7 @@ module ActionDispatch
session = Rack::Test::Session.new(_mock_session)
- env.reverse_merge!(default_env)
+ env.merge!(rack_env)
# NOTE: rack-test v0.5 doesn't build a default uri correctly
# Make sure requested path is always a full uri
diff --git a/actionpack/lib/action_view/helpers/asset_tag_helpers/stylesheet_tag_helpers.rb b/actionpack/lib/action_view/helpers/asset_tag_helpers/stylesheet_tag_helpers.rb
index 2eb3eb31af..343153c8c5 100644
--- a/actionpack/lib/action_view/helpers/asset_tag_helpers/stylesheet_tag_helpers.rb
+++ b/actionpack/lib/action_view/helpers/asset_tag_helpers/stylesheet_tag_helpers.rb
@@ -17,7 +17,7 @@ module ActionView
def asset_tag(source, options)
# We force the :request protocol here to avoid a double-download bug in IE7 and IE8
- tag("link", { "rel" => "stylesheet", "type" => Mime::CSS, "media" => "screen", "href" => ERB::Util.html_escape(path_to_asset(source, :protocol => :request)) }.merge(options), false, false)
+ tag("link", { "rel" => "stylesheet", "type" => Mime::CSS, "media" => "screen", "href" => path_to_asset(source, :protocol => :request) }.merge(options))
end
def custom_dir
diff --git a/actionpack/lib/action_view/helpers/url_helper.rb b/actionpack/lib/action_view/helpers/url_helper.rb
index acd5e46e33..0c2e1aa3a9 100644
--- a/actionpack/lib/action_view/helpers/url_helper.rb
+++ b/actionpack/lib/action_view/helpers/url_helper.rb
@@ -279,6 +279,7 @@ module ActionView
# processed normally, otherwise no action is taken.
# * <tt>:remote</tt> - If set to true, will allow the Unobtrusive JavaScript drivers to control the
# submit behavior. By default this behavior is an ajax submit.
+ # * <tt>:form</tt> - This hash will be form attributes
# * <tt>:form_class</tt> - This controls the class of the form within which the submit button will
# be placed
#
@@ -295,6 +296,12 @@ module ActionView
# # </form>"
#
#
+ # <%= button_to "Create", :action => "create", :remote => true, :form => { "data-type" => "json" } %>
+ # # => "<form method="post" action="/images/create" class="button_to" data-remote="true" data-type="json">
+ # # <div><input value="Create" type="submit" /></div>
+ # # </form>"
+ #
+ #
# <%= button_to "Delete Image", { :action => "delete", :id => @image.id },
# :confirm => "Are you sure?", :method => :delete %>
# # => "<form method="post" action="/images/delete/1" class="button_to">
@@ -324,10 +331,11 @@ module ActionView
end
form_method = method.to_s == 'get' ? 'get' : 'post'
- form_class = html_options.delete('form_class') || 'button_to'
-
+ form_options = html_options.delete('form') || {}
+ form_options[:class] ||= html_options.delete('form_class') || 'button_to'
+
remote = html_options.delete('remote')
-
+
request_token_tag = ''
if form_method == 'post' && protect_against_forgery?
request_token_tag = tag(:input, :type => "hidden", :name => request_forgery_protection_token.to_s, :value => form_authenticity_token)
@@ -340,8 +348,10 @@ module ActionView
html_options.merge!("type" => "submit", "value" => name)
- ("<form method=\"#{form_method}\" action=\"#{ERB::Util.html_escape(url)}\" #{"data-remote=\"true\"" if remote} class=\"#{ERB::Util.html_escape(form_class)}\"><div>" +
- method_tag + tag("input", html_options) + request_token_tag + "</div></form>").html_safe
+ form_options.merge!(:method => form_method, :action => url)
+ form_options.merge!("data-remote" => "true") if remote
+
+ "#{tag(:form, form_options, true)}<div>#{method_tag}#{tag("input", html_options)}#{request_token_tag}</div></form>".html_safe
end
diff --git a/actionpack/lib/action_view/lookup_context.rb b/actionpack/lib/action_view/lookup_context.rb
index 9ec410ac2b..fa4bf70f77 100644
--- a/actionpack/lib/action_view/lookup_context.rb
+++ b/actionpack/lib/action_view/lookup_context.rb
@@ -1,5 +1,6 @@
require 'active_support/core_ext/array/wrap'
require 'active_support/core_ext/object/blank'
+require 'active_support/core_ext/module/remove_method'
module ActionView
# = Action View Lookup Context
@@ -17,23 +18,25 @@ module ActionView
mattr_accessor :registered_details
self.registered_details = []
- mattr_accessor :registered_detail_setters
- self.registered_detail_setters = []
-
def self.register_detail(name, options = {}, &block)
self.registered_details << name
- self.registered_detail_setters << [name, "#{name}="]
+ initialize = registered_details.map { |n| "self.#{n} = details[:#{n}]" }
- Accessors.send :define_method, :"_#{name}_defaults", &block
+ Accessors.send :define_method, :"default_#{name}", &block
Accessors.module_eval <<-METHOD, __FILE__, __LINE__ + 1
def #{name}
@details[:#{name}]
end
def #{name}=(value)
- value = Array.wrap(value.presence || _#{name}_defaults)
+ value = Array.wrap(value.presence || default_#{name})
_set_detail(:#{name}, value) if value != @details[:#{name}]
end
+
+ remove_possible_method :initialize_details
+ def initialize_details(details)
+ #{initialize.join("\n")}
+ end
METHOD
end
@@ -41,8 +44,9 @@ module ActionView
module Accessors #:nodoc:
end
- register_detail(:formats) { Mime::SET.symbols }
register_detail(:locale) { [I18n.locale, I18n.default_locale] }
+ register_detail(:formats) { Mime::SET.symbols }
+ register_detail(:handlers){ Template::Handlers.extensions }
class DetailsKey #:nodoc:
alias :eql? :equal?
@@ -60,18 +64,34 @@ module ActionView
end
end
- def initialize(view_paths, details = {}, prefixes = [])
- @details, @details_key = { :handlers => default_handlers }, nil
- @frozen_formats, @skip_default_locale = false, false
- @cache = true
- @prefixes = prefixes
+ # Add caching behavior on top of Details.
+ module DetailsCache
+ attr_accessor :cache
- self.view_paths = view_paths
- self.registered_detail_setters.each do |key, setter|
- send(setter, details[key])
+ # Calculate the details key. Remove the handlers from calculation to improve performance
+ # since the user cannot modify it explicitly.
+ def details_key #:nodoc:
+ @details_key ||= DetailsKey.get(@details) if @cache
+ end
+
+ # Temporary skip passing the details_key forward.
+ def disable_cache
+ old_value, @cache = @cache, false
+ yield
+ ensure
+ @cache = old_value
+ end
+
+ protected
+
+ def _set_detail(key, value)
+ @details_key = nil
+ @details = @details.dup if @details.frozen?
+ @details[key] = value.freeze
end
end
+ # Helpers related to template lookup using the lookup context information.
module ViewPaths
attr_reader :view_paths
@@ -81,17 +101,17 @@ module ActionView
@view_paths = ActionView::PathSet.new(Array.wrap(paths))
end
- def find(name, prefixes = [], partial = false, keys = [])
- @view_paths.find(*args_for_lookup(name, prefixes, partial, keys))
+ def find(name, prefixes = [], partial = false, keys = [], options = {})
+ @view_paths.find(*args_for_lookup(name, prefixes, partial, keys, options))
end
alias :find_template :find
- def find_all(name, prefixes = [], partial = false, keys = [])
- @view_paths.find_all(*args_for_lookup(name, prefixes, partial, keys))
+ def find_all(name, prefixes = [], partial = false, keys = [], options = {})
+ @view_paths.find_all(*args_for_lookup(name, prefixes, partial, keys, options))
end
- def exists?(name, prefixes = [], partial = false, keys = [])
- @view_paths.exists?(*args_for_lookup(name, prefixes, partial, keys))
+ def exists?(name, prefixes = [], partial = false, keys = [], options = {})
+ @view_paths.exists?(*args_for_lookup(name, prefixes, partial, keys, options))
end
alias :template_exists? :exists?
@@ -110,16 +130,29 @@ module ActionView
protected
- def args_for_lookup(name, prefixes, partial, keys) #:nodoc:
+ def args_for_lookup(name, prefixes, partial, keys, details_options) #:nodoc:
name, prefixes = normalize_name(name, prefixes)
- [name, prefixes, partial || false, @details, details_key, keys]
+ details, details_key = detail_args_for(details_options)
+ [name, prefixes, partial || false, details, details_key, keys]
+ end
+
+ # Compute details hash and key according to user options (e.g. passed from #render).
+ def detail_args_for(options)
+ return @details, details_key if options.empty? # most common path.
+ user_details = @details.merge(options)
+ [user_details, DetailsKey.get(user_details)]
end
# Support legacy foo.erb names even though we now ignore .erb
# as well as incorrectly putting part of the path in the template
# name instead of the prefix.
def normalize_name(name, prefixes) #:nodoc:
- name = name.to_s.gsub(handlers_regexp, '')
+ name = name.to_s.sub(handlers_regexp) do |match|
+ ActiveSupport::Deprecation.warn "Passing a template handler in the template name is deprecated. " \
+ "You can simply remove the handler name or pass render :handlers => [:#{match[1..-1]}] instead.", caller
+ ""
+ end
+
parts = name.split('/')
name = parts.pop
@@ -132,120 +165,82 @@ module ActionView
return name, prefixes
end
- def default_handlers #:nodoc:
- @@default_handlers ||= Template::Handlers.extensions
- end
-
def handlers_regexp #:nodoc:
@@handlers_regexp ||= /\.(?:#{default_handlers.join('|')})$/
end
end
- module Details
- attr_accessor :cache
-
- # Calculate the details key. Remove the handlers from calculation to improve performance
- # since the user cannot modify it explicitly.
- def details_key #:nodoc:
- @details_key ||= DetailsKey.get(@details) if @cache
- end
-
- # Temporary skip passing the details_key forward.
- def disable_cache
- old_value, @cache = @cache, false
- yield
- ensure
- @cache = old_value
- end
+ include Accessors
+ include DetailsCache
+ include ViewPaths
- # Freeze the current formats in the lookup context. By freezing them, you are guaranteeing
- # that next template lookups are not going to modify the formats. The controller can also
- # use this, to ensure that formats won't be further modified (as it does in respond_to blocks).
- def freeze_formats(formats, unless_frozen=false) #:nodoc:
- return if unless_frozen && @frozen_formats
- self.formats = formats
- @frozen_formats = true
- end
+ def initialize(view_paths, details = {}, prefixes = [])
+ @details, @details_key = {}, nil
+ @frozen_formats, @skip_default_locale = false, false
+ @cache = true
+ @prefixes = prefixes
- # Overload formats= to expand ["*/*"] values and automatically
- # add :html as fallback to :js.
- def formats=(values)
- if values
- values.concat(_formats_defaults) if values.delete "*/*"
- values << :html if values == [:js]
- end
- super(values)
- end
+ self.view_paths = view_paths
+ initialize_details(details)
+ end
- # Do not use the default locale on template lookup.
- def skip_default_locale!
- @skip_default_locale = true
- self.locale = nil
- end
+ # Freeze the current formats in the lookup context. By freezing them, you
+ # that next template lookups are not going to modify the formats. The con
+ # use this, to ensure that formats won't be further modified (as it does
+ def freeze_formats(formats, unless_frozen=false) #:nodoc:
+ return if unless_frozen && @frozen_formats
+ self.formats = formats
+ @frozen_formats = true
+ end
- # Overload locale to return a symbol instead of array.
- def locale
- @details[:locale].first
+ # Override formats= to expand ["*/*"] values and automatically
+ # add :html as fallback to :js.
+ def formats=(values)
+ if values
+ values.concat(default_formats) if values.delete "*/*"
+ values << :html if values == [:js]
end
+ super(values)
+ end
- # Overload locale= to also set the I18n.locale. If the current I18n.config object responds
- # to original_config, it means that it's has a copy of the original I18n configuration and it's
- # acting as proxy, which we need to skip.
- def locale=(value)
- if value
- config = I18n.config.respond_to?(:original_config) ? I18n.config.original_config : I18n.config
- config.locale = value
- end
+ # Do not use the default locale on template lookup.
+ def skip_default_locale!
+ @skip_default_locale = true
+ self.locale = nil
+ end
- super(@skip_default_locale ? I18n.locale : _locale_defaults)
- end
+ # Override locale to return a symbol instead of array.
+ def locale
+ @details[:locale].first
+ end
- # A method which only uses the first format in the formats array for layout lookup.
- # This method plays straight with instance variables for performance reasons.
- def with_layout_format
- if formats.size == 1
- yield
- else
- old_formats = formats
- _set_detail(:formats, formats[0,1])
-
- begin
- yield
- ensure
- _set_detail(:formats, old_formats)
- end
- end
+ # Overload locale= to also set the I18n.locale. If the current I18n.config object responds
+ # to original_config, it means that it's has a copy of the original I18n configuration and it's
+ # acting as proxy, which we need to skip.
+ def locale=(value)
+ if value
+ config = I18n.config.respond_to?(:original_config) ? I18n.config.original_config : I18n.config
+ config.locale = value
end
- # Update the details keys by merging the given hash into the current
- # details hash. If a block is given, the details are modified just during
- # the execution of the block and reverted to the previous value after.
- def update_details(new_details)
- old_details = @details.dup
+ super(@skip_default_locale ? I18n.locale : default_locale)
+ end
- registered_detail_setters.each do |key, setter|
- send(setter, new_details[key]) if new_details.key?(key)
- end
+ # A method which only uses the first format in the formats array for layout lookup.
+ # This method plays straight with instance variables for performance reasons.
+ def with_layout_format
+ if formats.size == 1
+ yield
+ else
+ old_formats = formats
+ _set_detail(:formats, formats[0,1])
begin
yield
ensure
- @details_key = nil
- @details = old_details
+ _set_detail(:formats, old_formats)
end
end
-
- protected
-
- def _set_detail(key, value)
- @details_key = nil
- @details = @details.dup if @details.frozen?
- @details[key] = value.freeze
- end
end
-
- include Accessors
- include Details
- include ViewPaths
end
end
diff --git a/actionpack/lib/action_view/renderer/abstract_renderer.rb b/actionpack/lib/action_view/renderer/abstract_renderer.rb
index 60c527beeb..c0936441ac 100644
--- a/actionpack/lib/action_view/renderer/abstract_renderer.rb
+++ b/actionpack/lib/action_view/renderer/abstract_renderer.rb
@@ -11,15 +11,22 @@ module ActionView
raise NotImplementedError
end
- # Checks if the given path contains a format and if so, change
- # the lookup context to take this new format into account.
- def wrap_formats(value)
- return yield unless value.is_a?(String)
-
- if value.sub!(formats_regexp, "")
- update_details(:formats => [$1.to_sym]){ yield }
- else
- yield
+ protected
+
+ def extract_details(options)
+ details = {}
+ @lookup_context.registered_details.each do |key|
+ next unless value = options[key]
+ details[key] = Array.wrap(value)
+ end
+ details
+ end
+
+ def extract_format(value, details)
+ if value.is_a?(String) && value.sub!(formats_regexp, "")
+ ActiveSupport::Deprecation.warn "Passing the format in the template name is deprecated. " \
+ "Please pass render with :formats => [:#{$1}] instead.", caller
+ details[:formats] ||= [$1.to_sym]
end
end
@@ -27,8 +34,6 @@ module ActionView
@@formats_regexp ||= /\.(#{Mime::SET.symbols.join('|')})$/
end
- protected
-
def instrument(name, options={})
ActiveSupport::Notifications.instrument("render_#{name}.action_view", options){ yield }
end
diff --git a/actionpack/lib/action_view/renderer/partial_renderer.rb b/actionpack/lib/action_view/renderer/partial_renderer.rb
index cd0f7054a9..e808fa3415 100644
--- a/actionpack/lib/action_view/renderer/partial_renderer.rb
+++ b/actionpack/lib/action_view/renderer/partial_renderer.rb
@@ -216,18 +216,15 @@ module ActionView
def render(context, options, block)
setup(context, options, block)
+ identifier = (@template = find_partial) ? @template.identifier : @path
- wrap_formats(@path) do
- identifier = ((@template = find_partial) ? @template.identifier : @path)
-
- if @collection
- instrument(:collection, :identifier => identifier || "collection", :count => @collection.size) do
- render_collection
- end
- else
- instrument(:partial, :identifier => identifier) do
- render_partial
- end
+ if @collection
+ instrument(:collection, :identifier => identifier || "collection", :count => @collection.size) do
+ render_collection
+ end
+ else
+ instrument(:partial, :identifier => identifier) do
+ render_partial
end
end
end
@@ -271,6 +268,7 @@ module ActionView
@options = options
@locals = options[:locals] || {}
@block = block
+ @details = extract_details(options)
if String === partial
@object = options[:object]
@@ -299,6 +297,7 @@ module ActionView
"and is followed by any combinations of letters, numbers, or underscores.")
end
+ extract_format(@path, @details)
self
end
@@ -326,7 +325,7 @@ module ActionView
def find_template(path=@path, locals=@locals.keys)
prefixes = path.include?(?/) ? [] : @lookup_context.prefixes
- @lookup_context.find_template(path, prefixes, true, locals)
+ @lookup_context.find_template(path, prefixes, true, locals, @details)
end
def collection_with_template
diff --git a/actionpack/lib/action_view/renderer/template_renderer.rb b/actionpack/lib/action_view/renderer/template_renderer.rb
index d04c00fd40..ac91d333ba 100644
--- a/actionpack/lib/action_view/renderer/template_renderer.rb
+++ b/actionpack/lib/action_view/renderer/template_renderer.rb
@@ -4,13 +4,12 @@ require 'active_support/core_ext/array/wrap'
module ActionView
class TemplateRenderer < AbstractRenderer #:nodoc:
def render(context, options)
- @view = context
-
- wrap_formats(options[:template] || options[:file]) do
- template = determine_template(options)
- freeze_formats(template.formats, true)
- render_template(template, options[:layout], options[:locals])
- end
+ @view = context
+ @details = extract_details(options)
+ extract_format(options[:file] || options[:template], @details)
+ template = determine_template(options)
+ freeze_formats(template.formats, true)
+ render_template(template, options[:layout], options[:locals])
end
# Determine the template to be rendered using the given options.
@@ -20,13 +19,13 @@ module ActionView
if options.key?(:text)
Template::Text.new(options[:text], formats.try(:first))
elsif options.key?(:file)
- with_fallbacks { find_template(options[:file], nil, false, keys) }
+ with_fallbacks { find_template(options[:file], nil, false, keys, @details) }
elsif options.key?(:inline)
handler = Template.handler_for_extension(options[:type] || "erb")
Template.new(options[:inline], "inline template", handler, :locals => keys)
elsif options.key?(:template)
options[:template].respond_to?(:render) ?
- options[:template] : find_template(options[:template], options[:prefixes], false, keys)
+ options[:template] : find_template(options[:template], options[:prefixes], false, keys, @details)
end
end
@@ -62,12 +61,11 @@ module ActionView
begin
with_layout_format do
layout =~ /^\// ?
- with_fallbacks { find_template(layout, nil, false, keys) } : find_template(layout, nil, false, keys)
+ with_fallbacks { find_template(layout, nil, false, keys, @details) } : find_template(layout, nil, false, keys, @details)
end
rescue ActionView::MissingTemplate
- update_details(:formats => nil) do
- raise unless template_exists?(layout)
- end
+ all_details = @details.merge(:formats => @lookup_context.default_formats)
+ raise unless template_exists?(layout, nil, false, keys, all_details)
end
end
end
diff --git a/actionpack/lib/action_view/test_case.rb b/actionpack/lib/action_view/test_case.rb
index 2cc85a9f69..c4d51d7946 100644
--- a/actionpack/lib/action_view/test_case.rb
+++ b/actionpack/lib/action_view/test_case.rb
@@ -54,10 +54,8 @@ module ActionView
end
def determine_default_helper_class(name)
- mod = name.sub(/Test$/, '').constantize
+ mod = name.sub(/Test$/, '').safe_constantize
mod.is_a?(Class) ? nil : mod
- rescue NameError
- nil
end
def helper_method(*methods)
diff --git a/actionpack/lib/sprockets/assets.rake b/actionpack/lib/sprockets/assets.rake
index 9b2f3a3f94..bb5cf6740a 100644
--- a/actionpack/lib/sprockets/assets.rake
+++ b/actionpack/lib/sprockets/assets.rake
@@ -6,58 +6,55 @@ namespace :assets do
if ENV["RAILS_GROUPS"].to_s.empty? || ENV["RAILS_ENV"].to_s.empty?
ENV["RAILS_GROUPS"] ||= "assets"
ENV["RAILS_ENV"] ||= "production"
- Kernel.exec $0, *ARGV
+ ruby $0, *ARGV
else
- Rake::Task["environment"].invoke
+ require "fileutils"
Rake::Task["tmp:cache:clear"].invoke
+ Rake::Task["assets:environment"].invoke
- # Ensure that action view is loaded and the appropriate sprockets hooks get executed
- ActionView::Base
-
- # Always compile files
- Rails.application.config.assets.compile = true
+ unless Rails.application.config.assets.enabled
+ raise "Cannot precompile assets if sprockets is disabled. Please set config.assets.enabled to true"
+ end
- # Always ignore asset host
- Rails.application.config.action_controller.asset_host = nil
+ # Ensure that action view is loaded and the appropriate sprockets hooks get executed
+ _ = ActionView::Base
config = Rails.application.config
+ config.assets.compile = true
+ config.assets.digest = false if ENV["RAILS_ASSETS_NONDIGEST"]
+
env = Rails.application.assets
- target = Pathname.new(File.join(Rails.public_path, config.assets.prefix))
- manifest = {}
+
+ # Always compile files and avoid use of existing precompiled assets
+ config.assets.compile = true
+ config.assets.digests = {}
+
+ target = File.join(Rails.public_path, config.assets.prefix)
+ static_compiler = Sprockets::StaticCompiler.new(env, target, :digest => config.assets.digest)
+
+ manifest = static_compiler.precompile(config.assets.precompile)
manifest_path = config.assets.manifest || target
+ FileUtils.mkdir_p(manifest_path)
- config.assets.precompile.each do |path|
- env.each_logical_path do |logical_path|
- if path.is_a?(Regexp)
- next unless path.match(logical_path)
- elsif path.is_a?(Proc)
- next unless path.call(logical_path)
- else
- next unless File.fnmatch(path.to_s, logical_path)
- end
-
- if asset = env.find_asset(logical_path)
- asset_path = config.assets.digest ? asset.digest_path : logical_path
- manifest[logical_path] = asset_path
- filename = target.join(asset_path)
-
- mkdir_p filename.dirname
- asset.write_to(filename)
- asset.write_to("#{filename}.gz") if filename.to_s =~ /\.(css|js)$/
- end
+ unless ENV["RAILS_ASSETS_NONDIGEST"]
+ File.open("#{manifest_path}/manifest.yml", 'wb') do |f|
+ YAML.dump(manifest, f)
end
- end
-
- File.open("#{manifest_path}/manifest.yml", 'wb') do |f|
- YAML.dump(manifest, f)
+ ENV["RAILS_ASSETS_NONDIGEST"] = "true"
+ ruby $0, *ARGV
end
end
end
desc "Remove compiled assets"
- task :clean => [:environment, 'tmp:cache:clear'] do
+ task :clean => ['assets:environment', 'tmp:cache:clear'] do
config = Rails.application.config
public_asset_path = File.join(Rails.public_path, config.assets.prefix)
rm_rf public_asset_path, :secure => true
end
+
+ task :environment do
+ Rails.application.initialize!(:assets)
+ Sprockets::Bootstrap.new(Rails.application).run
+ end
end
diff --git a/actionpack/lib/sprockets/bootstrap.rb b/actionpack/lib/sprockets/bootstrap.rb
new file mode 100644
index 0000000000..395b264fe7
--- /dev/null
+++ b/actionpack/lib/sprockets/bootstrap.rb
@@ -0,0 +1,37 @@
+module Sprockets
+ class Bootstrap
+ def initialize(app)
+ @app = app
+ end
+
+ # TODO: Get rid of config.assets.enabled
+ def run
+ app, config = @app, @app.config
+ return unless app.assets
+
+ config.assets.paths.each { |path| app.assets.append_path(path) }
+
+ if config.assets.compress
+ # temporarily hardcode default JS compressor to uglify. Soon, it will work
+ # the same as SCSS, where a default plugin sets the default.
+ unless config.assets.js_compressor == false
+ app.assets.js_compressor = LazyCompressor.new { Sprockets::Compressors.registered_js_compressor(config.assets.js_compressor || :uglifier) }
+ end
+
+ unless config.assets.css_compressor == false
+ app.assets.css_compressor = LazyCompressor.new { Sprockets::Compressors.registered_css_compressor(config.assets.css_compressor) }
+ end
+ end
+
+ if config.assets.compile
+ app.routes.prepend do
+ mount app.assets => config.assets.prefix
+ end
+ end
+
+ if config.assets.digest
+ app.assets = app.assets.index
+ end
+ end
+ end
+end
diff --git a/actionpack/lib/sprockets/compressors.rb b/actionpack/lib/sprockets/compressors.rb
index 351eff1085..cb3e13314b 100644
--- a/actionpack/lib/sprockets/compressors.rb
+++ b/actionpack/lib/sprockets/compressors.rb
@@ -1,4 +1,50 @@
module Sprockets
+ module Compressors
+ @@css_compressors = {}
+ @@js_compressors = {}
+ @@default_css_compressor = nil
+ @@default_js_compressor = nil
+
+ def self.register_css_compressor(name, klass, options = {})
+ @@default_css_compressor = name.to_sym if options[:default] || @@default_css_compressor.nil?
+ @@css_compressors[name.to_sym] = {:klass => klass.to_s, :require => options[:require]}
+ end
+
+ def self.register_js_compressor(name, klass, options = {})
+ @@default_js_compressor = name.to_sym if options[:default] || @@default_js_compressor.nil?
+ @@js_compressors[name.to_sym] = {:klass => klass.to_s, :require => options[:require]}
+ end
+
+ def self.registered_css_compressor(name)
+ if name.respond_to?(:to_sym)
+ compressor = @@css_compressors[name.to_sym] || @@css_compressors[@@default_css_compressor]
+ require compressor[:require] if compressor[:require]
+ compressor[:klass].constantize.new
+ else
+ name
+ end
+ end
+
+ def self.registered_js_compressor(name)
+ if name.respond_to?(:to_sym)
+ compressor = @@js_compressors[name.to_sym] || @@js_compressors[@@default_js_compressor]
+ require compressor[:require] if compressor[:require]
+ compressor[:klass].constantize.new
+ else
+ name
+ end
+ end
+
+ # The default compressors must be registered in default plugins (ex. Sass-Rails)
+ register_css_compressor(:scss, 'Sass::Rails::Compressor', :require => 'sass/rails/compressor', :default => true)
+ register_js_compressor(:uglifier, 'Uglifier', :require => 'uglifier', :default => true)
+
+ # Automaticaly register some compressors
+ register_css_compressor(:yui, 'YUI::CssCompressor', :require => 'yui/compressor')
+ register_js_compressor(:closure, 'Closure::Compiler', :require => 'closure-compiler')
+ register_js_compressor(:yui, 'YUI::JavaScriptCompressor', :require => 'yui/compressor')
+ end
+
# An asset compressor which does nothing.
#
# This compressor simply returns the asset as-is, without any compression
diff --git a/actionpack/lib/sprockets/helpers/rails_helper.rb b/actionpack/lib/sprockets/helpers/rails_helper.rb
index 457ab93ae3..e1d8fccf04 100644
--- a/actionpack/lib/sprockets/helpers/rails_helper.rb
+++ b/actionpack/lib/sprockets/helpers/rails_helper.rb
@@ -13,7 +13,6 @@ module Sprockets
controller = self.controller if respond_to?(:controller)
paths = RailsHelper::AssetPaths.new(config, controller)
paths.asset_environment = asset_environment
- paths.asset_prefix = asset_prefix
paths.asset_digests = asset_digests
paths.compile_assets = compile_assets?
paths.digest_assets = digest_assets?
@@ -57,10 +56,25 @@ module Sprockets
def asset_path(source, options = {})
source = source.logical_path if source.respond_to?(:logical_path)
- path = asset_paths.compute_public_path(source, 'assets', options.merge(:body => true))
+ path = asset_paths.compute_public_path(source, asset_prefix, options.merge(:body => true))
options[:body] ? "#{path}?body=1" : path
end
+ def image_path(source)
+ asset_path(source)
+ end
+ alias_method :path_to_image, :image_path # aliased to avoid conflicts with an image_path named route
+
+ def javascript_path(source)
+ asset_path(source)
+ end
+ alias_method :path_to_javascript, :javascript_path # aliased to avoid conflicts with an javascript_path named route
+
+ def stylesheet_path(source)
+ asset_path(source)
+ end
+ alias_method :path_to_stylesheet, :stylesheet_path # aliased to avoid conflicts with an stylesheet_path named route
+
private
def debug_assets?
compile_assets? && (Rails.application.config.assets.debug || params[:debug_assets])
@@ -102,10 +116,6 @@ module Sprockets
class AssetNotPrecompiledError < StandardError; end
- def compute_public_path(source, dir, options = {})
- super(source, asset_prefix, options)
- end
-
# Return the filesystem path for the source
def compute_source_path(source, ext)
asset_for(source, ext)
@@ -119,7 +129,7 @@ module Sprockets
end
def digest_for(logical_path)
- if asset_digests && (digest = asset_digests[logical_path])
+ if digest_assets && asset_digests && (digest = asset_digests[logical_path])
return digest
end
diff --git a/actionpack/lib/sprockets/railtie.rb b/actionpack/lib/sprockets/railtie.rb
index f05d835554..6b67fb1d2d 100644
--- a/actionpack/lib/sprockets/railtie.rb
+++ b/actionpack/lib/sprockets/railtie.rb
@@ -1,7 +1,10 @@
module Sprockets
- autoload :Helpers, "sprockets/helpers"
+ autoload :Bootstrap, "sprockets/bootstrap"
+ autoload :Helpers, "sprockets/helpers"
+ autoload :Compressors, "sprockets/compressors"
autoload :LazyCompressor, "sprockets/compressors"
autoload :NullCompressor, "sprockets/compressors"
+ autoload :StaticCompiler, "sprockets/static_compiler"
# TODO: Get rid of config.assets.enabled
class Railtie < ::Rails::Railtie
@@ -11,7 +14,7 @@ module Sprockets
load "sprockets/assets.rake"
end
- initializer "sprockets.environment" do |app|
+ initializer "sprockets.environment", :group => :assets do |app|
config = app.config
next unless config.assets.enabled
@@ -50,59 +53,7 @@ module Sprockets
# are compiled, and so that other Railties have an opportunity to
# register compressors.
config.after_initialize do |app|
- next unless app.assets
- config = app.config
-
- config.assets.paths.each { |path| app.assets.append_path(path) }
-
- if config.assets.compress
- # temporarily hardcode default JS compressor to uglify. Soon, it will work
- # the same as SCSS, where a default plugin sets the default.
- unless config.assets.js_compressor == false
- app.assets.js_compressor = LazyCompressor.new { expand_js_compressor(config.assets.js_compressor || :uglifier) }
- end
-
- unless config.assets.css_compressor == false
- app.assets.css_compressor = LazyCompressor.new { expand_css_compressor(config.assets.css_compressor) }
- end
- end
-
- if config.assets.compile
- app.routes.prepend do
- mount app.assets => config.assets.prefix
- end
- end
-
- if config.assets.digest
- app.assets = app.assets.index
- end
+ Sprockets::Bootstrap.new(app).run
end
-
- protected
- def expand_js_compressor(sym)
- case sym
- when :closure
- require 'closure-compiler'
- Closure::Compiler.new
- when :uglifier
- require 'uglifier'
- Uglifier.new
- when :yui
- require 'yui/compressor'
- YUI::JavaScriptCompressor.new
- else
- sym
- end
- end
-
- def expand_css_compressor(sym)
- case sym
- when :yui
- require 'yui/compressor'
- YUI::CssCompressor.new
- else
- sym
- end
- end
end
end
diff --git a/actionpack/lib/sprockets/static_compiler.rb b/actionpack/lib/sprockets/static_compiler.rb
new file mode 100644
index 0000000000..4a0078be46
--- /dev/null
+++ b/actionpack/lib/sprockets/static_compiler.rb
@@ -0,0 +1,52 @@
+require 'fileutils'
+
+module Sprockets
+ class StaticCompiler
+ attr_accessor :env, :target, :digest
+
+ def initialize(env, target, options = {})
+ @env = env
+ @target = target
+ @digest = options.key?(:digest) ? options.delete(:digest) : true
+ end
+
+ def precompile(paths)
+ Rails.application.config.assets.digest = digest
+ manifest = {}
+
+ env.each_logical_path do |logical_path|
+ next unless precompile_path?(logical_path, paths)
+ if asset = env.find_asset(logical_path)
+ manifest[logical_path] = compile(asset)
+ end
+ end
+ manifest
+ end
+
+ def compile(asset)
+ asset_path = digest_asset(asset)
+ filename = File.join(target, asset_path)
+ FileUtils.mkdir_p File.dirname(filename)
+ asset.write_to(filename)
+ asset.write_to("#{filename}.gz") if filename.to_s =~ /\.(css|js)$/
+ asset_path
+ end
+
+ def precompile_path?(logical_path, paths)
+ paths.each do |path|
+ if path.is_a?(Regexp)
+ return true if path.match(logical_path)
+ elsif path.is_a?(Proc)
+ return true if path.call(logical_path)
+ else
+ return true if File.fnmatch(path.to_s, logical_path)
+ end
+ end
+ false
+ end
+
+ def digest_asset(asset)
+ digest ? asset.digest_path : asset.logical_path
+ end
+ end
+end
diff --git a/actionpack/test/abstract/abstract_controller_test.rb b/actionpack/test/abstract/abstract_controller_test.rb
index 5823e64637..bf068aedcd 100644
--- a/actionpack/test/abstract/abstract_controller_test.rb
+++ b/actionpack/test/abstract/abstract_controller_test.rb
@@ -50,7 +50,7 @@ module AbstractController
end
def index_to_string
- self.response_body = render_to_string "index.erb"
+ self.response_body = render_to_string "index"
end
def action_with_ivars
@@ -63,11 +63,11 @@ module AbstractController
end
def rendering_to_body
- self.response_body = render_to_body :template => "naked_render.erb"
+ self.response_body = render_to_body :template => "naked_render"
end
def rendering_to_string
- self.response_body = render_to_string :template => "naked_render.erb"
+ self.response_body = render_to_string :template => "naked_render"
end
end
diff --git a/actionpack/test/controller/caching_test.rb b/actionpack/test/controller/caching_test.rb
index da3314fe6d..f3b180283f 100644
--- a/actionpack/test/controller/caching_test.rb
+++ b/actionpack/test/controller/caching_test.rb
@@ -197,7 +197,7 @@ class ActionCachingTestController < CachingController
caches_action :layout_false, :layout => false
caches_action :record_not_found, :four_oh_four, :simple_runtime_error
- layout 'talk_from_action.erb'
+ layout 'talk_from_action'
def index
@cache_this = MockTime.now.to_f.to_s
diff --git a/actionpack/test/controller/integration_test.rb b/actionpack/test/controller/integration_test.rb
index 23709e44e2..2ad95f5c29 100644
--- a/actionpack/test/controller/integration_test.rb
+++ b/actionpack/test/controller/integration_test.rb
@@ -493,7 +493,7 @@ class ApplicationIntegrationTest < ActionDispatch::IntegrationTest
routes.draw do
match '', :to => 'application_integration_test/test#index', :as => :empty_string
-
+
match 'foo', :to => 'application_integration_test/test#index', :as => :foo
match 'bar', :to => 'application_integration_test/test#index', :as => :bar
end
@@ -511,7 +511,7 @@ class ApplicationIntegrationTest < ActionDispatch::IntegrationTest
test "route helpers after controller access" do
get '/'
assert_equal '/', empty_string_path
-
+
get '/foo'
assert_equal '/foo', foo_path
@@ -528,11 +528,10 @@ class ApplicationIntegrationTest < ActionDispatch::IntegrationTest
assert_raise(NameError) { missing_path }
end
- test "process reuse the env we pass as argument" do
+ test "process do not modify the env passed as argument" do
env = { :SERVER_NAME => 'server', 'action_dispatch.custom' => 'custom' }
+ old_env = env.dup
get '/foo', nil, env
- assert_equal :get, env[:method]
- assert_equal 'server', env[:SERVER_NAME]
- assert_equal 'custom', env['action_dispatch.custom']
+ assert_equal old_env, env
end
end
diff --git a/actionpack/test/controller/layout_test.rb b/actionpack/test/controller/layout_test.rb
index cafe2b9320..25299eb8b8 100644
--- a/actionpack/test/controller/layout_test.rb
+++ b/actionpack/test/controller/layout_test.rb
@@ -79,7 +79,7 @@ class DefaultLayoutController < LayoutTest
end
class AbsolutePathLayoutController < LayoutTest
- layout File.expand_path(File.expand_path(__FILE__) + '/../../fixtures/layout_tests/layouts/layout_test.erb')
+ layout File.expand_path(File.expand_path(__FILE__) + '/../../fixtures/layout_tests/layouts/layout_test')
end
class HasOwnLayoutController < LayoutTest
@@ -184,7 +184,7 @@ class RenderWithTemplateOptionController < LayoutTest
end
class SetsNonExistentLayoutFile < LayoutTest
- layout "nofile.erb"
+ layout "nofile"
end
class LayoutExceptionRaised < ActionController::TestCase
diff --git a/actionpack/test/controller/new_base/render_file_test.rb b/actionpack/test/controller/new_base/render_file_test.rb
index 8b2fdf8f96..a961cbf849 100644
--- a/actionpack/test/controller/new_base/render_file_test.rb
+++ b/actionpack/test/controller/new_base/render_file_test.rb
@@ -10,7 +10,7 @@ module RenderFile
def with_instance_variables
@secret = 'in the sauce'
- render :file => File.join(File.dirname(__FILE__), '../../fixtures/test/render_file_with_ivar.erb')
+ render :file => File.join(File.dirname(__FILE__), '../../fixtures/test/render_file_with_ivar')
end
def without_file_key
@@ -19,7 +19,7 @@ module RenderFile
def without_file_key_with_instance_variable
@secret = 'in the sauce'
- render File.join(File.dirname(__FILE__), '../../fixtures/test/render_file_with_ivar.erb')
+ render File.join(File.dirname(__FILE__), '../../fixtures/test/render_file_with_ivar')
end
def relative_path
@@ -34,16 +34,16 @@ module RenderFile
def pathname
@secret = 'in the sauce'
- render :file => Pathname.new(File.dirname(__FILE__)).join(*%w[.. .. fixtures test dot.directory render_file_with_ivar.erb])
+ render :file => Pathname.new(File.dirname(__FILE__)).join(*%w[.. .. fixtures test dot.directory render_file_with_ivar])
end
def with_locals
- path = File.join(File.dirname(__FILE__), '../../fixtures/test/render_file_with_locals.erb')
+ path = File.join(File.dirname(__FILE__), '../../fixtures/test/render_file_with_locals')
render :file => path, :locals => {:secret => 'in the sauce'}
end
def without_file_key_with_locals
- path = FIXTURES.join('test/render_file_with_locals.erb').to_s
+ path = FIXTURES.join('test/render_file_with_locals').to_s
render path, :locals => {:secret => 'in the sauce'}
end
end
diff --git a/actionpack/test/controller/new_base/render_partial_test.rb b/actionpack/test/controller/new_base/render_partial_test.rb
index 83b0d039ad..b4a25c49c9 100644
--- a/actionpack/test/controller/new_base/render_partial_test.rb
+++ b/actionpack/test/controller/new_base/render_partial_test.rb
@@ -7,12 +7,12 @@ module RenderPartial
self.view_paths = [ActionView::FixtureResolver.new(
"render_partial/basic/_basic.html.erb" => "BasicPartial!",
"render_partial/basic/basic.html.erb" => "<%= @test_unchanged = 'goodbye' %><%= render :partial => 'basic' %><%= @test_unchanged %>",
- "render_partial/basic/with_json.html.erb" => "<%= render 'with_json.json' %>",
- "render_partial/basic/_with_json.json.erb" => "<%= render 'final' %>",
+ "render_partial/basic/with_json.html.erb" => "<%= render :partial => 'with_json', :formats => [:json] %>",
+ "render_partial/basic/_with_json.json.erb" => "<%= render :partial => 'final', :formats => [:json] %>",
"render_partial/basic/_final.json.erb" => "{ final: json }",
- "render_partial/basic/overriden.html.erb" => "<%= @test_unchanged = 'goodbye' %><%= render :partial => 'overriden' %><%= @test_unchanged %>",
- "render_partial/basic/_overriden.html.erb" => "ParentPartial!",
- "render_partial/child/_overriden.html.erb" => "OverridenPartial!"
+ "render_partial/basic/overriden.html.erb" => "<%= @test_unchanged = 'goodbye' %><%= render :partial => 'overriden' %><%= @test_unchanged %>",
+ "render_partial/basic/_overriden.html.erb" => "ParentPartial!",
+ "render_partial/child/_overriden.html.erb" => "OverridenPartial!"
)]
def html_with_json_inside_json
diff --git a/actionpack/test/controller/new_base/render_template_test.rb b/actionpack/test/controller/new_base/render_template_test.rb
index 584f2d772c..ba804421da 100644
--- a/actionpack/test/controller/new_base/render_template_test.rb
+++ b/actionpack/test/controller/new_base/render_template_test.rb
@@ -10,8 +10,8 @@ module RenderTemplate
"xml_template.xml.builder" => "xml.html do\n xml.p 'Hello'\nend",
"with_raw.html.erb" => "Hello <%=raw '<strong>this is raw</strong>' %>",
"with_implicit_raw.html.erb" => "Hello <%== '<strong>this is also raw</strong>' %>",
- "test/with_json.html.erb" => "<%= render :template => 'test/with_json.json' %>",
- "test/with_json.json.erb" => "<%= render :template => 'test/final' %>",
+ "test/with_json.html.erb" => "<%= render :template => 'test/with_json', :formats => [:json] %>",
+ "test/with_json.json.erb" => "<%= render :template => 'test/final', :formats => [:json] %>",
"test/final.json.erb" => "{ final: json }",
"test/with_error.html.erb" => "<%= idontexist %>"
)]
@@ -117,7 +117,7 @@ module RenderTemplate
assert_response "{ final: json }"
end
- test "rendering a template with error properly exceprts the code" do
+ test "rendering a template with error properly excerts the code" do
get :with_error
assert_status 500
assert_match "undefined local variable or method `idontexist'", response.body
diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb
index c46755417f..aea603b014 100644
--- a/actionpack/test/controller/render_test.rb
+++ b/actionpack/test/controller/render_test.rb
@@ -163,14 +163,14 @@ class TestController < ActionController::Base
# :ported:
def render_file_with_instance_variables
@secret = 'in the sauce'
- path = File.join(File.dirname(__FILE__), '../fixtures/test/render_file_with_ivar.erb')
+ path = File.join(File.dirname(__FILE__), '../fixtures/test/render_file_with_ivar')
render :file => path
end
# :ported:
def render_file_as_string_with_instance_variables
@secret = 'in the sauce'
- path = File.expand_path(File.join(File.dirname(__FILE__), '../fixtures/test/render_file_with_ivar.erb'))
+ path = File.expand_path(File.join(File.dirname(__FILE__), '../fixtures/test/render_file_with_ivar'))
render path
end
@@ -187,21 +187,21 @@ class TestController < ActionController::Base
def render_file_using_pathname
@secret = 'in the sauce'
- render :file => Pathname.new(File.dirname(__FILE__)).join('..', 'fixtures', 'test', 'dot.directory', 'render_file_with_ivar.erb')
+ render :file => Pathname.new(File.dirname(__FILE__)).join('..', 'fixtures', 'test', 'dot.directory', 'render_file_with_ivar')
end
def render_file_from_template
@secret = 'in the sauce'
- @path = File.expand_path(File.join(File.dirname(__FILE__), '../fixtures/test/render_file_with_ivar.erb'))
+ @path = File.expand_path(File.join(File.dirname(__FILE__), '../fixtures/test/render_file_with_ivar'))
end
def render_file_with_locals
- path = File.join(File.dirname(__FILE__), '../fixtures/test/render_file_with_locals.erb')
+ path = File.join(File.dirname(__FILE__), '../fixtures/test/render_file_with_locals')
render :file => path, :locals => {:secret => 'in the sauce'}
end
def render_file_as_string_with_locals
- path = File.expand_path(File.join(File.dirname(__FILE__), '../fixtures/test/render_file_with_locals.erb'))
+ path = File.expand_path(File.join(File.dirname(__FILE__), '../fixtures/test/render_file_with_locals'))
render path, :locals => {:secret => 'in the sauce'}
end
@@ -453,17 +453,13 @@ class TestController < ActionController::Base
render :action => "potential_conflicts"
end
- # :deprecated:
- # Tests being able to pick a .builder template over a .erb
- # For instance, being able to have hello.xml.builder and hello.xml.erb
- # and select one via "hello.builder" or "hello.erb"
def hello_world_from_rxml_using_action
- render :action => "hello_world_from_rxml.builder"
+ render :action => "hello_world_from_rxml", :handlers => [:builder]
end
# :deprecated:
def hello_world_from_rxml_using_template
- render :template => "test/hello_world_from_rxml.builder"
+ render :template => "test/hello_world_from_rxml", :handlers => [:builder]
end
def action_talk_to_layout
@@ -525,8 +521,8 @@ class TestController < ActionController::Base
render :action => "using_layout_around_block", :layout => "layouts/block_with_layout"
end
- def partial_dot_html
- render :partial => 'partial.html.erb'
+ def partial_formats_html
+ render :partial => 'partial', :formats => [:html]
end
def partial
@@ -797,7 +793,9 @@ class RenderTest < ActionController::TestCase
end
def test_render_file
- get :hello_world_file
+ assert_deprecated do
+ get :hello_world_file
+ end
assert_equal "Hello world!", @response.body
end
@@ -1233,8 +1231,8 @@ class RenderTest < ActionController::TestCase
assert_equal 'partial html', @response.body
end
- def test_should_render_html_partial_with_dot
- get :partial_dot_html
+ def test_should_render_html_partial_with_formats
+ get :partial_formats_html
assert_equal 'partial html', @response.body
end
diff --git a/actionpack/test/dispatch/mime_type_test.rb b/actionpack/test/dispatch/mime_type_test.rb
index 851fb59d51..08fe2127b9 100644
--- a/actionpack/test/dispatch/mime_type_test.rb
+++ b/actionpack/test/dispatch/mime_type_test.rb
@@ -107,8 +107,10 @@ class MimeTypeTest < ActiveSupport::TestCase
# Remove custom Mime::Type instances set in other tests, like Mime::GIF and Mime::IPHONE
types.delete_if { |type| !Mime.const_defined?(type.to_s.upcase) }
+
types.each do |type|
mime = Mime.const_get(type.to_s.upcase)
+ assert mime.respond_to?("#{type}?"), "#{mime.inspect} does not respond to #{type}?"
assert mime.send("#{type}?"), "#{mime.inspect} is not #{type}?"
invalid_types = types - [type]
invalid_types.delete(:html) if Mime::Type.html_types.include?(type)
diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb
index 9685b24c1c..c0b74bc9f9 100644
--- a/actionpack/test/dispatch/routing_test.rb
+++ b/actionpack/test/dispatch/routing_test.rb
@@ -863,6 +863,17 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest
assert_equal original_options, options
end
+ # tests the arguments modification free version of define_hash_access
+ def test_named_route_with_no_side_effects
+ original_options = { :host => 'test.host' }
+ options = original_options.dup
+
+ profile_customer_url("customer_model", options)
+
+ # verify that the options passed in have not changed from the original ones
+ assert_equal original_options, options
+ end
+
def test_projects_status
with_test_routes do
assert_equal '/projects/status', url_for(:controller => 'projects', :action => 'status', :only_path => true)
diff --git a/actionpack/test/dispatch/session/cookie_store_test.rb b/actionpack/test/dispatch/session/cookie_store_test.rb
index 301bf9c6d2..92df6967d6 100644
--- a/actionpack/test/dispatch/session/cookie_store_test.rb
+++ b/actionpack/test/dispatch/session/cookie_store_test.rb
@@ -5,7 +5,7 @@ class CookieStoreTest < ActionDispatch::IntegrationTest
SessionKey = '_myapp_session'
SessionSecret = 'b3c631c314c0bbca50c1b2843150fe33'
- Verifier = ActiveSupport::MessageVerifier.new(SessionSecret, 'SHA1')
+ Verifier = ActiveSupport::MessageVerifier.new(SessionSecret, :digest => 'SHA1')
SignedBar = Verifier.generate(:foo => "bar", :session_id => SecureRandom.hex(16))
class TestController < ActionController::Base
diff --git a/actionpack/test/fixtures/comments/empty.de.html.erb b/actionpack/test/fixtures/comments/empty.de.html.erb
new file mode 100644
index 0000000000..cffd90dd26
--- /dev/null
+++ b/actionpack/test/fixtures/comments/empty.de.html.erb
@@ -0,0 +1 @@
+<h1>Kein Kommentar</h1> \ No newline at end of file
diff --git a/actionpack/test/fixtures/comments/empty.html.builder b/actionpack/test/fixtures/comments/empty.html.builder
new file mode 100644
index 0000000000..2b0c7207a3
--- /dev/null
+++ b/actionpack/test/fixtures/comments/empty.html.builder
@@ -0,0 +1 @@
+xml.h1 'No Comment' \ No newline at end of file
diff --git a/actionpack/test/fixtures/comments/empty.html.erb b/actionpack/test/fixtures/comments/empty.html.erb
new file mode 100644
index 0000000000..827f3861de
--- /dev/null
+++ b/actionpack/test/fixtures/comments/empty.html.erb
@@ -0,0 +1 @@
+<h1>No Comment</h1> \ No newline at end of file
diff --git a/actionpack/test/fixtures/comments/empty.xml.erb b/actionpack/test/fixtures/comments/empty.xml.erb
new file mode 100644
index 0000000000..db1027cd7d
--- /dev/null
+++ b/actionpack/test/fixtures/comments/empty.xml.erb
@@ -0,0 +1 @@
+<error>No Comment</error> \ No newline at end of file
diff --git a/actionpack/test/fixtures/test/_layout_with_partial_and_yield.html.erb b/actionpack/test/fixtures/test/_layout_with_partial_and_yield.html.erb
index 5db0822f07..820e7db789 100644
--- a/actionpack/test/fixtures/test/_layout_with_partial_and_yield.html.erb
+++ b/actionpack/test/fixtures/test/_layout_with_partial_and_yield.html.erb
@@ -1,4 +1,4 @@
Before
-<%= render :partial => "test/partial.html.erb" %>
+<%= render :partial => "test/partial" %>
<%= yield %>
After
diff --git a/actionpack/test/template/asset_tag_helper_test.rb b/actionpack/test/template/asset_tag_helper_test.rb
index d93433deac..aa7304b3ed 100644
--- a/actionpack/test/template/asset_tag_helper_test.rb
+++ b/actionpack/test/template/asset_tag_helper_test.rb
@@ -366,6 +366,10 @@ class AssetTagHelperTest < ActionView::TestCase
assert stylesheet_link_tag('dir/other/file', 'dir/file2').html_safe?
end
+ def test_stylesheet_link_tag_escapes_options
+ assert_dom_equal %(<link href="/file.css" media="&lt;script&gt;" rel="stylesheet" type="text/css" />), stylesheet_link_tag('/file', :media => '<script>')
+ end
+
def test_custom_stylesheet_expansions
ENV["RAILS_ASSET_ID"] = ''
ActionView::Helpers::AssetTagHelper::register_stylesheet_expansion :robbery => ["bank", "robber"]
diff --git a/actionpack/test/template/compiled_templates_test.rb b/actionpack/test/template/compiled_templates_test.rb
index 8be0f452fb..8fc78283d8 100644
--- a/actionpack/test/template/compiled_templates_test.rb
+++ b/actionpack/test/template/compiled_templates_test.rb
@@ -10,24 +10,24 @@ class CompiledTemplatesTest < Test::Unit::TestCase
end
def test_template_gets_recompiled_when_using_different_keys_in_local_assigns
- assert_equal "one", render(:file => "test/render_file_with_locals_and_default.erb")
- assert_equal "two", render(:file => "test/render_file_with_locals_and_default.erb", :locals => { :secret => "two" })
+ assert_equal "one", render(:file => "test/render_file_with_locals_and_default")
+ assert_equal "two", render(:file => "test/render_file_with_locals_and_default", :locals => { :secret => "two" })
end
def test_template_changes_are_not_reflected_with_cached_templates
- assert_equal "Hello world!", render(:file => "test/hello_world.erb")
+ assert_equal "Hello world!", render(:file => "test/hello_world")
modify_template "test/hello_world.erb", "Goodbye world!" do
- assert_equal "Hello world!", render(:file => "test/hello_world.erb")
+ assert_equal "Hello world!", render(:file => "test/hello_world")
end
- assert_equal "Hello world!", render(:file => "test/hello_world.erb")
+ assert_equal "Hello world!", render(:file => "test/hello_world")
end
def test_template_changes_are_reflected_with_uncached_templates
- assert_equal "Hello world!", render_without_cache(:file => "test/hello_world.erb")
+ assert_equal "Hello world!", render_without_cache(:file => "test/hello_world")
modify_template "test/hello_world.erb", "Goodbye world!" do
- assert_equal "Goodbye world!", render_without_cache(:file => "test/hello_world.erb")
+ assert_equal "Goodbye world!", render_without_cache(:file => "test/hello_world")
end
- assert_equal "Hello world!", render_without_cache(:file => "test/hello_world.erb")
+ assert_equal "Hello world!", render_without_cache(:file => "test/hello_world")
end
private
diff --git a/actionpack/test/template/compressors_test.rb b/actionpack/test/template/compressors_test.rb
new file mode 100644
index 0000000000..583a1455ba
--- /dev/null
+++ b/actionpack/test/template/compressors_test.rb
@@ -0,0 +1,29 @@
+require 'abstract_unit'
+require 'rails/railtie'
+require 'sprockets/railtie'
+
+class CompressorsTest < ActiveSupport::TestCase
+ def test_register_css_compressor
+ Sprockets::Compressors.register_css_compressor(:null, Sprockets::NullCompressor)
+ compressor = Sprockets::Compressors.registered_css_compressor(:null)
+ assert_kind_of Sprockets::NullCompressor, compressor
+ end
+
+ def test_register_js_compressor
+ Sprockets::Compressors.register_js_compressor(:uglifier, 'Uglifier', :require => 'uglifier')
+ compressor = Sprockets::Compressors.registered_js_compressor(:uglifier)
+ assert_kind_of Uglifier, compressor
+ end
+
+ def test_register_default_css_compressor
+ Sprockets::Compressors.register_css_compressor(:null, Sprockets::NullCompressor, :default => true)
+ compressor = Sprockets::Compressors.registered_css_compressor(:default)
+ assert_kind_of Sprockets::NullCompressor, compressor
+ end
+
+ def test_register_default_js_compressor
+ Sprockets::Compressors.register_js_compressor(:null, Sprockets::NullCompressor, :default => true)
+ compressor = Sprockets::Compressors.registered_js_compressor(:default)
+ assert_kind_of Sprockets::NullCompressor, compressor
+ end
+end
diff --git a/actionpack/test/template/log_subscriber_test.rb b/actionpack/test/template/log_subscriber_test.rb
index 50e1cccd3b..752b0f23a8 100644
--- a/actionpack/test/template/log_subscriber_test.rb
+++ b/actionpack/test/template/log_subscriber_test.rb
@@ -27,7 +27,7 @@ class AVLogSubscriberTest < ActiveSupport::TestCase
end
def test_render_file_template
- @view.render(:file => "test/hello_world.erb")
+ @view.render(:file => "test/hello_world")
wait
assert_equal 1, @logger.logged(:info).size
diff --git a/actionpack/test/template/lookup_context_test.rb b/actionpack/test/template/lookup_context_test.rb
index 47b70f05ab..bac2530e3d 100644
--- a/actionpack/test/template/lookup_context_test.rb
+++ b/actionpack/test/template/lookup_context_test.rb
@@ -31,16 +31,6 @@ class LookupContextTest < ActiveSupport::TestCase
assert @lookup_context.formats.frozen?
end
- test "allows me to change some details to execute an specific block of code" do
- formats = Mime::SET
- @lookup_context.update_details(:locale => :pt) do
- assert_equal formats, @lookup_context.formats
- assert_equal :pt, @lookup_context.locale
- end
- assert_equal formats, @lookup_context.formats
- assert_equal :en, @lookup_context.locale
- end
-
test "provides getters and setters for formats" do
@lookup_context.formats = [:html]
assert_equal [:html], @lookup_context.formats
diff --git a/actionpack/test/template/render_test.rb b/actionpack/test/template/render_test.rb
index 8a582030f6..0ef3239f83 100644
--- a/actionpack/test/template/render_test.rb
+++ b/actionpack/test/template/render_test.rb
@@ -21,18 +21,48 @@ module RenderTestCases
end
def test_render_file
- assert_equal "Hello world!", @view.render(:file => "test/hello_world.erb")
+ assert_equal "Hello world!", @view.render(:file => "test/hello_world")
end
def test_render_file_not_using_full_path
- assert_equal "Hello world!", @view.render(:file => "test/hello_world.erb")
+ assert_equal "Hello world!", @view.render(:file => "test/hello_world")
end
def test_render_file_without_specific_extension
assert_equal "Hello world!", @view.render(:file => "test/hello_world")
end
- def test_render_file_with_localization
+ # Test if :formats, :locale etc. options are passed correctly to the resolvers.
+ def test_render_file_with_format
+ assert_match "<h1>No Comment</h1>", @view.render(:file => "comments/empty", :formats => [:html])
+ assert_match "<error>No Comment</error>", @view.render(:file => "comments/empty", :formats => [:xml])
+ assert_match "<error>No Comment</error>", @view.render(:file => "comments/empty", :formats => :xml)
+ end
+
+ def test_render_template_with_format
+ assert_match "<h1>No Comment</h1>", @view.render(:template => "comments/empty", :formats => [:html])
+ assert_match "<error>No Comment</error>", @view.render(:template => "comments/empty", :formats => [:xml])
+ end
+
+ def test_render_file_with_locale
+ assert_equal "<h1>Kein Kommentar</h1>", @view.render(:file => "comments/empty", :locale => [:de])
+ assert_equal "<h1>Kein Kommentar</h1>", @view.render(:file => "comments/empty", :locale => :de)
+ end
+
+ def test_render_template_with_locale
+ assert_equal "<h1>Kein Kommentar</h1>", @view.render(:template => "comments/empty", :locale => [:de])
+ end
+
+ def test_render_file_with_handlers
+ assert_equal "<h1>No Comment</h1>\n", @view.render(:file => "comments/empty", :handlers => [:builder])
+ assert_equal "<h1>No Comment</h1>\n", @view.render(:file => "comments/empty", :handlers => :builder)
+ end
+
+ def test_render_template_with_handlers
+ assert_equal "<h1>No Comment</h1>\n", @view.render(:template => "comments/empty", :handlers => [:builder])
+ end
+
+ def test_render_file_with_localization_on_context_level
old_locale, @view.locale = @view.locale, :da
assert_equal "Hey verden", @view.render(:file => "test/hello_world")
ensure
@@ -51,17 +81,17 @@ module RenderTestCases
end
def test_render_file_with_full_path
- template_path = File.join(File.dirname(__FILE__), '../fixtures/test/hello_world.erb')
+ template_path = File.join(File.dirname(__FILE__), '../fixtures/test/hello_world')
assert_equal "Hello world!", @view.render(:file => template_path)
end
def test_render_file_with_instance_variables
- assert_equal "The secret is in the sauce\n", @view.render(:file => "test/render_file_with_ivar.erb")
+ assert_equal "The secret is in the sauce\n", @view.render(:file => "test/render_file_with_ivar")
end
def test_render_file_with_locals
locals = { :secret => 'in the sauce' }
- assert_equal "The secret is in the sauce\n", @view.render(:file => "test/render_file_with_locals.erb", :locals => locals)
+ assert_equal "The secret is in the sauce\n", @view.render(:file => "test/render_file_with_locals", :locals => locals)
end
def test_render_file_not_using_full_path_with_dot_in_path
@@ -80,13 +110,18 @@ module RenderTestCases
assert_equal 'partial html', @view.render(:partial => 'test/partial')
end
+ def test_render_partial_with_selected_format
+ assert_equal 'partial html', @view.render(:partial => 'test/partial', :formats => :html)
+ assert_equal 'partial js', @view.render(:partial => 'test/partial', :formats => [:js])
+ end
+
def test_render_partial_at_top_level
- # file fixtures/_top_level_partial_only.erb (not fixtures/test)
+ # file fixtures/_top_level_partial_only (not fixtures/test)
assert_equal 'top level partial', @view.render(:partial => '/top_level_partial_only')
end
def test_render_partial_with_format_at_top_level
- # file fixtures/_top_level_partial.html.erb (not fixtures/test, with format extension)
+ # file fixtures/_top_level_partial.html (not fixtures/test, with format extension)
assert_equal 'top level partial html', @view.render(:partial => '/top_level_partial')
end
@@ -245,7 +280,7 @@ module RenderTestCases
end
def test_render_layout_with_block_and_other_partial_inside
- render = @view.render(:layout => "test/layout_with_partial_and_yield.html.erb") { "Yield!" }
+ render = @view.render(:layout => "test/layout_with_partial_and_yield") { "Yield!" }
assert_equal "Before\npartial html\nYield!\nAfter\n", render
end
@@ -282,24 +317,26 @@ module RenderTestCases
end
def test_render_ignores_templates_with_malformed_template_handlers
- %w(malformed malformed.erb malformed.html.erb malformed.en.html.erb).each do |name|
- assert_raise(ActionView::MissingTemplate) { @view.render(:file => "test/malformed/#{name}") }
+ ActiveSupport::Deprecation.silence do
+ %w(malformed malformed.erb malformed.html.erb malformed.en.html.erb).each do |name|
+ assert_raise(ActionView::MissingTemplate) { @view.render(:file => "test/malformed/#{name}") }
+ end
end
end
def test_render_with_layout
assert_equal %(<title></title>\nHello world!\n),
- @view.render(:file => "test/hello_world.erb", :layout => "layouts/yield")
+ @view.render(:file => "test/hello_world", :layout => "layouts/yield")
end
def test_render_with_layout_which_has_render_inline
assert_equal %(welcome\nHello world!\n),
- @view.render(:file => "test/hello_world.erb", :layout => "layouts/yield_with_render_inline_inside")
+ @view.render(:file => "test/hello_world", :layout => "layouts/yield_with_render_inline_inside")
end
def test_render_with_layout_which_renders_another_partial
assert_equal %(partial html\nHello world!\n),
- @view.render(:file => "test/hello_world.erb", :layout => "layouts/yield_with_render_partial_inside")
+ @view.render(:file => "test/hello_world", :layout => "layouts/yield_with_render_partial_inside")
end
def test_render_layout_with_block_and_yield
@@ -344,17 +381,17 @@ module RenderTestCases
def test_render_with_nested_layout
assert_equal %(<title>title</title>\n\n<div id="column">column</div>\n<div id="content">content</div>\n),
- @view.render(:file => "test/nested_layout.erb", :layout => "layouts/yield")
+ @view.render(:file => "test/nested_layout", :layout => "layouts/yield")
end
def test_render_with_file_in_layout
assert_equal %(\n<title>title</title>\n\n),
- @view.render(:file => "test/layout_render_file.erb")
+ @view.render(:file => "test/layout_render_file")
end
def test_render_layout_with_object
assert_equal %(<title>David</title>),
- @view.render(:file => "test/layout_render_object.erb")
+ @view.render(:file => "test/layout_render_object")
end
end
@@ -392,7 +429,7 @@ class LazyViewRenderTest < ActiveSupport::TestCase
if '1.9'.respond_to?(:force_encoding)
def test_render_utf8_template_with_magic_comment
with_external_encoding Encoding::ASCII_8BIT do
- result = @view.render(:file => "test/utf8_magic.html.erb", :layouts => "layouts/yield")
+ result = @view.render(:file => "test/utf8_magic.html", :layouts => "layouts/yield")
assert_equal Encoding::UTF_8, result.encoding
assert_equal "\nРусский \nтекст\n\nUTF-8\nUTF-8\nUTF-8\n", result
end
@@ -400,7 +437,7 @@ class LazyViewRenderTest < ActiveSupport::TestCase
def test_render_utf8_template_with_default_external_encoding
with_external_encoding Encoding::UTF_8 do
- result = @view.render(:file => "test/utf8.html.erb", :layouts => "layouts/yield")
+ result = @view.render(:file => "test/utf8.html", :layouts => "layouts/yield")
assert_equal Encoding::UTF_8, result.encoding
assert_equal "Русский текст\n\nUTF-8\nUTF-8\nUTF-8\n", result
end
@@ -409,7 +446,7 @@ class LazyViewRenderTest < ActiveSupport::TestCase
def test_render_utf8_template_with_incompatible_external_encoding
with_external_encoding Encoding::SHIFT_JIS do
begin
- @view.render(:file => "test/utf8.html.erb", :layouts => "layouts/yield")
+ @view.render(:file => "test/utf8.html", :layouts => "layouts/yield")
flunk 'Should have raised incompatible encoding error'
rescue ActionView::Template::Error => error
assert_match 'Your template was not saved as valid Shift_JIS', error.original_exception.message
@@ -420,7 +457,7 @@ class LazyViewRenderTest < ActiveSupport::TestCase
def test_render_utf8_template_with_partial_with_incompatible_encoding
with_external_encoding Encoding::SHIFT_JIS do
begin
- @view.render(:file => "test/utf8_magic_with_bare_partial.html.erb", :layouts => "layouts/yield")
+ @view.render(:file => "test/utf8_magic_with_bare_partial.html", :layouts => "layouts/yield")
flunk 'Should have raised incompatible encoding error'
rescue ActionView::Template::Error => error
assert_match 'Your template was not saved as valid Shift_JIS', error.original_exception.message
diff --git a/actionpack/test/template/sprockets_helper_test.rb b/actionpack/test/template/sprockets_helper_test.rb
index c0fb07a29b..fd3e01ec03 100644
--- a/actionpack/test/template/sprockets_helper_test.rb
+++ b/actionpack/test/template/sprockets_helper_test.rb
@@ -47,6 +47,16 @@ class SprocketsHelperTest < ActionView::TestCase
asset_path("logo.png", :digest => false)
end
+ test "custom_asset_path" do
+ @config.assets.prefix = '/s'
+ assert_match %r{/s/logo-[0-9a-f]+.png},
+ asset_path("logo.png")
+ assert_match %r{/s/logo-[0-9a-f]+.png},
+ asset_path("logo.png", :digest => true)
+ assert_match %r{/s/logo.png},
+ asset_path("logo.png", :digest => false)
+ end
+
test "asset_path with root relative assets" do
assert_equal "/images/logo",
asset_path("/images/logo")
@@ -112,6 +122,34 @@ class SprocketsHelperTest < ActionView::TestCase
end
end
+ test "image_tag" do
+ assert_dom_equal '<img alt="Xml" src="/assets/xml.png" />', image_tag("xml.png")
+ end
+
+ test "image_path" do
+ assert_match %r{/assets/logo-[0-9a-f]+.png},
+ image_path("logo.png")
+
+ assert_match %r{/assets/logo-[0-9a-f]+.png},
+ path_to_image("logo.png")
+ end
+
+ test "javascript_path" do
+ assert_match %r{/assets/application-[0-9a-f]+.js},
+ javascript_path("application.js")
+
+ assert_match %r{/assets/application-[0-9a-f]+.js},
+ path_to_javascript("application.js")
+ end
+
+ test "stylesheet_path" do
+ assert_match %r{/assets/application-[0-9a-f]+.css},
+ stylesheet_path("application.css")
+
+ assert_match %r{/assets/application-[0-9a-f]+.css},
+ path_to_stylesheet("application.css")
+ end
+
test "stylesheets served without a controller in do not use asset hosts when the default protocol is :request" do
@controller = nil
@config.action_controller.asset_host = "assets-%d.example.com"
@@ -135,7 +173,7 @@ class SprocketsHelperTest < ActionView::TestCase
asset_path("/images/logo.gif")
end
- test "javascript path" do
+ test "javascript path through asset_path" do
assert_match %r{/assets/application-[0-9a-f]+.js},
asset_path(:application, :ext => "js")
@@ -180,7 +218,7 @@ class SprocketsHelperTest < ActionView::TestCase
javascript_include_tag(:application)
end
- test "stylesheet path" do
+ test "stylesheet path through asset_path" do
assert_match %r{/assets/application-[0-9a-f]+.css}, asset_path(:application, :ext => "css")
assert_match %r{/assets/style-[0-9a-f]+.css}, asset_path("style", :ext => "css")
@@ -252,4 +290,12 @@ class SprocketsHelperTest < ActionView::TestCase
assert_not_equal prod_path, dev_path
end
+
+ test "precedence of `config.digest = false` over manifest.yml asset digests" do
+ Rails.application.config.assets.digests = {'logo.png' => 'logo-d1g3st.png'}
+ @config.assets.digest = false
+
+ assert_equal '/assets/logo.png',
+ asset_path("logo.png")
+ end
end
diff --git a/actionpack/test/template/streaming_render_test.rb b/actionpack/test/template/streaming_render_test.rb
index 023ce723ed..4d01352b43 100644
--- a/actionpack/test/template/streaming_render_test.rb
+++ b/actionpack/test/template/streaming_render_test.rb
@@ -28,7 +28,7 @@ class FiberedTest < ActiveSupport::TestCase
def test_streaming_works
content = []
- body = render_body(:template => "test/hello_world.erb", :layout => "layouts/yield")
+ body = render_body(:template => "test/hello_world", :layout => "layouts/yield")
body.each do |piece|
content << piece
@@ -42,12 +42,12 @@ class FiberedTest < ActiveSupport::TestCase
end
def test_render_file
- assert_equal "Hello world!", buffered_render(:file => "test/hello_world.erb")
+ assert_equal "Hello world!", buffered_render(:file => "test/hello_world")
end
def test_render_file_with_locals
locals = { :secret => 'in the sauce' }
- assert_equal "The secret is in the sauce\n", buffered_render(:file => "test/render_file_with_locals.erb", :locals => locals)
+ assert_equal "The secret is in the sauce\n", buffered_render(:file => "test/render_file_with_locals", :locals => locals)
end
def test_render_partial
@@ -64,27 +64,27 @@ class FiberedTest < ActiveSupport::TestCase
def test_render_with_layout
assert_equal %(<title></title>\nHello world!\n),
- buffered_render(:template => "test/hello_world.erb", :layout => "layouts/yield")
+ buffered_render(:template => "test/hello_world", :layout => "layouts/yield")
end
def test_render_with_layout_which_has_render_inline
assert_equal %(welcome\nHello world!\n),
- buffered_render(:template => "test/hello_world.erb", :layout => "layouts/yield_with_render_inline_inside")
+ buffered_render(:template => "test/hello_world", :layout => "layouts/yield_with_render_inline_inside")
end
def test_render_with_layout_which_renders_another_partial
assert_equal %(partial html\nHello world!\n),
- buffered_render(:template => "test/hello_world.erb", :layout => "layouts/yield_with_render_partial_inside")
+ buffered_render(:template => "test/hello_world", :layout => "layouts/yield_with_render_partial_inside")
end
def test_render_with_nested_layout
assert_equal %(<title>title</title>\n\n<div id="column">column</div>\n<div id="content">content</div>\n),
- buffered_render(:template => "test/nested_layout.erb", :layout => "layouts/yield")
+ buffered_render(:template => "test/nested_layout", :layout => "layouts/yield")
end
def test_render_with_file_in_layout
assert_equal %(\n<title>title</title>\n\n),
- buffered_render(:template => "test/layout_render_file.erb")
+ buffered_render(:template => "test/layout_render_file")
end
def test_render_with_handler_without_streaming_support
diff --git a/actionpack/test/template/url_helper_test.rb b/actionpack/test/template/url_helper_test.rb
index dbac2e1fc0..bc45fabf34 100644
--- a/actionpack/test/template/url_helper_test.rb
+++ b/actionpack/test/template/url_helper_test.rb
@@ -88,6 +88,10 @@ class UrlHelperTest < ActiveSupport::TestCase
)
end
+ def test_button_to_with_remote_and_form_options
+ assert_dom_equal "<form method=\"post\" action=\"http://www.example.com\" class=\"custom-class\" data-remote=\"true\" data-type=\"json\"><div><input type=\"submit\" value=\"Hello\" /></div></form>", button_to("Hello", "http://www.example.com", :remote => true, :form => { :class => "custom-class", "data-type" => "json" } )
+ end
+
def test_button_to_with_remote_and_javascript_confirm
assert_dom_equal(
"<form method=\"post\" action=\"http://www.example.com\" class=\"button_to\" data-remote=\"true\"><div><input data-confirm=\"Are you sure?\" type=\"submit\" value=\"Hello\" /></div></form>",