about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatt Jankowski <mjankowski@thoughtbot.com>2017-05-18 21:11:23 -0400
committerEugen Rochko <eugen@zeonfederated.com>2017-05-19 03:11:23 +0200
commit6e4c7d62118d5d1f2e966950edfdbc80cebd4d7c (patch)
tree886a8215d03ab975211a463bd33aee1331cc7bb9
parentd2542dcec0dafa8878efd2bd4fe53bd80256aa60 (diff)
Conditional validations no longer accept strings for if/unless (#3124)
-rw-r--r--app/controllers/remote_follow_controller.rb6
-rw-r--r--app/lib/application_extension.rb2
-rw-r--r--app/models/account.rb4
-rw-r--r--app/models/conversation.rb2
-rw-r--r--app/models/status.rb6
-rw-r--r--app/models/user.rb2
6 files changed, 13 insertions, 9 deletions
diff --git a/app/controllers/remote_follow_controller.rb b/app/controllers/remote_follow_controller.rb
index 625ce1488..2988231b1 100644
--- a/app/controllers/remote_follow_controller.rb
+++ b/app/controllers/remote_follow_controller.rb
@@ -4,7 +4,7 @@ class RemoteFollowController < ApplicationController
   layout 'public'
 
   before_action :set_account
-  before_action :gone, if: -> { @account.suspended? }
+  before_action :gone, if: :suspended_account?
 
   def new
     @remote_follow = RemoteFollow.new(session_params)
@@ -34,4 +34,8 @@ class RemoteFollowController < ApplicationController
   def set_account
     @account = Account.find_local!(params[:account_username])
   end
+
+  def suspended_account?
+    @account.suspended?
+  end
 end
diff --git a/app/lib/application_extension.rb b/app/lib/application_extension.rb
index 93c0f42f0..1d80b8c6d 100644
--- a/app/lib/application_extension.rb
+++ b/app/lib/application_extension.rb
@@ -4,6 +4,6 @@ module ApplicationExtension
   extend ActiveSupport::Concern
 
   included do
-    validates :website, url: true, unless: 'website.blank?'
+    validates :website, url: true, if: :website?
   end
 end
diff --git a/app/models/account.rb b/app/models/account.rb
index f418a0f8b..726e6c127 100644
--- a/app/models/account.rb
+++ b/app/models/account.rb
@@ -52,10 +52,10 @@ class Account < ApplicationRecord
   has_one :user, inverse_of: :account
 
   validates :username, presence: true
-  validates :username, uniqueness: { scope: :domain, case_sensitive: true }, unless: 'local?'
+  validates :username, uniqueness: { scope: :domain, case_sensitive: true }, unless: :local?
 
   # Local user validations
-  with_options if: 'local?' do
+  with_options if: :local? do
     validates :username, format: { with: /\A[a-z0-9_]+\z/i }, uniqueness: { scope: :domain, case_sensitive: false }, length: { maximum: 30 }
     validates :display_name, length: { maximum: 30 }
     validates :note, length: { maximum: 160 }
diff --git a/app/models/conversation.rb b/app/models/conversation.rb
index 3715e1049..08c1ce945 100644
--- a/app/models/conversation.rb
+++ b/app/models/conversation.rb
@@ -10,7 +10,7 @@
 #
 
 class Conversation < ApplicationRecord
-  validates :uri, uniqueness: true, if: :uri
+  validates :uri, uniqueness: true, if: :uri?
 
   has_many :statuses
 
diff --git a/app/models/status.rb b/app/models/status.rb
index 760ecc928..70021eb65 100644
--- a/app/models/status.rb
+++ b/app/models/status.rb
@@ -50,10 +50,10 @@ class Status < ApplicationRecord
   has_one :notification, as: :activity, dependent: :destroy
   has_one :preview_card, dependent: :destroy
 
-  validates :uri, uniqueness: true, unless: 'local?'
-  validates :text, presence: true, unless: 'reblog?'
+  validates :uri, uniqueness: true, unless: :local?
+  validates :text, presence: true, unless: :reblog?
   validates_with StatusLengthValidator
-  validates :reblog, uniqueness: { scope: :account }, if: 'reblog?'
+  validates :reblog, uniqueness: { scope: :account }, if: :reblog?
 
   default_scope { order(id: :desc) }
 
diff --git a/app/models/user.rb b/app/models/user.rb
index 66a8edfc1..7cf3a1290 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -45,7 +45,7 @@ class User < ApplicationRecord
   belongs_to :account, inverse_of: :user, required: true
   accepts_nested_attributes_for :account
 
-  validates :locale, inclusion: I18n.available_locales.map(&:to_s), unless: 'locale.nil?'
+  validates :locale, inclusion: I18n.available_locales.map(&:to_s), if: :locale?
   validates :email, email: true
 
   scope :recent,    -> { order(id: :desc) }