Sha256: 836d19ecdec29d4c381e497275511e2497e26b57d44b8a06fb5223348b7987f4

Contents?: true

Size: 1.22 KB

Versions: 17

Compression:

Stored size: 1.22 KB

Contents

require 'spec_helper'

describe Searchlogic::ActiveRecord::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

17 entries across 17 versions & 1 rubygems

Version Path
searchlogic-2.5.19 spec/searchlogic/active_record/consistency_spec.rb
searchlogic-2.5.18 spec/searchlogic/active_record/consistency_spec.rb
searchlogic-2.5.17 spec/searchlogic/active_record/consistency_spec.rb
searchlogic-2.5.16 spec/searchlogic/active_record/consistency_spec.rb
searchlogic-2.5.15 spec/searchlogic/active_record/consistency_spec.rb
searchlogic-2.5.14 spec/searchlogic/active_record/consistency_spec.rb
searchlogic-2.5.13 spec/searchlogic/active_record/consistency_spec.rb
searchlogic-2.5.12 spec/searchlogic/active_record/consistency_spec.rb
searchlogic-2.5.11 spec/searchlogic/active_record/consistency_spec.rb
searchlogic-2.5.10 spec/searchlogic/active_record/consistency_spec.rb
searchlogic-2.5.9 spec/searchlogic/active_record/consistency_spec.rb
searchlogic-2.5.8 spec/searchlogic/active_record/consistency_spec.rb
searchlogic-2.5.7 spec/searchlogic/active_record/consistency_spec.rb
searchlogic-2.5.6 spec/searchlogic/active_record/consistency_spec.rb
searchlogic-2.5.5 spec/searchlogic/active_record/consistency_spec.rb
searchlogic-2.5.4 spec/searchlogic/active_record/consistency_spec.rb
searchlogic-2.5.3 spec/searchlogic/active_record/consistency_spec.rb