Charles Owen
2011-May-23 20:10 UTC
[rspec-users] bypass db:test:prepare but still load test db
We have a development database that has quite a few non-Rails convention names for tables and fields. Also we have quite a few primary-foreign key relationships. This database has been inherited from a legacy system. However, when we run the rspec then Rails runs a db:test:prepare that loads the system-generated schema.rb file. However, the schema.rb file doesn''t seem to play well with this legacy database and doesn''t translate some things well. So the schema.rb generated transforms some fields from varchar to number, etc. So in order to build the test database properly, I have made a few edits to the rspec.rake to run a db:test:purge and then a db:migrate to build the database structure from development. This is a bit of a hack and I don''t like it. What''s a better way? If I need to give you more details, I would be glad to. Using JRuby 1.5.6 Oracle Enhanced Driver Rails 2.3.11 I''m calling these two lines directly in the rspec.rake. Rake::Task[''db:test:purge''].invoke Rake::Task[''db:migrate''].invoke(''RAILS_ENV=test'') I''d be the last person to say that this is a great way of doing things. Thanks for any help, -- Posted via http://www.ruby-forum.com/.
Charles Owen
2011-May-23 20:12 UTC
[rspec-users] bypass db:test:prepare but still load test db
I guess another option would be to create our own schema.rb for the structure of our database and somehow amend the database.rake file to take this schema.rb instead of the one that gets generated via migrations. However, I''m not sure how I would do that and even if that''s a good idea. -- Posted via http://www.ruby-forum.com/.
Luke Melia
2011-May-23 20:36 UTC
[rspec-users] bypass db:test:prepare but still load test db
Hi Charles. We do something like this at Weplay for the same reasons: https://gist.github.com/987543 Maybe that will help. Cheers, Luke -- Luke Melia http://www.lukemelia.com/ On Monday, May 23, 2011 at 4:12 PM, Charles Owen wrote:> I guess another option would be to create our own schema.rb for the > structure of our database and somehow amend the database.rake file to > take this schema.rb instead of the one that gets generated via > migrations. However, I''m not sure how I would do that and even if > that''s a good idea. > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20110523/e0baecc1/attachment.html>
Charles Owen
2011-May-23 20:52 UTC
[rspec-users] bypass db:test:prepare but still load test db
Thanks, that is close to what I''m looking for. Where do I put the code for this, in the rspec.rake or in a separate rake file in my lib/tasks folder? I''m probably a step above a newbie so sorry if this sounds too rudimentary. -- Posted via http://www.ruby-forum.com/.
Charles Owen
2011-May-23 20:56 UTC
[rspec-users] bypass db:test:prepare but still load test db
What I had also done is commented this line out of my rspec.rake. spec_prereq = File.exist?(File.join(RAILS_ROOT, ''config'', ''database.yml'')) ? "db:test:prepare" : :noop Which I am assuming is running a db:test:prepare as a prerequisite for running the rspecs. So will the new code I write for the db:test:prepare be picked up by these lines above? -- Posted via http://www.ruby-forum.com/.
Luke Melia
2011-May-23 21:16 UTC
[rspec-users] bypass db:test:prepare but still load test db
No problem. We have it in lib/tasks/databases.rake. Cheers, Luke -- Luke Melia http://www.lukemelia.com/ On Monday, May 23, 2011 at 4:52 PM, Charles Owen wrote:> Thanks, that is close to what I''m looking for. Where do I put the code > for this, in the rspec.rake or in a separate rake file in my lib/tasks > folder? I''m probably a step above a newbie so sorry if this sounds too > rudimentary. > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20110523/34a7ad5c/attachment.html>
Luke Melia
2011-May-23 21:36 UTC
[rspec-users] bypass db:test:prepare but still load test db
Yeah, you may want to do this: remove_task "db:test:prepare" before you add the new definition of db:test:prepare. Then you can consider uncommenting the line you mentioned, or running rake db:test:prepare manually when you need it. -- Luke Melia http://www.lukemelia.com/ On Monday, May 23, 2011 at 4:56 PM, Charles Owen wrote:> What I had also done is commented this line out of my rspec.rake. > > spec_prereq = File.exist?(File.join(RAILS_ROOT, ''config'', > ''database.yml'')) ? "db:test:prepare" : :noop > > Which I am assuming is running a db:test:prepare as a prerequisite for > running the rspecs. > > So will the new code I write for the db:test:prepare be picked up by > these lines above? > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20110523/ae7eb64e/attachment.html>