Sha256: 0b5839333027d47f10239521cb3c7973a0055ff57809b8c8ba36d13512d66331

Contents?: true

Size: 1.7 KB

Versions: 2

Compression:

Stored size: 1.7 KB

Contents

require "helper"

class TestOhmBoundaries < Test::Unit::TestCase
  setup do
    Ohm.flush
  end

  class Person < Ohm::Model
    include Ohm::Boundaries

    attribute :name
    index :name
  end

  context "when there are no People" do
    should "have a nil Person.first" do
      assert_nil Person.first
    end

    should "have a nil Person.last" do
      assert_nil Person.last
    end
  end

  context "after creating a single Person named matz" do
    setup do
      @matz = Person.create(:name => "matz")
    end

    should "have matz as the first person" do
      assert_equal @matz, Person.first
    end

    should "have matz as the last person" do
      assert_equal @matz, Person.last
    end
  end

  context "after creating matz first then linus next" do
    setup do
      @matz  = Person.create(:name => "matz")
      @linus = Person.create(:name => "linus")
    end

    should "have matz as the first Person" do
      assert_equal @matz, Person.first
    end

    should "have linus as the last Person" do
      assert_equal @linus, Person.last
    end

    context "when searching name => matz" do
      test "matz is the first and last" do
        assert_equal @matz, Person.first(:name => "matz")
        assert_equal @matz, Person.last(:name => "matz")
      end
    end

    context "when searching name => linus" do
      test "linus is first and last" do
        assert_equal @linus, Person.first(:name => "linus")
        assert_equal @linus, Person.last(:name => "linus")
      end
    end

    context "when searching name => quentin" do
      should "have nil as first and last" do
        assert_nil Person.first(:name => "quentin")
        assert_nil Person.last(:name => "quentin")
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ohm-contrib-0.0.28 test/test_ohm_boundaries.rb
ohm-contrib-0.0.27 test/test_ohm_boundaries.rb