]> source.dussan.org Git - redmine.git/commitdiff
Removed the default 0 value for issues foreign keys.
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 17 Feb 2013 10:14:58 +0000 (10:14 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 17 Feb 2013 10:14:58 +0000 (10:14 +0000)
It prevents useless "... where id=0" queries and ensures that *_id attributes default to nil.

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@11417 e93f8b46-1217-0410-a6f0-8f06a7374b81

db/migrate/20130217094251_remove_issues_default_fk_values.rb [new file with mode: 0644]
test/unit/issue_test.rb

diff --git a/db/migrate/20130217094251_remove_issues_default_fk_values.rb b/db/migrate/20130217094251_remove_issues_default_fk_values.rb
new file mode 100644 (file)
index 0000000..9345cf0
--- /dev/null
@@ -0,0 +1,19 @@
+class RemoveIssuesDefaultFkValues < ActiveRecord::Migration
+  def up
+    change_column_default :issues, :tracker_id, nil
+    change_column_default :issues, :project_id, nil
+    change_column_default :issues, :status_id, nil
+    change_column_default :issues, :assigned_to_id, nil
+    change_column_default :issues, :priority_id, nil
+    change_column_default :issues, :author_id, nil
+  end
+
+  def down
+    change_column_default :issues, :tracker_id, 0
+    change_column_default :issues, :project_id, 0
+    change_column_default :issues, :status_id, 0
+    change_column_default :issues, :assigned_to_id, 0
+    change_column_default :issues, :priority_id, 0
+    change_column_default :issues, :author_id, 0
+  end
+end
index 8e3f8bfba69cf705ad6613ba17e02d2c119c0d2b..8f77140d3acf444043d84d132f9b7803b76822ab 100644 (file)
@@ -35,6 +35,19 @@ class IssueTest < ActiveSupport::TestCase
     User.current = nil
   end
 
+  def test_initialize
+    issue = Issue.new
+
+    assert_nil issue.project_id
+    assert_nil issue.tracker_id
+    assert_nil issue.author_id
+    assert_nil issue.assigned_to_id
+    assert_nil issue.category_id
+
+    assert_equal IssueStatus.default, issue.status
+    assert_equal IssuePriority.default, issue.priority
+  end
+
   def test_create
     issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 3,
                       :status_id => 1, :priority => IssuePriority.all.first,