Commit 763fff1bd6602f39f47784d7204eab131b60db50

Authored by Daniela Feitosa
1 parent bf859260

Conflicts:

app/controllers/public/profile_controller.rb
app/controllers/public/profile_controller.rb
@@ -185,7 +185,9 @@ class ProfileController < PublicController @@ -185,7 +185,9 @@ class ProfileController < PublicController
185 def leave_comment_on_activity 185 def leave_comment_on_activity
186 @comment = Comment.new(params[:comment]) 186 @comment = Comment.new(params[:comment])
187 @comment.author = user 187 @comment.author = user
188 - @activity = ActionTracker::Record.find(params[:comment][:source_id]) 188 + @activity = ActionTracker::Record.find(params[:source_id])
  189 + #FIXME pq n colocar source direto?
  190 + #@comment.source = ActionTracker::Record.find(params[:source_id])
189 @comment.source_type, @comment.source_id = (@activity.target_type == 'Article' ? ['Article', @activity.target_id] : [@activity.class.to_s, @activity.id]) 191 @comment.source_type, @comment.source_id = (@activity.target_type == 'Article' ? ['Article', @activity.target_id] : [@activity.class.to_s, @activity.id])
190 @tab_action = params[:tab_action] 192 @tab_action = params[:tab_action]
191 @message = @comment.save ? _("Comment successfully added.") : _("You can't leave an empty comment.") 193 @message = @comment.save ? _("Comment successfully added.") : _("You can't leave an empty comment.")
app/models/community.rb
@@ -79,4 +79,8 @@ class Community < Organization @@ -79,4 +79,8 @@ class Community < Organization
79 {:title => __('Community Info and settings'), :icon => 'edit-profile-group'} 79 {:title => __('Community Info and settings'), :icon => 'edit-profile-group'}
80 end 80 end
81 81
  82 + def activities
  83 + Scrap.find_by_sql("SELECT id, updated_at, '#{Scrap.to_s}' AS klass FROM #{Scrap.table_name} WHERE scraps.receiver_id = #{self.id} AND scraps.scrap_id IS NULL UNION SELECT id, updated_at, '#{ActionTracker::Record.to_s}' AS klass FROM #{ActionTracker::Record.table_name} WHERE action_tracker.target_id = #{self.id} ORDER BY updated_at DESC")
  84 + end
  85 +
