aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--actionpack/lib/action_view/helpers/form_tag_helper.rb4
-rw-r--r--actionpack/test/template/sprockets_helper_test.rb4
-rw-r--r--activerecord/lib/active_record/railties/databases.rake3
-rw-r--r--activerecord/lib/active_record/schema_dumper.rb4
-rw-r--r--activerecord/test/cases/attribute_methods_test.rb1
-rw-r--r--activerecord/test/cases/schema_dumper_test.rb15
-rw-r--r--activesupport/lib/active_support/cache.rb23
-rw-r--r--activesupport/lib/active_support/core_ext/string/output_safety.rb6
-rw-r--r--activesupport/lib/active_support/dependencies.rb11
-rw-r--r--activesupport/test/caching_test.rb17
-rw-r--r--activesupport/test/safe_buffer_test.rb6
11 files changed, 57 insertions, 37 deletions
diff --git a/actionpack/lib/action_view/helpers/form_tag_helper.rb b/actionpack/lib/action_view/helpers/form_tag_helper.rb
index 822686b09d..79f07400b2 100644
--- a/actionpack/lib/action_view/helpers/form_tag_helper.rb
+++ b/actionpack/lib/action_view/helpers/form_tag_helper.rb
@@ -417,7 +417,7 @@ module ActionView
options["data-confirm"] = confirm
end
- tag :input, { "type" => "submit", "name" => "commit", "value" => value }.update(options.stringify_keys)
+ tag :input, { "type" => "submit", "name" => "commit", "value" => value }.update(options)
end
# Creates a button element that defines a <tt>submit</tt> button,
@@ -503,7 +503,7 @@ module ActionView
options["data-confirm"] = confirm
end
- tag :input, { "type" => "image", "src" => path_to_image(source) }.update(options.stringify_keys)
+ tag :input, { "type" => "image", "src" => path_to_image(source) }.update(options)
end
# Creates a field set for grouping HTML form elements.
diff --git a/actionpack/test/template/sprockets_helper_test.rb b/actionpack/test/template/sprockets_helper_test.rb
index b9161b62c5..f4b5344d63 100644
--- a/actionpack/test/template/sprockets_helper_test.rb
+++ b/actionpack/test/template/sprockets_helper_test.rb
@@ -97,7 +97,7 @@ class SprocketsHelperTest < ActionView::TestCase
end
test "stylesheets served without a controller in scope cannot access the request" do
- remove_instance_variable("@controller")
+ @controller = nil
@config.action_controller.asset_host = Proc.new do |asset, request|
fail "This should not have been called."
end
@@ -107,7 +107,7 @@ class SprocketsHelperTest < ActionView::TestCase
end
test "stylesheets served without a controller in do not use asset hosts when the default protocol is :request" do
- remove_instance_variable("@controller")
+ @controller = nil
@config.action_controller.asset_host = "assets-%d.example.com"
@config.action_controller.default_asset_host_protocol = :request
@config.action_controller.perform_caching = true
diff --git a/activerecord/lib/active_record/railties/databases.rake b/activerecord/lib/active_record/railties/databases.rake
index 0ee7e20cf1..ec00f7faad 100644
--- a/activerecord/lib/active_record/railties/databases.rake
+++ b/activerecord/lib/active_record/railties/databases.rake
@@ -341,7 +341,8 @@ db_namespace = namespace :db do
desc 'Create a db/schema.rb file that can be portably used against any DB supported by AR'
task :dump => :load_config do
require 'active_record/schema_dumper'
- File.open(ENV['SCHEMA'] || "#{Rails.root}/db/schema.rb", "w") do |file|
+ filename = ENV['SCHEMA'] || "#{Rails.root}/db/schema.rb"
+ File.open(filename, "w:utf-8") do |file|
ActiveRecord::Base.establish_connection(Rails.env)
ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, file)
end
diff --git a/activerecord/lib/active_record/schema_dumper.rb b/activerecord/lib/active_record/schema_dumper.rb
index 19585f6214..6fe305f843 100644
--- a/activerecord/lib/active_record/schema_dumper.rb
+++ b/activerecord/lib/active_record/schema_dumper.rb
@@ -40,6 +40,10 @@ module ActiveRecord
def header(stream)
define_params = @version ? ":version => #{@version}" : ""
+ if stream.respond_to?(:external_encoding)
+ stream.puts "# encoding: #{stream.external_encoding.name}"
+ end
+
stream.puts <<HEADER
# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
diff --git a/activerecord/test/cases/attribute_methods_test.rb b/activerecord/test/cases/attribute_methods_test.rb
index b0896fb236..dbf5a1ba76 100644
--- a/activerecord/test/cases/attribute_methods_test.rb
+++ b/activerecord/test/cases/attribute_methods_test.rb
@@ -113,6 +113,7 @@ class AttributeMethodsTest < ActiveRecord::TestCase
# by inspecting it.
def test_allocated_object_can_be_inspected
topic = Topic.allocate
+ topic.instance_eval { @attributes = nil }
assert_nothing_raised { topic.inspect }
assert topic.inspect, "#<Topic not initialized>"
end
diff --git a/activerecord/test/cases/schema_dumper_test.rb b/activerecord/test/cases/schema_dumper_test.rb
index 4adecf8e83..5da3f59a1f 100644
--- a/activerecord/test/cases/schema_dumper_test.rb
+++ b/activerecord/test/cases/schema_dumper_test.rb
@@ -3,11 +3,20 @@ require 'stringio'
class SchemaDumperTest < ActiveRecord::TestCase
+ def setup
+ @stream = StringIO.new
+ end
+
def standard_dump
- stream = StringIO.new
+ @stream = StringIO.new
ActiveRecord::SchemaDumper.ignore_tables = []
- ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, stream)
- stream.string
+ ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, @stream)
+ @stream.string
+ end
+
+ def test_magic_comment
+ skip "only test magic comments on 1.9" if RUBY_VERSION < '1.9'
+ assert_match "# encoding: #{@stream.external_encoding.name}", standard_dump
end
def test_schema_dump
diff --git a/activesupport/lib/active_support/cache.rb b/activesupport/lib/active_support/cache.rb
index ac88c82709..2d2264e58a 100644
--- a/activesupport/lib/active_support/cache.rb
+++ b/activesupport/lib/active_support/cache.rb
@@ -557,15 +557,14 @@ module ActiveSupport
@expires_in = options[:expires_in]
@expires_in = @expires_in.to_f if @expires_in
@created_at = Time.now.to_f
- if defined?(value)
+ if value.nil?
+ @value = nil
+ else
+ @value = Marshal.dump(value)
if should_compress?(value, options)
- @value = Zlib::Deflate.deflate(Marshal.dump(value))
+ @value = Zlib::Deflate.deflate(@value)
@compressed = true
- else
- @value = value
end
- else
- @value = nil
end
end
@@ -576,12 +575,8 @@ module ActiveSupport
# Get the value stored in the cache.
def value
- if defined?(@value)
- val = compressed? ? Marshal.load(Zlib::Inflate.inflate(@value)) : @value
- unless val.frozen?
- val.freeze rescue nil
- end
- val
+ if @value
+ Marshal.load(compressed? ? Zlib::Inflate.inflate(@value) : @value)
end
end
@@ -614,10 +609,8 @@ module ActiveSupport
def size
if @value.nil?
0
- elsif @value.respond_to?(:bytesize)
- @value.bytesize
else
- Marshal.dump(@value).bytesize
+ @value.bytesize
end
end
diff --git a/activesupport/lib/active_support/core_ext/string/output_safety.rb b/activesupport/lib/active_support/core_ext/string/output_safety.rb
index 3bf4edbdef..6d6c4912bb 100644
--- a/activesupport/lib/active_support/core_ext/string/output_safety.rb
+++ b/activesupport/lib/active_support/core_ext/string/output_safety.rb
@@ -86,6 +86,12 @@ module ActiveSupport #:nodoc:
end
end
+ def[](*args)
+ new_safe_buffer = super
+ new_safe_buffer.instance_eval { @dirty = false }
+ new_safe_buffer
+ end
+
def safe_concat(value)
raise SafeConcatError if dirty?
original_concat(value)
diff --git a/activesupport/lib/active_support/dependencies.rb b/activesupport/lib/active_support/dependencies.rb
index 8cd4d15e4c..3f6c93e860 100644
--- a/activesupport/lib/active_support/dependencies.rb
+++ b/activesupport/lib/active_support/dependencies.rb
@@ -478,10 +478,6 @@ module ActiveSupport #:nodoc:
qualified_name = qualified_name_for from_mod, const_name
path_suffix = qualified_name.underscore
- trace = caller.reject {|l| l.starts_with? __FILE__ }
- name_error = NameError.new("uninitialized constant #{qualified_name}")
- name_error.set_backtrace(trace)
-
file_path = search_for_file(path_suffix)
if file_path && ! loaded.include?(File.expand_path(file_path)) # We found a matching file to load
@@ -500,11 +496,12 @@ module ActiveSupport #:nodoc:
return parent.const_missing(const_name)
rescue NameError => e
raise unless e.missing_name? qualified_name_for(parent, const_name)
- raise name_error
end
- else
- raise name_error
end
+
+ raise NameError,
+ "uninitialized constant #{qualified_name}",
+ caller.reject {|l| l.starts_with? __FILE__ }
end
# Remove the constants that have been autoloaded, and those that have been
diff --git a/activesupport/test/caching_test.rb b/activesupport/test/caching_test.rb
index 402c6695aa..dff3d6ef0d 100644
--- a/activesupport/test/caching_test.rb
+++ b/activesupport/test/caching_test.rb
@@ -204,7 +204,7 @@ module CacheStoreBehavior
@cache.write('foo', 'bar', :compress => true)
raw_value = @cache.send(:read_entry, 'foo', {}).raw_value
assert_equal 'bar', @cache.read('foo')
- assert_equal 'bar', raw_value
+ assert_equal 'bar', Marshal.load(raw_value)
end
def test_read_and_write_compressed_large_data
@@ -270,10 +270,12 @@ module CacheStoreBehavior
assert !@cache.exist?('foo')
end
- def test_store_objects_should_be_immutable
+ def test_read_should_return_a_different_object_id_each_time_it_is_called
@cache.write('foo', 'bar')
- assert_raise(ActiveSupport::FrozenObjectError) { @cache.read('foo').gsub!(/.*/, 'baz') }
- assert_equal 'bar', @cache.read('foo')
+ assert_not_equal @cache.read('foo').object_id, @cache.read('foo').object_id
+ value = @cache.read('foo')
+ value << 'bingo'
+ assert_not_equal value, @cache.read('foo')
end
def test_original_store_objects_should_not_be_immutable
@@ -551,7 +553,8 @@ end
class MemoryStoreTest < ActiveSupport::TestCase
def setup
- @cache = ActiveSupport::Cache.lookup_store(:memory_store, :expires_in => 60, :size => 100)
+ @record_size = Marshal.dump("aaaaaaaaaa").bytesize
+ @cache = ActiveSupport::Cache.lookup_store(:memory_store, :expires_in => 60, :size => @record_size * 10)
end
include CacheStoreBehavior
@@ -566,7 +569,7 @@ class MemoryStoreTest < ActiveSupport::TestCase
@cache.write(5, "eeeeeeeeee") && sleep(0.001)
@cache.read(2) && sleep(0.001)
@cache.read(4)
- @cache.prune(30)
+ @cache.prune(@record_size * 3)
assert_equal true, @cache.exist?(5)
assert_equal true, @cache.exist?(4)
assert_equal false, @cache.exist?(3)
@@ -719,7 +722,7 @@ class CacheEntryTest < ActiveSupport::TestCase
def test_non_compress_values
entry = ActiveSupport::Cache::Entry.new("value")
assert_equal "value", entry.value
- assert_equal "value", entry.raw_value
+ assert_equal "value", Marshal.load(entry.raw_value)
assert_equal false, entry.compressed?
end
end
diff --git a/activesupport/test/safe_buffer_test.rb b/activesupport/test/safe_buffer_test.rb
index 7662e9b765..8f77999d25 100644
--- a/activesupport/test/safe_buffer_test.rb
+++ b/activesupport/test/safe_buffer_test.rb
@@ -106,4 +106,10 @@ class SafeBufferTest < ActiveSupport::TestCase
test "should not fail if the returned object is not a string" do
assert_kind_of NilClass, @buffer.slice("chipchop")
end
+
+ test "Should initialize @dirty to false for new instance when sliced" do
+ dirty = @buffer[0,0].send(:dirty?)
+ assert_not_nil dirty
+ assert !dirty
+ end
end