Support Ruby 2.4.

This commit is contained in:
Guo Xiang Tan
2017-04-15 12:11:02 +08:00
parent 86efc57390
commit 04016f0dec
29 changed files with 73 additions and 60 deletions

View File

@@ -24,8 +24,8 @@
{{#if model.number_of_suspensions}}
<div><span class="suspensions">{{model.number_of_suspensions}}</span>&nbsp;{{i18n 'user.staff_counters.suspensions'}}</div>
{{/if}}
{{#if model.number_of_warnings}}
<div><span class="warnings-received">{{model.number_of_warnings}}</span>&nbsp;{{i18n 'user.staff_counters.warnings_received'}}</div>
{{#if model.warnings_received_count}}
<div><span class="warnings-received">{{model.warnings_received_count}}</span>&nbsp;{{i18n 'user.staff_counters.warnings_received'}}</div>
{{/if}}
</div>
{{/unless}}

View File

@@ -465,7 +465,7 @@ class ApplicationController < ActionController::Base
# type - a machine-readable description of the error
# status - HTTP status code to return
def render_json_error(obj, opts={})
opts = { status: opts } if opts.is_a?(Fixnum)
opts = { status: opts } if opts.is_a?(Integer)
render json: MultiJson.dump(create_errors_json(obj, opts[:type])), status: opts[:status] || 422
end

View File

@@ -744,7 +744,7 @@ class UsersController < ApplicationController
result = {}
%W{number_of_deleted_posts number_of_flagged_posts number_of_flags_given number_of_suspensions number_of_warnings}.each do |info|
%W{number_of_deleted_posts number_of_flagged_posts number_of_flags_given number_of_suspensions warnings_received_count}.each do |info|
result[info] = @user.send(info)
end

View File

@@ -388,8 +388,8 @@ SQL
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 group.is_a?(Fixnum)
permission = CategoryGroup.permission_types[permission] unless permission.is_a?(Fixnum)
group = Group[group.to_sym].id unless group.is_a?(Integer)
permission = CategoryGroup.permission_types[permission] unless permission.is_a?(Integer)
[group, permission]
end

View File

@@ -8,7 +8,7 @@ class CategoryFeaturedUser < ActiveRecord::Base
def self.feature_users_in(category_or_category_id)
category_id =
if category_or_category_id.is_a?(Fixnum)
if category_or_category_id.is_a?(Integer)
category_or_category_id
else
category_or_category_id.id

View File

@@ -1,7 +1,7 @@
class DraftSequence < ActiveRecord::Base
def self.next!(user,key)
user_id = user
user_id = user.id unless user.class == Fixnum
user_id = user.id unless user.is_a?(Integer)
return 0 if user_id < 0
@@ -19,7 +19,7 @@ class DraftSequence < ActiveRecord::Base
return nil unless user
user_id = user
user_id = user.id unless user.class == Fixnum
user_id = user.id unless user.is_a?(Integer)
# perf critical path
r = exec_sql('select sequence from draft_sequences where user_id = ? and draft_key = ?', user_id, key).values

View File

@@ -42,7 +42,7 @@ class PluginStore
def self.cast_value(type, value)
case type
when "Fixnum" then value.to_i
when "Integer", "Fixnum" then value.to_i
when "TrueClass", "FalseClass" then value == "true"
when "JSON" then map_json(::JSON.parse(value))
else value

View File

@@ -118,7 +118,7 @@ class Topic < ActiveRecord::Base
has_many :invites, through: :topic_invites, source: :invite
has_many :topic_status_updates, dependent: :destroy
has_one :warning
has_one :user_warning
has_one :first_post, -> {where post_number: 1}, class_name: Post
# When we want to temporarily attach some data to a forum topic (usually before serialization)

View File

@@ -37,7 +37,7 @@ class User < ActiveRecord::Base
has_many :invites, dependent: :destroy
has_many :topic_links, dependent: :destroy
has_many :uploads
has_many :warnings
has_many :user_warnings
has_many :user_archived_messages, dependent: :destroy
has_many :email_change_requests, dependent: :destroy
has_many :directory_items, dependent: :delete_all
@@ -276,7 +276,7 @@ class User < ActiveRecord::Base
def approve(approved_by, send_mail=true)
self.approved = true
if approved_by.is_a?(Fixnum)
if approved_by.is_a?(Integer)
self.approved_by_id = approved_by
else
self.approved_by = approved_by
@@ -614,7 +614,7 @@ class User < ActiveRecord::Base
end
def warnings_received_count
warnings.count
user_warnings.count
end
def flags_received_count
@@ -889,10 +889,6 @@ class User < ActiveRecord::Base
.count
end
def number_of_warnings
self.warnings.count
end
def number_of_suspensions
UserHistory.for(self, :suspend_user).count
end

View File

@@ -1,4 +1,4 @@
class Warning < ActiveRecord::Base
class UserWarning < ActiveRecord::Base
belongs_to :user
belongs_to :topic
belongs_to :created_by, class_name: 'User'