Sha256: 7c832b679ad01a1da8c93e72c27a045d6d3eb3ce9c43ea5c455cf2d1bc4c7291

Contents?: true

Size: 1.32 KB

Versions: 23

Compression:

Stored size: 1.32 KB

Contents

require File.expand_path("../../../spec_helper", __FILE__)

describe "Friendly::Associations::Set" do
  before do
    @klass             = Class.new
    @association_klass = stub
    @set               = Friendly::Associations::Set.new(@klass, @association_klass)
    @assoc             = stub
    @association_klass.stubs(:new).
      with(@klass, :my_awesome_association, {}).returns(@assoc)
  end

  describe "adding an association" do
    before do
      @set.add(:my_awesome_association)
    end

    it "creates an association and adds it to its hash by name" do
      @set.associations[:my_awesome_association].should == @assoc
    end

    it "adds an instance method to the klass through which to acces the assoc" do
      @doc   = @klass.new
      @scope = stub
      @klass.stubs(:association_set).returns(@set)
      @assoc.stubs(:scope).with(@doc).returns(@scope)
      @doc.my_awesome_association.should == @scope
    end
  end

  it "can return the association by name" do
    @set.add(:my_awesome_association)
    @set.get(:my_awesome_association).should == @assoc
  end

  it "provides the scope for an association by name" do
    @doc   = stub
    @scope = stub
    @assoc.stubs(:scope).with(@doc).returns(@scope)
    @set.add(:my_awesome_association)
    @set.get_scope(:my_awesome_association, @doc).should == @scope
  end
end

Version data entries

23 entries across 23 versions & 7 rubygems

Version Path
ihoka-friendly-0.8.0.pre spec/unit/associations/set_spec.rb
ihoka-friendly-0.7.1.2 spec/unit/associations/set_spec.rb
ihoka-friendly-0.7.1.1 spec/unit/associations/set_spec.rb
ihoka-friendly-0.7.1 spec/unit/associations/set_spec.rb
ihoka-friendly-0.7.0 spec/unit/associations/set_spec.rb
friendly-0.6.0 spec/unit/associations/set_spec.rb
honkster-friendly-0.5.3 spec/unit/associations/set_spec.rb
honkster-friendly-0.5.2 spec/unit/associations/set_spec.rb
honkster-friendly-0.5.1 spec/unit/associations/set_spec.rb
wayne-friendly-0.5.1 spec/unit/associations/set_spec.rb
wego-friendly-0.5.1 spec/unit/associations/set_spec.rb
arunthampi-friendly-0.5.1 spec/unit/associations/set_spec.rb
friendly_postgres-0.5.1 spec/unit/associations/set_spec.rb
friendly-0.5.1 spec/unit/associations/set_spec.rb
friendly-0.5.0 spec/unit/associations/set_spec.rb
friendly_postgres-0.4.5 spec/unit/associations/set_spec.rb
friendly-0.4.5 spec/unit/associations/set_spec.rb
friendly-0.4.4 spec/unit/associations/set_spec.rb
friendly_postgres-0.4.3 spec/unit/associations/set_spec.rb
friendly-0.4.3 spec/unit/associations/set_spec.rb