speed up tests

add the ability to find the first notify private message
This commit is contained in:
Sam
2013-04-22 17:45:03 +10:00
parent 191008bcb7
commit cfc62dadff
10 changed files with 108 additions and 110 deletions

View File

@ -270,7 +270,26 @@ class Post < ActiveRecord::Base
end
def url
"/t/#{Slug.for(topic.title)}/#{topic.id}/#{post_number}"
Post.url(topic.title, topic.id, post_number)
end
def self.url(title, topic_id, post_number)
"/t/#{Slug.for(title)}/#{topic_id}/#{post_number}"
end
def self.urls(post_ids)
ids = post_ids.map{|u| u}
if ids.length > 0
urls = {}
Topic.joins(:posts).where('posts.id' => ids).
select(['posts.id as post_id','post_number', 'topics.title', 'topics.id']).
each do |t|
urls[t.post_id.to_i] = url(t.title, t.id, t.post_number)
end
urls
else
{}
end
end
def author_readable

View File

@ -6,7 +6,7 @@ class PostAction < ActiveRecord::Base
include RateLimiter::OnCreateRecord
attr_accessible :post_action_type_id, :post_id, :user_id, :post, :user, :post_action_type, :message
attr_accessible :post_action_type_id, :post_id, :user_id, :post, :user, :post_action_type, :message, :related_post_id
belongs_to :post
belongs_to :user
@ -89,16 +89,21 @@ class PostAction < ActiveRecord::Base
end
end
related_post_id = nil
if target_usernames.present?
PostCreator.new(user,
related_post_id = PostCreator.new(user,
target_usernames: target_usernames,
archetype: Archetype.private_message,
subtype: subtype,
title: title,
raw: body
).create
).create.id
end
create(post_id: post.id, user_id: user.id, post_action_type_id: post_action_type_id, message: message)
create( post_id: post.id,
user_id: user.id,
post_action_type_id: post_action_type_id,
message: message,
related_post_id: related_post_id )
rescue ActiveRecord::RecordNotUnique
# can happen despite being .create
# since already bookmarked