Sha256: 57c39e05e3a1b4413e8714623abd9d7afd956406864684189636194cff38fff1

Contents?: true

Size: 1.02 KB

Versions: 3

Compression:

Stored size: 1.02 KB

Contents

require File.dirname(__FILE__) + '/helper'

context "Joins" do
  specify "simple == on an association" do
    sql = User.select { |m| m.account.email == 'chris@ozmm.org' }
    sql.to_hash.should ==  { 
      :conditions => "accounts.email = 'chris@ozmm.org'", 
      :include => [:account] 
    }
  end

  specify "simple mixed == on an association" do
    sql = User.select { |m| m.name == 'chris' && m.account.email == 'chris@ozmm.org' }
    sql.to_hash.should ==  { 
      :conditions => "(users.`name` = 'chris' AND accounts.email = 'chris@ozmm.org')", 
      :include => [:account] 
    }
  end

  specify "multiple associations" do
    sql = User.select { |m| m.ideas.title == 'New Freezer' || m.invites.email == 'pj@hyett.com' }
    sql.to_hash.should ==  { 
      :conditions => "(ideas.title = 'New Freezer' OR invites.email = 'pj@hyett.com')",
      :include => [:ideas, :invites]
    }
  end

  specify "non-existant associations" do
    sql = User.select { |m| m.liquor.brand == 'Jack' }
    should.raise { sql.to_hash } 
  end
end

Version data entries

3 entries across 2 versions & 1 rubygems

Version Path
ambition-0.1.1 test/join_test.rb
ambition-0.1.0 ./test/join_test.rb
ambition-0.1.1 ./test/join_test.rb