Skip to content
Snippets Groups Projects
Commit 240d5957 authored by danielgrippi's avatar danielgrippi
Browse files

removing photos_count method from StatusMessage in hopes of fixing the counter...

removing photos_count method from StatusMessage in hopes of fixing the counter (still a bit confused, though...)
parent 52df1f3e
No related branches found
No related tags found
No related merge requests found
......@@ -84,5 +84,4 @@ class Comment < ActiveRecord::Base
def parent= parent
self.post = parent
end
end
......@@ -40,10 +40,6 @@ class StatusMessage < Post
joins(:likes).where(:likes => {:author_id => person.id})
}
def photos_count
self.photos.size
end
def self.guids_for_author(person)
Post.connection.select_values(Post.where(:author_id => person.id).select('posts.guid').to_sql)
end
......@@ -177,7 +173,7 @@ class StatusMessage < Post
end
def update_photos_counter
StatusMessage.where(:id => self.id).
self.class.where(:id => self.id).
update_all(:photos_count => self.photos.count)
end
......@@ -192,6 +188,5 @@ class StatusMessage < Post
def self.tag_stream(tag_ids)
joins(:tags).where(:tags => {:id => tag_ids})
end
end
......@@ -244,4 +244,22 @@ describe Photo do
}.should_not change(StatusMessage, :count)
end
end
describe 'photo cache counter' do
it "works" do
@s = @user.build_post(:status_message, :text => "sup?", :to => @aspect.id)
@s.save!
@s.reload.photos_count.should == 0
@s.photos << @photo
@s.save!
@s.reload.photos_count.should == 1
@s.photos << @photo2
@s.save!
@s.reload.photos_count.should == 2
@s.photos.last.destroy
@s.reload.photos_count.should == 1
@s.photos.first.destroy
@s.reload.photos_count.should == 0
end
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment