Commit 23d32ba1d58f96ecb3b92da4b5f371e93cad9dca
1 parent
f31c657e
Exists in
master
and in
28 other branches
Some fixes
Showing
14 changed files
with
128 additions
and
117 deletions
Show diff stats
app/controllers/public/profile_controller.rb
... | ... | @@ -3,17 +3,14 @@ class ProfileController < PublicController |
3 | 3 | needs_profile |
4 | 4 | before_filter :check_access_to_profile, :except => [:join, :join_not_logged, :index, :add] |
5 | 5 | before_filter :store_location, :only => [:join, :join_not_logged, :report_abuse] |
6 | - before_filter :login_required, :only => [:add, :join, :join_not_logged, :leave, :unblock, :leave_scrap, :remove_scrap, :remove_activity, :view_more_scraps, :view_more_activities, :view_more_network_activities, :report_abuse, :register_report] | |
6 | + before_filter :login_required, :only => [:add, :join, :join_not_logged, :leave, :unblock, :leave_scrap, :remove_scrap, :remove_activity, :view_more_scraps, :view_more_activities, :view_more_network_activities, :report_abuse, :register_report, :leave_comment_on_activity] | |
7 | 7 | |
8 | 8 | helper TagsHelper |
9 | 9 | |
10 | 10 | def index |
11 | - @activities = @profile.tracked_actions.paginate(:per_page => 30, :page => params[:page]) | |
12 | - @wall_items = [] | |
13 | 11 | @network_activities = !@profile.is_a?(Person) ? @profile.tracked_notifications.paginate(:per_page => 30, :page => params[:page]) : [] |
14 | 12 | if logged_in? && current_person.follows?(@profile) |
15 | 13 | @network_activities = @profile.tracked_notifications.paginate(:per_page => 30, :page => params[:page]) if @network_activities.empty? |
16 | - @wall_items = @profile.scraps_received.not_replies.paginate(:per_page => 30, :page => params[:page]) | |
17 | 14 | @activities = @profile.activities.paginate(:per_page => 30, :page => params[:page]) |
18 | 15 | end |
19 | 16 | @tags = profile.article_tags |
... | ... | @@ -187,7 +184,7 @@ class ProfileController < PublicController |
187 | 184 | |
188 | 185 | def leave_comment_on_activity |
189 | 186 | @comment = Comment.new(params[:comment]) |
190 | - @comment.author = user #'if logged_in? | |
187 | + @comment.author = user | |
191 | 188 | @comment.source = ActionTracker::Record.find(params[:comment][:source_id]) |
192 | 189 | @tab_action = params[:tab_action] |
193 | 190 | @message = @comment.save ? _("Comment successfully added.") : _("You can't leave an empty comment.") |
... | ... | @@ -201,7 +198,6 @@ class ProfileController < PublicController |
201 | 198 | end |
202 | 199 | |
203 | 200 | def view_more_activities |
204 | -# @activities = @profile.tracked_actions.paginate(:per_page => 30, :page => params[:page]) | |
205 | 201 | @activities = @profile.activities.paginate(:per_page => 30, :page => params[:page]) |
206 | 202 | render :partial => 'profile_activities_scraps', :locals => {:activities => @activities} |
207 | 203 | end | ... | ... |
app/models/action_tracker_notification.rb
... | ... | @@ -11,4 +11,3 @@ class ActionTrackerNotification < ActiveRecord::Base |
11 | 11 | end |
12 | 12 | |
13 | 13 | ActionTracker::Record.has_many :action_tracker_notifications, :class_name => 'ActionTrackerNotification', :foreign_key => 'action_tracker_id', :dependent => :destroy |
14 | -ActionTracker::Record.has_many :comments, :class_name => 'Comment', :foreign_key => 'source_id', :dependent => :destroy, :order => 'created_at asc' | ... | ... |
app/models/article.rb
... | ... | @@ -2,7 +2,7 @@ require 'hpricot' |
2 | 2 | |
3 | 3 | class Article < ActiveRecord::Base |
4 | 4 | |
5 | - track_actions :create_article, :after_create, :keep_params => [:name, :url, :lead], :if => Proc.new { |a| a.is_trackable? && !a.image? }, :custom_target => :action_tracker_target | |
5 | + track_actions :create_article, :after_create, :keep_params => [:name, :url, :lead, :id], :if => Proc.new { |a| a.is_trackable? && !a.image? }, :custom_target => :action_tracker_target | |
6 | 6 | |
7 | 7 | # xss_terminate plugin can't sanitize array fields |
8 | 8 | before_save :sanitize_tag_list |
... | ... | @@ -15,7 +15,7 @@ class Article < ActiveRecord::Base |
15 | 15 | |
16 | 16 | belongs_to :last_changed_by, :class_name => 'Person', :foreign_key => 'last_changed_by_id' |
17 | 17 | |
18 | - has_many :comments, :dependent => :destroy, :order => 'created_at asc', :as => :source | |
18 | + has_many :comments, :class_name => 'Comment', :foreign_key => 'source_id', :dependent => :destroy, :order => 'created_at asc' | |
19 | 19 | |
20 | 20 | has_many :article_categorizations, :conditions => [ 'articles_categories.virtual = ?', false ] |
21 | 21 | has_many :categories, :through => :article_categorizations |
... | ... | @@ -133,7 +133,10 @@ class Article < ActiveRecord::Base |
133 | 133 | article.advertise = true |
134 | 134 | end |
135 | 135 | |
136 | - after_update do |article| | |
136 | + after_update :update_creation_activity | |
137 | + def update_creation_activity | |
138 | + a = ActionTracker::Record.all.select {|a| a.verb == 'create_article' && a.target == article.profile} | |
139 | + a.first.touch | |
137 | 140 | #update article's activity |
138 | 141 | end |
139 | 142 | ... | ... |
app/models/comment.rb
1 | 1 | class Comment < ActiveRecord::Base |
2 | 2 | |
3 | -# track_actions :leave_comment, :after_create, :keep_params => ["article.title", "article.url", "title", "url", "body"], :custom_target => :action_tracker_target | |
4 | - | |
5 | 3 | validates_presence_of :body |
6 | 4 | |
7 | - belongs_to :source, :foreign_key => :source_id, :counter_cache => true, :polymorphic => true | |
5 | + belongs_to :source, :counter_cache => true, :polymorphic => true | |
8 | 6 | alias :article :source |
9 | 7 | alias :article= :source= |
10 | 8 | ... | ... |
app/views/profile/_comment.rhtml
... | ... | @@ -3,14 +3,14 @@ |
3 | 3 | |
4 | 4 | <div class="comment-content comment-logged-in"> |
5 | 5 | |
6 | - <%# if comment.author %> | |
7 | - <%= link_to image_tag(profile_icon(comment.author, :minor)) + | |
8 | - content_tag('span', comment.author_name, :class => 'comment-info'), | |
9 | - comment.author.url, | |
6 | + <% if Person.find(comment.author_id) %> | |
7 | + <%= link_to image_tag(profile_icon(Person.find(comment.author_id), :minor)) + | |
8 | + content_tag('span', Person.find(comment.author_id).name, :class => 'comment-info'), | |
9 | + Person.find(comment.author_id).url, | |
10 | 10 | :class => 'comment-picture', |
11 | - :title => comment.author_name | |
11 | + :title => Person.find(comment.author_id).name | |
12 | 12 | %> |
13 | - <%# end %> | |
13 | + <% end %> | |
14 | 14 | |
15 | 15 | <div class="comment-details"> |
16 | 16 | <h4><%= comment.title %></h4> |
... | ... | @@ -23,11 +23,11 @@ |
23 | 23 | </div> |
24 | 24 | </div> |
25 | 25 | |
26 | - <%# if logged_in? && (user == profile || user == comment.author || user.has_permission?(:moderate_comments, profile)) %> | |
26 | + <% if logged_in? && (user == profile || user == Person.find(comment.author_id) || user.has_permission?(:moderate_comments, profile)) %> | |
27 | 27 | <% button_bar(:style => 'float: right; margin-top: 0px;') do %> |
28 | - <%= icon_button(:delete, _('Remove this comment and all its replies'), { :profile => params[:profile], :remove_comment => comment.id, :view => params[:view] }, :method => :post, :confirm => _('Are you sure you want to remove this comment and all its replies?')) %> | |
28 | + <%= icon_button(:delete, _('Remove'), { :profile => params[:profile], :remove_comment => comment.id, :view => params[:view] }, :method => :post, :confirm => _('Are you sure you want to remove this comment and all its replies?')) %> | |
29 | 29 | <% end %> |
30 | - <%# end %> | |
30 | + <% end %> | |
31 | 31 | |
32 | 32 | <div class="comment_reply post_comment_box closed"> |
33 | 33 | <% if @comment && @comment.errors.any? && @comment.reply_of_id.to_i == comment.id %> |
... | ... | @@ -39,7 +39,7 @@ |
39 | 39 | }); |
40 | 40 | </script> |
41 | 41 | <% end %> |
42 | - <%= report_abuse(comment.author, :comment_link, comment) if comment.author %> | |
42 | + <%= report_abuse(Person.find(comment.author_id), :comment_link, comment) if Person.find(comment.author_id) %> | |
43 | 43 | <%= link_to_function _('Reply'), |
44 | 44 | "var f = add_comment_reply_form(this, %s); f.find('input[name=comment[title]], textarea').val(''); return false" % comment.id, |
45 | 45 | :class => 'comment-footer comment-footer-link comment-footer-hide', |
... | ... | @@ -49,7 +49,7 @@ |
49 | 49 | |
50 | 50 | </div> |
51 | 51 | |
52 | - <% unless comment.replies.blank? %> | |
52 | + <% unless Comment.find(comment.id).replies.blank? %> | |
53 | 53 | <ul class="comment-replies"> |
54 | 54 | <% comment.replies.each do |reply| %> |
55 | 55 | <%= render :partial => 'comment', :locals => { :comment => reply } %> | ... | ... |
app/views/profile/_profile.rhtml
... | ... | @@ -18,7 +18,6 @@ |
18 | 18 | <% tabs << {:title => _('Network'), :id => 'profile-network', :content => (render :partial => 'profile_network')} %> |
19 | 19 | <% end %> |
20 | 20 | |
21 | - <% tabs << {:title => _('Activity'), :id => 'profile-activity', :content => (render :partial => 'profile_activity')} %> | |
22 | 21 | <% tabs << {:title => _('Profile'), :id => 'person-profile', :content => (render :partial => 'person_profile')} %> |
23 | 22 | <% end %> |
24 | 23 | ... | ... |
app/views/profile/_profile_activities.rhtml
... | ... | @@ -1,28 +0,0 @@ |
1 | -<li class='profile-activity-item <%= activity.verb %>' id='profile-activity-item-<%= activity.id %>'> | |
2 | - <%= render :partial => activity.verb, :locals => { :activity => activity }%> | |
3 | - <hr /> | |
4 | - | |
5 | - <%# if logged_in? && current_person.follows?(activity.sender) && activity.root.nil? %> | |
6 | - <span class='profile-wall-send-reply'><%= link_to_function _('Comment'), "hide_and_show(['#profile-wall-reply-response-#{activity.id}'],['#profile-wall-reply-#{activity.id}', '#profile-wall-reply-form-#{activity.id}']);$('reply_content_#{activity.id}').value='';$('activity_id_#{activity.id}').value='#{activity.id}';return false", :class => "profile-send-reply" %></span> | |
7 | - <%# end %> | |
8 | - | |
9 | - <ul class="profile-wall-activities-comments" style='padding-left: 50px;width:auto'> | |
10 | - <%= render :partial => 'comment', :collection => activity.comments %> | |
11 | - </ul> | |
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 | - <%= hidden_field :comment, :author_id, :value => user.id %> | |
20 | - <%= submit_button :add, _('Leave a comment') %> | |
21 | - <%= button_to_function :cancel, _('Cancel'), "hide_and_show(['#profile-wall-reply-#{activity.id}'],[]);return false" %> | |
22 | - <% end %> | |
23 | - </p> | |
24 | - </div> | |
25 | - <div id='profile-wall-message-response-<%=activity.id%>' class='profile-wall-message-response'></div> | |
26 | - </div> | |
27 | - | |
28 | -</li> |
app/views/profile/_profile_activities_scraps.rhtml
1 | 1 | <% activities.each do |a| %> |
2 | 2 | <% activity = a.klass.constantize.find(a.id) %> |
3 | 3 | <% if activity.kind_of?(ActionTracker::Record) && @profile.person? %> |
4 | - <%= render :partial => 'profile_activities', :locals => {:activity => activity} %> | |
4 | + <%= render :partial => 'profile_activity', :locals => {:activity => activity} %> | |
5 | 5 | <% else %> |
6 | 6 | <%= render :partial => 'profile_scrap', :locals => {:scrap => activity } %> |
7 | 7 | <% end %> | ... | ... |
app/views/profile/_profile_activity.rhtml
1 | -<div id='profile-activity'> | |
2 | - <h3><%= _("%s's activity") % @profile.name %></h3> | |
3 | - <ul> | |
4 | - <%= render :partial => 'profile_activities_scraps', :locals => {:activities => @activities} %> | |
1 | +<li class='profile-activity-item <%= activity.verb %>' id='profile-activity-item-<%= activity.id %>'> | |
2 | + <%= render :partial => activity.verb, :locals => { :activity => activity }%> | |
3 | + <hr /> | |
4 | + | |
5 | + <% if logged_in? && current_person.follows?(activity.user) %> | |
6 | + <span class='profile-wall-send-reply'><%= link_to_function _('Comment'), "hide_and_show(['#profile-wall-reply-response-#{activity.id}'],['#profile-wall-reply-#{activity.id}', '#profile-wall-reply-form-#{activity.id}']);$('reply_content_#{activity.id}').value='';$('activity_id_#{activity.id}').value='#{activity.id}';return false", :class => "profile-send-reply" %></span> | |
7 | + <% end %> | |
8 | + | |
9 | + <ul class="profile-wall-activities-comments" style='padding-left: 50px;width:auto'> | |
10 | + <%= render :partial => 'comment', :collection => activity.comments %> | |
5 | 11 | </ul> |
6 | -</div> | |
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> | |
26 | + | |
27 | +</li> | ... | ... |
app/views/profile/_profile_wall.rhtml
... | ... | @@ -16,13 +16,3 @@ |
16 | 16 | <%= button_to_remote :add, _('View more'), :url => {:action => 'view_more_activities', :page => (@activities.current_page + 1)}, :update => "profile_activities_page_#{@activities.current_page}" %> |
17 | 17 | </div> |
18 | 18 | <% end %> |
19 | - | |
20 | -<!-- | |
21 | -<ul id='profile_scraps'> | |
22 | - <%#= render :partial => 'profile_scraps', :locals => {:scraps => @wall_items} %> | |
23 | -</ul> | |
24 | - | |
25 | -<% if @profile.person? %> | |
26 | - <%#= render :partial => 'profile_activity' %> | |
27 | -<% end %> | |
28 | ---> | ... | ... |
config/initializers/action_tracker.rb
... | ... | @@ -8,11 +8,6 @@ ActionTrackerConfig.verbs = { |
8 | 8 | :description => lambda { _('published an article: %{title}') % { :title => '{{link_to(truncate(ta.get_name), ta.get_url)}}' } } |
9 | 9 | }, |
10 | 10 | |
11 | - :remove_article => { | |
12 | - :description => lambda { n_('removed 1 article: %{title}', 'removed %{num} articles: %{title}', get_name.size) % { :num => get_name.size, :title => '{{ta.get_name.collect{ |n| truncate(n) }.to_sentence(:connector => "%s")}}' % _("and") } }, | |
13 | - :type => :groupable | |
14 | - }, | |
15 | - | |
16 | 11 | :new_friendship => { |
17 | 12 | :description => lambda { n_('has made 1 new friend:<br />%{name}', 'has made %{num} new friends:<br />%{name}', get_friend_name.size) % { :num => get_friend_name.size, :name => '{{ta.collect_group_with_index(:friend_name){ |n,i| link_to(image_tag(ta.get_friend_profile_custom_icon[i] || default_or_themed_icon("/images/icons-app/person-icon.png")), ta.get_friend_url[i], :title => n)}.join}}' } }, |
18 | 13 | :type => :groupable |
... | ... | @@ -27,24 +22,11 @@ ActionTrackerConfig.verbs = { |
27 | 22 | :description => lambda { _('has joined the community.') }, |
28 | 23 | }, |
29 | 24 | |
30 | - :remove_member_in_community => { | |
31 | - :description => lambda { _('has left the community.') }, | |
32 | - }, | |
33 | - | |
34 | - :leave_community => { | |
35 | - :description => lambda { n_('has left 1 community:<br />%{name}', 'has left %{num} communities:<br />%{name}', get_resource_name.size) % { :num => get_resource_name.size, :name => '{{ta.collect_group_with_index(:resource_name){ |n,i| link_to(image_tag(ta.get_resource_profile_custom_icon[i] || default_or_themed_icon("/images/icons-app/community-icon.png")), ta.get_resource_url[i], :title => n)}.join}}' } }, | |
36 | - :type => :groupable | |
37 | - }, | |
38 | - | |
39 | 25 | :upload_image => { |
40 | 26 | :description => lambda { n_('uploaded 1 image:<br />%{thumbnails}<br />%{details}', 'uploaded %{num} images:<br />%{thumbnails}<br />%{details}', get_view_url.size) % { :num => get_view_url.size, :thumbnails => '{{ta.collect_group_with_index(:thumbnail_path){ |t,i| content_tag(:span, link_to(image_tag(t), ta.get_view_url[i]))}.last(3).join}}', :details => '{{unique_with_count(ta.collect_group_with_index(:parent_name){ |n,i| link_to(n, ta.get_parent_url[i])}, "%s").join("<br />")}}' % _("in the gallery") } }, |
41 | 27 | :type => :groupable |
42 | 28 | }, |
43 | 29 | |
44 | - :leave_comment => { | |
45 | - :description => lambda { _('has left a comment entitled "%{title}" on the article %{article}: <br /> "%{comment}" (%{read})') % { :title => "{{truncate(ta.get_title)}}", :article => "{{link_to(truncate(ta.get_article_title), ta.get_article_url)}}", :comment => "{{truncate(ta.get_body, 50)}}", :read => '{{link_to("%s", ta.get_url)}}' % _("read") } } | |
46 | - }, | |
47 | - | |
48 | 30 | :leave_scrap => { |
49 | 31 | :description => lambda { _('sent a message to %{receiver}: <br /> "%{message}"') % { :receiver => "{{link_to(ta.get_receiver_name, ta.get_receiver_url)}}", :message => "{{auto_link_urls(ta.get_content)}}" } } |
50 | 32 | }, | ... | ... |
test/functional/profile_controller_test.rb
... | ... | @@ -1169,7 +1169,7 @@ class ProfileControllerTest < ActionController::TestCase |
1169 | 1169 | assert_equal 40, profile.tracked_actions.count |
1170 | 1170 | get :view_more_activities, :profile => profile.identifier, :page => 2 |
1171 | 1171 | assert_response :success |
1172 | - assert_template '_profile_bla' | |
1172 | + assert_template '_profile_activities_scraps' | |
1173 | 1173 | assert_equal 10, assigns(:activities).count |
1174 | 1174 | end |
1175 | 1175 | |
... | ... | @@ -1287,5 +1287,42 @@ class ProfileControllerTest < ActionController::TestCase |
1287 | 1287 | get :index, :profile => profile.identifier |
1288 | 1288 | |
1289 | 1289 | assert_equivalent [scrap,activity], assigns(:activities).map {|a| a.klass.constantize.find(a.id)} |
1290 | - end | |
1290 | + end | |
1291 | + | |
1292 | + should "be logged in to leave comment on an activity" do | |
1293 | + article = TinyMceArticle.create!(:profile => profile, :name => 'An article about free software') | |
1294 | + activity = ActionTracker::Record.last | |
1295 | + count = activity.comments.count | |
1296 | + | |
1297 | + post :leave_comment_on_activity, :profile => profile.identifier, :comment => {:body => 'something', :source_id => activity.id} | |
1298 | + assert_equal count, activity.comments.count | |
1299 | + assert_redirected_to :controller => 'account', :action => 'login' | |
1300 | + end | |
1301 | + | |
1302 | + should "leave a comment in own activity" do | |
1303 | + login_as(profile.identifier) | |
1304 | + TinyMceArticle.create!(:profile => profile, :name => 'An article about free software') | |
1305 | + activity = ActionTracker::Record.last | |
1306 | + count = activity.comments.count | |
1307 | + | |
1308 | + assert_equal 0, count | |
1309 | + post :leave_comment_on_activity, :profile => profile.identifier, :comment => {:body => 'something', :source_id => activity.id} | |
1310 | + assert_equal count + 1, activity.comments.count | |
1311 | + assert_response :success | |
1312 | + assert_equal "Comment successfully added.", assigns(:message) | |
1313 | + end | |
1314 | + | |
1315 | + should "leave a comment on another profile's activity" do | |
1316 | + login_as(profile.identifier) | |
1317 | + another_person = fast_create(Person) | |
1318 | + TinyMceArticle.create!(:profile => another_person, :name => 'An article about free software') | |
1319 | + activity = ActionTracker::Record.last | |
1320 | + count = activity.comments.count | |
1321 | + | |
1322 | + assert_equal 0, count | |
1323 | + post :leave_comment_on_activity, :profile => another_person.identifier, :comment => {:body => 'something', :source_id => activity.id} | |
1324 | + assert_equal count + 1, activity.comments.count | |
1325 | + assert_response :success | |
1326 | + assert_equal "Comment successfully added.", assigns(:message) | |
1327 | + end | |
1291 | 1328 | end | ... | ... |
test/unit/comment_test.rb
... | ... | @@ -74,6 +74,14 @@ class CommentTest < ActiveSupport::TestCase |
74 | 74 | assert_equal cc + 1, Article.find(art.id).comments_count |
75 | 75 | end |
76 | 76 | |
77 | + should 'update counter cache in activity' do | |
78 | + action = fast_create(ActionTracker::Record) | |
79 | + cc = action.comments_count | |
80 | + comment = fast_create(Comment, :source_id => action.id) | |
81 | + | |
82 | + assert_equal cc + 1, ActionTracker::Record.find(action.id).comments_count | |
83 | + end | |
84 | + | |
77 | 85 | should 'provide author name for authenticated authors' do |
78 | 86 | owner = create_user('testuser').person |
79 | 87 | assert_equal 'testuser', Comment.new(:author => owner).author_name |
... | ... | @@ -319,4 +327,6 @@ class CommentTest < ActiveSupport::TestCase |
319 | 327 | assert c.rejected? |
320 | 328 | end |
321 | 329 | |
330 | + should 'update article activity when add a comment' | |
331 | + should 'update activity when add a comment' | |
322 | 332 | end | ... | ... |
vendor/plugins/active_record_counter_cache_on_polymorphic_association/init.rb
... | ... | @@ -2,31 +2,35 @@ |
2 | 2 | # |
3 | 3 | # https://rails.lighthouseapp.com/projects/8994/tickets/2452-counter_cache-not-updated-when-an-item-updates-its-polymorphic-owner |
4 | 4 | |
5 | -ActiveRecord::Associations::ClassMethods.module_eval do | |
6 | - | |
7 | - def replace(record) | |
8 | - counter_cache_name = @reflection.counter_cache_column | |
9 | - if record.nil? | |
10 | - if counter_cache_name && !@owner.new_record? | |
11 | - record.class.base_class.decrement_counter(counter_cache_name, @owner[@reflection.primary_key_name]) if @owner[@reflection.primary_key_name] | |
12 | - end | |
13 | - @target = @owner[@reflection.primary_key_name] = @owner[@reflection.options[:foreign_type]] = nil | |
14 | - else | |
15 | - @target = (AssociationProxy === record ? record.target : record) | |
16 | - | |
17 | - if counter_cache_name && !@owner.new_record? | |
18 | - record.class.base_class.increment_counter(counter_cache_name, record.id) | |
19 | - record.class.base_class.decrement_counter(counter_cache_name, @owner[@reflection.primary_key_name]) if @owner[@reflection.primary_key_name] | |
20 | - end | |
21 | - | |
22 | - @owner[@reflection.primary_key_name] = record.id | |
23 | - @owner[@reflection.options[:foreign_type]] = record.class.base_class.name.to_s | |
24 | - | |
25 | - @updated = true | |
26 | - end | |
27 | - | |
28 | - loaded | |
29 | - record | |
30 | - end | |
31 | - | |
32 | -end | |
5 | +#ActiveRecord::Associations.module_eval do | |
6 | +# | |
7 | +# def replace(record) | |
8 | +# | |
9 | +# counter_cache_name = @reflection.counter_cache_column | |
10 | +# | |
11 | +# if record.nil? | |
12 | +# if counter_cache_name && !@owner.new_record? | |
13 | +# record.class.base_class.decrement_counter(counter_cache_name, @owner[@reflection.primary_key_name]) if @owner[@reflection.primary_key_name] | |
14 | +# end | |
15 | +# | |
16 | +# @target = @owner[@reflection.primary_key_name] = @owner[@reflection.options[:foreign_type]] = nil | |
17 | +# else | |
18 | +# @target = (AssociationProxy === record ? record.target : record) | |
19 | +# | |
20 | +# if counter_cache_name && !@owner.new_record? | |
21 | +# record.class.base_class.increment_counter(counter_cache_name, record.id) | |
22 | +# record.class.base_class.decrement_counter(counter_cache_name, @owner[@reflection.primary_key_name]) if @owner[@reflection.primary_key_name] | |
23 | +# end | |
24 | +# | |
25 | +# @owner[@reflection.primary_key_name] = record.id | |
26 | +# @owner[@reflection.options[:foreign_type]] = record.class.base_class.name.to_s | |
27 | +# | |
28 | +# | |
29 | +# @updated = true | |
30 | +# end | |
31 | +# | |
32 | +# loaded | |
33 | +# record | |
34 | +# end | |
35 | +# | |
36 | +#end | ... | ... |