From fb25bab7dd0ac761702d23ff60decbca9d03dd56 Mon Sep 17 00:00:00 2001 From: hukl Date: Sun, 29 Mar 2009 00:00:47 +0100 Subject: Added unit test to verify the basic functionality of the find_with_outdated_translations method. Found and fixed some issued on the way. [ x ] Testing rocks --- app/models/page.rb | 6 +++--- test/unit/page_test.rb | 24 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/app/models/page.rb b/app/models/page.rb index 107ceb9..5f0d389 100644 --- a/app/models/page.rb +++ b/app/models/page.rb @@ -72,7 +72,7 @@ class Page < ActiveRecord::Base end end - def self.find_outdated_translations options = {} + def self.find_with_outdated_translations options = {} defaults_options = { :include => :globalize_translations } @@ -145,8 +145,8 @@ class Page < ActiveRecord::Base if translations.size > 1 && default && custom time = default.updated_at - custom.updated_at - difference = (time/24/3600).to_i.abs - if 1 < difference + difference = (time/3600).to_i.abs + if 23 < difference return true else return false diff --git a/test/unit/page_test.rb b/test/unit/page_test.rb index 77c6243..04a7ba5 100644 --- a/test/unit/page_test.rb +++ b/test/unit/page_test.rb @@ -105,4 +105,28 @@ class PageTest < ActiveSupport::TestCase assert_equal after, d.body end + + def test_find_with_outdated_translations + Node.delete_all + Page.delete_all + I18n.locale = :de + + assert_not_nil page = Page.create!( :title => "Hallo" ) + page.reload + assert_equal 2, page.globalize_translations.size + assert_equal [], Page.find_with_outdated_translations + + I18n.locale = :en + page.title = "Hello" + page.save + + assert_equal 3, page.globalize_translations.size + assert_equal 0, Page.find_with_outdated_translations.count + + english = *page.globalize_translations.select {|x| x.locale == :en} + PageTranslation.record_timestamps = false + english.update_attributes(:updated_at => (Time.now+25.hours)) + PageTranslation.record_timestamps = true + assert_equal 1, Page.find_with_outdated_translations.count + end end -- cgit v1.3