@@ -7,4 +7,12 comments_001: | |||||
7 | comments: my first comment |
|
7 | comments: my first comment | |
8 | created_on: 2006-12-10 18:10:10 +01:00 |
|
8 | created_on: 2006-12-10 18:10:10 +01:00 | |
9 | updated_on: 2006-12-10 18:10:10 +01:00 |
|
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 | No newline at end of file |
|
18 |
@@ -22,7 +22,7 require 'news_controller' | |||||
22 | class NewsController; def rescue_action(e) raise e end; end |
|
22 | class NewsController; def rescue_action(e) raise e end; end | |
23 |
|
23 | |||
24 | class NewsControllerTest < Test::Unit::TestCase |
|
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 | def setup |
|
27 | def setup | |
28 | @controller = NewsController.new |
|
28 | @controller = NewsController.new | |
@@ -46,6 +46,94 class NewsControllerTest < Test::Unit::TestCase | |||||
46 | assert_not_nil assigns(:newss) |
|
46 | assert_not_nil assigns(:newss) | |
47 | end |
|
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 | def test_preview |
|
137 | def test_preview | |
50 | get :preview, :project_id => 1, |
|
138 | get :preview, :project_id => 1, | |
51 | :news => {:title => '', |
|
139 | :news => {:title => '', |
@@ -152,4 +152,12 class TimelogControllerTest < Test::Unit::TestCase | |||||
152 | assert_nil assigns(:from) |
|
152 | assert_nil assigns(:from) | |
153 | assert_nil assigns(:to) |
|
153 | assert_nil assigns(:to) | |
154 | end |
|
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 | end |
|
163 | end |
General Comments 0
You need to be logged in to leave comments.
Login now