mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-27 17:46:05 -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.
|
# it then creates the row instead.
|
||||||
def change(user_id, topic_id, attrs)
|
def change(user_id, topic_id, attrs)
|
||||||
# Sometimes people pass objs instead of the ids. We can handle that.
|
# Sometimes people pass objs instead of the ids. We can handle that.
|
||||||
topic_id = topic_id.id if topic_id.is_a?(Topic)
|
topic_id = topic_id.id if topic_id.is_a?(::Topic)
|
||||||
user_id = user_id.id if user_id.is_a?(User)
|
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
|
TopicUser.transaction do
|
||||||
attrs = attrs.dup
|
attrs = attrs.dup
|
||||||
|
@ -84,7 +87,7 @@ class TopicUser < ActiveRecord::Base
|
||||||
|
|
||||||
attrs_sql = attrs_array.map { |t| "#{t[0]} = ?" }.join(", ")
|
attrs_sql = attrs_array.map { |t| "#{t[0]} = ?" }.join(", ")
|
||||||
vals = attrs_array.map { |t| t[1] }
|
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
|
if rows == 0
|
||||||
now = DateTime.now
|
now = DateTime.now
|
||||||
|
@ -95,7 +98,7 @@ class TopicUser < ActiveRecord::Base
|
||||||
attrs[:notification_level] ||= notification_levels[:tracking]
|
attrs[:notification_level] ||= notification_levels[:tracking]
|
||||||
end
|
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
|
else
|
||||||
observe_after_save_callbacks_for topic_id, user_id
|
observe_after_save_callbacks_for topic_id, user_id
|
||||||
end
|
end
|
||||||
|
|
|
@ -106,7 +106,7 @@ class PostCreator
|
||||||
post.topic.update_attributes(attrs)
|
post.topic.update_attributes(attrs)
|
||||||
|
|
||||||
# Update topic user data
|
# Update topic user data
|
||||||
TopicUser.change(post.user,
|
TopicUser.change(post.user.id,
|
||||||
post.topic.id,
|
post.topic.id,
|
||||||
posted: true,
|
posted: true,
|
||||||
last_read_post_number: post.post_number,
|
last_read_post_number: post.post_number,
|
||||||
|
|
Loading…
Reference in a new issue