features/step_definitions/rails_steps.rb in paperclip-2.7.2 vs features/step_definitions/rails_steps.rb in paperclip-2.7.4

- old
+ new

@@ -69,15 +69,11 @@ """ } end Given /^I add this snippet to the User model:$/ do |snippet| - file_name = "app/models/user.rb" - in_current_dir do - content = File.read(file_name) - File.open(file_name, 'w') { |f| f << content.sub(/end\Z/, "#{snippet}\nend") } - end + insert_snippet_into_file("app/models/user.rb", snippet) end Given /^I start the rails application$/ do in_current_dir do require "./config/environment" @@ -111,10 +107,16 @@ File.open("Gemfile", "w") { |file| file.write(gemfile_template.sub(/RAILS_VERSION/, framework_version)) } end end end +Given /^I add attr_accessible to a Rails 3.2 application$/ do + if framework_version?("3.2") + insert_snippet_into_file("app/models/user.rb", "attr_accessible :attachment\n") + end +end + Given /^I add the paperclip rake task to a Rails 2.3 application$/ 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") } @@ -155,9 +157,17 @@ When /^I comment out the gem "([^"]*)" from the Gemfile$/ do |gemname| comment_out_gem_in_gemfile gemname end module FileHelpers + def insert_snippet_into_file(file_name, snippet) + in_current_dir do + content = File.read(file_name) + File.open(file_name, 'w') { |f| f << content.sub(/end\Z/, "#{snippet}\nend") } + content = File.read(file_name) + end + end + def append_to(path, contents) in_current_dir do File.open(path, "a") do |file| file.puts file.puts contents