diff --git a/app/controllers/public/profile_controller.rb b/app/controllers/public/profile_controller.rb index ba00e6b..8e2b061 100644 --- a/app/controllers/public/profile_controller.rb +++ b/app/controllers/public/profile_controller.rb @@ -185,7 +185,9 @@ class ProfileController < PublicController def leave_comment_on_activity @comment = Comment.new(params[:comment]) @comment.author = user - @activity = ActionTracker::Record.find(params[:comment][:source_id]) + @activity = ActionTracker::Record.find(params[:source_id]) + #FIXME pq n colocar source direto? + #@comment.source = ActionTracker::Record.find(params[:source_id]) @comment.source_type, @comment.source_id = (@activity.target_type == 'Article' ? ['Article', @activity.target_id] : [@activity.class.to_s, @activity.id]) @tab_action = params[:tab_action] @message = @comment.save ? _("Comment successfully added.") : _("You can't leave an empty comment.") diff --git a/app/models/community.rb b/app/models/community.rb index cb028b7..bd4cfdf 100644 --- a/app/models/community.rb +++ b/app/models/community.rb @@ -79,4 +79,8 @@ class Community < Organization {:title => __('Community Info and settings'), :icon => 'edit-profile-group'} end + def activities + 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") + end + end diff --git a/app/models/scrap.rb b/app/models/scrap.rb index fb0a5db..a3673a2 100644 --- a/app/models/scrap.rb +++ b/app/models/scrap.rb @@ -11,10 +11,6 @@ class Scrap < ActiveRecord::Base named_scope :not_replies, :conditions => {:scrap_id => nil} -######### COMO OS AMIGOS VÃO SABER Q O AMIGO RECEBEU COMENTÁRIO? ACHO QUE TEM QUE TER AÇÃO -# 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 -# track_actions :leave_scrap_to_self, :after_create, :keep_params => ['sender.name', 'content'], :if => Proc.new{|s| s.receiver == s.sender} - after_create do |scrap| scrap.root.update_attribute('updated_at', DateTime.now) unless scrap.root.nil? Scrap::Notifier.deliver_mail(scrap) if scrap.send_notification? diff --git a/app/views/profile/_profile_activities_scraps.rhtml b/app/views/profile/_profile_activities_scraps.rhtml index 66601ba..6d491df 100644 --- a/app/views/profile/_profile_activities_scraps.rhtml +++ b/app/views/profile/_profile_activities_scraps.rhtml @@ -1,6 +1,6 @@ <% activities.each do |a| %> <% activity = a.klass.constantize.find(a.id) %> - <% if activity.kind_of?(ActionTracker::Record) && @profile.person? %> + <% if activity.kind_of?(ActionTracker::Record) %> <%= render :partial => 'profile_activity', :locals => {:activity => activity} %> <% else %> <%= render :partial => 'profile_scrap', :locals => {:scrap => activity } %> diff --git a/app/views/profile/_profile_activity.rhtml b/app/views/profile/_profile_activity.rhtml index 0637f50..034ab32 100644 --- a/app/views/profile/_profile_activity.rhtml +++ b/app/views/profile/_profile_activity.rhtml @@ -10,18 +10,6 @@ <%= render :partial => 'comment', :collection => activity.comments %> - + <%= render :partial => 'profile_comment_form', :locals => { :activity => activity } %> diff --git a/app/views/profile/_profile_comment_form.rhtml b/app/views/profile/_profile_comment_form.rhtml new file mode 100644 index 0000000..1ee10b8 --- /dev/null +++ b/app/views/profile/_profile_comment_form.rhtml @@ -0,0 +1,11 @@ +
+
+

+ <% form_tag :url => {:controller => 'profile', :action => 'leave_comment_on_activity'}, :update => 'profile_activities' do %> + <%= text_area :comment, :body, {:id => "reply_content_#{activity.id}", :cols => 50, :rows => 1, :class => 'submit-with-keypress'} %> + <%= hidden_field_tag :source_id, activity.id, :id => "activity_id_#{activity.id}" %> + <% end %> +

