Sha256: 3f19200af3fc95731245f48fa4e7892ebabdf20d47b8dd4711c8a8ef63a13e13

Contents?: true

Size: 1.49 KB

Versions: 8

Compression:

Stored size: 1.49 KB

Contents

require 'cases/helper'
require 'models/notification'
require 'models/user'

class SuppressorTest < ActiveRecord::TestCase
  def test_suppresses_create
    assert_no_difference -> { Notification.count } do
      Notification.suppress do
        Notification.create
        Notification.create!
        Notification.new.save
        Notification.new.save!
      end
    end
  end

  def test_suppresses_update
    user = User.create! token: 'asdf'

    User.suppress do
      user.update token: 'ghjkl'
      assert_equal 'asdf', user.reload.token

      user.update! token: 'zxcvbnm'
      assert_equal 'asdf', user.reload.token

      user.token = 'qwerty'
      user.save
      assert_equal 'asdf', user.reload.token

      user.token = 'uiop'
      user.save!
      assert_equal 'asdf', user.reload.token
    end
  end

  def test_suppresses_create_in_callback
    assert_difference -> { User.count } do
      assert_no_difference -> { Notification.count } do
        Notification.suppress { UserWithNotification.create! }
      end
    end
  end

  def test_resumes_saving_after_suppression_complete
    Notification.suppress { UserWithNotification.create! }

    assert_difference -> { Notification.count } do
      Notification.create!(message: "New Comment")
    end
  end

  def test_suppresses_validations_on_create
    assert_no_difference -> { Notification.count } do
      Notification.suppress do
        User.create
        User.create!
        User.new.save
        User.new.save!
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
ibm_db-5.2.0 test/cases/suppressor_test.rb
ibm_db-5.1.0 test/cases/suppressor_test.rb
ibm_db-5.0.5 test/cases/suppressor_test.rb
ibm_db-5.0.4 test/cases/suppressor_test.rb
ibm_db-5.0.3 test/cases/suppressor_test.rb
ibm_db-5.0.2 test/cases/suppressor_test.rb
ibm_db-4.0.0-x86-mingw32 test/cases/suppressor_test.rb
ibm_db-4.0.0 test/cases/suppressor_test.rb