Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add statuses destroy logic.

  • Loading branch information...
commit 4e95873eca815864ad172088ab1d7e6004ae404e 1 parent 3b66d32
@chloerei chloerei authored
View
5 app/models/reply.rb
@@ -3,6 +3,7 @@ class Reply
include Mongoid::Timestamps
field :content
+ has_many :statuses, :validate => false, :class_name => 'Status::Base', :dependent => :delete
has_and_belongs_to_many :mention_users, :class_name => 'User', :validate => false
belongs_to :topic
@@ -13,7 +14,7 @@ class Reply
attr_accessible :content
after_create :increment_topic_reply_cache, :add_replier_ids
- after_destroy :decrement_topic_reply_cache
+ before_destroy :decrement_topic_reply_cache
before_save :extract_mentions
after_create :send_menetion_notifications, :create_status
@@ -26,7 +27,7 @@ def increment_topic_reply_cache
def decrement_topic_reply_cache
# ignore user and time cache
- topic.inc :replies_count, -1
+ topic.inc :replies_count, -1 if topic && !topic.frozen?
end
def add_replier_ids
View
5 app/models/stream.rb
@@ -21,6 +21,11 @@ def push_status(status)
$redis.ltrim store_key, 0, Stream.status_limit - 1
end
+ # slow than fetch_statuses, but complete than fetch_statuses
+ def statuses
+ Status::Base.where(:_id.in => status_ids).desc(:created_at)
+ end
+
def fetch_statuses(options = {})
page = (options[:page] || 1).to_i
per_page = (options[:per_page] || 20).to_i
View
3  app/models/topic.rb
@@ -13,7 +13,8 @@ class Topic
scope :marked_by, lambda { |user| where(:marker_ids => user.id) }
scope :replied_by, lambda { |user| where(:replier_ids => user.id) }
- has_many :replies, :validate => false, :dependent => :delete
+ has_many :replies, :validate => false, :dependent => :destroy
+ has_many :statuses, :validate => false, :class_name => 'Status::Base', :dependent => :delete
belongs_to :user
belongs_to :last_replied_by, :class_name => 'User'
field :actived_at, :type => Time
View
7 app/models/user.rb
@@ -118,10 +118,9 @@ def unban!
end
def clean!
- self.replies.delete_all
- topic_ids = self.topics.only(:id).to_a.map{|topic| topic.id}
- Reply.delete_all :conditions => {:topic_id => {"$in" => topic_ids}}
- self.topics.delete_all
+ self.replies.destroy
+ self.topics.destroy
+ self.statuses.delete_all
end
def self.authenticate(login, password)
View
22 test/unit/user_test.rb
@@ -108,6 +108,7 @@ def test_clean
def test_destroy
make_content
+
assert_difference "Topic.count", -1 do
assert_difference "Reply.count", -3 do
@user.destroy
@@ -116,21 +117,12 @@ def test_destroy
end
def make_content
- t = @user.topics.create :title => 'title', :content => 'content', :tags => 'tag1 tag2'
- r = t.replies.new :content => 'content'
- r.user = @admin
- r.save
- r = t.replies.new :content => 'content'
- r.user = @user
- r.save
-
- t = @admin.topics.create :title => 'title', :content => 'content', :tags => 'tag1 tag2'
- r = t.replies.new :content => 'content'
- r.user = @admin
- r.save
- r = t.replies.new :content => 'content'
- r.user = @user
- r.save
+ topic = Factory :topic, :user => @user
+ Factory :reply, :topic => topic
+ Factory :reply, :topic => topic, :user => @user
+ topic2 = Factory :topic
+ Factory :reply, :topic => topic2
+ Factory :reply, :topic => topic2, :user => @user
end
def test_remember_token

0 comments on commit 4e95873

Please sign in to comment.
Something went wrong with that request. Please try again.