Sha256: c1e9d74300e38ecb1e8479b292e92e76ff6063b4a3f9aee62a878cdb065260c5

Contents?: true

Size: 1.17 KB

Versions: 6

Compression:

Stored size: 1.17 KB

Contents

require 'helper'

class TestActiveRecordCallbacHooks < Test::Unit::TestCase
  should "have all callbacks functioning properly" do
    book = Book.new(:name => "set cleo id", :author => "Rob Meyer")
    assert_nil book.cleo_id
    assert_nil Cleo::Reference.find(:first, :conditions => ["record_type = ? and record_id = ?", "Book", book.id])

    assert book.save!
    book_id = book.id

    assert book.cleo_id
    ref = Cleo::Reference.find(:first, :conditions => ["record_type = ? and record_id = ?", "Book", book_id])
    assert_not_nil ref

    assert book.destroy
    assert_nil Cleo::Reference.find(:first, :conditions => ["record_type = ? and record_id = ?", "Book", book_id])
    assert_nil Cleo.find(ref.id)
  end

  should "update cleo on record update" do
    book = Book.new(:name => "update cleo", :author => "Rob Meyer")
    assert book.save!
    cleo_record = Cleo.find(book.cleo_id)
    assert_not_nil cleo_record
    book.name = "Updated my Cleo"
    assert book.save!

    updated_cleo_record = Cleo.find(book.cleo_id)
    assert_equal book.name.downcase, updated_cleo_record.name
    assert_not_equal cleo_record.name, updated_cleo_record.name

    assert book.destroy
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
acts_as_cleo-2.4.5 test/unit/test_active_record_callback_hooks.rb
acts_as_cleo-2.4.4 test/unit/test_active_record_callback_hooks.rb
acts_as_cleo-2.4.3 test/unit/test_active_record_callback_hooks.rb
acts_as_cleo-2.4.2 test/unit/test_active_record_callback_hooks.rb
acts_as_cleo-2.4.1 test/unit/test_active_record_callback_hooks.rb
acts_as_cleo-2.4.0 test/unit/test_active_record_callback_hooks.rb