Permalink
Browse files

Merge branch '2-1-unsure' into tarmo_2-1-unsure

  • Loading branch information...
2 parents 482f6aa + 3b76700 commit 11d9669038a1aaa0107b9c16b36a38772b68c716 @tarmo tarmo committed Aug 24, 2008
View
@@ -1,5 +1,7 @@
*2.1.1 (next release)*
+* All 2xx requests are considered successful [Josh Peek]
+
* Deprecate the limited follow_redirect in functional tests. If you wish to follow redirects, use integration tests. [Michael Koziarski]
* Fixed that AssetTagHelper#compute_public_path shouldn't cache the asset_host along with the source or per-request proc's won't run [DHH]
@@ -1151,7 +1151,7 @@ def initialize_current_url
def log_processing
if logger && logger.info?
- logger.info "\n\nProcessing #{controller_class_name}\##{action_name} (for #{request_origin}) [#{request.method.to_s.upcase}]"
+ logger.info "\n\nProcessing #{self.class.name}\##{action_name} (for #{request_origin}) [#{request.method.to_s.upcase}]"
logger.info " Session ID: #{@_session.session_id}" if @_session and @_session.respond_to?(:session_id)
logger.info " Parameters: #{respond_to?(:filter_parameters) ? filter_parameters(params).inspect : params.inspect}"
end
@@ -171,7 +171,7 @@ def message
# Was the response successful?
def success?
- response_code == 200
+ (200..299).include?(response_code)
end
# Was the URL not found?
@@ -442,7 +442,7 @@ def mail_to(email_address, name = nil, html_options = {})
email_address_obfuscated.gsub!(/\./, html_options.delete("replace_dot")) if html_options.has_key?("replace_dot")
if encode == "javascript"
- "document.write('#{content_tag("a", name || email_address, html_options.merge({ "href" => "mailto:"+email_address+extras }))}');".each_byte do |c|
+ "document.write('#{content_tag("a", name || email_address_obfuscated, html_options.merge({ "href" => "mailto:"+email_address+extras }))}');".each_byte do |c|
string << sprintf("%%%x", c)
end
"<script type=\"#{Mime::JS}\">eval(unescape('#{string}'))</script>"
@@ -7,6 +7,7 @@ class ContainedEmptyController < ActionController::Base
end
class ContainedNonEmptyController < ActionController::Base
def public_action
+ render :nothing => true
end
hide_action :hidden_action
@@ -105,6 +106,18 @@ def hide_mocha_methods_from_controller(controller)
class PerformActionTest < Test::Unit::TestCase
+ class MockLogger
+ attr_reader :logged
+
+ def initialize
+ @logged = []
+ end
+
+ def method_missing(method, *args)
+ @logged << args.first
+ end
+ end
+
def use_controller(controller_class)
@controller = controller_class.new
@@ -142,6 +155,13 @@ def test_get_on_hidden_should_fail
get :another_hidden_action
assert_response 404
end
+
+ def test_namespaced_action_should_log_module_name
+ use_controller Submodule::ContainedNonEmptyController
+ @controller.logger = MockLogger.new
+ get :public_action
+ assert_match /Processing\sSubmodule::ContainedNonEmptyController#public_action/, @controller.logger.logged[1]
+ end
end
class DefaultUrlOptionsTest < Test::Unit::TestCase
@@ -284,6 +284,7 @@ def test_mail_to_with_replace_options
assert_dom_equal "<a href=\"&#109;&#97;&#105;&#108;&#116;&#111;&#58;%6d%65@%64%6f%6d%61%69%6e.%63%6f%6d\">My email</a>", mail_to("me@domain.com", "My email", :encode => "hex", :replace_at => "(at)")
assert_dom_equal "<a href=\"&#109;&#97;&#105;&#108;&#116;&#111;&#58;%6d%65@%64%6f%6d%61%69%6e.%63%6f%6d\">&#109;&#101;&#40;&#97;&#116;&#41;&#100;&#111;&#109;&#97;&#105;&#110;&#40;&#100;&#111;&#116;&#41;&#99;&#111;&#109;</a>", mail_to("me@domain.com", nil, :encode => "hex", :replace_at => "(at)", :replace_dot => "(dot)")
assert_dom_equal "<script type=\"text/javascript\">eval(unescape('%64%6f%63%75%6d%65%6e%74%2e%77%72%69%74%65%28%27%3c%61%20%68%72%65%66%3d%22%6d%61%69%6c%74%6f%3a%6d%65%40%64%6f%6d%61%69%6e%2e%63%6f%6d%22%3e%4d%79%20%65%6d%61%69%6c%3c%2f%61%3e%27%29%3b'))</script>", mail_to("me@domain.com", "My email", :encode => "javascript", :replace_at => "(at)", :replace_dot => "(dot)")
+ assert_dom_equal "<script type=\"text/javascript\">eval(unescape('%64%6f%63%75%6d%65%6e%74%2e%77%72%69%74%65%28%27%3c%61%20%68%72%65%66%3d%22%6d%61%69%6c%74%6f%3a%6d%65%40%64%6f%6d%61%69%6e%2e%63%6f%6d%22%3e%6d%65%28%61%74%29%64%6f%6d%61%69%6e%28%64%6f%74%29%63%6f%6d%3c%2f%61%3e%27%29%3b'))</script>", mail_to("me@domain.com", nil, :encode => "javascript", :replace_at => "(at)", :replace_dot => "(dot)")
end
def protect_against_forgery?
@@ -189,6 +189,9 @@ def observed_subclasses
def add_observer!(klass)
klass.add_observer(self)
+ if respond_to?(:after_find) && !klass.method_defined?(:after_find)
+ klass.class_eval 'def after_find() end'
+ end
end
end
end
@@ -143,12 +143,12 @@ def test_observing_subclasses
assert_equal developer.name, multi_observer.record.name
end
- def test_after_find_cannot_be_observed_when_its_not_defined_on_the_model
+ def test_after_find_can_be_observed_when_its_not_defined_on_the_model
observer = MinimalisticObserver.instance
assert_equal Minimalistic, MinimalisticObserver.observed_class
minimalistic = Minimalistic.find(1)
- assert_nil observer.minimalistic
+ assert_equal minimalistic, observer.minimalistic
end
def test_after_find_can_be_observed_when_its_defined_on_the_model
@@ -159,6 +159,34 @@ def test_after_find_can_be_observed_when_its_defined_on_the_model
assert_equal topic, observer.topic
end
+ def test_after_find_is_not_created_if_its_not_used
+ # use a fresh class so an observer can't have defined an
+ # after_find on it
+ model_class = Class.new(ActiveRecord::Base)
+ observer_class = Class.new(ActiveRecord::Observer)
+ observer_class.observe(model_class)
+
+ observer = observer_class.instance
+
+ assert !model_class.method_defined?(:after_find)
+ end
+
+ def test_after_find_is_not_clobbered_if_it_already_exists
+ # use a fresh observer class so we can instantiate it (Observer is
+ # a Singleton)
+ model_class = Class.new(ActiveRecord::Base) do
+ def after_find; end
+ end
+ original_method = model_class.instance_method(:after_find)
+ observer_class = Class.new(ActiveRecord::Observer) do
+ def after_find; end
+ end
+ observer_class.observe(model_class)
+
+ observer = observer_class.instance
+ assert_equal original_method, model_class.instance_method(:after_find)
+ end
+
def test_invalid_observer
assert_raise(ArgumentError) { Topic.observers = Object.new; Topic.instantiate_observers }
end
@@ -8,7 +8,7 @@ def to_json(options = nil)
if ActiveSupport.use_standard_json_time_format
xmlschema.inspect
else
- %("#{strftime("%Y/%m/%d %H:%M:%S %z")}")
+ strftime('"%Y/%m/%d %H:%M:%S %z"')
end
end
end
@@ -630,13 +630,17 @@ def reload_plugins?
# You can add gems with the #gem method.
attr_accessor :gems
- # Adds a single Gem dependency to the rails application.
+ # Adds a single Gem dependency to the rails application. By default, it will require
+ # the library with the same name as the gem. Use :lib to specify a different name.
#
# # gem 'aws-s3', '>= 0.4.0'
# # require 'aws/s3'
# config.gem 'aws-s3', :lib => 'aws/s3', :version => '>= 0.4.0', \
# :source => "http://code.whytheluckystiff.net"
#
+ # To require a library be installed, but not attempt to load it, pass :lib => false
+ #
+ # config.gem 'qrp', :version => '0.4.1', :lib => false
def gem(name, options = {})
@gems << Rails::GemDependency.new(name, options)
end
@@ -58,7 +58,7 @@ def gem_dir(base_directory)
def load
return if @loaded || @load_paths_added == false
- require(@lib || @name)
+ require(@lib || @name) unless @lib == false
@loaded = true
rescue LoadError
puts $!.to_s
@@ -11,6 +11,7 @@ def setup
@gem_with_source = Rails::GemDependency.new "hpricot", :source => "http://code.whytheluckystiff.net"
@gem_with_version = Rails::GemDependency.new "hpricot", :version => "= 0.6"
@gem_with_lib = Rails::GemDependency.new "aws-s3", :lib => "aws/s3"
+ @gem_without_load = Rails::GemDependency.new "hpricot", :lib => false
end
def test_configuration_adds_gem_dependency
@@ -62,5 +63,13 @@ def test_gem_with_lib_loading
@gem_with_lib.add_load_paths
@gem_with_lib.load
end
+
+ def test_gem_without_lib_loading
+ @gem_without_load.expects(:gem).with(@gem_without_load.name)
+ @gem_without_load.expects(:require).with(@gem_without_load.lib).never
+ @gem_without_load.add_load_paths
+ @gem_without_load.load
+ end
+
end
end

0 comments on commit 11d9669

Please sign in to comment.