removing photos_count method from StatusMessage in hopes of fixing the counter (still a bit confused, though...)

This commit is contained in:
danielgrippi 2012-01-13 23:33:51 -08:00
parent 52df1f3e84
commit 240d595714
3 changed files with 19 additions and 7 deletions

View file

@ -84,5 +84,4 @@ class Comment < ActiveRecord::Base
def parent= parent
self.post = parent
end
end

View file

@ -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

View file

@ -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