Sha256: cf5c56a6a4cc5e7d93a9a8c3120c69fb6423ab0a71d0cbcd2afabc456f62827e

Contents?: true

Size: 980 Bytes

Versions: 7

Compression:

Stored size: 980 Bytes

Contents

require 'spec_helper'
class Foo < ActiveRecord::Base
  belongs_to :that
  has_many :foo_bars
  has_many :bars, :through => :foo_bars
  has_one :noob
end

class Bar < ActiveRecord::Base
  has_many :foo_bars
  has_many :foos, :through => :foo_bars
end

describe ConnectionManager::Associations do
  
  it "should add associations as keys to @defined_associations" do
    Foo.defined_associations.keys.should eql([:belongs_to,:has_many,:has_one]) 
    Bar.defined_associations.keys.should eql([:has_many])
  end
  
  context "defined_association values" do
    it "should be an array of association options (which are Arrays as well)" do
      Foo.defined_associations[:belongs_to].should eql([[:that]])
      Foo.defined_associations[:has_many].should eql([[:foo_bars],[:bars, {:through=>:foo_bars, :extend=>[]}]]) # when options are present active_record addes the :extend option defaulted to []
      Foo.defined_associations[:has_one].should eql([[:noob]])
    end
  end
  
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
connection_manager-0.2.6 spec/lib/associations_spec.rb
connection_manager-0.2.5 spec/lib/associations_spec.rb
connection_manager-0.2.4 spec/lib/associations_spec.rb
connection_manager-0.2.3 spec/lib/associations_spec.rb
connection_manager-0.2.2 spec/lib/associations_spec.rb
connection_manager-0.2.1 spec/lib/associations_spec.rb
connection_manager-0.2.0 spec/lib/associations_spec.rb