Sha256: 664cb4d42f0ed9bd7045f487f02cd54a47432407f8cd895140005c9631087f0d

Contents?: true

Size: 1.39 KB

Versions: 5

Compression:

Stored size: 1.39 KB

Contents

require 'helper'

class GroupedScope::HasManyThroughTest < GroupedScope::TestCase
  
  before do
    @e1 = FactoryGirl.create(:employee, :group_id => 1)
    @e1.departments << Department.hr << Department.finance
    @e2 = FactoryGirl.create(:employee, :group_id => 1)
    @e2.departments << Department.it
    @all_group_departments = [Department.hr, Department.it, Department.finance]
  end
  
  describe 'For default association' do

    it 'scope to owner' do
      assert_sql(/"employee_id" = #{@e1.id}/) do
        @e1.departments(true)
      end
    end
    
    it 'scope count to owner' do
      assert_sql(/"employee_id" = #{@e1.id}/) do
        @e1.departments(true).count
      end
    end
    
  end
  
  describe 'For grouped association' do

    it 'scope to group' do
      
      assert_sql(/"employee_id" IN \(SELECT "employees"\."id" FROM "employees"  WHERE "employees"\."group_id" = #{@e1.group_id}\)/) do
        @e2.group.departments(true)
      end
    end
    
    it 'scope count to group' do
      assert_sql(/"employee_id" IN \(SELECT "employees"\."id" FROM "employees"  WHERE "employees"\."group_id" = #{@e1.group_id}\)/) do
        @e1.group.departments(true).count
      end
    end
    
    it 'have a group count equal to sum of separate owner counts' do
      assert_equal @e1.departments(true).count + @e2.departments(true).count, @e2.group.departments(true).count
    end
    
  end
  
  
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
grouped_scope-3.2.1 test/cases/has_many_through_test.rb
grouped_scope-3.2.0 test/cases/has_many_through_test.rb
grouped_scope-3.1.2 test/cases/has_many_through_test.rb
grouped_scope-3.1.1 test/cases/has_many_through_test.rb
grouped_scope-3.1.0 test/cases/has_many_through_test.rb