Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fix #preferences lookup not typecasting values [#2 state:resolved]

  • Loading branch information...
commit eeb1b86f5544b12b01f24b55f664256cb5100d9a 1 parent 359df0a
Aaron Pfeifer obrie authored
2  CHANGELOG.rdoc
Source Rendered
... ... @@ -1,5 +1,7 @@
1 1 == master
2 2
  3 +* Fix #preferences lookup not typecasting values
  4 +
3 5 == 0.4.1 / 2010-03-07
4 6
5 7 * Add support for per-group default preferences
5 lib/preferences.rb
@@ -317,7 +317,10 @@ def preferences(group = nil)
317 317 end
318 318 end
319 319
320   - preferences.dup
  320 + preferences.inject({}) do |typed_preferences, (name, value)|
  321 + typed_preferences[name] = value.nil? ? value : preference_definitions[name].type_cast(value)
  322 + typed_preferences
  323 + end
321 324 end
322 325
323 326 # Queries whether or not a value is present for the given preference.
10 test/functional/preferences_test.rb
@@ -968,6 +968,11 @@ def test_should_use_unsaved_changes_over_stored_preferences
968 968 assert_equal e = {'notifications' => false, 'language' => 'English'}, @user.preferences
969 969 end
970 970
  971 + def test_should_typecast_unsaved_changes
  972 + @user.write_preference(:notifications, 'true')
  973 + assert_equal e = {'notifications' => true, 'language' => 'English'}, @user.preferences
  974 + end
  975 +
971 976 def test_should_cache_results
972 977 assert_queries(1) { @user.preferences }
973 978 assert_queries(0) { @user.preferences }
@@ -1019,6 +1024,11 @@ def test_should_merge_stored_preferences_with_unsaved_changes
1019 1024 assert_equal e = {'notifications' => false, 'language' => 'Spanish'}, @user.preferences(:chat)
1020 1025 end
1021 1026
  1027 + def test_should_typecast_unsaved_changes
  1028 + @user.write_preference(:notifications, 'true', :chat)
  1029 + assert_equal e = {'notifications' => true, 'language' => 'English'}, @user.preferences
  1030 + end
  1031 +
1022 1032 def test_should_cache_results
1023 1033 assert_queries(1) { @user.preferences(:chat) }
1024 1034 assert_queries(0) { @user.preferences(:chat) }

0 comments on commit eeb1b86

Please sign in to comment.
Something went wrong with that request. Please try again.