From 07f733c6315980bde120c98c6b8a25e2773ee6bf Mon Sep 17 00:00:00 2001 From: Yehuda Katz + Carl Lerche Date: Mon, 18 May 2009 16:15:43 -0700 Subject: Ported simple benchmarking in new base --- actionpack/Rakefile | 4 ++-- actionpack/lib/action_controller/abstract.rb | 1 + .../lib/action_controller/abstract/benchmarker.rb | 28 ++++++++++++++++++++++ .../lib/action_controller/abstract/logger.rb | 1 + .../action_controller/base/chained/benchmarking.rb | 2 +- actionpack/lib/action_controller/new_base/base.rb | 1 + actionpack/test/controller/logging_test.rb | 5 ++++ 7 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 actionpack/lib/action_controller/abstract/benchmarker.rb diff --git a/actionpack/Rakefile b/actionpack/Rakefile index 41b190130e..57c3276cb9 100644 --- a/actionpack/Rakefile +++ b/actionpack/Rakefile @@ -21,8 +21,8 @@ task :default => [ :test ] # Run the unit tests -desc "Run all unit tests" -task :test => [:test_action_pack, :test_active_record_integration] +desc "Run all unit tests" # Do not remove :test_new_base +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/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 ||= [] -- cgit v1.2.3 From 20deb677a23d2a57f0a946dc98debe0fcdb70c40 Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Mon, 18 May 2009 20:17:35 -0300 Subject: Add missing models and fixtures [#2673 state:resolved] Signed-off-by: Pratik Naik --- .../has_many_through_associations_test.rb | 46 +++++++++++----------- .../test/cases/autosave_association_test.rb | 7 +++- activerecord/test/cases/named_scope_test.rb | 4 +- 3 files changed, 32 insertions(+), 25 deletions(-) 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 51c70b9819..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) } @@ -23,49 +23,49 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase assert_queries(1) do posts(:thinking).people << people(:david) end - + assert_queries(1) do assert posts(:thinking).people.include?(people(:david)) end - + assert posts(:thinking).reload.people(true).include?(people(:david)) end def test_associating_new assert_queries(1) { posts(:thinking) } new_person = nil # so block binding catches it - + assert_queries(0) do new_person = Person.new :first_name => 'bob' end - + # Associating new records always saves them # Thus, 1 query for the new person record, 1 query for the new join table record assert_queries(2) do posts(:thinking).people << new_person end - + assert_queries(1) do assert posts(:thinking).people.include?(new_person) end - + assert posts(:thinking).reload.people(true).include?(new_person) end def test_associate_new_by_building assert_queries(1) { posts(:thinking) } - + assert_queries(0) do posts(:thinking).people.build(:first_name=>"Bob") posts(:thinking).people.new(:first_name=>"Ted") end - + # Should only need to load the association once assert_queries(1) do assert posts(:thinking).people.collect(&:first_name).include?("Bob") assert posts(:thinking).people.collect(&:first_name).include?("Ted") end - + # 2 queries for each new record (1 to save the record itself, 1 for the join model) # * 2 new records = 4 # + 1 query to save the actual post = 5 @@ -73,22 +73,22 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase posts(:thinking).body += '-changed' posts(:thinking).save end - + assert posts(:thinking).reload.people(true).collect(&:first_name).include?("Bob") assert posts(:thinking).reload.people(true).collect(&:first_name).include?("Ted") end def test_delete_association assert_queries(2){posts(:welcome);people(:michael); } - + assert_queries(1) do posts(:welcome).people.delete(people(:michael)) end - + assert_queries(1) do assert posts(:welcome).people.empty? end - + assert posts(:welcome).reload.people(true).empty? end @@ -118,36 +118,36 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase def test_replace_association assert_queries(4){posts(:welcome);people(:david);people(:michael); posts(:welcome).people(true)} - + # 1 query to delete the existing reader (michael) # 1 query to associate the new reader (david) assert_queries(2) do posts(:welcome).people = [people(:david)] end - + assert_queries(0){ assert posts(:welcome).people.include?(people(:david)) assert !posts(:welcome).people.include?(people(:michael)) } - + assert posts(:welcome).reload.people(true).include?(people(:david)) assert !posts(:welcome).reload.people(true).include?(people(:michael)) end def test_associate_with_create assert_queries(1) { posts(:thinking) } - + # 1 query for the new record, 1 for the join table record # No need to update the actual collection yet! assert_queries(2) do posts(:thinking).people.create(:first_name=>"Jeb") end - + # *Now* we actually need the collection so it's loaded assert_queries(1) do assert posts(:thinking).people.collect(&:first_name).include?("Jeb") end - + assert posts(:thinking).reload.people(true).collect(&:first_name).include?("Jeb") end @@ -165,15 +165,15 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase def test_clear_associations assert_queries(2) { posts(:welcome);posts(:welcome).people(true) } - + assert_queries(1) do posts(:welcome).people.clear end - + assert_queries(0) do assert posts(:welcome).people.empty? end - + assert posts(:welcome).reload.people(true).empty? end 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 69d01d5c2a..92fe48cb5a 100644 --- a/activerecord/test/cases/named_scope_test.rb +++ b/activerecord/test/cases/named_scope_test.rb @@ -373,7 +373,7 @@ class NamedScopeTest < ActiveRecord::TestCase end end -class DynamicScopeMatchTest < ActiveRecord::TestCase +class DynamicScopeMatchTest < ActiveRecord::TestCase def test_scoped_by_no_match assert_nil ActiveRecord::DynamicScopeMatch.match("not_scoped_at_all") end @@ -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"}) -- cgit v1.2.3 From 6dc3a6a954b742ac7160593f94962b9b93a2ce25 Mon Sep 17 00:00:00 2001 From: Chad Woolley Date: Tue, 19 May 2009 12:50:26 +0200 Subject: Upgrade CI server to latest RubyGems [#2665 state:resolved] Signed-off-by: Pratik Naik --- ci/ci_setup_notes.txt | 2 +- ci/cruise_config.rb | 2 +- ci/geminstaller.yml | 2 ++ 3 files changed, 4 insertions(+), 2 deletions(-) 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 -- cgit v1.2.3 From e2ed1a1ca4f2dbfb9eb2c31fd1ddd45562afef25 Mon Sep 17 00:00:00 2001 From: Bryan Helmkamp Date: Tue, 19 May 2009 10:24:26 -0400 Subject: Allow MemCacheStore to be initialized with a MemCache object instead of addresses and options --- activesupport/CHANGELOG | 2 ++ .../lib/active_support/cache/mem_cache_store.rb | 17 +++++++++++------ activesupport/test/caching_test.rb | 14 ++++++++++---- 3 files changed, 23 insertions(+), 10 deletions(-) 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 -- cgit v1.2.3 From 0bdef30f35501953ffdcb34f1c8d3a1e23f9434d Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Tue, 19 May 2009 12:19:58 -0700 Subject: Lazy-require Kernel#silence_warnings --- railties/lib/rails/plugin.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) 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 -- cgit v1.2.3 From 4a6f4b92ad2f48dc7906d223fe4708d36624bd50 Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Tue, 19 May 2009 23:48:05 +0200 Subject: Change integration test helpers to accept Rack environment instead of just HTTP Headers. Before : get '/path', {}, 'Accept' => 'text/javascript' After : get '/path', {}, 'HTTP_ACCEPT' => 'text/javascript' --- .../lib/action_controller/testing/integration.rb | 10 ++++----- actionpack/test/controller/integration_test.rb | 24 +++++++++++----------- 2 files changed, 16 insertions(+), 18 deletions(-) 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) -- cgit v1.2.3 From f503a5dc97d18794cc0eda5ffe77e2cd7d762d47 Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Tue, 19 May 2009 23:57:49 +0200 Subject: Missing CHANGELOG entry for 4a6f4b92ad2f --- actionpack/CHANGELOG | 5 +++++ 1 file changed, 5 insertions(+) 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] -- cgit v1.2.3 From d8fffe7b23acce42bc3941d7bba47e07a66aed67 Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Wed, 20 May 2009 00:06:14 +0200 Subject: Replace ad hoc Rack::Test with ActionController::IntegrationTest --- actionpack/Rakefile | 2 +- actionpack/test/new_base/test_helper.rb | 16 +++++++--------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/actionpack/Rakefile b/actionpack/Rakefile index 57c3276cb9..6ce8179646 100644 --- a/actionpack/Rakefile +++ b/actionpack/Rakefile @@ -21,7 +21,7 @@ task :default => [ :test ] # Run the unit tests -desc "Run all unit tests" # Do not remove :test_new_base +desc "Run all unit tests" task :test => [:test_action_pack, :test_active_record_integration, :test_new_base] Rake::TestTask.new(:test_action_pack) do |t| 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) -- cgit v1.2.3