summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/models/page.rb6
-rw-r--r--test/unit/page_test.rb24
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
72 end 72 end
73 end 73 end
74 74
75 def self.find_outdated_translations options = {} 75 def self.find_with_outdated_translations options = {}
76 defaults_options = { 76 defaults_options = {
77 :include => :globalize_translations 77 :include => :globalize_translations
78 } 78 }
@@ -145,8 +145,8 @@ class Page < ActiveRecord::Base
145 145
146 if translations.size > 1 && default && custom 146 if translations.size > 1 && default && custom
147 time = default.updated_at - custom.updated_at 147 time = default.updated_at - custom.updated_at
148 difference = (time/24/3600).to_i.abs 148 difference = (time/3600).to_i.abs
149 if 1 < difference 149 if 23 < difference
150 return true 150 return true
151 else 151 else
152 return false 152 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
105 105
106 assert_equal after, d.body 106 assert_equal after, d.body
107 end 107 end
108
109 def test_find_with_outdated_translations
110 Node.delete_all
111 Page.delete_all
112 I18n.locale = :de
113
114 assert_not_nil page = Page.create!( :title => "Hallo" )
115 page.reload
116 assert_equal 2, page.globalize_translations.size
117 assert_equal [], Page.find_with_outdated_translations
118
119 I18n.locale = :en
120 page.title = "Hello"
121 page.save
122
123 assert_equal 3, page.globalize_translations.size
124 assert_equal 0, Page.find_with_outdated_translations.count
125
126 english = *page.globalize_translations.select {|x| x.locale == :en}
127 PageTranslation.record_timestamps = false
128 english.update_attributes(:updated_at => (Time.now+25.hours))
129 PageTranslation.record_timestamps = true
130 assert_equal 1, Page.find_with_outdated_translations.count
131 end
108end 132end