set_blank_decriptions_to_nil.patch

Marius BALTEANU, 2017-02-18 20:17

Download (2.06 KB)

View differences:

app/models/issue.rb
407 407
    if arg.is_a?(String)
408 408
      arg = arg.gsub(/(\r\n|\n|\r)/, "\r\n")
409 409
    end
410
    write_attribute(:description, arg)
410
    write_attribute(:description, arg.blank? ? nil : arg)
411 411
  end
412 412

  
413 413
  def deleted_attachment_ids
db/migrate/20170218185644_migrate_blank_description_to_nil.rb
1
class MigrateBlankDescriptionToNil < ActiveRecord::Migration
2
  def up
3
    Issue.where(:description => '').update_all(:description => nil)
4
  end
5

  
6
  def down
7
    Issue.where(:description => nil).update_all(:description => '')
8
  end
9
end
test/unit/issue_test.rb
79 79
    assert_save issue
80 80
  end
81 81

  
82
  def test_create_with_blank_description_should_set_description_to_nil
83
    issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 3, :subject => 'test_create', :description => '')
84
    assert issue.save
85

  
86
    assert issue.description.nil?
87
  end
88

  
82 89
  def test_start_date_format_should_be_validated
83 90
    set_language_if_valid 'en'
84 91
    ['2012', 'ABC', '2012-15-20'].each do |invalid_date|
......
354 361
        :subject => 'Assignment test',
355 362
        :assigned_to => group,
356 363
        :is_private => true)
357
  
364

  
358 365
      Role.find(2).update! :issues_visibility => 'default'
359 366
      issues = Issue.visible(User.find(8)).to_a
360 367
      assert issues.any?
361 368
      assert issues.include?(issue)
362
  
369

  
363 370
      Role.find(2).update! :issues_visibility => 'own'
364 371
      issues = Issue.visible(User.find(8)).to_a
365 372
      assert issues.any?