diff options
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/README.rdoc | 8 | ||||
-rw-r--r-- | actionpack/actionpack.gemspec | 4 | ||||
-rw-r--r-- | actionpack/lib/action_controller/metal/params_wrapper.rb | 41 | ||||
-rw-r--r-- | actionpack/lib/action_controller/test_case.rb | 7 | ||||
-rw-r--r-- | actionpack/lib/action_dispatch/http/rack_cache.rb | 8 | ||||
-rw-r--r-- | actionpack/lib/action_dispatch/middleware/cookies.rb | 6 | ||||
-rw-r--r-- | actionpack/lib/action_dispatch/testing/performance_test.rb | 19 | ||||
-rw-r--r-- | actionpack/lib/action_view/helpers/atom_feed_helper.rb | 4 | ||||
-rw-r--r-- | actionpack/lib/sprockets/railtie.rb | 12 | ||||
-rw-r--r-- | actionpack/test/controller/log_subscriber_test.rb | 6 | ||||
-rw-r--r-- | actionpack/test/controller/params_wrapper_test.rb | 75 | ||||
-rw-r--r-- | actionpack/test/dispatch/cookies_test.rb | 12 | ||||
-rw-r--r-- | actionpack/test/dispatch/rack_cache_test.rb | 21 | ||||
-rw-r--r-- | actionpack/test/template/atom_feed_helper_test.rb | 18 |
14 files changed, 145 insertions, 96 deletions
diff --git a/actionpack/README.rdoc b/actionpack/README.rdoc index 5db4cff66b..5919b5c6d4 100644 --- a/actionpack/README.rdoc +++ b/actionpack/README.rdoc @@ -33,7 +33,7 @@ A short rundown of some of the major features: * Actions grouped in controller as methods instead of separate command objects and can therefore share helper methods - CustomersController < ActionController::Base + class CustomersController < ActionController::Base def show @customer = find_customer end @@ -58,7 +58,7 @@ A short rundown of some of the major features: * ERB templates (static content mixed with dynamic output from ruby) - <% for post in @posts %> + <% @posts.each do |post| %> Title: <%= post.title %> <% end %> @@ -81,7 +81,7 @@ A short rundown of some of the major features: xml.language "en-us" xml.ttl "40" - for item in @recent_items + @recent_items.each do |item| xml.item do xml.title(item_title(item)) xml.description(item_description(item)) @@ -293,7 +293,7 @@ And the templates look like this: </body></html> weblog/index.html.erb: - <% for post in @posts %> + <% @posts.each do |post| %> <p><%= link_to(post.title, :action => "show", :id => post.id) %></p> <% end %> diff --git a/actionpack/actionpack.gemspec b/actionpack/actionpack.gemspec index 606abac83a..0b4e7027ed 100644 --- a/actionpack/actionpack.gemspec +++ b/actionpack/actionpack.gemspec @@ -24,8 +24,8 @@ Gem::Specification.new do |s| s.add_dependency('i18n', '~> 0.6.0beta1') s.add_dependency('rack', '~> 1.3.0.beta') s.add_dependency('rack-test', '~> 0.6.0') - s.add_dependency('rack-mount', '~> 0.8.0') - s.add_dependency('sprockets', '~> 2.0.0.beta.2') + s.add_dependency('rack-mount', '~> 0.8.1') + s.add_dependency('sprockets', '~> 2.0.0.beta.3') s.add_dependency('tzinfo', '~> 0.3.27') s.add_dependency('erubis', '~> 2.7.0') end diff --git a/actionpack/lib/action_controller/metal/params_wrapper.rb b/actionpack/lib/action_controller/metal/params_wrapper.rb index aa7c1e09c2..5500f88930 100644 --- a/actionpack/lib/action_controller/metal/params_wrapper.rb +++ b/actionpack/lib/action_controller/metal/params_wrapper.rb @@ -2,6 +2,7 @@ require 'active_support/core_ext/class/attribute' require 'active_support/core_ext/hash/slice' require 'active_support/core_ext/hash/except' require 'active_support/core_ext/array/wrap' +require 'active_support/core_ext/module/anonymous' require 'action_dispatch/http/mime_types' module ActionController @@ -36,11 +37,11 @@ module ActionController # {"name" => "Konata", "user" => {"name" => "Konata"}} # # You can also specify the key in which the parameters should be wrapped to, - # and also the list of attributes it should wrap by using either +:only+ or - # +:except+ options like this: + # and also the list of attributes it should wrap by using either +:include+ or + # +:exclude+ options like this: # # class UsersController < ApplicationController - # wrap_parameters :person, :only => [:username, :password] + # wrap_parameters :person, :include => [:username, :password] # end # # If you're going to pass the parameters to an +ActiveModel+ object (such as @@ -52,7 +53,7 @@ module ActionController # wrap_parameters Person # end # - # You still could pass +:only+ and +:except+ to set the list of attributes + # You still could pass +:include+ and +:exclude+ to set the list of attributes # you want to wrap. # # By default, if you don't specify the key in which the parameters would be @@ -72,7 +73,7 @@ module ActionController included do class_attribute :_wrapper_options - self._wrapper_options = {:format => []} + self._wrapper_options = { :format => [] } end module ClassMethods @@ -90,7 +91,7 @@ module ActionController # # wraps parameters by determine the wrapper key from Person class # (+person+, in this case) and the list of attribute names # - # wrap_parameters :only => [:username, :title] + # wrap_parameters :include => [:username, :title] # # wraps only +:username+ and +:title+ attributes from parameters. # # wrap_parameters false @@ -99,9 +100,9 @@ module ActionController # ==== Options # * <tt>:format</tt> - The list of formats in which the parameters wrapper # will be enabled. - # * <tt>:only</tt> - The list of attribute names which parameters wrapper + # * <tt>:include</tt> - The list of attribute names which parameters wrapper # will wrap into a nested hash. - # * <tt>:except</tt> - The list of attribute names which parameters wrapper + # * <tt>:exclude</tt> - The list of attribute names which parameters wrapper # will exclude from a nested hash. def wrap_parameters(name_or_model_or_options, options = {}) model = nil @@ -140,6 +141,8 @@ module ActionController # This method also does namespace lookup. Foo::Bar::UsersController will # 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 @@ -161,22 +164,22 @@ module ActionController def _set_wrapper_defaults(options, model=nil) options = options.dup - unless options[:only] || options[:except] + unless options[:include] || options[:exclude] model ||= _default_wrap_model if model.respond_to?(:attribute_names) && model.attribute_names.present? - options[:only] = model.attribute_names + options[:include] = model.attribute_names end end - unless options[:name] + unless options[:name] || self.anonymous? model ||= _default_wrap_model options[:name] = model ? model.to_s.demodulize.underscore : controller_name.singularize end - options[:only] = Array.wrap(options[:only]).collect(&:to_s) if options[:only] - options[:except] = Array.wrap(options[:except]).collect(&:to_s) if options[:except] - options[:format] = Array.wrap(options[:format]) + options[:include] = Array.wrap(options[:include]).collect(&:to_s) if options[:include] + options[:exclude] = Array.wrap(options[:exclude]).collect(&:to_s) if options[:exclude] + options[:format] = Array.wrap(options[:format]) self._wrapper_options = options end @@ -213,11 +216,11 @@ module ActionController # Returns the list of parameters which will be selected for wrapped. def _wrap_parameters(parameters) - value = if only = _wrapper_options[:only] - parameters.slice(*only) + value = if include_only = _wrapper_options[:include] + parameters.slice(*include_only) else - except = _wrapper_options[:except] || [] - parameters.except(*(except + EXCLUDE_PARAMETERS)) + exclude = _wrapper_options[:exclude] || [] + parameters.except(*(exclude + EXCLUDE_PARAMETERS)) end { _wrapper_key => value } @@ -226,7 +229,7 @@ module ActionController # Checks if we should perform parameters wrapping. def _wrapper_enabled? ref = request.content_mime_type.try(:ref) - _wrapper_formats.include?(ref) && !request.request_parameters[_wrapper_key] + _wrapper_formats.include?(ref) && _wrapper_key && !request.request_parameters[_wrapper_key] end end end diff --git a/actionpack/lib/action_controller/test_case.rb b/actionpack/lib/action_controller/test_case.rb index 0085f542aa..89ff5ba174 100644 --- a/actionpack/lib/action_controller/test_case.rb +++ b/actionpack/lib/action_controller/test_case.rb @@ -2,6 +2,7 @@ require 'rack/session/abstract/id' require 'active_support/core_ext/object/blank' require 'active_support/core_ext/object/to_query' require 'active_support/core_ext/class/attribute' +require 'active_support/core_ext/module/anonymous' module ActionController module TemplateAssertions @@ -413,7 +414,11 @@ module ActionController @request.env['REQUEST_METHOD'] = http_method parameters ||= {} - @request.assign_parameters(@routes, @controller.class.name.underscore.sub(/_controller$/, ''), action.to_s, parameters) + controller_class_name = @controller.class.anonymous? ? + "anonymous_controller" : + @controller.class.name.underscore.sub(/_controller$/, '') + + @request.assign_parameters(@routes, controller_class_name, action.to_s, parameters) @request.session = ActionController::TestSession.new(session) if session @request.session["flash"] = @request.flash.update(flash || {}) diff --git a/actionpack/lib/action_dispatch/http/rack_cache.rb b/actionpack/lib/action_dispatch/http/rack_cache.rb index b5c1435903..cc8edee300 100644 --- a/actionpack/lib/action_dispatch/http/rack_cache.rb +++ b/actionpack/lib/action_dispatch/http/rack_cache.rb @@ -14,11 +14,15 @@ module ActionDispatch end def read(key) - @store.read(key) || [] + if data = @store.read(key) + Marshal.load(data) + else + [] + end end def write(key, value) - @store.write(key, value) + @store.write(key, Marshal.dump(value)) end ::Rack::Cache::MetaStore::RAILS = self diff --git a/actionpack/lib/action_dispatch/middleware/cookies.rb b/actionpack/lib/action_dispatch/middleware/cookies.rb index 24ebb8fed7..0057f64dd3 100644 --- a/actionpack/lib/action_dispatch/middleware/cookies.rb +++ b/actionpack/lib/action_dispatch/middleware/cookies.rb @@ -167,8 +167,8 @@ module ActionDispatch handle_options(options) - @set_cookies[key] = options - @delete_cookies.delete(key) + @set_cookies[key.to_s] = options + @delete_cookies.delete(key.to_s) value end @@ -181,7 +181,7 @@ module ActionDispatch handle_options(options) value = @cookies.delete(key.to_s) - @delete_cookies[key] = options + @delete_cookies[key.to_s] = options value end diff --git a/actionpack/lib/action_dispatch/testing/performance_test.rb b/actionpack/lib/action_dispatch/testing/performance_test.rb index e7aeb45fb3..13fe693c32 100644 --- a/actionpack/lib/action_dispatch/testing/performance_test.rb +++ b/actionpack/lib/action_dispatch/testing/performance_test.rb @@ -1,17 +1,10 @@ require 'active_support/testing/performance' -begin - module ActionDispatch - # An integration test that runs a code profiler on your test methods. - # Profiling output for combinations of each test method, measurement, and - # output format are written to your tmp/performance directory. - # - # By default, process_time is measured and both flat and graph_html output - # formats are written, so you'll have two output files per test method. - class PerformanceTest < ActionDispatch::IntegrationTest - include ActiveSupport::Testing::Performance - end +module ActionDispatch + # An integration test that runs a code profiler on your test methods. + # Profiling output for combinations of each test method, measurement, and + # output format are written to your tmp/performance directory. + class PerformanceTest < ActionDispatch::IntegrationTest + include ActiveSupport::Testing::Performance end -rescue NameError - $stderr.puts "Specify ruby-prof as application's dependency in Gemfile to run benchmarks." end diff --git a/actionpack/lib/action_view/helpers/atom_feed_helper.rb b/actionpack/lib/action_view/helpers/atom_feed_helper.rb index 889ea8a763..a087688a2c 100644 --- a/actionpack/lib/action_view/helpers/atom_feed_helper.rb +++ b/actionpack/lib/action_view/helpers/atom_feed_helper.rb @@ -34,7 +34,7 @@ module ActionView # feed.title("My great blog!") # feed.updated(@posts.first.created_at) # - # for post in @posts + # @posts.each do |post| # feed.entry(post) do |entry| # entry.title(post.title) # entry.content(post.body, :type => 'html') @@ -66,7 +66,7 @@ module ActionView # feed.updated((@posts.first.created_at)) # feed.tag!(openSearch:totalResults, 10) # - # for post in @posts + # @posts.each do |post| # feed.entry(post) do |entry| # entry.title(post.title) # entry.content(post.body, :type => 'html') diff --git a/actionpack/lib/sprockets/railtie.rb b/actionpack/lib/sprockets/railtie.rb index c75b7d4de0..8cee3babe2 100644 --- a/actionpack/lib/sprockets/railtie.rb +++ b/actionpack/lib/sprockets/railtie.rb @@ -34,15 +34,7 @@ module Sprockets app.assets = asset_environment(app) ActiveSupport.on_load(:action_view) do - if app.assets.respond_to?(:context_class) - context = app.assets.context_class - - # TODO: Remove this condition when Sprockets 2.0.beta.3 is released - else - context = app.assets.context - end - - context.instance_eval do + app.assets.context_class.instance_eval do include ::ActionView::Helpers::SprocketsHelper end end @@ -99,7 +91,7 @@ module Sprockets compressor when :yui require 'yui/compressor' - YUI::JavaScriptCompressor.new(:munge => true) + YUI::CssCompressor.new else sym end diff --git a/actionpack/test/controller/log_subscriber_test.rb b/actionpack/test/controller/log_subscriber_test.rb index 5d7a51e902..80c4fa2ee5 100644 --- a/actionpack/test/controller/log_subscriber_test.rb +++ b/actionpack/test/controller/log_subscriber_test.rb @@ -4,7 +4,7 @@ require "action_controller/log_subscriber" module Another class LogSubscribersController < ActionController::Base - wrap_parameters :person, :only => :name, :format => :json + wrap_parameters :person, :include => :name, :format => :json def show render :nothing => true @@ -34,11 +34,11 @@ module Another cache_page("Super soaker", "/index.html") render :nothing => true end - + def with_exception raise Exception end - + end end diff --git a/actionpack/test/controller/params_wrapper_test.rb b/actionpack/test/controller/params_wrapper_test.rb index ae4ad8eb9c..7bef1e8d5d 100644 --- a/actionpack/test/controller/params_wrapper_test.rb +++ b/actionpack/test/controller/params_wrapper_test.rb @@ -2,7 +2,21 @@ require 'abstract_unit' module Admin; class User; end; end +module ParamsWrapperTestHelp + def with_default_wrapper_options(&block) + @controller.class._wrapper_options = {:format => [:json]} + @controller.class.inherited(@controller.class) + yield + end + + def assert_parameters(expected) + assert_equal expected, self.class.controller_class.last_parameters + end +end + class ParamsWrapperTest < ActionController::TestCase + include ParamsWrapperTestHelp + class UsersController < ActionController::Base class << self attr_accessor :last_parameters @@ -51,9 +65,9 @@ class ParamsWrapperTest < ActionController::TestCase end end - def test_specify_only_option + def test_specify_include_option with_default_wrapper_options do - UsersController.wrap_parameters :only => :username + UsersController.wrap_parameters :include => :username @request.env['CONTENT_TYPE'] = 'application/json' post :parse, { 'username' => 'sikachu', 'title' => 'Developer' } @@ -61,9 +75,9 @@ class ParamsWrapperTest < ActionController::TestCase end end - def test_specify_except_option + def test_specify_exclude_option with_default_wrapper_options do - UsersController.wrap_parameters :except => :title + UsersController.wrap_parameters :exclude => :title @request.env['CONTENT_TYPE'] = 'application/json' post :parse, { 'username' => 'sikachu', 'title' => 'Developer' } @@ -71,9 +85,9 @@ class ParamsWrapperTest < ActionController::TestCase end end - def test_specify_both_wrapper_name_and_only_option + def test_specify_both_wrapper_name_and_include_option with_default_wrapper_options do - UsersController.wrap_parameters :person, :only => :username + UsersController.wrap_parameters :person, :include => :username @request.env['CONTENT_TYPE'] = 'application/json' post :parse, { 'username' => 'sikachu', 'title' => 'Developer' } @@ -166,20 +180,11 @@ class ParamsWrapperTest < ActionController::TestCase assert_parameters({ 'username' => 'sikachu', 'title' => 'Developer', 'user' => { 'username' => 'sikachu', 'title' => 'Developer' }}) end end - - private - def with_default_wrapper_options(&block) - @controller.class._wrapper_options = {:format => [:json]} - @controller.class.inherited(@controller.class) - yield - end - - def assert_parameters(expected) - assert_equal expected, UsersController.last_parameters - end end class NamespacedParamsWrapperTest < ActionController::TestCase + include ParamsWrapperTestHelp + module Admin module Users class UsersController < ActionController::Base; @@ -247,14 +252,36 @@ class NamespacedParamsWrapperTest < ActionController::TestCase end end - private - def with_default_wrapper_options(&block) - @controller.class._wrapper_options = {:format => [:json]} - @controller.class.inherited(@controller.class) - yield +end + +class AnonymousControllerParamsWrapperTest < ActionController::TestCase + include ParamsWrapperTestHelp + + tests(Class.new(ActionController::Base) do + class << self + attr_accessor :last_parameters end - def assert_parameters(expected) - assert_equal expected, Admin::Users::UsersController.last_parameters + def parse + self.class.last_parameters = request.params.except(:controller, :action) + head :ok + end + end) + + def test_does_not_implicitly_wrap_params + with_default_wrapper_options do + @request.env['CONTENT_TYPE'] = 'application/json' + post :parse, { 'username' => 'sikachu' } + assert_parameters({ 'username' => 'sikachu' }) end + end + + def test_does_wrap_params_if_name_provided + with_default_wrapper_options do + @controller.class.wrap_parameters(:name => "guest") + @request.env['CONTENT_TYPE'] = 'application/json' + post :parse, { 'username' => 'sikachu' } + assert_parameters({ 'username' => 'sikachu', 'guest' => { 'username' => 'sikachu' }}) + end + end end diff --git a/actionpack/test/dispatch/cookies_test.rb b/actionpack/test/dispatch/cookies_test.rb index ebc16694db..e42c39f527 100644 --- a/actionpack/test/dispatch/cookies_test.rb +++ b/actionpack/test/dispatch/cookies_test.rb @@ -121,7 +121,7 @@ class CookiesTest < ActionController::TestCase end def string_key - cookies['user_name'] = "david" + cookies['user_name'] = "dhh" head :ok end @@ -417,14 +417,18 @@ class CookiesTest < ActionController::TestCase assert_cookie_header "user_name=; path=/; expires=Thu, 01-Jan-1970 00:00:00 GMT" end + def test_cookies_hash_is_indifferent_access - [:symbol_key, :string_key].each do |cookie_key| - get cookie_key + get :symbol_key assert_equal "david", cookies[:user_name] assert_equal "david", cookies['user_name'] - end + get :string_key + assert_equal "dhh", cookies[:user_name] + assert_equal "dhh", cookies['user_name'] end + + def test_setting_request_cookies_is_indifferent_access @request.cookies.clear @request.cookies[:user_name] = "andrew" diff --git a/actionpack/test/dispatch/rack_cache_test.rb b/actionpack/test/dispatch/rack_cache_test.rb new file mode 100644 index 0000000000..79d8a64d29 --- /dev/null +++ b/actionpack/test/dispatch/rack_cache_test.rb @@ -0,0 +1,21 @@ +require 'abstract_unit' +require 'action_dispatch/http/rack_cache' + +class RackCacheMetaStoreTest < ActiveSupport::TestCase + class ReadWriteHash < ::Hash + alias :read :[] + alias :write :[]= + end + + setup do + @store = ActionDispatch::RailsMetaStore.new(ReadWriteHash.new) + end + + test "stuff is deep duped" do + @store.write(:foo, { :bar => :original }) + hash = @store.read(:foo) + hash[:bar] = :changed + hash = @store.read(:foo) + assert_equal :original, hash[:bar] + end +end diff --git a/actionpack/test/template/atom_feed_helper_test.rb b/actionpack/test/template/atom_feed_helper_test.rb index 36102bbc4f..81d7444cf8 100644 --- a/actionpack/test/template/atom_feed_helper_test.rb +++ b/actionpack/test/template/atom_feed_helper_test.rb @@ -16,7 +16,7 @@ class ScrollsController < ActionController::Base feed.title("My great blog!") feed.updated((@scrolls.first.created_at)) - for scroll in @scrolls + @scrolls.each do |scroll| feed.entry(scroll) do |entry| entry.title(scroll.title) entry.content(scroll.body, :type => 'html') @@ -33,7 +33,7 @@ class ScrollsController < ActionController::Base feed.title("My great blog!") feed.updated((@scrolls.first.created_at)) - for scroll in @scrolls + @scrolls.each do |scroll| feed.entry(scroll, :url => "/otherstuff/" + scroll.to_param.to_s, :updated => Time.utc(2007, 1, scroll.id)) do |entry| entry.title(scroll.title) entry.content(scroll.body, :type => 'html') @@ -54,7 +54,7 @@ class ScrollsController < ActionController::Base author.name("DHH") end - for scroll in @scrolls + @scrolls.each do |scroll| feed.entry(scroll, :url => "/otherstuff/" + scroll.to_param.to_s, :updated => Time.utc(2007, 1, scroll.id)) do |entry| entry.title(scroll.title) entry.content(scroll.body, :type => 'html') @@ -68,7 +68,7 @@ class ScrollsController < ActionController::Base feed.title("My great blog!") feed.updated((@scrolls.first.created_at)) - for scroll in @scrolls + @scrolls.each do |scroll| feed.entry(scroll) do |entry| entry.title(scroll.title) entry.content(scroll.body, :type => 'html') @@ -86,7 +86,7 @@ class ScrollsController < ActionController::Base feed.title("My great blog!") feed.updated((@scrolls.first.created_at)) - for scroll in @scrolls + @scrolls.each do |scroll| feed.entry(scroll, :id => "tag:test.rubyonrails.org,2008:"+scroll.id.to_s) do |entry| entry.title(scroll.title) entry.content(scroll.body, :type => 'html') @@ -105,7 +105,7 @@ class ScrollsController < ActionController::Base feed.title("My great blog!") feed.updated((@scrolls.first.created_at)) - for scroll in @scrolls + @scrolls.each do |scroll| feed.entry(scroll) do |entry| entry.title(scroll.title) entry.content(scroll.body, :type => 'html') @@ -123,7 +123,7 @@ class ScrollsController < ActionController::Base feed.title("My great blog!") feed.updated((@scrolls.first.created_at)) - for scroll in @scrolls + @scrolls.each do |scroll| feed.entry(scroll) do |entry| entry.title(scroll.title) entry.content(scroll.body, :type => 'html') @@ -140,7 +140,7 @@ class ScrollsController < ActionController::Base feed.title("My great blog!") feed.updated((@scrolls.first.created_at)) - for scroll in @scrolls + @scrolls.each do |scroll| feed.entry(scroll) do |entry| entry.title(scroll.title) entry.summary(:type => 'xhtml') do |xhtml| @@ -165,7 +165,7 @@ class ScrollsController < ActionController::Base feed.title("My great blog!") feed.updated((@scrolls.first.created_at)) - for scroll in @scrolls + @scrolls.each do |scroll| feed.entry(scroll) do |entry| entry.title(scroll.title) entry.content(scroll.body, :type => 'html') |