Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #10769 (new defect)

Opened 8 months ago

Last modified 8 months ago

test_stringify_and_symbolize_keys_on_indifferent_preserves_hash test case bug in ActiveSupport

Reported by: blackanger Assigned to: chuyeow
Priority: normal Milestone: 2.x
Component: ActiveSupport Version: edge
Severity: normal Keywords:
Cc:

Description

Hi Rails Team,

I come from the company named NibiruTech of china ,we found a bug:

I changed as following:

/activesupport/test/core_ext/hash_ext_test.rb

def test_stringify_and_symbolize_keys_on_indifferent_preserves_hash

h = HashWithIndifferentAccess.new

h[:first] = 1

# h.stringify_keys!

assert_equal 1, hfirst?

h = HashWithIndifferentAccess.new

hfirst? = 1

# h.symbolize_keys!

assert_equal 1, h[:first]

end

when i rake test , all test be passed. in other words,your this test don't have cover the two methods : symbolize_keys! and stringify_keys!

it should be:

def test_stringify_and_symbolize_keys_on_indifferent_preserves_hash

h = HashWithIndifferentAccess.new

h[:first] = 1

h.stringify_keys!

assert_equal 1, hfirst?

h.each_key {|k| assert_not_equal k,:first}

h = HashWithIndifferentAccess.new

hfirst? = 1

h.symbolize_keys!

assert_equal 1, h[:first]

h.each_key {|k| assert_not_equal k,:first}

end

this line be added: h.each_key {|k| assert_not_equal k,:first}

Change History

01/12/08 06:32:03 changed by blackanger

  • type changed from defect to task.

01/14/08 06:54:08 changed by blackanger

sorry , It should be :

def test_stringify_and_symbolize_keys_on_indifferent_preserves_hash

h = HashWithIndifferentAccess.new h[:first] = 1 h.stringify_keys! assert_equal 1, h[:first] h = HashWithIndifferentAccess.new hfirst? = 1 h.symbolize_keys! assert_equal 1, hfirst?

end

01/14/08 06:56:42 changed by blackanger

sorry , It should be :

def test_stringify_and_symbolize_keys_on_indifferent_preserves_hash

h = HashWithIndifferentAccess.new

h[:first] = 1

h.stringify_keys!

assert_equal 1, h[:first]

h = HashWithIndifferentAccess.new

hfirst? = 1

h.symbolize_keys!

assert_equal 1, hfirst?

end

01/14/08 06:58:08 changed by blackanger

sorry , It should be :

def test_stringify_and_symbolize_keys_on_indifferent_preserves_hash

h = HashWithIndifferentAccess.new

h[:first] = 1

h.stringify_keys!

assert_equal 1, h[:first]

h = HashWithIndifferentAccess.new

h [ 'first' ] = 1

h.symbolize_keys!

assert_equal 1, h[ 'first' ]

end

01/14/08 07:53:55 changed by chuyeow

  • type changed from task to defect.
  • severity changed from major to normal.

You can use surround your code with {{{ (and 3 closing '}') to get your code formatted.

Anyway, you've come upon a bug that exposes a possible problem with HashWithIndifferentAccess - the current implementation converts everything to string keys internally. I'll see if I can make it behave a little less idiosyncratically (as the test suggests). Thanks for the report.

01/14/08 08:22:32 changed by blackanger

oh,I see ,thank you.