Commit bf97b6955ad026f409b7864ce94baf044d4f2dd7

Authored by JoenioCosta
1 parent b146eb60

ActionItem239: fixing error on make blank comments

git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1616 3f533792-8f58-4932-b0fe-aaf55b0a4547
app/controllers/public/content_viewer_controller.rb
... ... @@ -51,8 +51,10 @@ class ContentViewerController < PublicController
51 51 @comment = Comment.new(params[:comment])
52 52 @comment.author = user if logged_in?
53 53 @comment.article = @page
54   - if @comment.save!
  54 + if @comment.save
55 55 @comment = nil # clear the comment form
  56 + else
  57 + @form_div = 'opened'
56 58 end
57 59 end
58 60  
... ...
app/views/content_viewer/_comment_form.rhtml
... ... @@ -4,16 +4,20 @@
4 4  
5 5 <% focus_on = logged_in? ? 'title' : 'name' %>
6 6  
  7 +<%= error_messages_for :comment %>
  8 +
  9 +<% @form_div ||= 'closed' %>
  10 +
7 11 <div
8   - class="post_comment_box closed"
9   - onclick="f=$(<%= comment_form_id %>); f.style.display='block';
  12 + class="post_comment_box <%= @form_div %>"
  13 + onclick="f=$(<%= comment_form_id %>);
10 14 this.className = this.className.replace(/closed/,'opened');
11 15 f.commit.focus(); f['comment[<%= focus_on %>]'].focus();
12 16 this.onclick=null">
13 17  
14 18 <h4><%= _('Post a comment') %></h4>
15 19  
16   -<% form_tag( {}, { :id => comment_form_id, :style => 'display:none' } ) do %>
  20 +<% form_tag( {}, { :id => comment_form_id } ) do %>
17 21  
18 22 <% unless logged_in? %>
19 23  
... ...
app/views/layouts/application.rhtml
... ... @@ -26,6 +26,9 @@
26 26 stylesheet_import( "controller_"+ @controller.controller_name(), :themed_source => true )
27 27 %>
28 28  
  29 + <%# FIXME: for unknow reason the @import url(.../article.css) above dont work for class .post_comment_box.opened/closed %>
  30 + <%= stylesheet_link_tag 'article' %>
  31 +
29 32 <%# FIXME %>
30 33 <%= stylesheet_link_tag '/designs/templates/default/stylesheets/style.css' %>
31 34 <%= stylesheet_link_tag '/designs/icons/default/style.css' %>
... ...
public/stylesheets/article.css
... ... @@ -48,3 +48,10 @@
48 48 display: none;
49 49 }
50 50  
  51 +.post_comment_box.closed form {
  52 + display: none;
  53 +}
  54 +
  55 +.post_comment_box.opened form {
  56 + display: block;
  57 +}
... ...
test/functional/content_viewer_controller_test.rb
... ... @@ -173,4 +173,18 @@ class ContentViewerControllerTest &lt; Test::Unit::TestCase
173 173 assert_tag :tag => 'input', :attributes => { :type => 'text', :name => @controller.icaptcha_field }
174 174 end
175 175  
  176 + should 'show error messages when make a blank comment' do
  177 + login_as @profile.identifier
  178 + page = profile.articles.create!(:name => 'myarticle', :body => 'the body of the text')
  179 + post :view_page, :profile => @profile.identifier, :page => [ 'myarticle' ], :comment => { :title => '', :body => '' }
  180 + assert_tag :tag => 'div', :attributes => { :class => 'errorExplanation', :id => 'errorExplanation' }
  181 + end
  182 +
  183 + should 'show comment form opened on error' do
  184 + login_as @profile.identifier
  185 + page = profile.articles.create!(:name => 'myarticle', :body => 'the body of the text')
  186 + post :view_page, :profile => @profile.identifier, :page => [ 'myarticle' ], :comment => { :title => '', :body => '' }
  187 + assert_tag :tag => 'div', :attributes => { :class => 'post_comment_box opened' }
  188 + end
  189 +
176 190 end
... ...