##// END OF EJS Templates
Fixed: default category ignored when adding a document (#2328)....
Jean-Philippe Lang -
r2122:b21b6c365cc1
parent child
Show More
@@ -0,0 +1,37
1 # Redmine - project management software
2 # Copyright (C) 2006-2008 Jean-Philippe Lang
3 #
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
18 require File.dirname(__FILE__) + '/../test_helper'
19
20 class DocumentTest < Test::Unit::TestCase
21 fixtures :projects, :enumerations, :documents
22
23 def test_create
24 doc = Document.new(:project => Project.find(1), :title => 'New document', :category => Enumeration.find_by_name('User documentation'))
25 assert doc.save
26 end
27
28 def test_create_with_default_category
29 # Sets a default category
30 e = Enumeration.find_by_name('Technical documentation')
31 e.update_attributes(:is_default => true)
32
33 doc = Document.new(:project => Project.find(1), :title => 'New document')
34 assert_equal e, doc.category
35 assert doc.save
36 end
37 end
@@ -35,6 +35,7 class DocumentsController < ApplicationController
35 else
35 else
36 @grouped = documents.group_by(&:category)
36 @grouped = documents.group_by(&:category)
37 end
37 end
38 @document = @project.documents.build
38 render :layout => false if request.xhr?
39 render :layout => false if request.xhr?
39 end
40 end
40
41
@@ -28,4 +28,10 class Document < ActiveRecord::Base
28
28
29 validates_presence_of :project, :title, :category
29 validates_presence_of :project, :title, :category
30 validates_length_of :title, :maximum => 60
30 validates_length_of :title, :maximum => 60
31
32 def after_initialize
33 if new_record?
34 self.category ||= Enumeration.default('DCAT')
35 end
36 end
31 end
37 end
@@ -32,10 +32,19 class DocumentsControllerTest < Test::Unit::TestCase
32 end
32 end
33
33
34 def test_index
34 def test_index
35 # Sets a default category
36 e = Enumeration.find_by_name('Technical documentation')
37 e.update_attributes(:is_default => true)
38
35 get :index, :project_id => 'ecookbook'
39 get :index, :project_id => 'ecookbook'
36 assert_response :success
40 assert_response :success
37 assert_template 'index'
41 assert_template 'index'
38 assert_not_nil assigns(:grouped)
42 assert_not_nil assigns(:grouped)
43
44 # Default category selected in the new document form
45 assert_tag :select, :attributes => {:name => 'document[category_id]'},
46 :child => {:tag => 'option', :attributes => {:selected => 'selected'},
47 :content => 'Technical documentation'}
39 end
48 end
40
49
41 def test_new_with_one_attachment
50 def test_new_with_one_attachment
General Comments 0
You need to be logged in to leave comments. Login now