diff --git a/app/models/category.rb b/app/models/category.rb index c137be6b7dc..2b1a3966e40 100644 --- a/app/models/category.rb +++ b/app/models/category.rb @@ -276,11 +276,11 @@ SQL full = CategoryGroup.permission_types[:full] mapped = permissions.map do |group,permission| - group = group.id if Group === group + group = group.id if group.is_a?(Group) # subtle, using Group[] ensures the group exists in the DB - group = Group[group.to_sym].id unless Fixnum === group - permission = CategoryGroup.permission_types[permission] unless Fixnum === permission + group = Group[group.to_sym].id unless group.is_a?(Fixnum) + permission = CategoryGroup.permission_types[permission] unless permission.is_a?(Fixnum) [group, permission] end diff --git a/app/models/category_featured_user.rb b/app/models/category_featured_user.rb index 3bb639c168c..33268879b0c 100644 --- a/app/models/category_featured_user.rb +++ b/app/models/category_featured_user.rb @@ -8,7 +8,7 @@ class CategoryFeaturedUser < ActiveRecord::Base def self.feature_users_in(category_or_category_id) category_id = - if Fixnum === category_or_category_id + if category_or_category_id.is_a?(Fixnum) category_or_category_id else category_or_category_id.id diff --git a/app/models/topic_user.rb b/app/models/topic_user.rb index f9a3c0674d3..4053dd78af3 100644 --- a/app/models/topic_user.rb +++ b/app/models/topic_user.rb @@ -66,13 +66,12 @@ class TopicUser < ActiveRecord::Base result end - def get(topic,user) - topic = topic.id if Topic === topic - user = user.id if User === user - TopicUser.where('topic_id = ? and user_id = ?', topic, user).first + def get(topic, user) + topic = topic.id if topic.is_a?(Topic) + user = user.id if user.is_a?(User) + TopicUser.find_by(topic_id: topic, user_id: user) end - # Change attributes for a user (creates a record when none is present). First it tries an update # since there's more likely to be an existing record than not. If the update returns 0 rows affected # it then creates the row instead. @@ -117,8 +116,8 @@ class TopicUser < ActiveRecord::Base end def track_visit!(topic,user) - topic_id = Topic === topic ? topic.id : topic - user_id = User === user ? user.id : topic + topic_id = topic.is_a?(Topic) ? topic.id : topic + user_id = user.is_a?(User) ? user.id : topic now = DateTime.now rows = TopicUser.where({topic_id: topic_id, user_id: user_id}).update_all({last_visited_at: now}) diff --git a/app/models/user.rb b/app/models/user.rb index 08c561b510d..533d882beaa 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -200,7 +200,7 @@ class User < ActiveRecord::Base def approve(approved_by, send_mail=true) self.approved = true - if Fixnum === approved_by + if approved_by.is_a?(Fixnum) self.approved_by_id = approved_by else self.approved_by = approved_by diff --git a/lib/guardian.rb b/lib/guardian.rb index b80860a7260..1350c971b3e 100644 --- a/lib/guardian.rb +++ b/lib/guardian.rb @@ -197,7 +197,7 @@ class Guardian end def can_send_private_message?(target) - (User === target || Group === target) && + (target.is_a?(Group) || target.is_a?(User)) && # User is authenticated authenticated? && # Can't send message to yourself @@ -221,7 +221,7 @@ class Guardian end def is_me?(other) - other && authenticated? && User === other && @user == other + other && authenticated? && other.is_a?(User) && @user == other end def is_not_me?(other) diff --git a/lib/js_locale_helper.rb b/lib/js_locale_helper.rb index 6642a0dfd20..a558d7246cf 100644 --- a/lib/js_locale_helper.rb +++ b/lib/js_locale_helper.rb @@ -96,13 +96,13 @@ module JsLocaleHelper end def self.strip_out_message_formats!(hash, prefix = "", rval = {}) - if Hash === hash - hash.each do |k,v| - if Hash === v - rval.merge!(strip_out_message_formats!(v, prefix + (prefix.length > 0 ? "." : "") << k, rval)) - elsif k.to_s().end_with?("_MF") - rval[prefix + (prefix.length > 0 ? "." : "") << k] = v - hash.delete(k) + if hash.is_a?(Hash) + hash.each do |key, value| + if value.is_a?(Hash) + rval.merge!(strip_out_message_formats!(value, prefix + (prefix.length > 0 ? "." : "") << key, rval)) + elsif key.to_s.end_with?("_MF") + rval[prefix + (prefix.length > 0 ? "." : "") << key] = value + hash.delete(key) end end end diff --git a/lib/search.rb b/lib/search.rb index 2579e6b70f2..7b2c270caf9 100644 --- a/lib/search.rb +++ b/lib/search.rb @@ -47,7 +47,7 @@ class Search @limit = Search.per_facet * Search.facets.size @results = GroupedSearchResults.new(@opts[:type_filter]) - if Topic === @search_context && @search_context.posts_count < SiteSetting.min_posts_for_search_in_topic + if @search_context.is_a?(Topic) && @search_context.posts_count < SiteSetting.min_posts_for_search_in_topic @search_context = nil end end diff --git a/lib/site_setting_extension.rb b/lib/site_setting_extension.rb index d42d615b3a6..317fb99ebf2 100644 --- a/lib/site_setting_extension.rb +++ b/lib/site_setting_extension.rb @@ -191,7 +191,7 @@ module SiteSettingExtension val = (val == "t" || val == "true") ? 't' : 'f' end - if type == types[:fixnum] && !(Fixnum === val) + if type == types[:fixnum] && !val.is_a?(Fixnum) val = val.to_i end diff --git a/lib/tasks/qunit.rake b/lib/tasks/qunit.rake index 31cbe2a2df8..b39b37e4cfd 100644 --- a/lib/tasks/qunit.rake +++ b/lib/tasks/qunit.rake @@ -48,7 +48,7 @@ task "qunit:test" => :environment do # A bit of a hack until we can figure this out on Travis tries = 0 - while tries < 3 && $?.exitstatus === 124 && !quit + while tries < 3 && $?.exitstatus == 124 && !quit tries += 1 puts "\nTimed Out. Trying again...\n" rake_system(cmd) diff --git a/spec/support/helpers.rb b/spec/support/helpers.rb index a3753d732ba..1ae65ea4b2d 100644 --- a/spec/support/helpers.rb +++ b/spec/support/helpers.rb @@ -28,7 +28,7 @@ module Helpers args[:title] ||= "This is my title #{Helpers.next_seq}" user = args.delete(:user) || Fabricate(:user) guardian = Guardian.new(user) - args[:category] = args[:category].name if Category === args[:category] + args[:category] = args[:category].name if args[:category].is_a?(Category) TopicCreator.create(user, guardian, args) end @@ -37,7 +37,7 @@ module Helpers args[:raw] ||= "This is the raw body of my post, it is cool #{Helpers.next_seq}" args[:topic_id] = args[:topic].id if args[:topic] user = args.delete(:user) || Fabricate(:user) - args[:category] = args[:category].name if Category === args[:category] + args[:category] = args[:category].name if args[:category].is_a?(Category) PostCreator.create(user, args) end