lundi 2 mai 2016

Optimistic Locking starts with nil?

Let me preface this by saying that the behavior of rails optimistic locking seems to be working, I'm simply trying to understand why my unit test is returning the value it is. When running my unit test, to check if the lock_version increments, and assert_not_equal I get a passing test. And when I set the test to assert_equal it fails, but the message returns nil instead of 0. Why?

lock_version details Data_type => Number(38,0), Nullable => No, Data_default => 0

Unit Test

  test "optimistic locking increments" do
    invoice = create(:invoice)
    first  = Invoice.find(invoice.invoice_id)
    second = Invoice.find(invoice.invoice_id)
    first.currency  = "GBP"
    second.currency = "EUR"
    first.save
    second.save
    assert_equal first.lock_version, second.lock_version 
  end

Expected: nil Actual: 1

Aucun commentaire:

Enregistrer un commentaire