diff --git a/features/rake_tasks.feature b/features/rake_tasks.feature index ab5d6ad30..dba2cfb6f 100644 --- a/features/rake_tasks.feature +++ b/features/rake_tasks.feature @@ -5,6 +5,7 @@ Feature: Rake tasks And I run a rails generator to generate a "User" scaffold with "name:string" And I run a paperclip generator to add a paperclip "attachment" to the "User" model And I run a migration + And I prepare my old Rails application for rake task And I add this snippet to the User model: """ has_attached_file :attachment, :path => ":rails_root/public/system/:attachment/:style/:filename" diff --git a/features/step_definitions/attachment_steps.rb b/features/step_definitions/attachment_steps.rb index 4c9d42b8c..c3b78d606 100644 --- a/features/step_definitions/attachment_steps.rb +++ b/features/step_definitions/attachment_steps.rb @@ -22,9 +22,7 @@ class User < ActiveRecord::Base end When /^I upload the fixture "([^"]*)"$/ do |filename| - in_current_dir do - run_simple %(bundle exec rails runner "User.create!(:attachment => File.open('#{fixture_path(filename)}'))") - end + run_simple %(bundle exec #{runner_command} "User.create!(:attachment => File.open('#{fixture_path(filename)}'))") end Then /^the attachment "([^"]*)" should have a dimension of (\d+x\d+)$/ do |filename, dimension| @@ -51,14 +49,14 @@ class User < ActiveRecord::Base Then /^the attachment should have the same content type as the fixture "([^"]*)"$/ do |filename| in_current_dir do require 'mime/types' - attachment_content_type = `bundle exec rails runner "puts User.last.attachment_content_type"`.strip + attachment_content_type = `bundle exec #{runner_command} "puts User.last.attachment_content_type"`.strip attachment_content_type.should == MIME::Types.type_for(filename).first.content_type end end Then /^the attachment should have the same file size as the fixture "([^"]*)"$/ do |filename| in_current_dir do - attachment_file_size = `bundle exec rails runner "puts User.last.attachment_file_size"`.strip + attachment_file_size = `bundle exec #{runner_command} "puts User.last.attachment_file_size"`.strip attachment_file_size.should == File.size(fixture_path(filename)).to_s end end diff --git a/features/step_definitions/rails_steps.rb b/features/step_definitions/rails_steps.rb index 846f61c35..94eda20c4 100644 --- a/features/step_definitions/rails_steps.rb +++ b/features/step_definitions/rails_steps.rb @@ -113,6 +113,16 @@ end end +Given /^I prepare my old Rails application for rake task$/ do + if framework_version?("2.3") + require 'fileutils' + source = File.expand_path('lib/tasks/paperclip.rake') + destination = in_current_dir { File.expand_path("lib/tasks") } + FileUtils.cp source, destination + append_to "Rakefile", "require 'paperclip'" + end +end + Then /^the file at "([^"]*)" should be the same as "([^"]*)"$/ do |web_file, path| expected = IO.read(path) actual = if web_file.match %r{^https?://} diff --git a/features/support/rails.rb b/features/support/rails.rb index 12d4dccdf..06572017b 100644 --- a/features/support/rails.rb +++ b/features/support/rails.rb @@ -38,5 +38,9 @@ def new_application_command def generator_command framework_version?("3") ? "script/rails generate" : "script/generate" end + + def runner_command + framework_version?("3") ? "script/rails runner" : "script/runner" + end end World(RailsCommandHelpers)