Skip to content

Commit

Permalink
Make sure that we're copy the rake task to Rails' folder on Rails 2.3.x
Browse files Browse the repository at this point in the history
  • Loading branch information
sikachu committed Oct 14, 2011
1 parent cd856aa commit 948ddfa
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
1 change: 1 addition & 0 deletions features/rake_tasks.feature
Expand Up @@ -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"
Expand Down
8 changes: 3 additions & 5 deletions features/step_definitions/attachment_steps.rb
Expand Up @@ -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|
Expand All @@ -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
Expand Down
10 changes: 10 additions & 0 deletions features/step_definitions/rails_steps.rb
Expand Up @@ -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?://}
Expand Down
4 changes: 4 additions & 0 deletions features/support/rails.rb
Expand Up @@ -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)

0 comments on commit 948ddfa

Please sign in to comment.