+
+
+
diff --git a/config/environments/development.rb b/config/environments/development.rb index d67452f..0c45bc1 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -1,17 +1,21 @@ # Settings specified here will take precedence over those in config/environment.rb -# In the development environment your application's code is reloaded on -# every request. This slows down response time but is perfect for development -# since you don't have to restart the webserver when you make code changes. -config.cache_classes = false +# The production environment is meant for finished, "live" apps. +# Code is not reloaded between requests +config.cache_classes = true -# Log error messages when you accidentally call methods on nil. -config.whiny_nils = true +# Use a different logger for distributed setups +# config.logger = SyslogLogger.new -# Show full error reports and disable caching -config.action_controller.consider_all_requests_local = true -config.action_view.debug_rjs = true -config.action_controller.perform_caching = false +# Full error reports are disabled and caching is turned on +config.action_controller.consider_all_requests_local = false +config.action_controller.perform_caching = true +config.action_view.cache_template_loading = true -# Don't care if the mailer can't send -config.action_mailer.raise_delivery_errors = false +# Enable serving of images, stylesheets, and javascripts from an asset server +# config.action_controller.asset_host = "http://assets.example.com" + +# Disable delivery errors, bad email addresses will be ignored +# config.action_mailer.raise_delivery_errors = false + +config.cache_store = :mem_cache_store, "localhost" diff --git a/features/profile_activities.feature b/features/profile_activities.feature new file mode 100644 index 0000000..c2ffc4d --- /dev/null +++ b/features/profile_activities.feature @@ -0,0 +1,86 @@ +Feature: list activities of a profile + As a visitor + I want to see the activities of a profile + + Background: + Given the following users + | login | name | + | joaosilva | Joao Silva | + And the following articles + | owner | name | body | + | booking | article to comment | first paragraph | + And the following comments + | article | author | title | body | + | article with comment | booking | hi | how are you? | + + Scenario: see the activity of a profile + Given I am logged in as "joaosilva" + When I go to Jose Silva's homepage + Then I should see "first paragraph" within ".profile-activity-item" + And I should see "how are you?" within ".profile-wall-activities-comments" + + @selenium + Scenario: post a comment while not authenticated + Given I am on /booking/article-to-comment + And I fill in "Name" with "Joey Ramone" + And I fill in "e-mail" with "joey@ramones.com" + And I fill in "Title" with "Hey ho, let's go!" + And I fill in "Enter your comment" with "Hey ho, let's go!" + When I press "Post comment" + Then I should see "Hey ho, let's go" + + @selenium + Scenario: post comment while authenticated + Given I am logged in as "booking" + And I am on /booking/article-to-comment + And I fill in "Title" with "Hey ho, let's go!" + And I fill in "Enter your comment" with "Hey ho, let's go!" + When I press "Post comment" + Then I should see "Hey ho, let's go" + + @selenium + Scenario: redirect to right place after comment a picture + Given the following files + | owner | file | mime | + | booking | rails.png | image/png | + Given I am logged in as "booking" + And I am on /booking/rails.png?view=true + And I fill in "Title" with "Hey ho, let's go!" + And I fill in "Enter your comment" with "Hey ho, let's go!" + When I press "Post comment" + Then I should be exactly on /booking/rails.png?view=true + + @selenium + Scenario: show error messages when make a blank comment + Given I am logged in as "booking" + And I am on /booking/article-to-comment + When I press "Post comment" + Then I should see "Title can't be blank" + And I should see "Body can't be blank" + + @selenium + Scenario: disable post comment button + Given I am on /booking/article-to-comment + And I fill in "Name" with "Joey Ramone" + And I fill in "e-mail" with "joey@ramones.com" + And I fill in "Title" with "Hey ho, let's go!" + And I fill in "Enter your comment" with "Hey ho, let's go!" + When I press "Post comment" + Then the "value.Post comment" button should not be enabled + And I should see "Hey ho, let's go" + + @selenium + Scenario: render comment form and go to bottom + Given I am on /booking/article-with-comment + When I follow "Post a comment" within ".post-comment-button" + Then I should see "Enter your comment" within "div#page-comment-form div.post_comment_box.opened" + And I should be exactly on /booking/article-with-comment + And I should be moved to anchor "comment_form" + + @selenium + Scenario: keep comments field filled while trying to do a comment + Given I am on /booking/article-with-comment + And I fill in "Name" with "Joey Ramone" + When I press "Post comment" + Then the "Name" field should contain "Joey Ramone" + And I should see "errors prohibited" diff --git a/public/javascripts/application.js b/public/javascripts/application.js index 68a6d19..e436cd4 100644 --- a/public/javascripts/application.js +++ b/public/javascripts/application.js @@ -711,3 +711,24 @@ Array.min = function(array) { return Math.min.apply(Math, array); }; +jQuery(function($){ + $('.submit-with-keypress').live('keydown', function(e) { + field = this; + if (e.keyCode == 13) { + e.preventDefault(); + var form = $(field).closest("form"); + $.ajax({ + url: form.attr("action"), + data: form.serialize(), + beforeSend: function() { + loading_for_button($(field)); + }, + success: function(data) { + $('#profile_activities').html(data); + $('.submit-with-keypress').val(''); + } + }); + return false; + } + }); +}); -- libgit2 0.21.2