Sha256: 15a54b96dfcc052346226096f408564817247d5f9047708deb57b99816891bff

Contents?: true

Size: 1.32 KB

Versions: 62

Compression:

Stored size: 1.32 KB

Contents

require 'test_helper'

module Workarea
  class LockableTest < TestCase
    class Foo
      include Lockable

      def id
        '123'
      end
    end

    setup :foo
    teardown :unlock_foo

    def foo
      @foo ||= Foo.new
    end

    def unlock_foo
      foo.unlock!
    end

    def test_lock_key
      assert_equal('workarea/lockable_test/foo/123/lock', Foo.new.lock_key)
    end

    def test_default_lock_value
      assert_equal(foo.default_lock_value, foo.default_lock_value)
      refute_equal(Foo.new.default_lock_value, foo.default_lock_value)
    end

    def test_locked?
      refute(foo.locked?)

      foo.lock!
      assert(foo.locked?)
    end

    def test_lock!
      assert(foo.lock!)
      assert_raises(Lock::Locked) { foo.lock! }
      assert_raises(Lock::Locked) { Foo.new.lock! }

      foo.unlock!

      foo.lock!(value: 'bar')
      assert_equal('bar', Lock.find(foo.lock_key))

      foo.unlock!(value: 'bar')

      foo.lock!(ex: 1)
      sleep 2 # wait for lock to expire

      refute(foo.locked?)
      assert(foo.lock!)
    end

    def test_unlock!
      assert(foo.unlock!)

      foo.lock!
      assert(foo.unlock!)
      refute(foo.locked?)

      foo.lock!(value: 'bar')
      assert(foo.unlock!)
      assert(foo.locked?)
      assert(foo.unlock!(value: 'bar'))
      refute(foo.locked?)
    end
  end
end

Version data entries

62 entries across 62 versions & 1 rubygems

Version Path
workarea-core-3.5.15 test/models/workarea/lockable_test.rb
workarea-core-3.4.36 test/models/workarea/lockable_test.rb
workarea-core-3.5.14 test/models/workarea/lockable_test.rb
workarea-core-3.4.35 test/models/workarea/lockable_test.rb
workarea-core-3.5.13 test/models/workarea/lockable_test.rb
workarea-core-3.4.34 test/models/workarea/lockable_test.rb
workarea-core-3.5.12 test/models/workarea/lockable_test.rb
workarea-core-3.4.33 test/models/workarea/lockable_test.rb
workarea-core-3.5.11 test/models/workarea/lockable_test.rb
workarea-core-3.5.10 test/models/workarea/lockable_test.rb
workarea-core-3.4.32 test/models/workarea/lockable_test.rb
workarea-core-3.5.9 test/models/workarea/lockable_test.rb
workarea-core-3.4.31 test/models/workarea/lockable_test.rb
workarea-core-3.5.8 test/models/workarea/lockable_test.rb
workarea-core-3.4.30 test/models/workarea/lockable_test.rb
workarea-core-3.5.7 test/models/workarea/lockable_test.rb
workarea-core-3.4.29 test/models/workarea/lockable_test.rb
workarea-core-3.5.6 test/models/workarea/lockable_test.rb
workarea-core-3.4.28 test/models/workarea/lockable_test.rb
workarea-core-3.5.5 test/models/workarea/lockable_test.rb