82 end 86 end
app/models/scrap.rb
@@ -11,10 +11,6 @@ class Scrap < ActiveRecord::Base @@ -11,10 +11,6 @@ class Scrap < ActiveRecord::Base
11 11
12 named_scope :not_replies, :conditions => {:scrap_id => nil} 12 named_scope :not_replies, :conditions => {:scrap_id => nil}
13 13
14 -######### COMO OS AMIGOS VÃO SABER Q O AMIGO RECEBEU COMENTÁRIO? ACHO QUE TEM QUE TER AÇÃO  
15 -# track_actions :leave_scrap, :after_create, :keep_params => ['sender.name', 'content', 'receiver.name', 'receiver.url'], :if => Proc.new{|s| s.receiver != s.sender}, :custom_target => :action_tracker_target  
16 -# track_actions :leave_scrap_to_self, :after_create, :keep_params => ['sender.name', 'content'], :if => Proc.new{|s| s.receiver == s.sender}  
17 -  
18 after_create do |scrap| 14 after_create do |scrap|
19 scrap.root.update_attribute('updated_at', DateTime.now) unless scrap.root.nil? 15 scrap.root.update_attribute('updated_at', DateTime.now) unless scrap.root.nil?
20 Scrap::Notifier.deliver_mail(scrap) if scrap.send_notification? 16 Scrap::Notifier.deliver_mail(scrap) if scrap.send_notification?
app/views/profile/_profile_activities_scraps.rhtml
1 <% activities.each do |a| %> 1 <% activities.each do |a| %>
2 <% activity = a.klass.constantize.find(a.id) %> 2 <% activity = a.klass.constantize.find(a.id) %>
3 - <% if activity.kind_of?(ActionTracker::Record) && @profile.person? %> 3 + <% if activity.kind_of?(ActionTracker::Record) %>
4 <%= render :partial => 'profile_activity', :locals => {:activity => activity} %> 4 <%= render :partial => 'profile_activity', :locals => {:activity => activity} %>
5 <% else %> 5 <% else %>
6 <%= render :partial => 'profile_scrap', :locals => {:scrap => activity } %> 6 <%= render :partial => 'profile_scrap', :locals => {:scrap => activity } %>
app/views/profile/_profile_activity.rhtml
@@ -10,18 +10,6 @@ @@ -10,18 +10,6 @@
10 <%= render :partial => 'comment', :collection => activity.comments %> 10 <%= render :partial => 'comment', :collection => activity.comments %>
11 </ul> 11 </ul>
12 12
13 - <div id='profile-wall-reply-<%= activity.id%>' style='display:none;width:auto;'>  
14 - <div id='profile-wall-reply-form-<%= activity.id%>' style='display:none;'>  
15 - <p class='profile-wall-reply'>  
16 - <% form_remote_tag :url => {:controller => 'profile', :action => 'leave_comment_on_activity'}, :update => "profile_activities", :success =>"hide_and_show(['#profile-wall-reply-form-#{activity.id}'],['#profile-wall-reply-response-#{activity.id}'])" do %>  
17 - <%= limited_text_area :comment, :body, 420, "reply_content_#{activity.id}", :cols => 50, :rows => 2 %>  
18 - <%= hidden_field :comment, :source_id, :id => "activity_id_#{activity.id}" %>  
19 - <%= submit_button :add, _('Leave a comment') %>  
20 - <%= button_to_function :cancel, _('Cancel'), "hide_and_show(['#profile-wall-reply-#{activity.id}'],[]);return false" %>  
21 - <% end %>  
22 - </p>  
23 - </div>  
24 - <div id='profile-wall-message-response-<%=activity.id%>' class='profile-wall-message-response'></div>  
25 - </div> 13 + <%= render :partial => 'profile_comment_form', :locals => { :activity => activity } %>
26 14
27 </li> 15 </li>
app/views/profile/_profile_comment_form.rhtml 0 → 100644
@@ -0,0 +1,11 @@ @@ -0,0 +1,11 @@
  1 +<div id='profile-wall-reply-<%= activity.id%>'>
  2 + <div id='profile-wall-reply-form-<%= activity.id%>'>
  3 + <p class='profile-wall-reply'>
  4 + <% form_tag :url => {:controller => 'profile', :action => 'leave_comment_on_activity'}, :update => 'profile_activities' do %>
  5 + <%= text_area :comment, :body, {:id => "reply_content_#{activity.id}", :cols => 50, :rows => 1, :class => 'submit-with-keypress'} %>
  6 + <%= hidden_field_tag :source_id, activity.id, :id => "activity_id_#{activity.id}" %>
  7 + <% end %>
  8 + </p>
  9 + </div>
  10 + <div id='profile-wall-message-response-<%=activity.id%>' class='profile-wall-message-response'></div>
  11 +</div>
config/environments/development.rb
1 # Settings specified here will take precedence over those in config/environment.rb 1 # Settings specified here will take precedence over those in config/environment.rb
2 2
3 -# In the development environment your application's code is reloaded on  
4 -# every request. This slows down response time but is perfect for development  
5 -# since you don't have to restart the webserver when you make code changes.  
6 -config.cache_classes = false 3 +# The production environment is meant for finished, "live" apps.
  4 +# Code is not reloaded between requests
  5 +config.cache_classes = true
7 6
8 -# Log error messages when you accidentally call methods on nil.  
9 -config.whiny_nils = true 7 +# Use a different logger for distributed setups
  8 +# config.logger = SyslogLogger.new
10 9
11 -# Show full error reports and disable caching  
12 -config.action_controller.consider_all_requests_local = true  
13 -config.action_view.debug_rjs = true  
14 -config.action_controller.perform_caching = false 10 +# Full error reports are disabled and caching is turned on
  11 +config.action_controller.consider_all_requests_local = false
  12 +config.action_controller.perform_caching = true
  13 +config.action_view.cache_template_loading = true
15 14
16 -# Don't care if the mailer can't send  
17 -config.action_mailer.raise_delivery_errors = false 15 +# Enable serving of images, stylesheets, and javascripts from an asset server
  16 +# config.action_controller.asset_host = "http://assets.example.com"
  17 +
  18 +# Disable delivery errors, bad email addresses will be ignored
  19 +# config.action_mailer.raise_delivery_errors = false
  20 +
  21 +config.cache_store = :mem_cache_store, "localhost"
