Sha256: fa790e2d65946c7581c99a2705bd63fc024a0313c3205f4a5931f543186ff8b2

Contents?: true

Size: 1020 Bytes

Versions: 5

Compression:

Stored size: 1020 Bytes

Contents

require 'test_helper'

class CassandraObject::CallbacksTest < CassandraObject::TestCase
  class TestIssue < CassandraObject::Base
    self.column_family = 'Issues'
    key :uuid
    attribute :description, type: :string

    %w(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 ['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

5 entries across 5 versions & 1 rubygems

Version Path
gotime-cassandra_object-2.4.2 test/callbacks_test.rb
gotime-cassandra_object-2.4.1 test/callbacks_test.rb
gotime-cassandra_object-2.4.0 test/callbacks_test.rb
gotime-cassandra_object-2.3.6 test/callbacks_test.rb
gotime-cassandra_object-2.3.5 test/callbacks_test.rb