mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-23 15:48:43 -05:00
my spec suite has been playing up attempting to clean some stuff by avoiding type checks
This commit is contained in:
parent
4512956c68
commit
966513a66d
2 changed files with 8 additions and 5 deletions
|
@ -69,8 +69,11 @@ class TopicUser < ActiveRecord::Base
|
|||
# it then creates the row instead.
|
||||
def change(user_id, topic_id, attrs)
|
||||
# Sometimes people pass objs instead of the ids. We can handle that.
|
||||
topic_id = topic_id.id if topic_id.is_a?(Topic)
|
||||
user_id = user_id.id if user_id.is_a?(User)
|
||||
topic_id = topic_id.id if topic_id.is_a?(::Topic)
|
||||
user_id = user_id.id if user_id.is_a?(::User)
|
||||
|
||||
topic_id = topic_id.to_i
|
||||
user_id = user_id.to_i
|
||||
|
||||
TopicUser.transaction do
|
||||
attrs = attrs.dup
|
||||
|
@ -84,7 +87,7 @@ class TopicUser < ActiveRecord::Base
|
|||
|
||||
attrs_sql = attrs_array.map { |t| "#{t[0]} = ?" }.join(", ")
|
||||
vals = attrs_array.map { |t| t[1] }
|
||||
rows = TopicUser.update_all([attrs_sql, *vals], topic_id: topic_id.to_i, user_id: user_id)
|
||||
rows = TopicUser.update_all([attrs_sql, *vals], topic_id: topic_id, user_id: user_id)
|
||||
|
||||
if rows == 0
|
||||
now = DateTime.now
|
||||
|
@ -95,7 +98,7 @@ class TopicUser < ActiveRecord::Base
|
|||
attrs[:notification_level] ||= notification_levels[:tracking]
|
||||
end
|
||||
|
||||
TopicUser.create(attrs.merge!(user_id: user_id, topic_id: topic_id.to_i, first_visited_at: now ,last_visited_at: now))
|
||||
TopicUser.create(attrs.merge!(user_id: user_id, topic_id: topic_id, first_visited_at: now ,last_visited_at: now))
|
||||
else
|
||||
observe_after_save_callbacks_for topic_id, user_id
|
||||
end
|
||||
|
|
|
@ -106,7 +106,7 @@ class PostCreator
|
|||
post.topic.update_attributes(attrs)
|
||||
|
||||
# Update topic user data
|
||||
TopicUser.change(post.user,
|
||||
TopicUser.change(post.user.id,
|
||||
post.topic.id,
|
||||
posted: true,
|
||||
last_read_post_number: post.post_number,
|
||||
|
|
Loading…
Reference in a new issue