Only run `test:prepare` task if available.

Per comment on #949, check if the task is defined instead of switching only on the Rails version.