paploo / sequel_eager_test

A test of Sequel's eager loading that fails in a spot that I think it should pass.

This URL has Read+Write access

name age message
file README.txt Loading commit data...
directory config/
directory db/
file init.rb
directory lib/
directory log/
file run_tests.rb
directory spec/
README.txt
===== SOLUTIONS FOUND =====
The issue was that the :key option takes Symbols *ONLY*... I inadvertently
gave a String out of habit.  :)  It all runs fine now!

===== OVERVIEW =====

This project is either a test of an eager loading bug I found in Sequel 3.0.0, or
a demonstration of my lack of understanding of eager associations in Sequel 3.0.0.

My assumption is that by writing my own :eager_block, I could solve the problem,
but I'd expect that Sequel 3.0.0 would do fine for me with such simple
associations.

===== INSTALLATION =====

To install:
1. Create a database
2. Enter the correct parameters into "config/db_config.rb"
3. Run "ruby init.rb" (this will automatically rebuild the schema and data each time).

===== RUNNING =====

To run the tests, simply run
  $ spec -r init.rb spec"
or, if you like prettier output:
  $ spec -r init.rb -f specdoc spec
 or, if you are lazy, you can run:
  # ruby run_tests.rb
  
All of the tests are in the spec directory, and should all pass if the bug if fixed.

===== DETAILS =====

BUG DESCRIPTION:

Associations that do not use the default foreign key assignment do not work with
eager loading.


TEST ENVIRONMENT:

MacBook Pro / 2.66 GHz Intel Core 2 Duo / 4 GB RAM
Mac OS X 10.5.6
Ruby 1.9.1p0
PostgreSQL 8.2.4
Relevant Gems:
  sequel (3.0.0)
  rspec (1.2.6)


TEST OBJECT MODEL:

For this example, I have created a simple, though artificially contrived object
model:

Author:
 - has many articles
 - has many aliases
 
Article:
 - belongs to article via :article_id
 
Alias:
 - belongs to article via :foo_id
 
Note that in real-life foo_id may break convention for a variety of good reasons
including legacy databases and compelx object models where multiple references
to a table may exist via different foreign keys.


SPEC OUTPUT:

My spec output looks like this (if there are no bugs, everything should run clean).

Alias
- should return all aliases
- should have one author
- should eager load authors (FAILED - 1)

Article
- should return all articles
- should have one author
- should eager load authors

Author
- should return all authors
- should have many articles
- should have many aliases
- should eager load articles
- should eager load aliases (FAILED - 2)

1)
'Alias should eager load authors' FAILED
expected nil? to return false, got true
/Users/paploo/Projects/Ruby/sequel_eager_test/spec/alias_spec.rb:20:in `block (3 levels) in <top (required)>'
/Users/paploo/Projects/Ruby/sequel_eager_test/spec/alias_spec.rb:19:in `each'
/Users/paploo/Projects/Ruby/sequel_eager_test/spec/alias_spec.rb:19:in `block (2 levels) in <top (required)>'

2)
'Author should eager load aliases' FAILED
expected zero? to return false, got true
/Users/paploo/Projects/Ruby/sequel_eager_test/spec/author_spec.rb:46:in `block (3 levels) in <top (required)>'
/Users/paploo/Projects/Ruby/sequel_eager_test/spec/author_spec.rb:45:in `each'
/Users/paploo/Projects/Ruby/sequel_eager_test/spec/author_spec.rb:45:in `block (2 levels) in <top (required)>'

Finished in 0.036813 seconds

11 examples, 2 failures