From 966513a66d97e2c022e623ea39f34f81ab3b7988 Mon Sep 17 00:00:00 2001 From: Sam Date: Fri, 28 Jun 2013 12:18:04 +1000 Subject: [PATCH] my spec suite has been playing up attempting to clean some stuff by avoiding type checks --- app/models/topic_user.rb | 11 +++++++---- lib/post_creator.rb | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/app/models/topic_user.rb b/app/models/topic_user.rb index 50254bb43..1db00d2d5 100644 --- a/app/models/topic_user.rb +++ b/app/models/topic_user.rb @@ -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 diff --git a/lib/post_creator.rb b/lib/post_creator.rb index 2507ec4a3..7bdcd409b 100644 --- a/lib/post_creator.rb +++ b/lib/post_creator.rb @@ -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,