features/profile_activities.feature 0 → 100644
@@ -0,0 +1,86 @@ @@ -0,0 +1,86 @@
  1 +Feature: list activities of a profile
  2 + As a visitor
  3 + I want to see the activities of a profile
  4 +
  5 + Background:
  6 + Given the following users
  7 + | login | name |
  8 + | joaosilva | Joao Silva |
  9 + And the following articles
  10 + | owner | name | body |
  11 + | booking | article to comment | first paragraph |
  12 + And the following comments
  13 + | article | author | title | body |
  14 + | article with comment | booking | hi | how are you? |
  15 +
  16 + Scenario: see the activity of a profile
  17 + Given I am logged in as "joaosilva"
  18 + When I go to Jose Silva's homepage
  19 + Then I should see "first paragraph" within ".profile-activity-item"
  20 + And I should see "how are you?" within ".profile-wall-activities-comments"
  21 +
  22 + @selenium
  23 + Scenario: post a comment while not authenticated
  24 + Given I am on /booking/article-to-comment
  25 + And I fill in "Name" with "Joey Ramone"
  26 + And I fill in "e-mail" with "joey@ramones.com"
  27 + And I fill in "Title" with "Hey ho, let's go!"
  28 + And I fill in "Enter your comment" with "Hey ho, let's go!"
  29 + When I press "Post comment"
  30 + Then I should see "Hey ho, let's go"
  31 +
  32 + @selenium
  33 + Scenario: post comment while authenticated
  34 + Given I am logged in as "booking"
  35 + And I am on /booking/article-to-comment
  36 + And I fill in "Title" with "Hey ho, let's go!"
  37 + And I fill in "Enter your comment" with "Hey ho, let's go!"
  38 + When I press "Post comment"
  39 + Then I should see "Hey ho, let's go"
  40 +
  41 + @selenium
  42 + Scenario: redirect to right place after comment a picture
  43 + Given the following files
  44 + | owner | file | mime |
  45 + | booking | rails.png | image/png |
  46 + Given I am logged in as "booking"
  47 + And I am on /booking/rails.png?view=true
  48 + And I fill in "Title" with "Hey ho, let's go!"
  49 + And I fill in "Enter your comment" with "Hey ho, let's go!"
  50 + When I press "Post comment"
  51 + Then I should be exactly on /booking/rails.png?view=true
  52 +
  53 + @selenium
  54 + Scenario: show error messages when make a blank comment
  55 + Given I am logged in as "booking"
  56 + And I am on /booking/article-to-comment
  57 + When I press "Post comment"
  58 + Then I should see "Title can't be blank"
  59 + And I should see "Body can't be blank"
  60 +
  61 + @selenium
  62 + Scenario: disable post comment button
  63 + Given I am on /booking/article-to-comment
  64 + And I fill in "Name" with "Joey Ramone"
  65 + And I fill in "e-mail" with "joey@ramones.com"
  66 + And I fill in "Title" with "Hey ho, let's go!"
  67 + And I fill in "Enter your comment" with "Hey ho, let's go!"
  68 + When I press "Post comment"
  69 + Then the "value.Post comment" button should not be enabled
  70 + And I should see "Hey ho, let's go"
  71 +
  72 + @selenium
  73 + Scenario: render comment form and go to bottom
  74 + Given I am on /booking/article-with-comment
  75 + When I follow "Post a comment" within ".post-comment-button"
  76 + Then I should see "Enter your comment" within "div#page-comment-form div.post_comment_box.opened"
  77 + And I should be exactly on /booking/article-with-comment
  78 + And I should be moved to anchor "comment_form"
  79 +
  80 + @selenium
  81 + Scenario: keep comments field filled while trying to do a comment
  82 + Given I am on /booking/article-with-comment
  83 + And I fill in "Name" with "Joey Ramone"
  84 + When I press "Post comment"
  85 + Then the "Name" field should contain "Joey Ramone"
  86 + And I should see "errors prohibited"
public/javascripts/application.js
@@ -711,3 +711,24 @@ Array.min = function(array) { @@ -711,3 +711,24 @@ Array.min = function(array) {
711 return Math.min.apply(Math, array); 711 return Math.min.apply(Math, array);
712 }; 712 };
713 713
  714 +jQuery(function($){
  715 + $('.submit-with-keypress').live('keydown', function(e) {
  716 + field = this;
  717 + if (e.keyCode == 13) {
  718 + e.preventDefault();
  719 + var form = $(field).closest("form");
  720 + $.ajax({
  721 + url: form.attr("action"),
  722 + data: form.serialize(),
  723 + beforeSend: function() {
  724 + loading_for_button($(field));
  725 + },
  726 + success: function(data) {
  727 + $('#profile_activities').html(data);
  728 + $('.submit-with-keypress').val('');
  729 + }
  730 + });
  731 + return false;
  732 + }
  733 + });
  734 +});