##// END OF EJS Templates
Add NewsController and TimelogController tests....
Jean-Philippe Lang -
r1255:1c4bcc5b558e
parent child
Show More
@@ -1,10 +1,18
1 1 # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
2 2 comments_001:
3 3 commented_type: News
4 4 commented_id: 1
5 5 id: 1
6 6 author_id: 1
7 7 comments: my first comment
8 8 created_on: 2006-12-10 18:10:10 +01:00
9 9 updated_on: 2006-12-10 18:10:10 +01:00
10 comments_002:
11 commented_type: News
12 commented_id: 1
13 id: 2
14 author_id: 2
15 comments: This is an other comment
16 created_on: 2006-12-10 18:12:10 +01:00
17 updated_on: 2006-12-10 18:12:10 +01:00
10 18 No newline at end of file
@@ -1,59 +1,147
1 1 # redMine - project management software
2 2 # Copyright (C) 2006-2007 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 require File.dirname(__FILE__) + '/../test_helper'
19 19 require 'news_controller'
20 20
21 21 # Re-raise errors caught by the controller.
22 22 class NewsController; def rescue_action(e) raise e end; end
23 23
24 24 class NewsControllerTest < Test::Unit::TestCase
25 fixtures :projects, :users, :roles, :members, :enabled_modules
25 fixtures :projects, :users, :roles, :members, :enabled_modules, :news, :comments
26 26
27 27 def setup
28 28 @controller = NewsController.new
29 29 @request = ActionController::TestRequest.new
30 30 @response = ActionController::TestResponse.new
31 31 User.current = nil
32 32 end
33 33
34 34 def test_index
35 35 get :index
36 36 assert_response :success
37 37 assert_template 'index'
38 38 assert_not_nil assigns(:newss)
39 39 assert_nil assigns(:project)
40 40 end
41 41
42 42 def test_index_with_project
43 43 get :index, :project_id => 1
44 44 assert_response :success
45 45 assert_template 'index'
46 46 assert_not_nil assigns(:newss)
47 47 end
48 48
49 def test_show
50 get :show, :id => 1
51 assert_response :success
52 assert_template 'show'
53 assert_tag :tag => 'h2', :content => /eCookbook first release/
54 end
55
56 def test_show_not_found
57 get :show, :id => 999
58 assert_response 404
59 end
60
61 def test_get_new
62 @request.session[:user_id] = 2
63 get :new, :project_id => 1
64 assert_response :success
65 assert_template 'new'
66 end
67
68 def test_post_new
69 @request.session[:user_id] = 2
70 post :new, :project_id => 1, :news => { :title => 'NewsControllerTest',
71 :description => 'This is the description',
72 :summary => '' }
73 assert_redirected_to 'projects/ecookbook/news'
74
75 news = News.find_by_title('NewsControllerTest')
76 assert_not_nil news
77 assert_equal 'This is the description', news.description
78 assert_equal User.find(2), news.author
79 assert_equal Project.find(1), news.project
80 end
81
82 def test_get_edit
83 @request.session[:user_id] = 2
84 get :edit, :id => 1
85 assert_response :success
86 assert_template 'edit'
87 end
88
89 def test_post_edit
90 @request.session[:user_id] = 2
91 post :edit, :id => 1, :news => { :description => 'Description changed by test_post_edit' }
92 assert_redirected_to 'news/show/1'
93 news = News.find(1)
94 assert_equal 'Description changed by test_post_edit', news.description
95 end
96
97 def test_post_new_with_validation_failure
98 @request.session[:user_id] = 2
99 post :new, :project_id => 1, :news => { :title => '',
100 :description => 'This is the description',
101 :summary => '' }
102 assert_response :success
103 assert_template 'new'
104 assert_not_nil assigns(:news)
105 assert assigns(:news).new_record?
106 assert_tag :tag => 'div', :attributes => { :id => 'errorExplanation' },
107 :content => /1 error/
108 end
109
110 def test_add_comment
111 @request.session[:user_id] = 2
112 post :add_comment, :id => 1, :comment => { :comments => 'This is a NewsControllerTest comment' }
113 assert_redirected_to 'news/show/1'
114
115 comment = News.find(1).comments.find(:first, :order => 'created_on DESC')
116 assert_not_nil comment
117 assert_equal 'This is a NewsControllerTest comment', comment.comments
118 assert_equal User.find(2), comment.author
119 end
120
121 def test_destroy_comment
122 comments_count = News.find(1).comments.size
123 @request.session[:user_id] = 2
124 post :destroy_comment, :id => 1, :comment_id => 2
125 assert_redirected_to 'news/show/1'
126 assert_nil Comment.find_by_id(2)
127 assert_equal comments_count - 1, News.find(1).comments.size
128 end
129
130 def test_destroy
131 @request.session[:user_id] = 2
132 post :destroy, :id => 1
133 assert_redirected_to 'projects/ecookbook/news'
134 assert_nil News.find_by_id(1)
135 end
136
49 137 def test_preview
50 138 get :preview, :project_id => 1,
51 139 :news => {:title => '',
52 140 :description => 'News description',
53 141 :summary => ''}
54 142 assert_response :success
55 143 assert_template 'common/_preview'
56 144 assert_tag :tag => 'fieldset', :attributes => { :class => 'preview' },
57 145 :content => /News description/
58 146 end
59 147 end
@@ -1,155 +1,163
1 1 # redMine - project management software
2 2 # Copyright (C) 2006-2007 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 require File.dirname(__FILE__) + '/../test_helper'
19 19 require 'timelog_controller'
20 20
21 21 # Re-raise errors caught by the controller.
22 22 class TimelogController; def rescue_action(e) raise e end; end
23 23
24 24 class TimelogControllerTest < Test::Unit::TestCase
25 25 fixtures :projects, :roles, :members, :issues, :time_entries, :users, :trackers, :enumerations, :issue_statuses
26 26
27 27 def setup
28 28 @controller = TimelogController.new
29 29 @request = ActionController::TestRequest.new
30 30 @response = ActionController::TestResponse.new
31 31 end
32 32
33 33 def test_create
34 34 @request.session[:user_id] = 3
35 35 post :edit, :project_id => 1,
36 36 :time_entry => {:comments => 'Some work on TimelogControllerTest',
37 37 :activity_id => '10',
38 38 :spent_on => '2008-03-14',
39 39 :issue_id => '1',
40 40 :hours => '7.3'}
41 41 assert_redirected_to 'projects/ecookbook/timelog/details'
42 42
43 43 i = Issue.find(1)
44 44 t = TimeEntry.find_by_comments('Some work on TimelogControllerTest')
45 45 assert_not_nil t
46 46 assert_equal 7.3, t.hours
47 47 assert_equal 3, t.user_id
48 48 assert_equal i, t.issue
49 49 assert_equal i.project, t.project
50 50 end
51 51
52 52 def test_update
53 53 entry = TimeEntry.find(1)
54 54 assert_equal 1, entry.issue_id
55 55 assert_equal 2, entry.user_id
56 56
57 57 @request.session[:user_id] = 1
58 58 post :edit, :id => 1,
59 59 :time_entry => {:issue_id => '2',
60 60 :hours => '8'}
61 61 assert_redirected_to 'projects/ecookbook/timelog/details'
62 62 entry.reload
63 63
64 64 assert_equal 8, entry.hours
65 65 assert_equal 2, entry.issue_id
66 66 assert_equal 2, entry.user_id
67 67 end
68 68
69 69 def destroy
70 70 @request.session[:user_id] = 2
71 71 post :destroy, :id => 1
72 72 assert_redirected_to 'projects/ecookbook/timelog/details'
73 73 assert_nil TimeEntry.find_by_id(1)
74 74 end
75 75
76 76 def test_report_no_criteria
77 77 get :report, :project_id => 1
78 78 assert_response :success
79 79 assert_template 'report'
80 80 end
81 81
82 82 def test_report_one_criteria
83 83 get :report, :project_id => 1, :period => 'week', :date_from => "2007-04-01", :date_to => "2007-04-30", :criterias => ['project']
84 84 assert_response :success
85 85 assert_template 'report'
86 86 assert_not_nil assigns(:total_hours)
87 87 assert_equal "8.65", "%.2f" % assigns(:total_hours)
88 88 end
89 89
90 90 def test_report_two_criterias
91 91 get :report, :project_id => 1, :period => 'month', :date_from => "2007-01-01", :date_to => "2007-12-31", :criterias => ["member", "activity"]
92 92 assert_response :success
93 93 assert_template 'report'
94 94 assert_not_nil assigns(:total_hours)
95 95 assert_equal "162.90", "%.2f" % assigns(:total_hours)
96 96 end
97 97
98 98 def test_report_one_criteria_no_result
99 99 get :report, :project_id => 1, :period => 'week', :date_from => "1998-04-01", :date_to => "1998-04-30", :criterias => ['project']
100 100 assert_response :success
101 101 assert_template 'report'
102 102 assert_not_nil assigns(:total_hours)
103 103 assert_equal "0.00", "%.2f" % assigns(:total_hours)
104 104 end
105 105
106 106 def test_details_at_project_level
107 107 get :details, :project_id => 1
108 108 assert_response :success
109 109 assert_template 'details'
110 110 assert_not_nil assigns(:entries)
111 111 assert_equal 4, assigns(:entries).size
112 112 # project and subproject
113 113 assert_equal [1, 3], assigns(:entries).collect(&:project_id).uniq.sort
114 114 assert_not_nil assigns(:total_hours)
115 115 assert_equal "162.90", "%.2f" % assigns(:total_hours)
116 116 # display all time by default
117 117 assert_nil assigns(:from)
118 118 assert_nil assigns(:to)
119 119 end
120 120
121 121 def test_details_at_project_level_with_date_range
122 122 get :details, :project_id => 1, :from => '2007-03-20', :to => '2007-04-30'
123 123 assert_response :success
124 124 assert_template 'details'
125 125 assert_not_nil assigns(:entries)
126 126 assert_equal 3, assigns(:entries).size
127 127 assert_not_nil assigns(:total_hours)
128 128 assert_equal "12.90", "%.2f" % assigns(:total_hours)
129 129 assert_equal '2007-03-20'.to_date, assigns(:from)
130 130 assert_equal '2007-04-30'.to_date, assigns(:to)
131 131 end
132 132
133 133 def test_details_at_project_level_with_period
134 134 get :details, :project_id => 1, :period => '7_days'
135 135 assert_response :success
136 136 assert_template 'details'
137 137 assert_not_nil assigns(:entries)
138 138 assert_not_nil assigns(:total_hours)
139 139 assert_equal Date.today - 7, assigns(:from)
140 140 assert_equal Date.today, assigns(:to)
141 141 end
142 142
143 143 def test_details_at_issue_level
144 144 get :details, :issue_id => 1
145 145 assert_response :success
146 146 assert_template 'details'
147 147 assert_not_nil assigns(:entries)
148 148 assert_equal 2, assigns(:entries).size
149 149 assert_not_nil assigns(:total_hours)
150 150 assert_equal 154.25, assigns(:total_hours)
151 151 # display all time by default
152 152 assert_nil assigns(:from)
153 153 assert_nil assigns(:to)
154 154 end
155
156 def test_details_csv_export
157 get :details, :project_id => 1, :format => 'csv'
158 assert_response :success
159 assert_equal 'text/csv', @response.content_type
160 assert @response.body.include?("Date,User,Activity,Project,Issue,Tracker,Subject,Hours,Comment\n")
161 assert @response.body.include?("\n04/21/2007,redMine Admin,Design,eCookbook,2,Feature request,Add ingredients categories,1.0,\"\"\n")
162 end
155 163 end
General Comments 0
You need to be logged in to leave comments. Login now