]> source.dussan.org Git - redmine.git/commitdiff
Fixed: editing a message may cause sticky attribute to be NULL (#3356).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 14 Jun 2009 09:19:20 +0000 (09:19 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 14 Jun 2009 09:19:20 +0000 (09:19 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2787 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/message.rb
db/migrate/20090614091200_fix_messages_sticky_null.rb [new file with mode: 0644]
test/unit/message_test.rb

index 92bcb1275c6bb4101c42e7b0b769a01b4bbeb06e..f3741328654c49fc5f37e97e40cf040c9c32e7b5 100644 (file)
@@ -66,6 +66,10 @@ class Message < ActiveRecord::Base
     board.reset_counters!
   end
   
+  def sticky=(arg)
+    write_attribute :sticky, (arg == true || arg.to_s == '1' ? 1 : 0)
+  end
+  
   def sticky?
     sticky == 1
   end
diff --git a/db/migrate/20090614091200_fix_messages_sticky_null.rb b/db/migrate/20090614091200_fix_messages_sticky_null.rb
new file mode 100644 (file)
index 0000000..cbe7417
--- /dev/null
@@ -0,0 +1,9 @@
+class FixMessagesStickyNull < ActiveRecord::Migration
+  def self.up
+    Message.update_all('sticky = 0', 'sticky IS NULL')
+  end
+
+  def self.down
+    # nothing to do
+  end
+end
index d88e98bcf7172e7e81490217dab664b23cb2ab26..09857fbc9594075b14cc72976521dc22125bbef8 100644 (file)
@@ -128,4 +128,19 @@ class MessageTest < Test::Unit::TestCase
     author.roles_for_project(message.project).first.remove_permission!(:delete_own_messages)
     assert !message.reload.destroyable_by?(author.reload)
   end
+  
+  def test_set_sticky
+    message = Message.new
+    assert_equal 0, message.sticky
+    message.sticky = nil
+    assert_equal 0, message.sticky
+    message.sticky = false
+    assert_equal 0, message.sticky
+    message.sticky = true
+    assert_equal 1, message.sticky
+    message.sticky = '0'
+    assert_equal 0, message.sticky
+    message.sticky = '1'
+    assert_equal 1, message.sticky
+  end
 end