Sha256: 44a12b79532ced8b4eaa8d01643e15e307e0e884b053e49f58d7d4780b6cd9d4

Contents?: true

Size: 1.25 KB

Versions: 9

Compression:

Stored size: 1.25 KB

Contents

require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")

describe "Consistency" do
  it "should merge joins with consistent conditions" do
    user_group = UserGroup.create
    user_group.users.user_groups_name_like("name").user_groups_id_gt(10).scope(:find)[:joins].should == [
      "INNER JOIN \"user_groups_users\" ON \"user_groups_users\".user_id = \"users\".id",
      "INNER JOIN \"user_groups\" ON \"user_groups\".id = \"user_groups_users\".user_group_id"
    ]
  end
  
  it "should respect parenthesis when reordering conditions" do
    joins = [
      "INNER JOIN \"table\" ON (\"b\".user_id = \"a\".id)",
      "INNER JOIN \"table\" ON (\"b\".id = \"a\".user_group_id)"
    ]
    ActiveRecord::Base.send(:merge_joins, joins).should == [
      "INNER JOIN \"table\" ON \"a\".id = \"b\".user_id",
      "INNER JOIN \"table\" ON \"a\".user_group_id = \"b\".id"
    ]
  end
  
  it "shuold not convert joins to strings when delegating via associations" do
    User.alias_scope :has_id_gt, lambda { User.id_gt(10).has_name.orders_id_gt(10) }
    User.alias_scope :has_name, lambda { User.orders_created_at_after(Time.now).name_equals("ben").username_equals("ben") }
    Company.users_has_id_gt.proxy_options[:joins].should == {:users=>[:orders]}
  end
end

Version data entries

9 entries across 9 versions & 3 rubygems

Version Path
aq1018-searchlogic-2.4.17 spec/active_record/consistency_spec.rb
aq1018-searchlogic-2.4.16 spec/active_record/consistency_spec.rb
aq1018-searchlogic-2.4.15 spec/active_record/consistency_spec.rb
searchlogic-2.4.14 spec/active_record/consistency_spec.rb
searchlogic-2.4.13 spec/active_record/consistency_spec.rb
searchlogic-2.4.12 spec/active_record/consistency_spec.rb
searchlogic-2.4.11 spec/active_record/consistency_spec.rb
lazy-searchlogic-2.4.10 spec/active_record/consistency_spec.rb
searchlogic-2.4.10 spec/active_record/consistency_spec.rb