Mercurial > hg > soundsoftware-site
comparison test/functional/news_controller_test.rb @ 22:40f7cfd4df19
* Update to SVN trunk rev 4173
author | Chris Cannam <chris.cannam@soundsoftware.ac.uk> |
---|---|
date | Fri, 24 Sep 2010 14:06:04 +0100 |
parents | 513646585e45 |
children | 94944d00e43c |
comparison
equal
deleted
inserted
replaced
14:1d32c0a0efbf | 22:40f7cfd4df19 |
---|---|
63 get :new, :project_id => 1 | 63 get :new, :project_id => 1 |
64 assert_response :success | 64 assert_response :success |
65 assert_template 'new' | 65 assert_template 'new' |
66 end | 66 end |
67 | 67 |
68 def test_post_new | 68 def test_post_create |
69 ActionMailer::Base.deliveries.clear | 69 ActionMailer::Base.deliveries.clear |
70 Setting.notified_events << 'news_added' | 70 Setting.notified_events << 'news_added' |
71 | 71 |
72 @request.session[:user_id] = 2 | 72 @request.session[:user_id] = 2 |
73 post :new, :project_id => 1, :news => { :title => 'NewsControllerTest', | 73 post :create, :project_id => 1, :news => { :title => 'NewsControllerTest', |
74 :description => 'This is the description', | 74 :description => 'This is the description', |
75 :summary => '' } | 75 :summary => '' } |
76 assert_redirected_to 'projects/ecookbook/news' | 76 assert_redirected_to 'projects/ecookbook/news' |
77 | 77 |
78 news = News.find_by_title('NewsControllerTest') | 78 news = News.find_by_title('NewsControllerTest') |
88 get :edit, :id => 1 | 88 get :edit, :id => 1 |
89 assert_response :success | 89 assert_response :success |
90 assert_template 'edit' | 90 assert_template 'edit' |
91 end | 91 end |
92 | 92 |
93 def test_post_edit | 93 def test_put_update |
94 @request.session[:user_id] = 2 | 94 @request.session[:user_id] = 2 |
95 post :edit, :id => 1, :news => { :description => 'Description changed by test_post_edit' } | 95 put :update, :id => 1, :news => { :description => 'Description changed by test_post_edit' } |
96 assert_redirected_to 'news/1' | 96 assert_redirected_to 'news/1' |
97 news = News.find(1) | 97 news = News.find(1) |
98 assert_equal 'Description changed by test_post_edit', news.description | 98 assert_equal 'Description changed by test_post_edit', news.description |
99 end | 99 end |
100 | 100 |
101 def test_post_new_with_validation_failure | 101 def test_post_create_with_validation_failure |
102 @request.session[:user_id] = 2 | 102 @request.session[:user_id] = 2 |
103 post :new, :project_id => 1, :news => { :title => '', | 103 post :create, :project_id => 1, :news => { :title => '', |
104 :description => 'This is the description', | 104 :description => 'This is the description', |
105 :summary => '' } | 105 :summary => '' } |
106 assert_response :success | 106 assert_response :success |
107 assert_template 'new' | 107 assert_template 'new' |
108 assert_not_nil assigns(:news) | 108 assert_not_nil assigns(:news) |
109 assert assigns(:news).new_record? | 109 assert assigns(:news).new_record? |
110 assert_tag :tag => 'div', :attributes => { :id => 'errorExplanation' }, | 110 assert_tag :tag => 'div', :attributes => { :id => 'errorExplanation' }, |
111 :content => /1 error/ | 111 :content => /1 error/ |
112 end | |
113 | |
114 def test_add_comment | |
115 @request.session[:user_id] = 2 | |
116 post :add_comment, :id => 1, :comment => { :comments => 'This is a NewsControllerTest comment' } | |
117 assert_redirected_to 'news/1' | |
118 | |
119 comment = News.find(1).comments.find(:first, :order => 'created_on DESC') | |
120 assert_not_nil comment | |
121 assert_equal 'This is a NewsControllerTest comment', comment.comments | |
122 assert_equal User.find(2), comment.author | |
123 end | |
124 | |
125 def test_empty_comment_should_not_be_added | |
126 @request.session[:user_id] = 2 | |
127 assert_no_difference 'Comment.count' do | |
128 post :add_comment, :id => 1, :comment => { :comments => '' } | |
129 assert_response :success | |
130 assert_template 'show' | |
131 end | |
132 end | |
133 | |
134 def test_destroy_comment | |
135 comments_count = News.find(1).comments.size | |
136 @request.session[:user_id] = 2 | |
137 post :destroy_comment, :id => 1, :comment_id => 2 | |
138 assert_redirected_to 'news/1' | |
139 assert_nil Comment.find_by_id(2) | |
140 assert_equal comments_count - 1, News.find(1).comments.size | |
141 end | 112 end |
142 | 113 |
143 def test_destroy | 114 def test_destroy |
144 @request.session[:user_id] = 2 | 115 @request.session[:user_id] = 2 |
145 post :destroy, :id => 1 | 116 post :destroy, :id => 1 |