Sha256: 6952cb6e749739cc619135e3f1e59a8d7e1ed22f2b7b1d88121f0d6bc2794f37

Contents?: true

Size: 1.02 KB

Versions: 7

Compression:

Stored size: 1.02 KB

Contents

require 'test_helper'

class Superstore::CallbacksTest < Superstore::TestCase
  class TestIssue < Superstore::Base
    self.table_name = 'issues'
    string :description

    %w(before_validation after_validation after_save after_create after_update after_destroy).each do |method|
      send(method) do
        callback_history << method
      end
    end

    def reset_callback_history
      @callback_history = []
    end

    def callback_history
      @callback_history ||= []
    end
  end

  test 'create' do
    issue = TestIssue.create

    assert_equal ['before_validation', 'after_validation', 'after_save', 'after_create'], issue.callback_history
  end

  test 'update' do
    issue = TestIssue.create
    issue.reset_callback_history

    issue.update_attribute :description, 'foo'

    assert_equal ['after_save', 'after_update'], issue.callback_history
  end

  test 'destroy' do
    issue = TestIssue.create
    issue.reset_callback_history

    issue.destroy

    assert_equal ['after_destroy'], issue.callback_history
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
superstore-2.4.0 test/unit/callbacks_test.rb
superstore-2.3.0 test/unit/callbacks_test.rb
superstore-2.2.0 test/unit/callbacks_test.rb
superstore-2.1.3 test/unit/callbacks_test.rb
superstore-2.1.2 test/unit/callbacks_test.rb
superstore-2.1.1 test/unit/callbacks_test.rb
superstore-2.1.0 test/unit/callbacks_test.rb