I am working with a legacy database that does not always follow the
conventions for table names, primary key and foreign key column names,
and join table names.
This is no problem in my application code because Rails allows me to
override the defaults. However it is making unit testing next to
impossible because fixtures will still try and insert data into the
wrong tables.
Changing the database schema is not an option at this point as the
database is already deployed to a production environment and has been
for some time.
The problem and solution are described here:
http://dev.rubyonrails.org/ticket/1911
I eagerly downloaded the patches and tried to apply them (I list the
steps below). The patches failed, and unit tests that worked previously
(the ones involving tables that followed the naming convention) failed.
So in other words, broken rails. I went back to a clean trunk and those
tests passed again.
Everything I did was sort of haphazard and based on guesswork. It
doesn’t seem like there is any definitive source for information on the
patching process. Here are my general questions:
The URL above lists a number of patches. Do I need to install them
cumulatively starting from the earliest one, or can I just install the
most recent one?
I tried both and both failed and left rails in a broken state until I
started again with a clean trunk.
What is the process for incorporating these patches into release and
development versions of Rails? Is there one? I checked out the latest
stable branch and the fix was not there.
So that brings up the next question, is there a particular version of
rails that I need to run these patches against? If that version is older
than what I already have, won’t I be losing newer functionality and
fixes?
How do I deal with patches that fail? What do I do with reject files?
Once I have successfully applied a patch to a checked-out Rails trunk,
assuming I can do so, how do I make that my new system-wide Rails,
replacing the one under /usr/local/lib/ruby/…?
Sorry for the annoying questions that are probably second nature to all
you patchers out there but completely opaque to me.
For the record, here is what I tried and failed to do.
This is based on the following article:
http://sean.treadway.info/articles/2005/06/23/patch-your-rails-trunk
mkdir rails_tmp
cd rails_tmp
svn co http://dev.rubyonrails.org/svn/rails/branches/stable
cd stable/activerecord
curl
“http://dev.rubyonrails.org/attachment/ticket/1911/more_flexible_fixture_architecture.patch?format=raw”
| patch -p0
Here is the output of the last command:
% Total % Received % Xferd Average Speed Time Time Time
Current
Dload Upload Total Spent Left
Speed
100 21717 100 21717 0 0 27745 0 --:–:-- --:–:-- --:–:–
99912
patching file test/fixtures_test.rb
Hunk #1 succeeded at 108 (offset 40 lines).
Hunk #2 succeeded at 107 with fuzz 2.
Hunk #3 FAILED at 218.
1 out of 3 hunks FAILED – saving rejects to file
test/fixtures_test.rb.rej
patching file test/fixtures/topics2.yml
patching file lib/active_record/fixtures.rb
Hunk #1 succeeded at 9 with fuzz 2 (offset 7 lines).
Hunk #2 FAILED at 240.
Hunk #3 FAILED at 477.
Hunk #4 succeeded at 612 (offset 11 lines).
Hunk #5 succeeded at 625 (offset 7 lines).
2 out of 5 hunks FAILED – saving rejects to file
lib/active_record/fixtures.rb.rej
Hope someone can help me make sense of this. If I can’t get this to
work, I am facing one of two equally dismal prospects: 1) developing my
rails app without unit testing (I don’t really consider this an option)
and 2) going back to java, struts, hibernate, spring, and all
that…
Thanks
DT