Skip to content

Commit

Permalink
Refactory AssociationReflectionTest and add some defered stubs.
Browse files Browse the repository at this point in the history
  • Loading branch information
metaskills committed Sep 24, 2008
1 parent ccb540c commit 96d0858
Showing 1 changed file with 32 additions and 22 deletions.
54 changes: 32 additions & 22 deletions test/grouped_scope/association_reflection_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,51 +5,61 @@ class AssociationReflectionTest < GroupedScope::TestCase
def setup
setup_environment
end

context 'Raise and exception' do

setup { @reflection_klass = GroupedScope::AssociationReflection }

should 'when a association does not exist' do
assert_raise(ArgumentError) { @reflection_klass.new(Employee,:foobars) }

context 'For initialization' do

context 'Raise and exception' do

setup { @reflection_klass = GroupedScope::AssociationReflection }

should 'when a association does not exist' do
assert_raise(ArgumentError) { @reflection_klass.new(Employee,:foobars) }
end

should 'when the association is not a has_many or a has_and_belongs_to_many' do
Employee.class_eval { belongs_to(:foo) }
assert_raise(ArgumentError) { @reflection_klass.new(Employee,:foo) }
end

end

should 'when the association is not a has_many or a has_and_belongs_to_many' do
Employee.class_eval { belongs_to(:foo) }
assert_raise(ArgumentError) { @reflection_klass.new(Employee,:foo) }
should_eventually 'TEST COLLECTION READER METHOD GENERATION' do

end

end


context 'For #ungrouped_reflection' do

setup do
@ungrouped_reflection = Employee.reflections[:reports]
@grouped_reflection = Employee.reflections[:grouped_scope_reports]
end

should 'access ungrouped reflection' do
assert_equal Employee.reflections[:reports],
Employee.reflections[:grouped_scope_reports].ungrouped_reflection
assert_equal @ungrouped_reflection, @grouped_reflection.ungrouped_reflection
end

should 'delegate instance methods to #ungrouped_reflection' do
[:class_name,:klass,:table_name,:quoted_table_name,:primary_key_name,:active_record,
:association_foreign_key,:counter_cache_column,:source_reflection].each do |m|
assert_equal Employee.reflections[:reports].send(m),
Employee.reflections[:grouped_scope_reports].send(m),
"The method #{m.inspect} does not appear to be proxed to the ungrouped reflection."
assert_equal @ungrouped_reflection.send(m), @grouped_reflection.send(m),
"The method #{m.inspect} does not appear to be proxied to the ungrouped reflection."
end
end

should 'not delegate to #ungrouped_reflection for #options and #name' do
assert_not_equal Employee.reflections[:reports].name, Employee.reflections[:grouped_scope_reports].name
assert_not_equal Employee.reflections[:reports].options, Employee.reflections[:grouped_scope_reports].options
assert_not_equal @ungrouped_reflection.name, @grouped_reflection.name
assert_not_equal @ungrouped_reflection.options, @grouped_reflection.options
end

should 'derive class name to same as ungrouped reflection' do
assert_equal Employee.reflections[:reports].send(:derive_class_name),
Employee.reflections[:grouped_scope_reports].send(:derive_class_name)
assert_equal @ungrouped_reflection.send(:derive_class_name), @grouped_reflection.send(:derive_class_name)
end

should 'derive primary key name to same as ungrouped reflection' do
assert_equal Employee.reflections[:reports].send(:derive_primary_key_name),
Employee.reflections[:grouped_scope_reports].send(:derive_primary_key_name)
assert_equal @ungrouped_reflection.send(:derive_primary_key_name), @grouped_reflection.send(:derive_primary_key_name)
end

end
Expand Down

0 comments on commit 96d0858

Please sign in to comment.