Sha256: 1f914206e3402431eedaf47627409d164b700ed088a1dc4a2e86aba19698af06

Contents?: true

Size: 1.83 KB

Versions: 13

Compression:

Stored size: 1.83 KB

Contents

require 'helper'

describe Toy::References do
  uses_constants('User', 'Game')

  it "defaults references to empty hash" do
    User.references.should == {}
  end

  describe ".reference?" do
    before do
      Game.reference(:user)
    end

    it "returns true if attribute (symbol)" do
      Game.reference?(:user).should be_true
    end

    it "returns true if attribute (string)" do
      Game.reference?('user').should be_true
    end

    it "returns false if not attribute" do
      Game.reference?(:foobar).should be_false
    end
  end

  describe "declaring a reference" do
    before do
      @reference = Game.reference(:user)
    end

    it "knows about its references" do
      Game.references[:user].should == Toy::Reference.new(Game, :user)
    end

    it "returns reference" do
      @reference.should == Toy::Reference.new(Game, :user)
    end
  end

  describe "declaring a reference with options" do
    before do
      @reference = Game.reference(:user, :some_option => true)
    end
    let(:reference) { @reference }

    it "sets type" do
      reference.type.should be(User)
    end

    it "sets options" do
      reference.options.should == {:some_option => true}
    end
  end

  describe "declaring a reference with type" do
    before do
      @reference = Game.reference(:creator, User)
    end
    let(:reference) { @reference }

    it "sets type" do
      reference.type.should be(User)
    end

    it "sets options" do
      reference.options.should == {}
    end
  end

  describe "declaring a reference with type and options" do
    before do
      @reference = Game.reference(:creator, User, :some_option => true)
    end
    let(:reference) { @reference }

    it "sets type" do
      reference.type.should be(User)
    end

    it "sets options" do
      reference.options.should == {:some_option => true}
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
toystore-0.8.3 spec/toy/references_spec.rb
toystore-0.8.2 spec/toy/references_spec.rb
toystore-0.8.1 spec/toy/references_spec.rb
toystore-0.8.0 spec/toy/references_spec.rb
toystore-0.7.0 spec/toy/references_spec.rb
toystore-0.6.6 spec/toy/references_spec.rb
toystore-0.6.5 spec/toy/references_spec.rb
toystore-0.6.4 spec/toy/references_spec.rb
toystore-0.6.3 spec/toy/references_spec.rb
toystore-0.6.2 spec/toy/references_spec.rb
toystore-0.6.1 spec/toy/references_spec.rb
toystore-0.6 spec/toy/references_spec.rb
toystore-0.5 spec/toy/references_spec.rb