From 239cbd2d5869c6ee49787ca877b94ed4675bd6db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Tue, 5 Mar 2013 01:42:44 +0100 Subject: [PATCH] enforce coding convention replaced every `and` by `&&` and every `or` by `||` --- app/controllers/admin/export_controller.rb | 2 +- app/controllers/application_controller.rb | 5 ++--- app/controllers/clicks_controller.rb | 2 +- app/controllers/email_controller.rb | 2 +- app/controllers/list_controller.rb | 4 ++-- app/controllers/post_actions_controller.rb | 2 +- app/controllers/session_controller.rb | 2 +- app/controllers/topics_controller.rb | 2 +- .../users/omniauth_callbacks_controller.rb | 4 ++-- app/controllers/users_controller.rb | 18 +++++++++--------- app/helpers/application_helper.rb | 2 +- app/mailers/user_notifications.rb | 2 +- app/models/post.rb | 2 +- app/models/post_action.rb | 6 +++--- app/models/site_setting.rb | 2 +- app/models/topic.rb | 4 ++-- app/models/user.rb | 2 +- app/serializers/post_serializer.rb | 10 +++++----- app/serializers/topic_list_serializer.rb | 2 +- app/serializers/topic_view_serializer.rb | 6 +++--- config/initializers/mini_profiler.rb | 16 ++++++++-------- config/initializers/sidekiq.rb | 2 +- config/initializers/verify_config.rb | 4 ++-- lib/discourse_iife.rb | 2 +- lib/export/json_encoder.rb | 4 ++-- lib/freedom_patches/active_record_base.rb | 2 +- lib/guardian.rb | 2 +- lib/image_sizer.rb | 2 +- lib/jobs.rb | 2 +- lib/jobs/importer.rb | 10 +++++----- lib/jobs/user_email.rb | 2 +- lib/oneboxer/discourse_onebox.rb | 2 +- lib/oneboxer/open_graph_onebox.rb | 2 +- lib/oneboxer/wikipedia_onebox.rb | 2 +- lib/post_revisor.rb | 2 +- lib/rate_limiter/on_create_record.rb | 2 +- lib/text_sentinel.rb | 6 +++--- lib/topic_view.rb | 4 ++-- spec/components/jobs_spec.rb | 2 +- 39 files changed, 75 insertions(+), 76 deletions(-) diff --git a/app/controllers/admin/export_controller.rb b/app/controllers/admin/export_controller.rb index 46962a09f12..c9ffbb795b8 100644 --- a/app/controllers/admin/export_controller.rb +++ b/app/controllers/admin/export_controller.rb @@ -1,6 +1,6 @@ class Admin::ExportController < Admin::AdminController def create - unless Export.is_export_running? or Import.is_import_running? + unless Export.is_export_running? || Import.is_import_running? job_id = Jobs.enqueue( :exporter, user_id: current_user.id ) render json: success_json.merge( job_id: job_id ) else diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index a2ff8b3238c..0d0f97cc979 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -223,7 +223,7 @@ class ApplicationController < ActionController::Base end def mini_profiler_enabled? - defined?(Rack::MiniProfiler) and current_user.try(:admin?) + defined?(Rack::MiniProfiler) && current_user.try(:admin?) end def authorize_mini_profiler @@ -250,8 +250,7 @@ class ApplicationController < ActionController::Base def check_xhr unless (controller_name == 'forums' || controller_name == 'user_open_ids') - # render 'default/empty' unless ((request.format && request.format.json?) or request.xhr?) - raise RenderEmpty.new unless ((request.format && request.format.json?) or request.xhr?) + raise RenderEmpty.new unless ((request.format && request.format.json?) || request.xhr?) end end diff --git a/app/controllers/clicks_controller.rb b/app/controllers/clicks_controller.rb index 1a691e715da..9515247a97a 100644 --- a/app/controllers/clicks_controller.rb +++ b/app/controllers/clicks_controller.rb @@ -4,7 +4,7 @@ class ClicksController < ApplicationController def track requires_parameter(:url) - if params[:topic_id].present? or params[:post_id].present? + if params[:topic_id].present? || params[:post_id].present? args = {url: params[:url], ip: request.remote_ip} args[:user_id] = current_user.id if current_user.present? args[:post_id] = params[:post_id].to_i if params[:post_id].present? diff --git a/app/controllers/email_controller.rb b/app/controllers/email_controller.rb index 2f69ec7146d..a3ba6705b53 100644 --- a/app/controllers/email_controller.rb +++ b/app/controllers/email_controller.rb @@ -12,7 +12,7 @@ class EmailController < ApplicationController @user = User.find_by_temporary_key(params[:key]) # Don't allow the use of a key while logged in as a different user - @user = nil if current_user.present? and (@user != current_user) + @user = nil if current_user.present? && (@user != current_user) if @user.present? @user.update_column(:email_digests, false) diff --git a/app/controllers/list_controller.rb b/app/controllers/list_controller.rb index 3de4a30ac76..7c65a35d0cd 100644 --- a/app/controllers/list_controller.rb +++ b/app/controllers/list_controller.rb @@ -10,7 +10,7 @@ class ListController < ApplicationController list_opts = {page: params[:page]} # html format means we need to farm exclude from the site options - if params[:format].blank? or params[:format] == "html" + if params[:format].blank? || params[:format] == "html" #TODO objectify this stuff SiteSetting.top_menu.split('|').each do |f| s = f.split(",") @@ -35,7 +35,7 @@ class ListController < ApplicationController list = nil # If they choose uncategorized, return topics NOT in a category - if params[:category] == Slug.for(SiteSetting.uncategorized_name) or params[:category] == SiteSetting.uncategorized_name + if params[:category] == Slug.for(SiteSetting.uncategorized_name) || params[:category] == SiteSetting.uncategorized_name list = query.list_uncategorized else @category = Category.where("slug = ? or id = ?", params[:category], params[:category].to_i).includes(:featured_users).first diff --git a/app/controllers/post_actions_controller.rb b/app/controllers/post_actions_controller.rb index 3645dabc006..0f45111ea2b 100644 --- a/app/controllers/post_actions_controller.rb +++ b/app/controllers/post_actions_controller.rb @@ -12,7 +12,7 @@ class PostActionsController < ApplicationController post_action = PostAction.act(current_user, @post, action.id, params[:message]) - if post_action.blank? or post_action.errors.present? + if post_action.blank? || post_action.errors.present? render_json_error(post_action) else # We need to reload or otherwise we are showing the old values on the front end diff --git a/app/controllers/session_controller.rb b/app/controllers/session_controller.rb index 0d0d388f44b..babdf8826da 100644 --- a/app/controllers/session_controller.rb +++ b/app/controllers/session_controller.rb @@ -15,7 +15,7 @@ class SessionController < ApplicationController if @user.present? # If the site requires user approval and the user is not approved yet - if SiteSetting.must_approve_users? and !@user.approved? + if SiteSetting.must_approve_users? && !@user.approved? render :json => {error: I18n.t("login.not_approved")} return end diff --git a/app/controllers/topics_controller.rb b/app/controllers/topics_controller.rb index 80e8a8ccea0..cf5328d0a09 100644 --- a/app/controllers/topics_controller.rb +++ b/app/controllers/topics_controller.rb @@ -25,7 +25,7 @@ class TopicsController < ApplicationController create_topic_view anonymous_etag(@topic_view.topic) do - redirect_to_correct_topic and return if slugs_do_not_match + redirect_to_correct_topic && return if slugs_do_not_match View.create_for(@topic_view.topic, request.remote_ip, current_user) track_visit_to_topic perform_show_response diff --git a/app/controllers/users/omniauth_callbacks_controller.rb b/app/controllers/users/omniauth_callbacks_controller.rb index e1be38da8c2..a09b9a6763b 100644 --- a/app/controllers/users/omniauth_callbacks_controller.rb +++ b/app/controllers/users/omniauth_callbacks_controller.rb @@ -156,7 +156,7 @@ class Users::OmniauthCallbacksController < ApplicationController user = user_open_id.user # If we have to approve users - if SiteSetting.must_approve_users? and !user.approved? + if SiteSetting.must_approve_users? && !user.approved? @data = {awaiting_approval: true} else log_on_user(user) @@ -222,7 +222,7 @@ class Users::OmniauthCallbacksController < ApplicationController user = User.find_by_email(email) if user - if SiteSetting.must_approve_users? and !user.approved? + if SiteSetting.must_approve_users? && !user.approved? @data = {awaiting_approval: true} else log_on_user(user) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 058ee3b937f..4465385b131 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -89,7 +89,7 @@ class UsersController < ApplicationController else # Contact the Discourse Hub server - email_given = (params[:email].present? or current_user.present?) + email_given = (params[:email].present? || current_user.present?) available_locally = User.username_available?(params[:username]) global_match = false available_globally, suggestion_from_discourse_hub = begin @@ -101,9 +101,9 @@ class UsersController < ApplicationController end end - if available_globally and available_locally + if available_globally && available_locally render json: {available: true, global_match: (global_match ? true : false)} - elsif available_locally and !available_globally + elsif available_locally && !available_globally if email_given # Nickname and email do not match what's registered on the discourse hub. render json: {available: false, global_match: false, suggestion: suggestion_from_discourse_hub} @@ -113,7 +113,7 @@ class UsersController < ApplicationController # Don't give a suggestion until we get the email and try to match it with on the discourse hub. render json: {available: false} end - elsif available_globally and !available_locally + elsif available_globally && !available_locally # Already registered on this site with the matching nickname and email address. Why are you signing up again? render json: {available: false, suggestion: User.suggest_username(params[:username])} else @@ -128,7 +128,7 @@ class UsersController < ApplicationController def create - if params[:password_confirmation] != honeypot_value or params[:challenge] != challenge_value.try(:reverse) + if params[:password_confirmation] != honeypot_value || params[:challenge] != challenge_value.try(:reverse) # Don't give any indication that we caught you in the honeypot return render(:json => {success: true, active: false, message: I18n.t("login.activate_email", email: params[:email]) }) end @@ -145,7 +145,7 @@ class UsersController < ApplicationController end user.password_required! unless auth - DiscourseHub.register_nickname( user.username, user.email ) if user.valid? and SiteSetting.call_discourse_hub? + DiscourseHub.register_nickname( user.username, user.email ) if user.valid? && SiteSetting.call_discourse_hub? if user.save @@ -174,7 +174,7 @@ class UsersController < ApplicationController TwitterUserInfo.create(:user_id => user.id, :screen_name => auth[:twitter_screen_name], :twitter_user_id => auth[:twitter_user_id]) end - if auth[:facebook].present? and FacebookUserInfo.find_by_facebook_user_id(auth[:facebook][:facebook_user_id]).nil? + if auth[:facebook].present? && FacebookUserInfo.find_by_facebook_user_id(auth[:facebook][:facebook_user_id]).nil? FacebookUserInfo.create!(auth[:facebook].merge(user_id: user.id)) end @@ -232,11 +232,11 @@ class UsersController < ApplicationController if @user.blank? flash[:error] = I18n.t('password_reset.no_token') else - if request.put? and params[:password].present? + if request.put? && params[:password].present? @user.password = params[:password] if @user.save - if SiteSetting.must_approve_users? and !@user.approved? + if SiteSetting.must_approve_users? && !@user.approved? @requires_approval = true flash[:success] = I18n.t('password_reset.success_unapproved') else diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 05b365262e4..c8e46c5ab86 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -25,7 +25,7 @@ module ApplicationHelper end def mini_profiler_enabled? - defined?(Rack::MiniProfiler) and admin? + defined?(Rack::MiniProfiler) && admin? end def admin? diff --git a/app/mailers/user_notifications.rb b/app/mailers/user_notifications.rb index 22b63aaede3..ba40d7b40e8 100644 --- a/app/mailers/user_notifications.rb +++ b/app/mailers/user_notifications.rb @@ -49,7 +49,7 @@ class UserNotifications < ActionMailer::Base @markdown_linker = MarkdownLinker.new(Discourse.base_url) # Don't send email unless there is content in it - if @new_topics.present? or @notifications.present? + if @new_topics.present? || @notifications.present? mail to: user.email, subject: I18n.t('user_notifications.digest.subject_template', :site_name => @site_name, diff --git a/app/models/post.rb b/app/models/post.rb index 49929e4c3e6..d8fad397056 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -206,7 +206,7 @@ class Post < ActiveRecord::Base parent_raw = parent_post.raw.sub(/\[quote.+\/quote\]/m, '') - if raw[parent_raw] or (parent_raw.size < SHORT_POST_CHARS) + if raw[parent_raw] || (parent_raw.size < SHORT_POST_CHARS) return cooked.sub(/\/m, '') end diff --git a/app/models/post_action.rb b/app/models/post_action.rb index aceb8b24475..d8a6dc57009 100644 --- a/app/models/post_action.rb +++ b/app/models/post_action.rb @@ -123,9 +123,9 @@ class PostAction < ActiveRecord::Base end before_create do - raise AlreadyFlagged if is_flag? and PostAction.where(user_id: user_id, - post_id: post_id, - post_action_type_id: PostActionType.flag_types.values).exists? + raise AlreadyFlagged if is_flag? && PostAction.where(user_id: user_id, + post_id: post_id, + post_action_type_id: PostActionType.flag_types.values).exists? end after_save do diff --git a/app/models/site_setting.rb b/app/models/site_setting.rb index 559183de2b2..6bcf8305eb0 100644 --- a/app/models/site_setting.rb +++ b/app/models/site_setting.rb @@ -155,7 +155,7 @@ class SiteSetting < ActiveRecord::Base client_setting(:educate_until_posts, 2) def self.call_discourse_hub? - self.enforce_global_nicknames? and self.discourse_org_access_key.present? + self.enforce_global_nicknames? && self.discourse_org_access_key.present? end def self.topic_title_length diff --git a/app/models/topic.rb b/app/models/topic.rb index fb99a697e1e..478cbc35bed 100644 --- a/app/models/topic.rb +++ b/app/models/topic.rb @@ -272,7 +272,7 @@ class Topic < ActiveRecord::Base Topic.transaction do old_category = category - if category_id.present? and category_id != cat.id + if category_id.present? && category_id != cat.id Category.update_all 'topic_count = topic_count - 1', ['id = ?', category_id] end @@ -444,7 +444,7 @@ class Topic < ActiveRecord::Base end end - posted = if topic_user.present? and current_user.present? + posted = if topic_user.present? && current_user.present? current_user if topic_user.posted? end diff --git a/app/models/user.rb b/app/models/user.rb index 06016d6447d..1300cc3d3b2 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -528,7 +528,7 @@ class User < ActiveRecord::Base end def password_validator - if (@raw_password and @raw_password.length < 6) || (@password_required && !@raw_password) + if (@raw_password && @raw_password.length < 6) || (@password_required && !@raw_password) errors.add(:password, "must be 6 letters or longer") end end diff --git a/app/serializers/post_serializer.rb b/app/serializers/post_serializer.rb index a51258cf3d3..97e5db7d08c 100644 --- a/app/serializers/post_serializer.rb +++ b/app/serializers/post_serializer.rb @@ -153,10 +153,10 @@ class PostSerializer < ApplicationSerializer can_act: scope.post_can_act?(object, sym, taken_actions: post_actions)} # The following only applies if you're logged in - if action_summary[:can_act] and scope.current_user.present? + if action_summary[:can_act] && scope.current_user.present? action_summary[:can_clear_flags] = scope.is_admin? && PostActionType.flag_types.values.include?(id) - if post_actions.present? and post_actions.has_key?(id) + if post_actions.present? && post_actions.has_key?(id) action_summary[:acted] = true action_summary[:can_undo] = scope.can_delete?(post_actions[id]) end @@ -188,7 +188,7 @@ class PostSerializer < ApplicationSerializer def include_link_counts? return true if @single_post_link_counts.present? - @topic_view.present? and @topic_view.link_counts.present? and @topic_view.link_counts[object.id].present? + @topic_view.present? && @topic_view.link_counts.present? && @topic_view.link_counts[object.id].present? end def include_read? @@ -196,11 +196,11 @@ class PostSerializer < ApplicationSerializer end def include_reply_to_user? - object.quoteless? and object.reply_to_user + object.quoteless? && object.reply_to_user end def include_bookmarked? - post_actions.present? and post_actions.keys.include?(PostActionType.types[:bookmark]) + post_actions.present? && post_actions.keys.include?(PostActionType.types[:bookmark]) end private diff --git a/app/serializers/topic_list_serializer.rb b/app/serializers/topic_list_serializer.rb index 285d1229fc6..a4c5cb39ea5 100644 --- a/app/serializers/topic_list_serializer.rb +++ b/app/serializers/topic_list_serializer.rb @@ -9,7 +9,7 @@ class TopicListSerializer < ApplicationSerializer end def include_more_topics_url? - object.more_topics_url.present? and (object.topics.size == SiteSetting.topics_per_page) + object.more_topics_url.present? && (object.topics.size == SiteSetting.topics_per_page) end end diff --git a/app/serializers/topic_view_serializer.rb b/app/serializers/topic_view_serializer.rb index d7e62a6fc1b..337dd11ffb0 100644 --- a/app/serializers/topic_view_serializer.rb +++ b/app/serializers/topic_view_serializer.rb @@ -174,19 +174,19 @@ class TopicViewSerializer < ApplicationSerializer end def include_participants? - object.initial_load? and object.posts_count.present? + object.initial_load? && object.posts_count.present? end def suggested_topics object.suggested_topics.topics end def include_suggested_topics? - at_bottom and object.suggested_topics.present? + at_bottom && object.suggested_topics.present? end # Whether we're at the bottom of a topic (last page) def at_bottom - posts.present? and (@highest_number_in_posts == object.highest_post_number) + posts.present? && (@highest_number_in_posts == object.highest_post_number) end def highest_post_number diff --git a/config/initializers/mini_profiler.rb b/config/initializers/mini_profiler.rb index 69346a8506e..f8ecef9897f 100644 --- a/config/initializers/mini_profiler.rb +++ b/config/initializers/mini_profiler.rb @@ -6,12 +6,12 @@ if defined?(Rack::MiniProfiler) # For our app, let's just show mini profiler always, polling is chatty so nuke that Rack::MiniProfiler.config.pre_authorize_cb = lambda do |env| - (env['HTTP_USER_AGENT'] !~ /iPad|iPhone|Nexus 7/) and - (env['PATH_INFO'] !~ /^\/message-bus/) and - (env['PATH_INFO'] !~ /topics\/timings/) and - (env['PATH_INFO'] !~ /assets/) and - (env['PATH_INFO'] !~ /jasmine/) and - (env['PATH_INFO'] !~ /users\/.*\/avatar/) and + (env['HTTP_USER_AGENT'] !~ /iPad|iPhone|Nexus 7/) && + (env['PATH_INFO'] !~ /^\/message-bus/) && + (env['PATH_INFO'] !~ /topics\/timings/) && + (env['PATH_INFO'] !~ /assets/) && + (env['PATH_INFO'] !~ /jasmine/) && + (env['PATH_INFO'] !~ /users\/.*\/avatar/) && (env['PATH_INFO'] !~ /srv\/status/) end @@ -27,7 +27,7 @@ if defined?(Rack::MiniProfiler) inst = Class.new class << inst def start(name,id,payload) - if Rack::MiniProfiler.current and name !~ /(process_action.action_controller)|(render_template.action_view)/ + if Rack::MiniProfiler.current && name !~ /(process_action.action_controller)|(render_template.action_view)/ @prf ||= {} @prf[id] ||= [] @prf[id] << Rack::MiniProfiler.start_step("#{payload[:serializer] if name =~ /serialize.serializer/} #{name}") @@ -35,7 +35,7 @@ if defined?(Rack::MiniProfiler) end def finish(name,id,payload) - if Rack::MiniProfiler.current and name !~ /(process_action.action_controller)|(render_template.action_view)/ + if Rack::MiniProfiler.current && name !~ /(process_action.action_controller)|(render_template.action_view)/ t = @prf[id].pop @prf.delete id unless t Rack::MiniProfiler.finish_step t diff --git a/config/initializers/sidekiq.rb b/config/initializers/sidekiq.rb index fa1c85bbc8f..571a034f101 100644 --- a/config/initializers/sidekiq.rb +++ b/config/initializers/sidekiq.rb @@ -2,7 +2,7 @@ require "#{Rails.root}/lib/discourse_redis" $redis = DiscourseRedis.new -if Rails.env.development? and !ENV['DO_NOT_FLUSH_REDIS'] +if Rails.env.development? && !ENV['DO_NOT_FLUSH_REDIS'] puts "Flushing redis (development mode)" $redis.flushall end diff --git a/config/initializers/verify_config.rb b/config/initializers/verify_config.rb index 231b4de4296..926de1f3e5a 100644 --- a/config/initializers/verify_config.rb +++ b/config/initializers/verify_config.rb @@ -1,12 +1,12 @@ # Check that the app is configured correctly. Raise some helpful errors if something is wrong. -if Rails.env.production? and ['localhost', 'production.localhost'].include?(Discourse.current_hostname) +if Rails.env.production? && ['localhost', 'production.localhost'].include?(Discourse.current_hostname) puts < 0 + end while rows && rows.size > 0 @table_data[table_name][:rows].flatten!(1) @table_data[table_name][:row_count] = @table_data[table_name][:rows].size diff --git a/lib/freedom_patches/active_record_base.rb b/lib/freedom_patches/active_record_base.rb index 89d5d7eba64..21c97119783 100644 --- a/lib/freedom_patches/active_record_base.rb +++ b/lib/freedom_patches/active_record_base.rb @@ -25,7 +25,7 @@ class ActiveRecord::Base begin yield rescue ActiveRecord::StatementInvalid => e - if e.message =~ /deadlock detected/ and (retries.nil? || retries > 0) + if e.message =~ /deadlock detected/ && (retries.nil? || retries > 0) retry_lock_error(retries ? retries - 1 : nil, &block) else raise e diff --git a/lib/guardian.rb b/lib/guardian.rb index 2301c7aba68..ff8981f4a88 100644 --- a/lib/guardian.rb +++ b/lib/guardian.rb @@ -345,7 +345,7 @@ class Guardian when :like return false if post.user == @user when :vote then - return false if opts[:voted_in_topic] and post.topic.has_meta_data_boolean?(:single_vote) + return false if opts[:voted_in_topic] && post.topic.has_meta_data_boolean?(:single_vote) end return true diff --git a/lib/image_sizer.rb b/lib/image_sizer.rb index 8b3e7d5bf7f..58b858adf7c 100644 --- a/lib/image_sizer.rb +++ b/lib/image_sizer.rb @@ -3,7 +3,7 @@ module ImageSizer # Resize an image to the aspect ratio we want def self.resize(width, height) max_width = SiteSetting.max_image_width.to_f - return nil if width.blank? or height.blank? + return nil if width.blank? || height.blank? w = width.to_f h = height.to_f diff --git a/lib/jobs.rb b/lib/jobs.rb index 103c9f1fa6d..f2a94dd33b2 100644 --- a/lib/jobs.rb +++ b/lib/jobs.rb @@ -19,7 +19,7 @@ module Jobs opts = opts.with_indifferent_access if opts.delete(:sync_exec) - if opts.has_key?(:current_site_id) and opts[:current_site_id] != RailsMultisite::ConnectionManagement.current_db + if opts.has_key?(:current_site_id) && opts[:current_site_id] != RailsMultisite::ConnectionManagement.current_db raise ArgumentError.new("You can't connect to another database when executing a job synchronously.") else return execute(opts) diff --git a/lib/jobs/importer.rb b/lib/jobs/importer.rb index 708eb0c8ed7..ff4053b54de 100644 --- a/lib/jobs/importer.rb +++ b/lib/jobs/importer.rb @@ -125,8 +125,8 @@ module Jobs end def set_schema_info(arg) - if arg[:source] and arg[:source].downcase == 'discourse' - if arg[:version] and arg[:version] <= Export.current_schema_version + if arg[:source] && arg[:source].downcase == 'discourse' + if arg[:version] && arg[:version] <= Export.current_schema_version @export_schema_version = arg[:version] if arg[:table_count] == ordered_models_for_import.size true @@ -210,7 +210,7 @@ module Jobs # The indexdef statements don't create the primary keys, so we need to find the primary key and do it ourselves. pkey_index_def = @index_definitions[model.table_name].find { |ixdef| ixdef =~ / ([\S]{1,}_pkey) / } - if pkey_index_def and pkey_index_name = / ([\S]{1,}_pkey) /.match(pkey_index_def)[1] + if pkey_index_def && pkey_index_name = / ([\S]{1,}_pkey) /.match(pkey_index_def)[1] model.exec_sql( "ALTER TABLE ONLY #{model.table_name} ADD PRIMARY KEY USING INDEX #{pkey_index_name}" ) end @@ -263,9 +263,9 @@ module Jobs def send_notification # Doesn't work. "WARNING: Can't mass-assign protected attributes: created_at" # Still a problem with the activerecord schema_cache I think. - # if @user_info and @user_info[:user_id] + # if @user_info && @user_info[:user_id] # user = User.where(id: @user_info[:user_id]).first - # if user and user.email == @user_info[:email] + # if user && user.email == @user_info[:email] # SystemMessage.new(user).create('import_succeeded') # end # end diff --git a/lib/jobs/user_email.rb b/lib/jobs/user_email.rb index 42cf787d471..c9e7c612252 100644 --- a/lib/jobs/user_email.rb +++ b/lib/jobs/user_email.rb @@ -15,7 +15,7 @@ module Jobs user = User.where(id: args[:user_id]).first return unless user.present? - seen_recently = (user.last_seen_at.present? and user.last_seen_at > SiteSetting.email_time_window_mins.minutes.ago) + seen_recently = (user.last_seen_at.present? && user.last_seen_at > SiteSetting.email_time_window_mins.minutes.ago) email_args = {} diff --git a/lib/oneboxer/discourse_onebox.rb b/lib/oneboxer/discourse_onebox.rb index 9fe7308ea9b..8933f883d87 100644 --- a/lib/oneboxer/discourse_onebox.rb +++ b/lib/oneboxer/discourse_onebox.rb @@ -26,7 +26,7 @@ module Oneboxer @template = 'user' when 'topics' - if route[:post_number].present? and route[:post_number].to_i > 1 + if route[:post_number].present? && route[:post_number].to_i > 1 # Post Link post = Post.where(topic_id: route[:topic_id], post_number: route[:post_number].to_i).first Guardian.new.ensure_can_see!(post) diff --git a/lib/oneboxer/open_graph_onebox.rb b/lib/oneboxer/open_graph_onebox.rb index 30ca1274ec3..129d7f93126 100644 --- a/lib/oneboxer/open_graph_onebox.rb +++ b/lib/oneboxer/open_graph_onebox.rb @@ -13,7 +13,7 @@ module Oneboxer # A site is supposed to supply all the basic og attributes, but some don't (like deviant art) # If it just has image and no title, embed it as an image. - return BaseOnebox.image_html(@opts['image'], nil, @url) if @opts['image'].present? and @opts['title'].blank? + return BaseOnebox.image_html(@opts['image'], nil, @url) if @opts['image'].present? && @opts['title'].blank? @opts['title'] ||= @opts['description'] return nil if @opts['title'].blank? diff --git a/lib/oneboxer/wikipedia_onebox.rb b/lib/oneboxer/wikipedia_onebox.rb index bfcef67cbc9..54457a5bb67 100644 --- a/lib/oneboxer/wikipedia_onebox.rb +++ b/lib/oneboxer/wikipedia_onebox.rb @@ -41,7 +41,7 @@ module Oneboxer unless paras.empty? cnt = 0 - while text.length < MAX_TEXT and cnt <= 3 + while text.length < MAX_TEXT && cnt <= 3 text << " " unless cnt == 0 paragraph = paras[cnt].inner_text[0..MAX_TEXT] paragraph.gsub!(/\[\d+\]/mi, "") diff --git a/lib/post_revisor.rb b/lib/post_revisor.rb index 984eb1743e7..74522e1a1b3 100644 --- a/lib/post_revisor.rb +++ b/lib/post_revisor.rb @@ -91,7 +91,7 @@ class PostRevisor # If found, update its description body = @post.cooked matches = body.scan(/\(.*)\<\/p\>/) - if matches and matches[0] and matches[0][0] + if matches && matches[0] && matches[0][0] new_description = matches[0][0] new_description = nil if new_description == I18n.t("category.replace_paragraph") category.update_column(:description, new_description) diff --git a/lib/rate_limiter/on_create_record.rb b/lib/rate_limiter/on_create_record.rb index 33d27a103a4..de8d3804bf8 100644 --- a/lib/rate_limiter/on_create_record.rb +++ b/lib/rate_limiter/on_create_record.rb @@ -47,7 +47,7 @@ class RateLimiter rate_limiter = send(limiter_method) return unless rate_limiter.present? - if @performed.present? and @performed[limiter_method] + if @performed.present? && @performed[limiter_method] rate_limiter.rollback! @performed[limiter_method] = false end diff --git a/lib/text_sentinel.rb b/lib/text_sentinel.rb index 5a482369f51..a07232aeeeb 100644 --- a/lib/text_sentinel.rb +++ b/lib/text_sentinel.rb @@ -40,7 +40,7 @@ class TextSentinel return false if @text.blank? || @text.strip.blank? # Entropy check if required - return false if @opts[:min_entropy].present? and (entropy < @opts[:min_entropy]) + return false if @opts[:min_entropy].present? && (entropy < @opts[:min_entropy]) # We don't have a comprehensive list of symbols, but this will eliminate some noise non_symbols = @text.gsub(TextSentinel.non_symbols_regexp, '').size @@ -48,10 +48,10 @@ class TextSentinel # Don't allow super long strings without spaces - return false if @opts[:max_word_length] and @text =~ /\w{#{@opts[:max_word_length]},}(\s|$)/ + return false if @opts[:max_word_length] && @text =~ /\w{#{@opts[:max_word_length]},}(\s|$)/ # We don't allow all upper case content in english - return false if (@text =~ /[A-Z]+/) and (@text == @text.upcase) + return false if (@text =~ /[A-Z]+/) && (@text == @text.upcase) true end diff --git a/lib/topic_view.rb b/lib/topic_view.rb index 179f9490243..e8018c26ff6 100644 --- a/lib/topic_view.rb +++ b/lib/topic_view.rb @@ -11,7 +11,7 @@ class TopicView # Special case: If the topic is private and the user isn't logged in, ask them # to log in! - if @topic.present? and @topic.private_message? and user.blank? + if @topic.present? && @topic.private_message? && user.blank? raise Discourse::NotLoggedIn.new end @@ -52,7 +52,7 @@ class TopicView def next_page last_post = @posts.last - if last_post.present? and (@topic.highest_post_number > last_post.post_number) + if last_post.present? && (@topic.highest_post_number > last_post.post_number) (@posts[0].post_number / SiteSetting.posts_per_page) + 1 end end diff --git a/spec/components/jobs_spec.rb b/spec/components/jobs_spec.rb index 3ca5c0592a7..000cf2d41ac 100644 --- a/spec/components/jobs_spec.rb +++ b/spec/components/jobs_spec.rb @@ -28,7 +28,7 @@ describe Jobs do it "should enqueue with the correct database id when the current_site_id option is given" do Sidekiq::Client.expects(:enqueue).with do |arg1, arg2| - arg2[:current_site_id] == 'test_db' and arg2[:sync_exec].nil? + arg2[:current_site_id] == 'test_db' && arg2[:sync_exec].nil? end Jobs.enqueue(:process_post, post_id: 1, current_site_id: 'test_db') end