Sha256: f9327f2cfb2334e3da7bc622a87f0edb506b18089c8d338c14a5b4054a7c707f

Contents?: true

Size: 1.04 KB

Versions: 16

Compression:

Stored size: 1.04 KB

Contents

require 'test_helper'

class CassandraObject::CallbacksTest < CassandraObject::TestCase
  class TestIssue < CassandraObject::Base
    self.column_family = '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_create', 'after_save'], issue.callback_history
  end

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

    issue.update_attribute :description, 'foo'

    assert_equal ['after_update', 'after_save'], 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

16 entries across 16 versions & 1 rubygems

Version Path
gotime-cassandra_object-2.13.0 test/unit/callbacks_test.rb
gotime-cassandra_object-2.12.5 test/unit/callbacks_test.rb
gotime-cassandra_object-2.12.4 test/unit/callbacks_test.rb
gotime-cassandra_object-2.12.3 test/unit/callbacks_test.rb
gotime-cassandra_object-2.12.2 test/unit/callbacks_test.rb
gotime-cassandra_object-2.12.1 test/unit/callbacks_test.rb
gotime-cassandra_object-2.12.0 test/unit/callbacks_test.rb
gotime-cassandra_object-2.11.9 test/unit/callbacks_test.rb
gotime-cassandra_object-2.11.8 test/unit/callbacks_test.rb
gotime-cassandra_object-2.11.7 test/unit/callbacks_test.rb
gotime-cassandra_object-2.11.6 test/unit/callbacks_test.rb
gotime-cassandra_object-2.11.5 test/unit/callbacks_test.rb
gotime-cassandra_object-2.11.4 test/unit/callbacks_test.rb
gotime-cassandra_object-2.11.3 test/unit/callbacks_test.rb
gotime-cassandra_object-2.11.2 test/unit/callbacks_test.rb
gotime-cassandra_object-2.11.1 test/unit/callbacks_test.rb