diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2009-03-03 19:10:42 -0800 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2009-03-03 19:10:42 -0800 |
commit | 8ef46f0d61c5e4a2b92708585a5157dac96a6817 (patch) | |
tree | a828e6cc95e3f3ab8a055304e3fcff90f3df889c | |
parent | cb534524389bb4f407fc268a0bb7a7cffb6785a9 (diff) | |
parent | ce56c5daa81d61a745b88220014a846a0eea46a4 (diff) | |
download | rails-8ef46f0d61c5e4a2b92708585a5157dac96a6817.tar.gz rails-8ef46f0d61c5e4a2b92708585a5157dac96a6817.tar.bz2 rails-8ef46f0d61c5e4a2b92708585a5157dac96a6817.zip |
Merge branch 'master' of git@github.com:rails/rails
-rw-r--r-- | actionmailer/lib/action_mailer/part.rb | 5 | ||||
-rw-r--r-- | actionmailer/test/mail_service_test.rb | 1 | ||||
-rw-r--r-- | actionpack/lib/action_controller/routing/segments.rb | 2 | ||||
-rw-r--r-- | actionpack/test/activerecord/active_record_store_test.rb | 21 | ||||
-rw-r--r-- | actionpack/test/controller/resources_test.rb | 12 | ||||
-rw-r--r-- | activerecord/lib/active_record/session_store.rb | 10 | ||||
-rw-r--r-- | railties/lib/initializer.rb | 6 | ||||
-rw-r--r-- | railties/lib/rails/rack/metal.rb | 16 | ||||
-rw-r--r-- | railties/test/fixtures/metal/multiplemetals/app/metal/metal_a.rb | 5 | ||||
-rw-r--r-- | railties/test/fixtures/metal/multiplemetals/app/metal/metal_b.rb | 5 | ||||
-rw-r--r-- | railties/test/fixtures/metal/singlemetal/app/metal/foo_metal.rb | 5 | ||||
-rw-r--r-- | railties/test/fixtures/metal/subfolders/app/metal/Folder/metal_a.rb | 7 | ||||
-rw-r--r-- | railties/test/fixtures/metal/subfolders/app/metal/Folder/metal_b.rb | 7 | ||||
-rw-r--r-- | railties/test/metal_test.rb | 57 |
14 files changed, 149 insertions, 10 deletions
diff --git a/actionmailer/lib/action_mailer/part.rb b/actionmailer/lib/action_mailer/part.rb index 977c0b2b5c..2bbb59cdb6 100644 --- a/actionmailer/lib/action_mailer/part.rb +++ b/actionmailer/lib/action_mailer/part.rb @@ -88,7 +88,10 @@ module ActionMailer part.parts << prt end - part.set_content_type(real_content_type, nil, ctype_attrs) if real_content_type =~ /multipart/ + if real_content_type =~ /multipart/ + ctype_attrs.delete 'charset' + part.set_content_type(real_content_type, nil, ctype_attrs) + end end headers.each { |k,v| part[k] = v } diff --git a/actionmailer/test/mail_service_test.rb b/actionmailer/test/mail_service_test.rb index 1e04531753..26ba652f2a 100644 --- a/actionmailer/test/mail_service_test.rb +++ b/actionmailer/test/mail_service_test.rb @@ -330,6 +330,7 @@ class ActionMailerTest < Test::Unit::TestCase assert_equal "multipart/mixed", created.content_type assert_equal "multipart/alternative", created.parts.first.content_type assert_equal "bar", created.parts.first.header['foo'].to_s + assert_nil created.parts.first.charset assert_equal "text/plain", created.parts.first.parts.first.content_type assert_equal "text/html", created.parts.first.parts[1].content_type assert_equal "application/octet-stream", created.parts[1].content_type diff --git a/actionpack/lib/action_controller/routing/segments.rb b/actionpack/lib/action_controller/routing/segments.rb index cbb1a9c09a..358b4a6487 100644 --- a/actionpack/lib/action_controller/routing/segments.rb +++ b/actionpack/lib/action_controller/routing/segments.rb @@ -318,7 +318,7 @@ module ActionController end def regexp_chunk - '(\.[^/?\.]+)?' + '/|(\.[^/?\.]+)?' end def to_s diff --git a/actionpack/test/activerecord/active_record_store_test.rb b/actionpack/test/activerecord/active_record_store_test.rb index 6a75e6050d..7998f9c22f 100644 --- a/actionpack/test/activerecord/active_record_store_test.rb +++ b/actionpack/test/activerecord/active_record_store_test.rb @@ -21,6 +21,11 @@ class ActiveRecordStoreTest < ActionController::IntegrationTest render :text => "foo: #{session[:foo].inspect}" end + def call_reset_session + reset_session + head :ok + end + def rescue_action(e) raise end end @@ -61,6 +66,22 @@ class ActiveRecordStoreTest < ActionController::IntegrationTest end end + def test_setting_session_value_after_session_reset + with_test_route_set do + get '/set_session_value' + assert_response :success + assert cookies['_session_id'] + + get '/call_reset_session' + assert_response :success + assert_not_equal [], headers['Set-Cookie'] + + get '/get_session_value' + assert_response :success + assert_equal 'foo: nil', response.body + end + end + def test_prevents_session_fixation with_test_route_set do get '/set_session_value' diff --git a/actionpack/test/controller/resources_test.rb b/actionpack/test/controller/resources_test.rb index ae2639d245..c441cfd4cf 100644 --- a/actionpack/test/controller/resources_test.rb +++ b/actionpack/test/controller/resources_test.rb @@ -750,9 +750,17 @@ class ResourcesTest < ActionController::TestCase end def test_with_path_segment - with_restful_routing :messages, :as => 'reviews' do - assert_simply_restful_for :messages, :as => 'reviews' + with_restful_routing :messages do + assert_simply_restful_for :messages + assert_recognizes({:controller => "messages", :action => "index"}, "/messages") + assert_recognizes({:controller => "messages", :action => "index"}, "/messages/") end + + with_restful_routing :messages, :as => 'reviews' do + assert_simply_restful_for :messages, :as => 'reviews' + assert_recognizes({:controller => "messages", :action => "index"}, "/reviews") + assert_recognizes({:controller => "messages", :action => "index"}, "/reviews/") + end end def test_multiple_with_path_segment_and_controller diff --git a/activerecord/lib/active_record/session_store.rb b/activerecord/lib/active_record/session_store.rb index de199d30bf..3cc4640f42 100644 --- a/activerecord/lib/active_record/session_store.rb +++ b/activerecord/lib/active_record/session_store.rb @@ -287,8 +287,7 @@ module ActiveRecord def get_session(env, sid) Base.silence do sid ||= generate_sid - session = @@session_class.find_by_session_id(sid) - session ||= @@session_class.new(:session_id => sid, :data => {}) + session = find_session(sid) env[SESSION_RECORD_KEY] = session [sid, session.data] end @@ -296,7 +295,7 @@ module ActiveRecord def set_session(env, sid, session_data) Base.silence do - record = env[SESSION_RECORD_KEY] + record = env[SESSION_RECORD_KEY] ||= find_session(sid) record.data = session_data return false unless record.save @@ -310,5 +309,10 @@ module ActiveRecord return true end + + def find_session(id) + @@session_class.find_by_session_id(id) || + @@session_class.new(:session_id => id, :data => {}) + end end end diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb index 24ce3e75ff..edea4e513a 100644 --- a/railties/lib/initializer.rb +++ b/railties/lib/initializer.rb @@ -559,6 +559,7 @@ Run `rake gems:install` to install the missing gems. end def initialize_metal + Rails::Rack::Metal.requested_metals = configuration.metals Rails::Rack::Metal.metal_paths += plugin_loader.engine_metal_paths configuration.middleware.insert_before( @@ -715,6 +716,11 @@ Run `rake gems:install` to install the missing gems. @plugins = plugins.nil? ? nil : plugins.map { |p| p.to_sym } end + # The list of metals to load. If this is set to <tt>nil</tt>, all metals will + # be loaded in alphabetical order. If this is set to <tt>[]</tt>, no metals will + # be loaded. Otherwise metals will be loaded in the order specified + attr_accessor :metals + # The path to the root of the plugins directory. By default, it is in # <tt>vendor/plugins</tt>. attr_accessor :plugin_paths diff --git a/railties/lib/rails/rack/metal.rb b/railties/lib/rails/rack/metal.rb index 8dac992ef2..bce59f4c78 100644 --- a/railties/lib/rails/rack/metal.rb +++ b/railties/lib/rails/rack/metal.rb @@ -8,16 +8,26 @@ module Rails cattr_accessor :metal_paths self.metal_paths = ["#{Rails.root}/app/metal"] + cattr_accessor :requested_metals def self.metals matcher = /#{Regexp.escape('/app/metal/')}(.*)\.rb\Z/ metal_glob = metal_paths.map{ |base| "#{base}/**/*.rb" } + all_metals = {} Dir[*metal_glob].sort.map do |file| - path = file.match(matcher)[1] - require path - path.classify.constantize + file = file.match(matcher)[1] + all_metals[file.classify] = file end + + load_list = requested_metals || all_metals.keys + + load_list.map do |requested_metal| + if metal = all_metals[requested_metal] + require metal + requested_metal.constantize + end + end.compact end def initialize(app) diff --git a/railties/test/fixtures/metal/multiplemetals/app/metal/metal_a.rb b/railties/test/fixtures/metal/multiplemetals/app/metal/metal_a.rb new file mode 100644 index 0000000000..b8e7001351 --- /dev/null +++ b/railties/test/fixtures/metal/multiplemetals/app/metal/metal_a.rb @@ -0,0 +1,5 @@ +class MetalA < Rails::Rack::Metal + def self.call(env) + [200, { "Content-Type" => "text/html"}, "Hi"] + end +end diff --git a/railties/test/fixtures/metal/multiplemetals/app/metal/metal_b.rb b/railties/test/fixtures/metal/multiplemetals/app/metal/metal_b.rb new file mode 100644 index 0000000000..adc2f45fcf --- /dev/null +++ b/railties/test/fixtures/metal/multiplemetals/app/metal/metal_b.rb @@ -0,0 +1,5 @@ +class MetalB < Rails::Rack::Metal + def self.call(env) + [200, { "Content-Type" => "text/html"}, "Hi"] + end +end diff --git a/railties/test/fixtures/metal/singlemetal/app/metal/foo_metal.rb b/railties/test/fixtures/metal/singlemetal/app/metal/foo_metal.rb new file mode 100644 index 0000000000..9ade2ce8e7 --- /dev/null +++ b/railties/test/fixtures/metal/singlemetal/app/metal/foo_metal.rb @@ -0,0 +1,5 @@ +class FooMetal < Rails::Rack::Metal + def self.call(env) + [200, { "Content-Type" => "text/html"}, "Hi"] + end +end diff --git a/railties/test/fixtures/metal/subfolders/app/metal/Folder/metal_a.rb b/railties/test/fixtures/metal/subfolders/app/metal/Folder/metal_a.rb new file mode 100644 index 0000000000..71a5a62eb8 --- /dev/null +++ b/railties/test/fixtures/metal/subfolders/app/metal/Folder/metal_a.rb @@ -0,0 +1,7 @@ +module Folder + class MetalA < Rails::Rack::Metal + def self.call(env) + [200, { "Content-Type" => "text/html"}, "Hi"] + end + end +end diff --git a/railties/test/fixtures/metal/subfolders/app/metal/Folder/metal_b.rb b/railties/test/fixtures/metal/subfolders/app/metal/Folder/metal_b.rb new file mode 100644 index 0000000000..430d7bfed6 --- /dev/null +++ b/railties/test/fixtures/metal/subfolders/app/metal/Folder/metal_b.rb @@ -0,0 +1,7 @@ +module Folder + class MetalB < Rails::Rack::Metal + def self.call(env) + [200, { "Content-Type" => "text/html"}, "Hi"] + end + end +end diff --git a/railties/test/metal_test.rb b/railties/test/metal_test.rb new file mode 100644 index 0000000000..cff231ed00 --- /dev/null +++ b/railties/test/metal_test.rb @@ -0,0 +1,57 @@ +require 'abstract_unit' +require 'initializer' + +class MetalTest < Test::Unit::TestCase + def test_metals_should_return_list_of_found_metal_apps + use_appdir("singlemetal") do + assert_equal(["FooMetal"], found_metals_as_string_array) + end + end + + def test_metals_should_return_alphabetical_list_of_found_metal_apps + use_appdir("multiplemetals") do + assert_equal(["MetalA", "MetalB"], found_metals_as_string_array) + end + end + + def test_metals_load_order_should_be_overriden_by_requested_metals + use_appdir("multiplemetals") do + Rails::Rack::Metal.requested_metals = ["MetalB", "MetalA"] + assert_equal(["MetalB", "MetalA"], found_metals_as_string_array) + end + end + + def test_metals_not_listed_should_not_load + use_appdir("multiplemetals") do + Rails::Rack::Metal.requested_metals = ["MetalB"] + assert_equal(["MetalB"], found_metals_as_string_array) + end + end +p + def test_metal_finding_should_work_with_subfolders + use_appdir("subfolders") do + assert_equal(["Folder::MetalA", "Folder::MetalB"], found_metals_as_string_array) + end + end + + def test_metal_finding_with_requested_metals_should_work_with_subfolders + use_appdir("subfolders") do + Rails::Rack::Metal.requested_metals = ["Folder::MetalB"] + assert_equal(["Folder::MetalB"], found_metals_as_string_array) + end + end + + private + + def use_appdir(root) + dir = "#{File.dirname(__FILE__)}/fixtures/metal/#{root}" + Rails::Rack::Metal.metal_paths = ["#{dir}/app/metal"] + Rails::Rack::Metal.requested_metals = nil + $LOAD_PATH << "#{dir}/app/metal" + yield + end + + def found_metals_as_string_array + Rails::Rack::Metal.metals.map { |m| m.to_s } + end +end |