Sha256: cb5e324e5cfc0c35fd965a9daea6e04b9ac0a8ecf18699cd62f2e4f16873a4a1

Contents?: true

Size: 1.3 KB

Versions: 4

Compression:

Stored size: 1.3 KB

Contents

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

class GroupedScope::HasManyThroughAssociationTest < GroupedScope::TestCase
  
  def setup
    setup_environment
    @e1 = Factory(:employee, :group_id => 1)
    @e1.departments << Department.hr << Department.finance
    @e2 = Factory(:employee, :group_id => 1)
    @e2.departments << Department.it
    @all_group_departments = [Department.hr, Department.it, Department.finance]
  end
  
  
  context 'For default association' do

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

    should 'scope to group' do
      assert_sql(/employee_id IN \(#{@e1.id},#{@e2.id}\)/) do
        @e2.group.departments(true)
      end
    end
    
    should 'scope count to group' do
      assert_sql(/employee_id IN \(#{@e1.id},#{@e2.id}\)/) do
        @e1.group.departments(true).count
      end
    end
    
    should 'have a group count equal to sum of seperate owner counts' do
      assert_equal @e1.departments(true).count + @e2.departments(true).count, @e2.group.departments(true).count
    end
    
  end
  
  
  
end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
decisiv-grouped_scope-0.5.1.1 test/grouped_scope/has_many_through_association_test.rb
decisiv-grouped_scope-0.6.0.1 test/grouped_scope/has_many_through_association_test.rb
metaskills-grouped_scope-0.5.1 test/grouped_scope/has_many_through_association_test.rb
metaskills-grouped_scope-0.6.0 test/grouped_scope/has_many_through_association_test.rb