Commit 03d33e497dcbb6979a6cfca726df697b8bbb68fa

Authored by Rodrigo Souto
1 parent 9a98d064

Fixed test: comment.feature

app/views/content_viewer/_comment_form.rhtml
... ... @@ -21,8 +21,6 @@ function submit_comment_form(button) {
21 21 }
22 22 </script>
23 23  
24   -<% focus_on = logged_in? ? 'title' : 'name' %>
25   -
26 24 <% if @comment && @comment.errors.any? && @comment.reply_of_id.blank? %>
27 25 <%= error_messages_for :comment %>
28 26 <script type="text/javascript">jQuery(function() { document.location.href = '#page-comment-form'; });</script>
... ... @@ -32,17 +30,7 @@ function submit_comment_form(button) {
32 30  
33 31 <div class="post_comment_box <%= @form_div %>">
34 32  
35   -<% if display_link %>
36   - <h4 onclick="var d = jQuery(this).parent('.post_comment_box');
37   - if (d.hasClass('closed')) {
38   - d.removeClass('closed');
39   - d.addClass('opened');
40   - d.find('input[name=comment[title]], textarea').val('');
41   - d.find('.comment_form input[name=comment[<%= focus_on %>]]').focus();
42   - }">
43   - <%= content_tag('a', '', :name => 'comment_form') + _('Post a comment') %>
44   - </h4>
45   -<% end %>
  33 + <%= link_to(_('Post a comment'), '#', :class => 'display-comment-form') if display_link %>
46 34  
47 35 <% unless pass_without_comment_captcha? %>
48 36 <div id="recaptcha-container" style="display: none">
... ... @@ -62,8 +50,6 @@ function submit_comment_form(button) {
62 50 <% end %>
63 51  
64 52 <% form_tag( url, { :class => 'comment_form' } ) do %>
65   - <%= hidden_field_tag(:confirm, 'false') %>
66   -
67 53 <%= required_fields_message %>
68 54  
69 55 <% unless logged_in? %>
... ... @@ -84,10 +70,13 @@ function submit_comment_form(button) {
84 70 <%= labelled_form_field(_('Title'), text_field(:comment, :title)) %>
85 71 <%= required labelled_form_field(_('Enter your comment'), text_area(:comment, :body, :rows => 5)) %>
86 72  
  73 + <%= hidden_field_tag(:confirm, 'false') %>
  74 + <%= hidden_field_tag(:view, params[:view])%>
  75 +
87 76 <% button_bar do %>
88 77 <%= submit_button('add', _('Post comment'), :onclick => "submit_comment_form(this); return false") %>
89 78 <% if cancel_triggers_hide %>
90   - <%= button_to_function :cancel, _('Cancel'), "f=jQuery(this).parents('.post_comment_box'); f.removeClass('opened'); f.addClass('closed'); return false" %>
  79 + <%= button :cancel, _('Cancel'), '', :id => 'cancel-comment' %>
91 80 <% else %>
92 81 <%= button('cancel', _('Cancel'), {:action => 'view_page', :profile => profile.identifier, :page => @comment.article.explode_path})%>
93 82 <% end %>
... ... @@ -95,3 +84,5 @@ function submit_comment_form(button) {
95 84 <% end %>
96 85  
97 86 </div><!-- end class="post_comment_box" -->
  87 +
  88 +<%= javascript_include_tag 'comment_form'%>
... ...
app/views/content_viewer/view_page.rhtml
... ... @@ -90,7 +90,7 @@
90 90 <% end %>
91 91  
92 92 <% if @page.accept_comments? && @comments_count > 1 %>
93   - <p class="post-comment-button"><a href="#comment_form" onclick="jQuery('#page-comment-form h4').first().trigger('click')"><%= _('Post a comment') %></a></p>
  93 + <%= link_to(_('Post a comment'), '#', :class => 'display-comment-form') %>
94 94 <% end %>
95 95  
96 96 <ul class="article-comments-list">
... ...
features/comment.feature
... ... @@ -14,19 +14,23 @@ Feature: comment
14 14 | article | author | title | body |
15 15 | article with comment | booking | hi | how are you? |
16 16 | article with comment | booking | hello | i am fine |
  17 + And feature "captcha_for_logged_users" is disabled on environment
  18 + And I am logged in as "booking"
17 19  
18 20 Scenario: not post a comment without javascript
19 21 Given I am on /booking/article-to-comment
20   - And I fill in "Name" with "Joey Ramone"
21   - And I fill in "e-mail" with "joey@ramones.com"
  22 + And I follow "Post a comment"
22 23 And I fill in "Title" with "Hey ho, let's go!"
23 24 And I fill in "Enter your comment" with "Hey ho, let's go!"
24 25 When I press "Post comment"
25 26 Then I should not see "Hey ho, let's go"
26 27  
  28 + # This test requires some way to overcome the captcha with unauthenticated
  29 + # user.
27 30 @selenium-fixme
28 31 Scenario: post a comment while not authenticated
29 32 Given I am on /booking/article-to-comment
  33 + And I follow "Post a comment"
30 34 And I fill in "Name" with "Joey Ramone"
31 35 And I fill in "e-mail" with "joey@ramones.com"
32 36 And I fill in "Title" with "Hey ho, let's go!"
... ... @@ -34,58 +38,57 @@ Feature: comment
34 38 When I press "Post comment"
35 39 Then I should see "Hey ho, let's go"
36 40  
37   - @selenium-fixme
  41 + @selenium
38 42 Scenario: post comment while authenticated
39   - Given I am logged in as "booking"
40   - And I am on /booking/article-to-comment
  43 + Given I am on /booking/article-to-comment
  44 + And I follow "Post a comment"
41 45 And I fill in "Title" with "Hey ho, let's go!"
42 46 And I fill in "Enter your comment" with "Hey ho, let's go!"
43 47 When I press "Post comment"
44 48 Then I should see "Hey ho, let's go"
45 49  
46   - @selenium-fixme
  50 + @selenium
47 51 Scenario: redirect to right place after comment a picture
48 52 Given the following files
49 53 | owner | file | mime |
50 54 | booking | rails.png | image/png |
51   - Given I am logged in as "booking"
52 55 And I am on /booking/rails.png?view=true
  56 + And I follow "Post a comment"
53 57 And I fill in "Title" with "Hey ho, let's go!"
54 58 And I fill in "Enter your comment" with "Hey ho, let's go!"
55 59 When I press "Post comment"
56 60 Then I should be exactly on /booking/rails.png?view=true
57 61  
58   - @selenium-fixme
  62 + @selenium
59 63 Scenario: show error messages when make a blank comment
60   - Given I am logged in as "booking"
61   - And I am on /booking/article-to-comment
  64 + Given I am on /booking/article-to-comment
  65 + And I follow "Post a comment"
62 66 When I press "Post comment"
63   - Then I should see "Title can't be blank"
64   - And I should see "Body can't be blank"
  67 + Then I should see "Body can't be blank"
65 68  
66 69 @selenium-fixme
67 70 Scenario: disable post comment button
68 71 Given I am on /booking/article-to-comment
69   - And I fill in "Name" with "Joey Ramone"
70   - And I fill in "e-mail" with "joey@ramones.com"
  72 + And I follow "Post a comment"
71 73 And I fill in "Title" with "Hey ho, let's go!"
72 74 And I fill in "Enter your comment" with "Hey ho, let's go!"
73 75 When I press "Post comment"
74   - Then the "value.Post comment" button should not be enabled
75   - And I should see "Hey ho, let's go"
  76 +# Implement these steps...
  77 +# Then "Post comment" button should not be enabled
  78 +# And I should see "Hey ho, let's go"
76 79  
77   - @selenium-fixme
  80 + @selenium
78 81 Scenario: render comment form and go to bottom
79 82 Given I am on /booking/article-with-comment
80   - When I follow "Post a comment" within ".post-comment-button"
81   - Then I should see "Enter your comment" within "div#page-comment-form div.post_comment_box.opened"
82   - And I should be exactly on /booking/article-with-comment
83   - And I should be moved to anchor "comment_form"
  83 + When I follow "Post a comment"
  84 + Then I should see "Enter your comment"
  85 + And I should be on /booking/article-with-comment
84 86  
85   - @selenium-fixme
  87 + @selenium
86 88 Scenario: keep comments field filled while trying to do a comment
87 89 Given I am on /booking/article-with-comment
88   - And I fill in "Name" with "Joey Ramone"
  90 + And I follow "Post a comment"
  91 + And I fill in "Title" with "Joey Ramone"
89 92 When I press "Post comment"
90   - Then the "Name" field should contain "Joey Ramone"
91   - And I should see "errors prohibited"
  93 + Then the "Title" field should contain "Joey Ramone"
  94 + And I should see "Body can't be blank"
... ...
features/step_definitions/web_steps.rb
... ... @@ -210,6 +210,16 @@ Then /^(?:|I )should be on (.+)$/ do |page_name|
210 210 end
211 211 end
212 212  
  213 +Then /^(?:|I )should be exactly on (.+)$/ do |page_name|
  214 + uri = URI.parse(current_url)
  215 + path_with_params = "#{uri.path}?#{uri.query}"
  216 + if path_with_params.respond_to? :should
  217 + path_with_params.should == path_to(page_name)
  218 + else
  219 + assert_equal path_to(page_name), path_with_params
  220 + end
  221 +end
  222 +
213 223 Then /^(?:|I )should have the following query string:$/ do |expected_pairs|
214 224 query = URI.parse(current_url).query
215 225 actual_params = query ? CGI.parse(query) : {}
... ...
public/javascripts/comment_form.js 0 → 100644
... ... @@ -0,0 +1,23 @@
  1 +jQuery('.display-comment-form').click(function(){
  2 + toggleBox('.post_comment_box');
  3 + jQuery('.display-comment-form').hide();
  4 + jQuery('form.comment_form input').first().focus();
  5 + return false;
  6 +});
  7 +
  8 +jQuery('#cancel-comment').click(function(){
  9 + toggleBox('.post_comment_box');
  10 + jQuery('.display-comment-form').show();
  11 + return false
  12 +})
  13 +
  14 +function toggleBox(div_selector){
  15 + div = jQuery(div_selector);
  16 + if(div.hasClass('opened')) {
  17 + div.removeClass('opened');
  18 + div.addClass('closed');
  19 + } else {
  20 + div.removeClass('closed');
  21 + div.addClass('opened');
  22 + }
  23 +}
... ...
public/stylesheets/application.css
... ... @@ -1106,8 +1106,7 @@ a.comment-picture {
1106 1106 }
1107 1107 #article .article-comments-list, #article .article-comments-list ul, #article .article-comments-list li {
1108 1108 padding: 0;
1109   - margin: 0;
1110   - margin-bottom: 10px;
  1109 + margin: 25px 0 10px 0;
1111 1110 list-style: none;
1112 1111 }
1113 1112 .article-comment .button-bar {
... ... @@ -1273,20 +1272,24 @@ a.comment-picture {
1273 1272 background: transparent url(../images/loading-small.gif) no-repeat left center;
1274 1273 }
1275 1274  
  1275 +
1276 1276 .post_comment_box {
1277 1277 text-align: center;
1278 1278 padding: 0px 15px 5px 15px;
1279   - margin: 10px auto;
1280 1279 }
1281   -.post-comment-button a, .post_comment_box h4 {
  1280 +
  1281 +#comments_list a.display-comment-form {
1282 1282 padding: 1px 20px;
1283 1283 margin: 0px;
1284 1284 background: #eee;
1285   -}
1286   -.post-comment-button a, .post_comment_box.closed h4 {
1287   - display: inline;
1288 1285 border: 1px solid #888;
1289   - cursor: pointer;
  1286 + text-decoration: none;
  1287 + color: black;
  1288 + font-size: 14px;
  1289 + font-weight: bold;
  1290 + -moz-border-radius: 4px;
  1291 + -webkit-border-radius: 4px;
  1292 + border-radius: 4px;
1290 1293 }
1291 1294 .post_comment_box.opened {
1292 1295 border: 1px solid #888;
... ...