Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

  • Loading branch information...
commit eeb1b86f5544b12b01f24b55f664256cb5100d9a 1 parent 359df0a
@obrie obrie authored
View
2  CHANGELOG.rdoc
@@ -1,5 +1,7 @@
== master
+* Fix #preferences lookup not typecasting values
+
== 0.4.1 / 2010-03-07
* Add support for per-group default preferences
View
5 lib/preferences.rb
@@ -317,7 +317,10 @@ def preferences(group = nil)
end
end
- preferences.dup
+ preferences.inject({}) do |typed_preferences, (name, value)|
+ typed_preferences[name] = value.nil? ? value : preference_definitions[name].type_cast(value)
+ typed_preferences
+ end
end
# Queries whether or not a value is present for the given preference.
View
10 test/functional/preferences_test.rb
@@ -968,6 +968,11 @@ def test_should_use_unsaved_changes_over_stored_preferences
assert_equal e = {'notifications' => false, 'language' => 'English'}, @user.preferences
end
+ def test_should_typecast_unsaved_changes
+ @user.write_preference(:notifications, 'true')
+ assert_equal e = {'notifications' => true, 'language' => 'English'}, @user.preferences
+ end
+
def test_should_cache_results
assert_queries(1) { @user.preferences }
assert_queries(0) { @user.preferences }
@@ -1019,6 +1024,11 @@ def test_should_merge_stored_preferences_with_unsaved_changes
assert_equal e = {'notifications' => false, 'language' => 'Spanish'}, @user.preferences(:chat)
end
+ def test_should_typecast_unsaved_changes
+ @user.write_preference(:notifications, 'true', :chat)
+ assert_equal e = {'notifications' => true, 'language' => 'English'}, @user.preferences
+ end
+
def test_should_cache_results
assert_queries(1) { @user.preferences(:chat) }
assert_queries(0) { @user.preferences(:chat) }
Please sign in to comment.
Something went wrong with that request. Please try again.