Skip to content

Commit

Permalink
Merge branch '3-0-stable' into 3-0-9
Browse files Browse the repository at this point in the history
* 3-0-stable:
  Add support for using an ARCONFIG environment variable to specify the location of the config.yml file for running the tests
  Define ActiveSupport#to_param as to_str - closes rails#1663
  Revert "Make sure that we don't perform in-place mutation on SafeBuffer string"
  Make sure that we don't perform in-place mutation on SafeBuffer string
  Update CHANGELOG to mention the json_escape change
  Ensure number helpers can handle HTML safe strings - closes rails#1597.
  ensuring that json_escape returns html safe strings when passed an html safe string
  Fix issue rails#1598 by adding a dependency to the RDoc gem.
  Make sure `escape_javascript` return `SafeBuffer` if the incoming argument is already html_safe

Conflicts:
	actionpack/CHANGELOG
  • Loading branch information
tenderlove committed Jun 12, 2011
2 parents 66ec7e8 + 968816a commit d5e28c3
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 9 deletions.
2 changes: 2 additions & 0 deletions actionpack/CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
*Rails 3.0.9 (unreleased)*

* json_escape will now return a SafeBuffer string if it receives SafeBuffer string [tenderlove]

* Make sure escape_js returns SafeBuffer string if it receives SafeBuffer string [Prem Sichanugrist]

* Fix text helpers to work correctly with the new SafeBuffer restriction [Paul Gallagher, Arun Agrawal, Prem Sichanugrist]
Expand Down
2 changes: 1 addition & 1 deletion actionpack/lib/action_view/helpers/number_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ def number_with_delimiter(number, options = {})
defaults = I18n.translate(:'number.format', :locale => options[:locale], :default => {})
options = options.reverse_merge(defaults)

parts = number.to_s.split('.')
parts = number.to_s.to_str.split('.')
parts[0].gsub!(/(\d)(?=(\d\d\d)+(?!\d))/, "\\1#{options[:delimiter]}")
parts.join(options[:separator]).html_safe

Expand Down
7 changes: 7 additions & 0 deletions actionpack/test/template/number_helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -280,32 +280,39 @@ def test_number_helpers_outputs_are_html_safe
assert number_to_human(1).html_safe?
assert !number_to_human("<script></script>").html_safe?
assert number_to_human("asdf".html_safe).html_safe?
assert number_to_human("1".html_safe).html_safe?

assert number_to_human_size(1).html_safe?
assert number_to_human_size(1000000).html_safe?
assert !number_to_human_size("<script></script>").html_safe?
assert number_to_human_size("asdf".html_safe).html_safe?
assert number_to_human_size("1".html_safe).html_safe?

assert number_with_precision(1, :strip_insignificant_zeros => false).html_safe?
assert number_with_precision(1, :strip_insignificant_zeros => true).html_safe?
assert !number_with_precision("<script></script>").html_safe?
assert number_with_precision("asdf".html_safe).html_safe?
assert number_with_precision("1".html_safe).html_safe?

assert number_to_currency(1).html_safe?
assert !number_to_currency("<script></script>").html_safe?
assert number_to_currency("asdf".html_safe).html_safe?
assert number_to_currency("1".html_safe).html_safe?

assert number_to_percentage(1).html_safe?
assert !number_to_percentage("<script></script>").html_safe?
assert number_to_percentage("asdf".html_safe).html_safe?
assert number_to_percentage("1".html_safe).html_safe?

assert number_to_phone(1).html_safe?
assert !number_to_phone("<script></script>").html_safe?
assert number_to_phone("asdf".html_safe).html_safe?
assert number_to_phone("1".html_safe).html_safe?

assert number_with_delimiter(1).html_safe?
assert !number_with_delimiter("<script></script>").html_safe?
assert number_with_delimiter("asdf".html_safe).html_safe?
assert number_with_delimiter("1".html_safe).html_safe?
end

def test_number_helpers_should_raise_error_if_invalid_when_specified
Expand Down
8 changes: 8 additions & 0 deletions actionpack/test/template/url_helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class UrlHelperTest < ActiveSupport::TestCase
routes.draw do
match "/" => "foo#bar"
match "/other" => "foo#other"
match "/article/:id" => "foo#article", :as => :article
end

include routes.url_helpers
Expand Down Expand Up @@ -261,6 +262,13 @@ def test_link_tag_using_block_in_erb
assert_equal '<a href="/">Example site</a>', out
end

def test_link_tag_with_html_safe_string
assert_dom_equal(
"<a href=\"/article/Gerd_M%C3%BCller\">Gerd Müller</a>",
link_to("Gerd Müller", article_path("Gerd_Müller".html_safe))
)
end

def test_link_to_unless
assert_equal "Showing", link_to_unless(true, "Showing", url_hash)

Expand Down
22 changes: 18 additions & 4 deletions activerecord/RUNNING_UNIT_TESTS
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,31 @@ You can build postgres and mysql databases using the build_postgresql and build_

You can run a particular test file from the command line, e.g.

$ ruby test/cases/base_test.rb
$ ruby -Itest test/cases/base_test.rb

To run a specific test:

$ ruby test/cases/base_test.rb -n test_something_works
$ ruby -Itest test/cases/base_test.rb -n test_something_works

You can run with a database other than the default you set in test/config.yml, using the ARCONN
environment variable:

$ ARCONN=postgresql ruby test/cases/base_test.rb
$ ARCONN=postgresql ruby -Itest test/cases/base_test.rb

You can run all the tests for a given database via rake:

$ rake test_postgresql
$ rake test_mysql

The 'rake test' task will run all the tests for mysql, mysql2, sqlite3 and postgresql.

== Identity Map

By default the tests run with the Identity Map turned off. But all tests should pass whether or
not the identity map is on or off. You can turn it on using the IM env variable:

$ IM=true ruby -Itest test/case/base_test.rb

== Config file

By default, the config file is expected to be at the path test/config.yml. You can specify a
custom location with the ARCONFIG environment variable.
11 changes: 7 additions & 4 deletions activerecord/test/support/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@ def config

private

def config_file
Pathname.new(ENV['ARCONFIG'] || TEST_ROOT + '/config.yml')
end

def read_config
unless File.exist?(TEST_ROOT + '/config.yml')
FileUtils.cp TEST_ROOT + '/config.example.yml', TEST_ROOT + '/config.yml'
unless config_file.exist?
FileUtils.cp TEST_ROOT + '/config.example.yml', config_file
end

raw = File.read(TEST_ROOT + '/config.yml')
erb = Erubis::Eruby.new(raw)
erb = Erubis::Eruby.new(config_file.read)
expand_config(YAML.parse(erb.result(binding)).transform)
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ def to_s
self
end

def to_param
to_str
end

def to_yaml(*args)
to_str.to_yaml(*args)
end
Expand Down
6 changes: 6 additions & 0 deletions activesupport/test/core_ext/string_ext_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,12 @@ def to_s
assert !'ruby'.encoding_aware?
end
end

test "call to_param returns a normal string" do
string = @string.html_safe
assert string.html_safe?
assert !string.to_param.html_safe?
end
end

class StringExcludeTest < ActiveSupport::TestCase
Expand Down

0 comments on commit d5e28c3

Please sign in to comment.