Skip to content

Commit

Permalink
Test now passing.
Browse files Browse the repository at this point in the history
  • Loading branch information
metaskills committed Dec 5, 2011
1 parent 548c82e commit 913a61b
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 16 deletions.
19 changes: 16 additions & 3 deletions TODO
Expand Up @@ -13,6 +13,21 @@

Notes:

>> User.reflections[:boxes]
=> #<ActiveRecord::Reflection::ThroughReflection:0x007faafdddd538 @macro=:has_many, @name=:boxes, @options={:through=>:columns, :readonly=>false, :order=>"columns.position, boxes.position", :extend=>[UserBoxesAssociationExtension]}, @active_record=User(14 columns), @plural_name="boxes", @collection=true>
>> User.reflections[:boxes].source_reflection
=> #<ActiveRecord::Reflection::AssociationReflection:0x007faafdbf1d00 @macro=:has_many, @name=:boxes, @options={:order=>"position", :extend=>[]}, @active_record=Column(3 columns), @plural_name="boxes", @collection=true>
>> User.reflections[:boxes].through_reflection
=> #<ActiveRecord::Reflection::AssociationReflection:0x007faafddf4df0 @macro=:has_many, @name=:columns, @options={:order=>"position", :extend=>[]}, @active_record=User(14 columns), @plural_name="columns", @collection=true, @class_name="Column", @klass=Column(3 columns)>
>> User.reflections[:boxes].source_reflection_names
=> [:box, :boxes]
>> User.reflections[:boxes].source_options
=> {:order=>"position", :extend=>[]}
>> User.reflections[:boxes].through_options
=> {:order=>"position", :extend=>[]}
>> User.reflections[:boxes].class_name
=> "Box"


>> User.reflections[:columns].primary_key_column
=> #<ActiveRecord::ConnectionAdapters::PostgreSQLColumn:0x007fdcd859b868 @name="id", @sql_type="integer", @null=false, @limit=nil, @precision=nil, @scale=nil, @type=:integer, @default=nil, @primary=true, @coder=nil>
Expand All @@ -26,8 +41,6 @@
=> User(14 columns)




equalities = wheres.grep(Arel::Nodes::Equality)

>> ActiveRecord::Associations::AssociationScope.new(User.first.association(:columns)).scope.where_values
Expand Down Expand Up @@ -80,7 +93,7 @@

* Kill &block stuff.


* Make association conditions use pure SQL. Avoid 100's of IDs.



4 changes: 1 addition & 3 deletions lib/grouped_scope/arish/associations/association_scope.rb
Expand Up @@ -55,9 +55,7 @@ def add_constraints(scope)
scope = scope.where(interpolate(condition))
end
else
# GroupedScope changed this line.
# constraint = table[key].eq(foreign_table[foreign_key])
constraint = table[key].in(owner.group.ids)
constraint = table[key].eq(foreign_table[foreign_key])

if reflection.type
type = chain[i + 1].klass.base_class.name
Expand Down
Expand Up @@ -38,6 +38,9 @@ def find_ungrouped_reflection(model, name)
def ungrouped_reflection_options(ungrouped_reflection)
ungrouped_reflection.options.dup.tap do |options|
options[:class_name] = ungrouped_reflection.class_name
if ungrouped_reflection.source_reflection && options[:source].blank?
options[:source] = ungrouped_reflection.source_reflection.name
end
end
end

Expand Down
19 changes: 9 additions & 10 deletions test/grouped_scope/has_many_through_test.rb
Expand Up @@ -29,21 +29,20 @@ class GroupedScope::HasManyThroughTest < GroupedScope::TestCase
describe 'For grouped association' do

it 'scope to group' do
raise @e2.group.departments(true).inspect
assert_sql(/"employee_id" IN \(#{@e1.id}, #{@e2.id}\)/) do
@e2.group.departments(true)
end
end

# it 'scope count to group' do
# assert_sql(/employee_id IN \(#{@e1.id},#{@e2.id}\)/) do
# @e1.group.departments(true).count
# end
# end
#
# it '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
it 'scope count to group' do
assert_sql(/"employee_id" IN \(#{@e1.id}, #{@e2.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

Expand Down

0 comments on commit 913a61b

Please sign in to comment.