aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--actionpack/CHANGELOG5
-rw-r--r--actionpack/Rakefile2
-rw-r--r--actionpack/lib/action_controller/abstract.rb1
-rw-r--r--actionpack/lib/action_controller/abstract/benchmarker.rb28
-rw-r--r--actionpack/lib/action_controller/abstract/logger.rb1
-rw-r--r--actionpack/lib/action_controller/base/chained/benchmarking.rb2
-rw-r--r--actionpack/lib/action_controller/new_base/base.rb1
-rw-r--r--actionpack/lib/action_controller/testing/integration.rb10
-rw-r--r--actionpack/test/controller/integration_test.rb24
-rw-r--r--actionpack/test/controller/logging_test.rb5
-rw-r--r--actionpack/test/new_base/test_helper.rb16
-rw-r--r--activerecord/test/cases/associations/has_many_through_associations_test.rb2
-rw-r--r--activerecord/test/cases/autosave_association_test.rb7
-rw-r--r--activerecord/test/cases/named_scope_test.rb2
-rw-r--r--activesupport/CHANGELOG2
-rw-r--r--activesupport/lib/active_support/cache/mem_cache_store.rb17
-rw-r--r--activesupport/test/caching_test.rb14
-rw-r--r--ci/ci_setup_notes.txt2
-rw-r--r--ci/cruise_config.rb2
-rw-r--r--ci/geminstaller.yml2
-rw-r--r--railties/lib/rails/plugin.rb3
21 files changed, 103 insertions, 45 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG
index c1dc6f2ab4..e3ad19558e 100644
--- a/actionpack/CHANGELOG
+++ b/actionpack/CHANGELOG
@@ -1,5 +1,10 @@
*Edge*
+* Change integration test helpers to accept Rack environment instead of just HTTP Headers [Pratik Naik]
+
+ Before : get '/path', {}, 'Accept' => 'text/javascript'
+ After : get '/path', {}, 'HTTP_ACCEPT' => 'text/javascript'
+
* Instead of checking Rails.env.test? in Failsafe middleware, check env["rails.raise_exceptions"] [Bryan Helmkamp]
* Fixed that TestResponse.cookies was returning cookies unescaped #1867 [Doug McInnes]
diff --git a/actionpack/Rakefile b/actionpack/Rakefile
index 41b190130e..6ce8179646 100644
--- a/actionpack/Rakefile
+++ b/actionpack/Rakefile
@@ -22,7 +22,7 @@ task :default => [ :test ]
# Run the unit tests
desc "Run all unit tests"
-task :test => [:test_action_pack, :test_active_record_integration]
+task :test => [:test_action_pack, :test_active_record_integration, :test_new_base]
Rake::TestTask.new(:test_action_pack) do |t|
t.libs << "test"
diff --git a/actionpack/lib/action_controller/abstract.rb b/actionpack/lib/action_controller/abstract.rb
index 48e33282ec..d6b7a44f5f 100644
--- a/actionpack/lib/action_controller/abstract.rb
+++ b/actionpack/lib/action_controller/abstract.rb
@@ -3,6 +3,7 @@ require "active_support/core_ext/module/delegation"
module AbstractController
autoload :Base, "action_controller/abstract/base"
+ autoload :Benchmarker, "action_controller/abstract/benchmarker"
autoload :Callbacks, "action_controller/abstract/callbacks"
autoload :Helpers, "action_controller/abstract/helpers"
autoload :Layouts, "action_controller/abstract/layouts"
diff --git a/actionpack/lib/action_controller/abstract/benchmarker.rb b/actionpack/lib/action_controller/abstract/benchmarker.rb
new file mode 100644
index 0000000000..9f5889c704
--- /dev/null
+++ b/actionpack/lib/action_controller/abstract/benchmarker.rb
@@ -0,0 +1,28 @@
+module AbstractController
+ module Benchmarker
+ extend ActiveSupport::DependencyModule
+
+ depends_on Logger
+
+ module ClassMethods
+ def benchmark(title, log_level = ::Logger::DEBUG, use_silence = true)
+ if logger && logger.level >= log_level
+ result = nil
+ ms = Benchmark.ms { result = use_silence ? silence { yield } : yield }
+ logger.add(log_level, "#{title} (#{('%.1f' % ms)}ms)")
+ result
+ else
+ yield
+ end
+ end
+
+ # Silences the logger for the duration of the block.
+ def silence
+ old_logger_level, logger.level = logger.level, ::Logger::ERROR if logger
+ yield
+ ensure
+ logger.level = old_logger_level if logger
+ end
+ end
+ end
+end \ No newline at end of file
diff --git a/actionpack/lib/action_controller/abstract/logger.rb b/actionpack/lib/action_controller/abstract/logger.rb
index 750a5c9fb6..980ede0bed 100644
--- a/actionpack/lib/action_controller/abstract/logger.rb
+++ b/actionpack/lib/action_controller/abstract/logger.rb
@@ -1,4 +1,5 @@
require 'active_support/core_ext/class/attribute_accessors'
+require 'active_support/core_ext/logger'
module AbstractController
module Logger
diff --git a/actionpack/lib/action_controller/base/chained/benchmarking.rb b/actionpack/lib/action_controller/base/chained/benchmarking.rb
index 66e9e9c31d..57a1ac8314 100644
--- a/actionpack/lib/action_controller/base/chained/benchmarking.rb
+++ b/actionpack/lib/action_controller/base/chained/benchmarking.rb
@@ -21,7 +21,7 @@ module ActionController #:nodoc:
# easy to include benchmarking statements in production software that will remain inexpensive because the benchmark
# will only be conducted if the log level is low enough.
def benchmark(title, log_level = Logger::DEBUG, use_silence = true)
- if logger && logger.level == log_level
+ if logger && logger.level >= log_level
result = nil
ms = Benchmark.ms { result = use_silence ? silence { yield } : yield }
logger.add(log_level, "#{title} (#{('%.1f' % ms)}ms)")
diff --git a/actionpack/lib/action_controller/new_base/base.rb b/actionpack/lib/action_controller/new_base/base.rb
index c25ffd5c84..756a0799fe 100644
--- a/actionpack/lib/action_controller/new_base/base.rb
+++ b/actionpack/lib/action_controller/new_base/base.rb
@@ -2,6 +2,7 @@ module ActionController
class Base < Http
abstract!
+ include AbstractController::Benchmarker
include AbstractController::Callbacks
include AbstractController::Helpers
include AbstractController::Logger
diff --git a/actionpack/lib/action_controller/testing/integration.rb b/actionpack/lib/action_controller/testing/integration.rb
index d6991ab4f5..a8e8f16d6c 100644
--- a/actionpack/lib/action_controller/testing/integration.rb
+++ b/actionpack/lib/action_controller/testing/integration.rb
@@ -62,8 +62,8 @@ module ActionController
# with 'HTTP_' if not already.
def xml_http_request(request_method, path, parameters = nil, headers = nil)
headers ||= {}
- headers['X-Requested-With'] = 'XMLHttpRequest'
- headers['Accept'] ||= [Mime::JS, Mime::HTML, Mime::XML, 'text/xml', Mime::ALL].join(', ')
+ headers['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest'
+ headers['HTTP_ACCEPT'] ||= [Mime::JS, Mime::HTML, Mime::XML, 'text/xml', Mime::ALL].join(', ')
process(request_method, path, parameters, headers)
end
alias xhr :xml_http_request
@@ -228,7 +228,7 @@ module ActionController
private
# Performs the actual request.
- def process(method, path, parameters = nil, headers = nil)
+ def process(method, path, parameters = nil, rack_environment = nil)
if path =~ %r{://}
location = URI.parse(path)
https! URI::HTTPS === location if location.scheme
@@ -265,9 +265,7 @@ module ActionController
}
env = Rack::MockRequest.env_for(path, opts)
- (headers || {}).each do |key, value|
- key = key.to_s.upcase.gsub(/-/, "_")
- key = "HTTP_#{key}" unless env.has_key?(key) || key =~ /^HTTP_/
+ (rack_environment || {}).each do |key, value|
env[key] = value
end
diff --git a/actionpack/test/controller/integration_test.rb b/actionpack/test/controller/integration_test.rb
index c616107324..a2b3ad2106 100644
--- a/actionpack/test/controller/integration_test.rb
+++ b/actionpack/test/controller/integration_test.rb
@@ -123,8 +123,8 @@ class SessionTest < Test::Unit::TestCase
def test_xml_http_request_get
path = "/index"; params = "blah"; headers = {:location => 'blah'}
headers_after_xhr = headers.merge(
- "X-Requested-With" => "XMLHttpRequest",
- "Accept" => "text/javascript, text/html, application/xml, text/xml, */*"
+ "HTTP_X_REQUESTED_WITH" => "XMLHttpRequest",
+ "HTTP_ACCEPT" => "text/javascript, text/html, application/xml, text/xml, */*"
)
@session.expects(:process).with(:get,path,params,headers_after_xhr)
@session.xml_http_request(:get,path,params,headers)
@@ -133,8 +133,8 @@ class SessionTest < Test::Unit::TestCase
def test_xml_http_request_post
path = "/index"; params = "blah"; headers = {:location => 'blah'}
headers_after_xhr = headers.merge(
- "X-Requested-With" => "XMLHttpRequest",
- "Accept" => "text/javascript, text/html, application/xml, text/xml, */*"
+ "HTTP_X_REQUESTED_WITH" => "XMLHttpRequest",
+ "HTTP_ACCEPT" => "text/javascript, text/html, application/xml, text/xml, */*"
)
@session.expects(:process).with(:post,path,params,headers_after_xhr)
@session.xml_http_request(:post,path,params,headers)
@@ -143,8 +143,8 @@ class SessionTest < Test::Unit::TestCase
def test_xml_http_request_put
path = "/index"; params = "blah"; headers = {:location => 'blah'}
headers_after_xhr = headers.merge(
- "X-Requested-With" => "XMLHttpRequest",
- "Accept" => "text/javascript, text/html, application/xml, text/xml, */*"
+ "HTTP_X_REQUESTED_WITH" => "XMLHttpRequest",
+ "HTTP_ACCEPT" => "text/javascript, text/html, application/xml, text/xml, */*"
)
@session.expects(:process).with(:put,path,params,headers_after_xhr)
@session.xml_http_request(:put,path,params,headers)
@@ -153,8 +153,8 @@ class SessionTest < Test::Unit::TestCase
def test_xml_http_request_delete
path = "/index"; params = "blah"; headers = {:location => 'blah'}
headers_after_xhr = headers.merge(
- "X-Requested-With" => "XMLHttpRequest",
- "Accept" => "text/javascript, text/html, application/xml, text/xml, */*"
+ "HTTP_X_REQUESTED_WITH" => "XMLHttpRequest",
+ "HTTP_ACCEPT" => "text/javascript, text/html, application/xml, text/xml, */*"
)
@session.expects(:process).with(:delete,path,params,headers_after_xhr)
@session.xml_http_request(:delete,path,params,headers)
@@ -163,17 +163,17 @@ class SessionTest < Test::Unit::TestCase
def test_xml_http_request_head
path = "/index"; params = "blah"; headers = {:location => 'blah'}
headers_after_xhr = headers.merge(
- "X-Requested-With" => "XMLHttpRequest",
- "Accept" => "text/javascript, text/html, application/xml, text/xml, */*"
+ "HTTP_X_REQUESTED_WITH" => "XMLHttpRequest",
+ "HTTP_ACCEPT" => "text/javascript, text/html, application/xml, text/xml, */*"
)
@session.expects(:process).with(:head,path,params,headers_after_xhr)
@session.xml_http_request(:head,path,params,headers)
end
def test_xml_http_request_override_accept
- path = "/index"; params = "blah"; headers = {:location => 'blah', "Accept" => "application/xml"}
+ path = "/index"; params = "blah"; headers = {:location => 'blah', "HTTP_ACCEPT" => "application/xml"}
headers_after_xhr = headers.merge(
- "X-Requested-With" => "XMLHttpRequest"
+ "HTTP_X_REQUESTED_WITH" => "XMLHttpRequest"
)
@session.expects(:process).with(:post,path,params,headers_after_xhr)
@session.xml_http_request(:post,path,params,headers)
diff --git a/actionpack/test/controller/logging_test.rb b/actionpack/test/controller/logging_test.rb
index 1f3ff4ef52..75afa2d133 100644
--- a/actionpack/test/controller/logging_test.rb
+++ b/actionpack/test/controller/logging_test.rb
@@ -11,6 +11,11 @@ class LoggingTest < ActionController::TestCase
class MockLogger
attr_reader :logged
+ attr_accessor :level
+
+ def initialize
+ @level = Logger::DEBUG
+ end
def method_missing(method, *args)
@logged ||= []
diff --git a/actionpack/test/new_base/test_helper.rb b/actionpack/test/new_base/test_helper.rb
index ec7dbffaae..9401e692f1 100644
--- a/actionpack/test/new_base/test_helper.rb
+++ b/actionpack/test/new_base/test_helper.rb
@@ -20,8 +20,8 @@ require 'action_controller/abstract'
require 'action_controller/new_base'
require 'pp' # require 'pp' early to prevent hidden_methods from not picking up the pretty-print methods until too late
-require 'rubygems'
-require 'rack/test'
+require 'action_controller/testing/process'
+require 'action_controller/testing/integration'
module Rails
def self.env
@@ -32,9 +32,7 @@ module Rails
end
# Temporary base class
-class Rack::TestCase < ActiveSupport::TestCase
- include Rack::Test::Methods
-
+class Rack::TestCase < ActionController::IntegrationTest
setup do
ActionController::Base.session_options[:key] = "abc"
ActionController::Base.session_options[:secret] = ("*" * 30)
@@ -82,7 +80,7 @@ class Rack::TestCase < ActiveSupport::TestCase
end
def assert_body(body)
- assert_equal body, Array.wrap(last_response.body).join
+ assert_equal body, Array.wrap(response.body).join
end
def self.assert_body(body)
@@ -92,7 +90,7 @@ class Rack::TestCase < ActiveSupport::TestCase
end
def assert_status(code)
- assert_equal code, last_response.status
+ assert_equal code, response.status
end
def self.assert_status(code)
@@ -110,7 +108,7 @@ class Rack::TestCase < ActiveSupport::TestCase
end
def assert_content_type(type)
- assert_equal type, last_response.headers["Content-Type"]
+ assert_equal type, response.headers["Content-Type"]
end
def self.assert_content_type(type)
@@ -120,7 +118,7 @@ class Rack::TestCase < ActiveSupport::TestCase
end
def assert_header(name, value)
- assert_equal value, last_response.headers[name]
+ assert_equal value, response.headers[name]
end
def self.assert_header(name, value)
diff --git a/activerecord/test/cases/associations/has_many_through_associations_test.rb b/activerecord/test/cases/associations/has_many_through_associations_test.rb
index c9baef5f7e..4254badef2 100644
--- a/activerecord/test/cases/associations/has_many_through_associations_test.rb
+++ b/activerecord/test/cases/associations/has_many_through_associations_test.rb
@@ -13,7 +13,7 @@ require 'models/pet'
require 'models/toy'
class HasManyThroughAssociationsTest < ActiveRecord::TestCase
- fixtures :posts, :readers, :people, :comments, :authors, :owners, :pets, :toys
+ fixtures :posts, :readers, :people, :comments, :authors, :owners, :pets, :toys, :jobs, :references
def test_associate_existing
assert_queries(2) { posts(:thinking);people(:david) }
diff --git a/activerecord/test/cases/autosave_association_test.rb b/activerecord/test/cases/autosave_association_test.rb
index 919b6f857c..f95b2c0079 100644
--- a/activerecord/test/cases/autosave_association_test.rb
+++ b/activerecord/test/cases/autosave_association_test.rb
@@ -12,6 +12,7 @@ require 'models/reader'
require 'models/ship'
require 'models/ship_part'
require 'models/treasure'
+require 'models/company'
class TestAutosaveAssociationsInGeneral < ActiveRecord::TestCase
def test_autosave_should_be_a_valid_option_for_has_one
@@ -38,6 +39,8 @@ class TestAutosaveAssociationsInGeneral < ActiveRecord::TestCase
end
class TestDefaultAutosaveAssociationOnAHasOneAssociation < ActiveRecord::TestCase
+ fixtures :companies, :accounts
+
def test_should_save_parent_but_not_invalid_child
firm = Firm.new(:name => 'GlobalMegaCorp')
assert firm.valid?
@@ -137,6 +140,8 @@ class TestDefaultAutosaveAssociationOnAHasOneAssociation < ActiveRecord::TestCas
end
class TestDefaultAutosaveAssociationOnABelongsToAssociation < ActiveRecord::TestCase
+ fixtures :companies
+
def test_should_save_parent_but_not_invalid_child
client = Client.new(:name => 'Joe (the Plumber)')
assert client.valid?
@@ -920,4 +925,4 @@ class TestAutosaveAssociationOnAHasAndBelongsToManyAssociation < ActiveRecord::T
end
include AutosaveAssociationOnACollectionAssociationTests
-end \ No newline at end of file
+end
diff --git a/activerecord/test/cases/named_scope_test.rb b/activerecord/test/cases/named_scope_test.rb
index cff648795f..92fe48cb5a 100644
--- a/activerecord/test/cases/named_scope_test.rb
+++ b/activerecord/test/cases/named_scope_test.rb
@@ -387,6 +387,8 @@ class DynamicScopeMatchTest < ActiveRecord::TestCase
end
class DynamicScopeTest < ActiveRecord::TestCase
+ fixtures :posts
+
def test_dynamic_scope
assert_equal Post.scoped_by_author_id(1).find(1), Post.find(1)
assert_equal Post.scoped_by_author_id_and_title(1, "Welcome to the weblog").first, Post.find(:first, :conditions => { :author_id => 1, :title => "Welcome to the weblog"})
diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG
index 032f0fb9c1..6551be01f9 100644
--- a/activesupport/CHANGELOG
+++ b/activesupport/CHANGELOG
@@ -1,5 +1,7 @@
*Edge*
+* Allow MemCacheStore to be initialized with a MemCache object instead of addresses and options [Bryan Helmkamp]
+
* Change spelling of Kyev timezone to Kyiv #2613 [Alexander Dymo]
* Add ActiveSupport.parse_json_times to disable time parsing in JSON backends that don't support it or don't need it. [rick]
diff --git a/activesupport/lib/active_support/cache/mem_cache_store.rb b/activesupport/lib/active_support/cache/mem_cache_store.rb
index 90b7526fe1..ab8eb72096 100644
--- a/activesupport/lib/active_support/cache/mem_cache_store.rb
+++ b/activesupport/lib/active_support/cache/mem_cache_store.rb
@@ -23,7 +23,12 @@ module ActiveSupport
DELETED = "DELETED\r\n"
end
- attr_reader :addresses
+ def self.build_mem_cache(*addresses)
+ addresses = addresses.flatten
+ options = addresses.extract_options!
+ addresses = ["localhost"] if addresses.empty?
+ MemCache.new(addresses, options)
+ end
# Creates a new MemCacheStore object, with the given memcached server
# addresses. Each address is either a host name, or a host-with-port string
@@ -34,11 +39,11 @@ module ActiveSupport
# If no addresses are specified, then MemCacheStore will connect to
# localhost port 11211 (the default memcached port).
def initialize(*addresses)
- addresses = addresses.flatten
- options = addresses.extract_options!
- addresses = ["localhost"] if addresses.empty?
- @addresses = addresses
- @data = MemCache.new(addresses, options)
+ if addresses.first.is_a?(MemCache)
+ @data = addresses.first
+ else
+ @data = self.class.build_mem_cache(*addresses)
+ end
extend Strategy::LocalCache
end
diff --git a/activesupport/test/caching_test.rb b/activesupport/test/caching_test.rb
index b845796fe5..ad19dcfd09 100644
--- a/activesupport/test/caching_test.rb
+++ b/activesupport/test/caching_test.rb
@@ -15,22 +15,28 @@ class CacheStoreSettingTest < ActiveSupport::TestCase
end
def test_mem_cache_fragment_cache_store
+ MemCache.expects(:new).with(%w[localhost], {})
store = ActiveSupport::Cache.lookup_store :mem_cache_store, "localhost"
assert_kind_of(ActiveSupport::Cache::MemCacheStore, store)
- assert_equal %w(localhost), store.addresses
+ end
+
+ def test_mem_cache_fragment_cache_store_with_given_mem_cache
+ mem_cache = MemCache.new
+ MemCache.expects(:new).never
+ store = ActiveSupport::Cache.lookup_store :mem_cache_store, mem_cache
+ assert_kind_of(ActiveSupport::Cache::MemCacheStore, store)
end
def test_mem_cache_fragment_cache_store_with_multiple_servers
+ MemCache.expects(:new).with(%w[localhost 192.168.1.1], {})
store = ActiveSupport::Cache.lookup_store :mem_cache_store, "localhost", '192.168.1.1'
assert_kind_of(ActiveSupport::Cache::MemCacheStore, store)
- assert_equal %w(localhost 192.168.1.1), store.addresses
end
def test_mem_cache_fragment_cache_store_with_options
+ MemCache.expects(:new).with(%w[localhost 192.168.1.1], { :namespace => "foo" })
store = ActiveSupport::Cache.lookup_store :mem_cache_store, "localhost", '192.168.1.1', :namespace => 'foo'
assert_kind_of(ActiveSupport::Cache::MemCacheStore, store)
- assert_equal %w(localhost 192.168.1.1), store.addresses
- assert_equal 'foo', store.instance_variable_get('@data').instance_variable_get('@namespace')
end
def test_object_assigned_fragment_cache_store
diff --git a/ci/ci_setup_notes.txt b/ci/ci_setup_notes.txt
index 63f1851b19..780277c939 100644
--- a/ci/ci_setup_notes.txt
+++ b/ci/ci_setup_notes.txt
@@ -47,7 +47,7 @@ $ sudo aptitude update
* If you did not configure no-root-gem installation via ~/.gemrc as shown above, then allow no-password sudo for gem installation:
$ sudo visudo
# add this line to bottom:
-ci ALL=NOPASSWD: /usr/local/bin/geminstaller, /usr/local/bin/ruby, /usr/local/bin/gem
+ci ALL=(ALL) NOPASSWD: ALL
* Start ccrb via init script and check for default homepage at port 3333
diff --git a/ci/cruise_config.rb b/ci/cruise_config.rb
index 7985e3c8df..2247a1b6ea 100644
--- a/ci/cruise_config.rb
+++ b/ci/cruise_config.rb
@@ -1,5 +1,5 @@
Project.configure do |project|
- project.build_command = 'ruby ci/ci_build.rb'
+ project.build_command = 'sudo update_rubygems && ruby ci/ci_build.rb'
project.email_notifier.emails = ['thewoolleyman@gmail.com']
# project.email_notifier.emails = ['thewoolleyman@gmail.com','michael@koziarski.com', 'david@loudthinking.com', 'jeremy@bitsweat.net', 'josh@joshpeek.com', 'pratiknaik@gmail.com', 'wycats@gmail.com']
project.email_notifier.from = 'thewoolleyman+railsci@gmail.com'
diff --git a/ci/geminstaller.yml b/ci/geminstaller.yml
index 387e370a6f..f1ef9b59a0 100644
--- a/ci/geminstaller.yml
+++ b/ci/geminstaller.yml
@@ -21,3 +21,5 @@ gems:
version: >= 2.2.3
- name: sqlite3-ruby
version: >= 1.2.2
+- name: rubygems-update
+ version: >= 1.3.3
diff --git a/railties/lib/rails/plugin.rb b/railties/lib/rails/plugin.rb
index e66166306a..49ec5c7fba 100644
--- a/railties/lib/rails/plugin.rb
+++ b/railties/lib/rails/plugin.rb
@@ -1,5 +1,3 @@
-require 'active_support/core_ext/kernel/reporting'
-
module Rails
# The Plugin class should be an object which provides the following methods:
#
@@ -141,6 +139,7 @@ module Rails
def evaluate_init_rb(initializer)
if has_init_file?
+ require 'active_support/core_ext/kernel/reporting'
silence_warnings do
# Allow plugins to reference the current configuration object
config = initializer.configuration