diff options
author | Manuel Menezes de Sequeira <MMSequeira@gmail.com> | 2011-10-05 22:14:49 +0100 |
---|---|---|
committer | Manuel Menezes de Sequeira <MMSequeira@gmail.com> | 2011-10-05 22:14:49 +0100 |
commit | 07343d2974ab77bfd21c0f35930cd394ba5b164e (patch) | |
tree | c64f8b54507d41ccb2c59cb096ee8b1f2a31e2df /actionpack | |
parent | 8d775d5f1d58e5c0d881383e8c6e869d1d360c8c (diff) | |
parent | d6c7185d77158caee933e84b247e37bb6a67bf58 (diff) | |
download | rails-07343d2974ab77bfd21c0f35930cd394ba5b164e.tar.gz rails-07343d2974ab77bfd21c0f35930cd394ba5b164e.tar.bz2 rails-07343d2974ab77bfd21c0f35930cd394ba5b164e.zip |
Merge branch 'master' of github.com:lifo/docrails
Diffstat (limited to 'actionpack')
22 files changed, 317 insertions, 127 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG index c3ff677529..e8c619723f 100644 --- a/actionpack/CHANGELOG +++ b/actionpack/CHANGELOG @@ -56,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/actionpack.gemspec b/actionpack/actionpack.gemspec index f1b7966b9c..96d583730a 100644 --- a/actionpack/actionpack.gemspec +++ b/actionpack/actionpack.gemspec @@ -16,16 +16,16 @@ Gem::Specification.new do |s| s.require_path = 'lib' s.requirements << 'none' - s.add_dependency('activesupport', version) - s.add_dependency('activemodel', version) - s.add_dependency('rack-cache', '~> 1.0.3') - s.add_dependency('builder', '~> 3.0.0') - s.add_dependency('i18n', '~> 0.6') - s.add_dependency('rack', '~> 1.3.2') - s.add_dependency('rack-test', '~> 0.6.1') - s.add_dependency('journey', '~> 1.0.0') - s.add_dependency('sprockets', '~> 2.0.0') - s.add_dependency('erubis', '~> 2.7.0') + s.add_dependency('activesupport', version) + s.add_dependency('activemodel', version) + s.add_dependency('rack-cache', '~> 1.1') + s.add_dependency('builder', '~> 3.0.0') + s.add_dependency('i18n', '~> 0.6') + s.add_dependency('rack', '~> 1.3.2') + s.add_dependency('rack-test', '~> 0.6.1') + s.add_dependency('journey', '~> 1.0.0') + s.add_dependency('sprockets', '~> 2.0.2') + s.add_dependency('erubis', '~> 2.7.0') - s.add_development_dependency('tzinfo', '~> 0.3.29') + s.add_development_dependency('tzinfo', '~> 0.3.29') end diff --git a/actionpack/lib/abstract_controller/asset_paths.rb b/actionpack/lib/abstract_controller/asset_paths.rb index b104d34fb5..c2a6809f58 100644 --- a/actionpack/lib/abstract_controller/asset_paths.rb +++ b/actionpack/lib/abstract_controller/asset_paths.rb @@ -3,7 +3,8 @@ module AbstractController extend ActiveSupport::Concern included do - config_accessor :asset_host, :asset_path, :assets_dir, :javascripts_dir, :stylesheets_dir + config_accessor :asset_host, :asset_path, :assets_dir, :javascripts_dir, + :stylesheets_dir, :default_asset_host_protocol end end end diff --git a/actionpack/lib/abstract_controller/rendering.rb b/actionpack/lib/abstract_controller/rendering.rb index ab2c532859..41fdc11196 100644 --- a/actionpack/lib/abstract_controller/rendering.rb +++ b/actionpack/lib/abstract_controller/rendering.rb @@ -120,8 +120,6 @@ module AbstractController view_renderer.render(view_context, options) end - private - DEFAULT_PROTECTED_INSTANCE_VARIABLES = %w( @_action_name @_response_body @_formats @_prefixes @_config @_view_context_class @_view_renderer @_lookup_context @@ -139,6 +137,8 @@ module AbstractController hash end + private + # Normalize args and options. # :api: private def _normalize_render(*args, &block) diff --git a/actionpack/lib/action_controller/test_case.rb b/actionpack/lib/action_controller/test_case.rb index a83fa74795..6913c1ef4a 100644 --- a/actionpack/lib/action_controller/test_case.rb +++ b/actionpack/lib/action_controller/test_case.rb @@ -333,9 +333,21 @@ module ActionController module ClassMethods # Sets the controller class name. Useful if the name can't be inferred from test class. - # Expects +controller_class+ as a constant. Example: <tt>tests WidgetController</tt>. + # Normalizes +controller_class+ before using. Examples: + # + # tests WidgetController + # tests :widget + # tests 'widget' + # def tests(controller_class) - self.controller_class = controller_class + case controller_class + when String, Symbol + self.controller_class = "#{controller_class.to_s.underscore}_controller".camelize.constantize + when Class + self.controller_class = controller_class + else + raise ArgumentError, "controller class must be a String, Symbol, or Class" + end end def controller_class=(new_class) @@ -352,9 +364,7 @@ module ActionController end def determine_default_controller_class(name) - name.sub(/Test$/, '').constantize - rescue NameError - nil + name.sub(/Test$/, '').safe_constantize end def prepare_controller_class(new_class) 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/url.rb b/actionpack/lib/action_dispatch/http/url.rb index caa1decb9e..170c68f3e0 100644 --- a/actionpack/lib/action_dispatch/http/url.rb +++ b/actionpack/lib/action_dispatch/http/url.rb @@ -64,14 +64,16 @@ module ActionDispatch end def host_or_subdomain_and_domain(options) - return options[:host] unless options[:subdomain] || options[:domain] + return options[:host] if options[:subdomain].nil? && options[:domain].nil? tld_length = options[:tld_length] || @@tld_length host = "" - host << (options[:subdomain] || extract_subdomain(options[:host], tld_length)) - host << "." - host << (options[:domain] || extract_domain(options[:host], tld_length)) + unless options[:subdomain] == false + host << (options[:subdomain] || extract_subdomain(options[:host], tld_length)) + host << "." + end + host << (options[:domain] || extract_domain(options[:host], tld_length)) host end end diff --git a/actionpack/lib/action_dispatch/routing/url_for.rb b/actionpack/lib/action_dispatch/routing/url_for.rb index 30048cd48a..8fc8dc191b 100644 --- a/actionpack/lib/action_dispatch/routing/url_for.rb +++ b/actionpack/lib/action_dispatch/routing/url_for.rb @@ -116,9 +116,10 @@ module ActionDispatch # If <tt>:only_path</tt> is false, this option must be # provided either explicitly, or via +default_url_options+. # * <tt>:subdomain</tt> - Specifies the subdomain of the link, using the +tld_length+ - # to split the domain from the host. - # * <tt>:domain</tt> - Specifies the domain of the link, using the +tld_length+ # to split the subdomain from the host. + # If false, removes all subdomains from the host part of the link. + # * <tt>:domain</tt> - Specifies the domain of the link, using the +tld_length+ + # to split the domain from the host. # * <tt>:tld_length</tt> - Number of labels the TLD id composed of, only used if # <tt>:subdomain</tt> or <tt>:domain</tt> are supplied. Defaults to # <tt>ActionDispatch::Http::URL.tld_length</tt>, which in turn defaults to 1. diff --git a/actionpack/lib/action_dispatch/testing/test_process.rb b/actionpack/lib/action_dispatch/testing/test_process.rb index f668b81b45..b08ff41950 100644 --- a/actionpack/lib/action_dispatch/testing/test_process.rb +++ b/actionpack/lib/action_dispatch/testing/test_process.rb @@ -5,12 +5,7 @@ require 'active_support/core_ext/hash/indifferent_access' module ActionDispatch module TestProcess def assigns(key = nil) - assigns = {}.with_indifferent_access - @controller.instance_variable_names.each do |ivar| - next if ActionController::Base.protected_instance_variables.include?(ivar) - assigns[ivar[1..-1]] = @controller.instance_variable_get(ivar) - end - + assigns = @controller.view_assigns.with_indifferent_access key.nil? ? assigns : assigns[key] end diff --git a/actionpack/lib/action_view/asset_paths.rb b/actionpack/lib/action_view/asset_paths.rb index cf30ad7e57..1d16e34df6 100644 --- a/actionpack/lib/action_view/asset_paths.rb +++ b/actionpack/lib/action_view/asset_paths.rb @@ -16,8 +16,6 @@ module ActionView # roots. Rewrite the asset path for cache-busting asset ids. Include # asset host, if configured, with the correct request protocol. # - # When include_host is true and the asset host does not specify the protocol - # the protocol parameter specifies how the protocol will be added. # When :relative (default), the protocol will be determined by the client using current protocol # When :request, the protocol will be the request protocol # Otherwise, the protocol is used (E.g. :http, :https, etc) @@ -25,11 +23,10 @@ module ActionView source = source.to_s return source if is_uri?(source) - options[:include_host] ||= true source = rewrite_extension(source, dir, options[:ext]) if options[:ext] source = rewrite_asset_path(source, dir, options) source = rewrite_relative_url_root(source, relative_url_root) - source = rewrite_host_and_protocol(source, options[:protocol]) if options[:include_host] + source = rewrite_host_and_protocol(source, options[:protocol]) source end @@ -89,9 +86,7 @@ module ActionView end def default_protocol - protocol = @config.action_controller.default_asset_host_protocol if @config.action_controller.present? - protocol ||= @config.default_asset_host_protocol - protocol || (has_request? ? :request : :relative) + @config.default_asset_host_protocol || (has_request? ? :request : :relative) end def invalid_asset_host!(help_message) @@ -120,19 +115,11 @@ module ActionView end def relative_url_root - if config.action_controller.present? - config.action_controller.relative_url_root - else - config.relative_url_root - end + config.relative_url_root end def asset_host_config - if config.action_controller.present? - config.action_controller.asset_host - else - config.asset_host - end + config.asset_host end # Returns the current request if one exists. 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/sprockets/assets.rake b/actionpack/lib/sprockets/assets.rake index e29661e4e7..a5145080c2 100644 --- a/actionpack/lib/sprockets/assets.rake +++ b/actionpack/lib/sprockets/assets.rake @@ -1,60 +1,95 @@ +require "fileutils" + namespace :assets do + def ruby_rake_task(task) + env = ENV['RAILS_ENV'] || 'production' + groups = ENV['RAILS_GROUPS'] || 'assets' + args = [$0, task,"RAILS_ENV=#{env}","RAILS_GROUPS=#{groups}"] + args << "--trace" if Rake.application.options.trace + ruby *args + end + + # We are currently running with no explicit bundler group + # and/or no explicit environment - we have to reinvoke rake to + # execute this task. + def invoke_or_reboot_rake_task(task) + if ENV['RAILS_GROUPS'].to_s.empty? || ENV['RAILS_ENV'].to_s.empty? + ruby_rake_task task + else + Rake::Task[task].invoke + end + end + desc "Compile all the assets named in config.assets.precompile" task :precompile do - # We need to do this dance because RAILS_GROUPS is used - # too early in the boot process and changing here is already too late. - if ENV["RAILS_GROUPS"].to_s.empty? || ENV["RAILS_ENV"].to_s.empty? - ENV["RAILS_GROUPS"] ||= "assets" - ENV["RAILS_ENV"] ||= "production" - ruby $0, *ARGV - else - require "fileutils" - Rake::Task["tmp:cache:clear"].invoke - Rake::Task["assets:environment"].invoke + invoke_or_reboot_rake_task "assets:precompile:all" + end + namespace :precompile do + def internal_precompile(digest=nil) unless Rails.application.config.assets.enabled - raise "Cannot precompile assets if sprockets is disabled. Please set config.assets.enabled to true" + warn "Cannot precompile assets if sprockets is disabled. Please set config.assets.enabled to true" + exit end - # Ensure that action view is loaded and the appropriate sprockets hooks get executed - ActionView::Base + # 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 - - # Always compile files and avoid use of existing precompiled assets - config.assets.compile = true + config.assets.digest = digest unless digest.nil? config.assets.digests = {} - target = File.join(Rails.public_path, config.assets.prefix) - static_compiler = Sprockets::StaticCompiler.new(env, target, :digest => config.assets.digest) + env = Rails.application.assets + target = File.join(Rails.public_path, config.assets.prefix) + compiler = Sprockets::StaticCompiler.new(env, + target, + config.assets.precompile, + :manifest_path => config.assets.manifest, + :digest => config.assets.digest, + :manifest => digest.nil?) + compiler.compile + end - manifest = static_compiler.precompile(config.assets.precompile) - manifest_path = config.assets.manifest || target - FileUtils.mkdir_p(manifest_path) + task :all do + Rake::Task["assets:precompile:primary"].invoke + # We need to reinvoke in order to run the secondary digestless + # asset compilation run - a fresh Sprockets environment is + # required in order to compile digestless assets as the + # environment has already cached the assets on the primary + # run. + ruby_rake_task "assets:precompile:nondigest" if Rails.application.config.assets.digest + end - unless ENV["RAILS_ASSETS_NONDIGEST"] - File.open("#{manifest_path}/manifest.yml", 'wb') do |f| - YAML.dump(manifest, f) - end - ENV["RAILS_ASSETS_NONDIGEST"] = "true" - ruby $0, *ARGV - end + task :primary => ["assets:environment", "tmp:cache:clear"] do + internal_precompile + end + + task :nondigest => ["assets:environment", "tmp:cache:clear"] do + internal_precompile(false) end end desc "Remove compiled assets" - 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 + task :clean do + invoke_or_reboot_rake_task "assets:clean:all" + end + + namespace :clean do + task :all => ["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 end task :environment do - Rails.application.initialize!(:assets) - Sprockets::Bootstrap.new(Rails.application).run + if Rails.application.config.assets.initialize_on_precompile + Rake::Task["environment"].invoke + else + Rails.application.initialize!(:assets) + Sprockets::Bootstrap.new(Rails.application).run + end end end diff --git a/actionpack/lib/sprockets/helpers.rb b/actionpack/lib/sprockets/helpers.rb index a952a55c5e..fee48386e0 100644 --- a/actionpack/lib/sprockets/helpers.rb +++ b/actionpack/lib/sprockets/helpers.rb @@ -1,5 +1,6 @@ module Sprockets module Helpers - autoload :RailsHelper, "sprockets/helpers/rails_helper" + autoload :RailsHelper, "sprockets/helpers/rails_helper" + autoload :IsolatedHelper, "sprockets/helpers/isolated_helper" end end diff --git a/actionpack/lib/sprockets/helpers/isolated_helper.rb b/actionpack/lib/sprockets/helpers/isolated_helper.rb new file mode 100644 index 0000000000..3adb928c45 --- /dev/null +++ b/actionpack/lib/sprockets/helpers/isolated_helper.rb @@ -0,0 +1,13 @@ +module Sprockets + module Helpers + module IsolatedHelper + def controller + nil + end + + def config + Rails.application.config.action_controller + end + end + end +end diff --git a/actionpack/lib/sprockets/helpers/rails_helper.rb b/actionpack/lib/sprockets/helpers/rails_helper.rb index c8c6c3ddd9..f866bc626e 100644 --- a/actionpack/lib/sprockets/helpers/rails_helper.rb +++ b/actionpack/lib/sprockets/helpers/rails_helper.rb @@ -8,9 +8,6 @@ module Sprockets def asset_paths @asset_paths ||= begin - config = self.config if respond_to?(:config) - config ||= Rails.application.config - controller = self.controller if respond_to?(:controller) paths = RailsHelper::AssetPaths.new(config, controller) paths.asset_environment = asset_environment paths.asset_digests = asset_digests @@ -65,6 +62,16 @@ module Sprockets 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]) diff --git a/actionpack/lib/sprockets/railtie.rb b/actionpack/lib/sprockets/railtie.rb index 6b67fb1d2d..3d330bd91a 100644 --- a/actionpack/lib/sprockets/railtie.rb +++ b/actionpack/lib/sprockets/railtie.rb @@ -1,3 +1,5 @@ +require "action_controller/railtie" + module Sprockets autoload :Bootstrap, "sprockets/bootstrap" autoload :Helpers, "sprockets/helpers" @@ -8,13 +10,13 @@ module Sprockets # TODO: Get rid of config.assets.enabled class Railtie < ::Rails::Railtie - config.default_asset_host_protocol = :relative + config.action_controller.default_asset_host_protocol = :relative rake_tasks do load "sprockets/assets.rake" end - initializer "sprockets.environment", :group => :assets do |app| + initializer "sprockets.environment", :group => :all do |app| config = app.config next unless config.assets.enabled @@ -41,8 +43,8 @@ module Sprockets ActiveSupport.on_load(:action_view) do include ::Sprockets::Helpers::RailsHelper - app.assets.context_class.instance_eval do + include ::Sprockets::Helpers::IsolatedHelper include ::Sprockets::Helpers::RailsHelper end end diff --git a/actionpack/lib/sprockets/static_compiler.rb b/actionpack/lib/sprockets/static_compiler.rb index 4a0078be46..32a9d66e6e 100644 --- a/actionpack/lib/sprockets/static_compiler.rb +++ b/actionpack/lib/sprockets/static_compiler.rb @@ -2,41 +2,50 @@ require 'fileutils' module Sprockets class StaticCompiler - attr_accessor :env, :target, :digest + attr_accessor :env, :target, :paths - def initialize(env, target, options = {}) + def initialize(env, target, paths, options = {}) @env = env @target = target + @paths = paths @digest = options.key?(:digest) ? options.delete(:digest) : true + @manifest = options.key?(:manifest) ? options.delete(:manifest) : true + @manifest_path = options.delete(:manifest_path) || target end - def precompile(paths) - Rails.application.config.assets.digest = digest + def compile manifest = {} - env.each_logical_path do |logical_path| - next unless precompile_path?(logical_path, paths) + next unless compile_path?(logical_path) if asset = env.find_asset(logical_path) - manifest[logical_path] = compile(asset) + manifest[logical_path] = write_asset(asset) end end - manifest + write_manifest(manifest) if @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 + def write_manifest(manifest) + FileUtils.mkdir_p(@manifest_path) + File.open("#{@manifest_path}/manifest.yml", 'wb') do |f| + YAML.dump(manifest, f) + end + end + + def write_asset(asset) + path_for(asset).tap do |path| + filename = File.join(target, path) + FileUtils.mkdir_p File.dirname(filename) + asset.write_to(filename) + asset.write_to("#{filename}.gz") if filename.to_s =~ /\.(css|js)$/ + end end - def precompile_path?(logical_path, paths) + def compile_path?(logical_path) paths.each do |path| - if path.is_a?(Regexp) + case path + when Regexp return true if path.match(logical_path) - elsif path.is_a?(Proc) + when Proc return true if path.call(logical_path) else return true if File.fnmatch(path.to_s, logical_path) @@ -45,8 +54,8 @@ module Sprockets false end - def digest_asset(asset) - digest ? asset.digest_path : asset.logical_path + def path_for(asset) + @digest ? asset.digest_path : asset.logical_path end end end diff --git a/actionpack/test/controller/test_test.rb b/actionpack/test/controller/test_test.rb index cba3aded2f..b64e275363 100644 --- a/actionpack/test/controller/test_test.rb +++ b/actionpack/test/controller/test_test.rb @@ -146,6 +146,17 @@ XML end end + class ViewAssignsController < ActionController::Base + def test_assigns + @foo = "foo" + render :nothing => true + end + + def view_assigns + { "bar" => "bar" } + end + end + def test_raw_post_handling params = ActiveSupport::OrderedHash[:page, {:name => 'page name'}, 'some key', 123] post :render_raw_post, params.dup @@ -256,6 +267,15 @@ XML assert_equal "foo", assigns["foo"] end + def test_view_assigns + @controller = ViewAssignsController.new + process :test_assigns + assert_equal nil, assigns(:foo) + assert_equal nil, assigns[:foo] + assert_equal "bar", assigns(:bar) + assert_equal "bar", assigns[:bar] + end + def test_assert_tag_tag process :test_html_output @@ -754,6 +774,22 @@ class CrazyNameTest < ActionController::TestCase end end +class CrazySymbolNameTest < ActionController::TestCase + tests :content + + def test_set_controller_class_using_symbol + assert_equal ContentController, self.class.controller_class + end +end + +class CrazyStringNameTest < ActionController::TestCase + tests 'content' + + def test_set_controller_class_using_string + assert_equal ContentController, self.class.controller_class + end +end + class NamedRoutesControllerTest < ActionController::TestCase tests ContentController diff --git a/actionpack/test/controller/url_for_test.rb b/actionpack/test/controller/url_for_test.rb index 484e996f31..11ced2df2a 100644 --- a/actionpack/test/controller/url_for_test.rb +++ b/actionpack/test/controller/url_for_test.rb @@ -67,6 +67,20 @@ module AbstractController ) end + def test_subdomain_may_be_removed + add_host! + assert_equal('http://basecamphq.com/c/a/i', + W.new.url_for(:subdomain => false, :controller => 'c', :action => 'a', :id => 'i') + ) + end + + def test_multiple_subdomains_may_be_removed + W.default_url_options[:host] = 'mobile.www.api.basecamphq.com' + assert_equal('http://basecamphq.com/c/a/i', + W.new.url_for(:subdomain => false, :controller => 'c', :action => 'a', :id => 'i') + ) + end + def test_domain_may_be_changed add_host! assert_equal('http://www.37signals.com/c/a/i', diff --git a/actionpack/test/dispatch/request_test.rb b/actionpack/test/dispatch/request_test.rb index 060bcfb5ec..a611252b31 100644 --- a/actionpack/test/dispatch/request_test.rb +++ b/actionpack/test/dispatch/request_test.rb @@ -15,6 +15,7 @@ class RequestTest < ActiveSupport::TestCase assert_equal 'http://www.example.com', url_for assert_equal 'http://api.example.com', url_for(:subdomain => 'api') + assert_equal 'http://example.com', url_for(:subdomain => false) assert_equal 'http://www.ror.com', url_for(:domain => 'ror.com') assert_equal 'http://api.ror.co.uk', url_for(:host => 'www.ror.co.uk', :subdomain => 'api', :tld_length => 2) assert_equal 'http://www.example.com:8080', url_for(:port => 8080) diff --git a/actionpack/test/template/sprockets_helper_test.rb b/actionpack/test/template/sprockets_helper_test.rb index b1e6db7b34..08b66fec8b 100644 --- a/actionpack/test/template/sprockets_helper_test.rb +++ b/actionpack/test/template/sprockets_helper_test.rb @@ -28,7 +28,6 @@ class SprocketsHelperTest < ActionView::TestCase application = Struct.new(:config, :assets).new(config, @assets) Rails.stubs(:application).returns(application) @config = config - @config.action_controller ||= ActiveSupport::InheritableOptions.new @config.perform_caching = true @config.assets.digest = true @config.assets.compile = true @@ -38,6 +37,10 @@ class SprocketsHelperTest < ActionView::TestCase "http://www.example.com" end + def config + @controller ? @controller.config : @config + end + test "asset_path" do assert_match %r{/assets/logo-[0-9a-f]+.png}, asset_path("logo.png") @@ -75,8 +78,9 @@ class SprocketsHelperTest < ActionView::TestCase end test "with a simple asset host the url should default to protocol relative" do + @controller.config.default_asset_host_protocol = :relative @controller.config.asset_host = "assets-%d.example.com" - assert_match %r{//assets-\d.example.com/assets/logo-[0-9a-f]+.png}, + assert_match %r{^//assets-\d.example.com/assets/logo-[0-9a-f]+.png}, asset_path("logo.png") end @@ -88,10 +92,11 @@ class SprocketsHelperTest < ActionView::TestCase end test "With a proc asset host that returns no protocol the url should be protocol relative" do + @controller.config.default_asset_host_protocol = :relative @controller.config.asset_host = Proc.new do |asset| "assets-999.example.com" end - assert_match %r{//assets-999.example.com/assets/logo-[0-9a-f]+.png}, + assert_match %r{^//assets-999.example.com/assets/logo-[0-9a-f]+.png}, asset_path("logo.png") end @@ -114,7 +119,7 @@ class SprocketsHelperTest < ActionView::TestCase test "stylesheets served without a controller in scope cannot access the request" do @controller = nil - @config.action_controller.asset_host = Proc.new do |asset, request| + @config.asset_host = Proc.new do |asset, request| fail "This should not have been called." end assert_raises ActionController::RoutingError do @@ -134,11 +139,27 @@ class SprocketsHelperTest < ActionView::TestCase 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" - @config.action_controller.default_asset_host_protocol = :request - @config.action_controller.perform_caching = true + @config.asset_host = "assets-%d.example.com" + @config.default_asset_host_protocol = :request + @config.perform_caching = true assert_match %r{/assets/logo-[0-9a-f]+.png}, asset_path("logo.png") @@ -152,12 +173,12 @@ class SprocketsHelperTest < ActionView::TestCase test "asset path with relative url root when controller isn't present but relative_url_root is" do @controller = nil - @config.action_controller.relative_url_root = "/collaboration/hieraki" + @config.relative_url_root = "/collaboration/hieraki" assert_equal "/collaboration/hieraki/images/logo.gif", 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") @@ -202,7 +223,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") 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>", |