Sha256: 466f41fa0a9417b36b8f9bb6106b9363aa37fa529137e6305b0ec2b10da8d5dc

Contents?: true

Size: 1.25 KB

Versions: 3

Compression:

Stored size: 1.25 KB

Contents

require 'spec_helper'

shared_examples_for 'an id factory' do
  it "is a singleton" do
    MassiveRecord::ORM::IdFactory::AtomicIncrementation.included_modules.should include(Singleton)
  end

  describe "#next_for" do
    it "responds_to next_for" do
      subject.should respond_to :next_for
    end

    it "uses incomming table name if it's a string" do
      subject.should_receive(:next_id).with(hash_including(:table => "test_table"))
      subject.next_for "test_table"
    end

    it "usees incomming table name if it's a symbol" do
      subject.should_receive(:next_id).with(hash_including(:table => "test_table"))
      subject.next_for :test_table
    end

    it "asks object for it's table name if it responds to that" do
      Person.should_receive(:table_name).any_number_of_times.and_return("people")
      subject.should_receive(:next_id).with(hash_including(:table => "people"))
      subject.next_for(Person)
    end

    it "returns uniq ids" do
      ids = 10.times.inject([]) do |ids|
        ids << subject.next_for(Person)
      end

      ids.should eq ids.uniq
    end
  end

  describe ".next_for" do
    it "delegates to it's instance" do
      subject.should_receive(:next_for).with("cars")
      described_class.next_for("cars")
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
massive_record-0.2.2 spec/shared/orm/id_factories.rb
massive_record-0.2.2.rc2 spec/shared/orm/id_factories.rb
massive_record-0.2.2.rc1 spec/shared/orm/id_factories.rb