Coursemology/coursemology2

View on GitHub
app/models/concerns/safe_mark_as_read_concern.rb

Summary

Maintainability
A
35 mins
Test Coverage
# frozen_string_literal: true
module SafeMarkAsReadConcern
  extend ActiveSupport::Concern

  def safely_mark_as_read!(options)
    unless respond_to?(:mark_as_read!) || Rails.env.production?
      raise "Did you have #{self.class.name} `acts_as_readable`?"
    end

    mark_as_read!(options)
  rescue ActiveRecord::RecordNotUnique
    raise if unread?(options[:for])
  end
end