Commit bf97b6955ad026f409b7864ce94baf044d4f2dd7
1 parent
b146eb60
Exists in
staging
and in
42 other branches
ActionItem239: fixing error on make blank comments
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1616 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
5 changed files
with
34 additions
and
4 deletions
Show diff stats
app/controllers/public/content_viewer_controller.rb
@@ -51,8 +51,10 @@ class ContentViewerController < PublicController | @@ -51,8 +51,10 @@ class ContentViewerController < PublicController | ||
51 | @comment = Comment.new(params[:comment]) | 51 | @comment = Comment.new(params[:comment]) |
52 | @comment.author = user if logged_in? | 52 | @comment.author = user if logged_in? |
53 | @comment.article = @page | 53 | @comment.article = @page |
54 | - if @comment.save! | 54 | + if @comment.save |
55 | @comment = nil # clear the comment form | 55 | @comment = nil # clear the comment form |
56 | + else | ||
57 | + @form_div = 'opened' | ||
56 | end | 58 | end |
57 | end | 59 | end |
58 | 60 |
app/views/content_viewer/_comment_form.rhtml
@@ -4,16 +4,20 @@ | @@ -4,16 +4,20 @@ | ||
4 | 4 | ||
5 | <% focus_on = logged_in? ? 'title' : 'name' %> | 5 | <% focus_on = logged_in? ? 'title' : 'name' %> |
6 | 6 | ||
7 | +<%= error_messages_for :comment %> | ||
8 | + | ||
9 | +<% @form_div ||= 'closed' %> | ||
10 | + | ||
7 | <div | 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 | this.className = this.className.replace(/closed/,'opened'); | 14 | this.className = this.className.replace(/closed/,'opened'); |
11 | f.commit.focus(); f['comment[<%= focus_on %>]'].focus(); | 15 | f.commit.focus(); f['comment[<%= focus_on %>]'].focus(); |
12 | this.onclick=null"> | 16 | this.onclick=null"> |
13 | 17 | ||
14 | <h4><%= _('Post a comment') %></h4> | 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 | <% unless logged_in? %> | 22 | <% unless logged_in? %> |
19 | 23 |
app/views/layouts/application.rhtml
@@ -26,6 +26,9 @@ | @@ -26,6 +26,9 @@ | ||
26 | stylesheet_import( "controller_"+ @controller.controller_name(), :themed_source => true ) | 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 | <%# FIXME %> | 32 | <%# FIXME %> |
30 | <%= stylesheet_link_tag '/designs/templates/default/stylesheets/style.css' %> | 33 | <%= stylesheet_link_tag '/designs/templates/default/stylesheets/style.css' %> |
31 | <%= stylesheet_link_tag '/designs/icons/default/style.css' %> | 34 | <%= stylesheet_link_tag '/designs/icons/default/style.css' %> |
public/stylesheets/article.css
test/functional/content_viewer_controller_test.rb
@@ -173,4 +173,18 @@ class ContentViewerControllerTest < Test::Unit::TestCase | @@ -173,4 +173,18 @@ class ContentViewerControllerTest < Test::Unit::TestCase | ||
173 | assert_tag :tag => 'input', :attributes => { :type => 'text', :name => @controller.icaptcha_field } | 173 | assert_tag :tag => 'input', :attributes => { :type => 'text', :name => @controller.icaptcha_field } |
174 | end | 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 | end | 190 | end |