Sha256: 89bad7946bfa20a19adcbff869681d87a380188484f8b25ac09d95d4ac037ee4

Contents?: true

Size: 536 Bytes

Versions: 9

Compression:

Stored size: 536 Bytes

Contents

class SupportSubscription < ApplicationRecord
  belongs_to :support_thread
  belongs_to :user

  scope :optin, ->{ where(subscription_type: :optin) }
  scope :optout, ->{ where(subscription_type: :optout) }

  validates :subscription_type, presence: true, inclusion: { in: %w{ optin optout } }
  validates :user_id, uniqueness: { scope: :support_thread_id }

  def toggle!
    case subscription_type
    when "optin"
      update(subscription_type: "optout")
    when "optout"
      update(subscription_type: "optin")
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
help_center-0.1.0 app/models/support_subscription.rb
help_center-0.0.9 app/models/support_subscription.rb
help_center-0.0.8 app/models/support_subscription.rb
help_center-0.0.7 app/models/support_subscription.rb
help_center-0.0.6 app/models/support_subscription.rb
help_center-0.0.4 app/models/support_subscription.rb
help_center-0.0.3 app/models/support_subscription.rb
help_center-0.0.2 app/models/support_subscription.rb
help_center-0.0.1 app/models/support_subscription.rb