Sha256: 50726a50fde9f08f40e06caed2fc02741afa0699117290e84f5014dc88487b40

Contents?: true

Size: 1.59 KB

Versions: 4

Compression:

Stored size: 1.59 KB

Contents

require 'spec_helper'

describe "HasManyRelations" do

  integration_test do

    before :all do
      @account = Z::Account.create!(
        :name => "ZObject Integration Test Account", 
        :status => "Draft",
        :currency => "USD", 
        :bill_cycle_day => 1)
      @billy = Z::Contact.create!(
        :account => @account,
        :first_name => "Billy",
        :last_name => "Blanks")
      @franky = Z::Contact.create!(
        :account => @account,
        :first_name => "Franky",
        :last_name => "Funhouse")
    end

    after :all do
      # Delete the account to cleanup in case a test failed.
      @account.delete if @account
    end

    it "can specify conditions and order" do
      Z::Account.instance_eval do
        has_many :billies, :conditions => { :first_name => "Billy" }, :order => [:first_name, :desc], :class_name => 'Z::Contact'
      end
      @account.billies.to_a == [@billy]
      @account.billies.scope.order_attribute.should == :first_name
      @account.billies.scope.order_direction.should == :desc
    end

    it "can behave like an array" do
      @account.contacts.size.should == 2
      @account.contacts.map(&:first_name).should =~ %w{Billy Franky}
    end

    it "can respond to functions on the Relation" do
      @account.contacts.unload
      @account.contacts.loaded?.should be_false
      @account.contacts.reload
      @account.contacts.loaded?.should be_true
      @account.contacts.where(:last_name => "Funhouse").to_a.should == [@franky]
      @account.contacts.loaded?.should be_true
      @account.contacts.to_a.should =~ [@billy, @franky]
    end

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
active_zuora-2.0.3 spec/has_many_integration_spec.rb
active_zuora-2.0.2 spec/has_many_integration_spec.rb
active_zuora-2.0.1 spec/has_many_integration_spec.rb
active_zuora-2.0.0 spec/has_many_integration_spec.rb