Permalink
Browse files

Merge pull request #115 from evendis/assign_nil_issue

Correctly handle nil assignments
  • Loading branch information...
parndt committed Mar 23, 2012
2 parents 2bb990a + 7ef3bca commit 811e37b261eefd7bb980a617e88c887cea685389
Showing with 20 additions and 1 deletion.
  1. +1 −1 lib/globalize/active_record/adapter.rb
  2. +19 −0 test/globalize3/dirty_tracking_test.rb
@@ -21,7 +21,7 @@ def fetch_stash(locale, name)
def fetch(locale, name)
Globalize.fallbacks(locale).each do |fallback|
- value = fetch_stash(fallback, name) || fetch_attribute(fallback, name)
+ value = stash.contains?(fallback, name) ? fetch_stash(fallback, name) : fetch_attribute(fallback, name)
unless fallbacks_for?(value)
set_metadata(value, :locale => fallback, :requested_locale => locale)
@@ -58,4 +58,23 @@ class DirtyTrackingTest < Test::Unit::TestCase
assert_equal ['content'], child.changed
end
+
+ test 'dirty tracking works for blank assignment' do
+ post = Post.create(:title => 'title', :content => 'content')
+ assert_equal [], post.changed
+
+ post.title = ''
+ assert_equal({ 'title' => ['title', ''] }, post.changes)
+ post.save
+ end
+
+ test 'dirty tracking works for nil assignment' do
+ post = Post.create(:title => 'title', :content => 'content')
+ assert_equal [], post.changed
+
+ post.title = nil
+ assert_equal({ 'title' => ['title', nil] }, post.changes)
+ post.save
+ end
+
end

0 comments on commit 811e37b

Please sign in to comment.