Commit 0d04ae1b by Jon Yurek

Responses to PR comments

parent f29f96b2
...@@ -14,11 +14,7 @@ Feature: Rails integration ...@@ -14,11 +14,7 @@ Feature: Rails integration
""" """
config.paperclip_defaults = {:url => "/paperclip/custom/:attachment/:style/:filename"} config.paperclip_defaults = {:url => "/paperclip/custom/:attachment/:style/:filename"}
""" """
Given I add this snippet to the User model: And I attach :attachment
"""
attr_accessible :name, :attachment if Rails::VERSION::MAJOR < 4
has_attached_file :attachment
"""
And I start the rails application And I start the rails application
When I go to the new user page When I go to the new user page
And I fill in "Name" with "something" And I fill in "Name" with "something"
...@@ -29,10 +25,9 @@ Feature: Rails integration ...@@ -29,10 +25,9 @@ Feature: Rails integration
And the file at "/paperclip/custom/attachments/original/5k.png" should be the same as "test/fixtures/5k.png" And the file at "/paperclip/custom/attachments/original/5k.png" should be the same as "test/fixtures/5k.png"
Scenario: Filesystem integration test Scenario: Filesystem integration test
Given I add this snippet to the User model: Given I attach :attachment with:
""" """
attr_accessible :name, :attachment if Rails::VERSION::MAJOR < 4 :url => "/system/:attachment/:style/:filename"
has_attached_file :attachment, :url => "/system/:attachment/:style/:filename"
""" """
And I start the rails application And I start the rails application
When I go to the new user page When I go to the new user page
...@@ -44,10 +39,8 @@ Feature: Rails integration ...@@ -44,10 +39,8 @@ Feature: Rails integration
And the file at "/system/attachments/original/5k.png" should be the same as "test/fixtures/5k.png" And the file at "/system/attachments/original/5k.png" should be the same as "test/fixtures/5k.png"
Scenario: S3 Integration test Scenario: S3 Integration test
Given I add this snippet to the User model: Given I attach :attachment with:
""" """
attr_accessible :name, :attachment if Rails::VERSION::MAJOR < 4
has_attached_file :attachment,
:storage => :s3, :storage => :s3,
:path => "/:attachment/:style/:filename", :path => "/:attachment/:style/:filename",
:s3_credentials => Rails.root.join("config/s3.yml"), :s3_credentials => Rails.root.join("config/s3.yml"),
......
...@@ -5,10 +5,9 @@ Feature: Rake tasks ...@@ -5,10 +5,9 @@ Feature: Rake tasks
And I run a rails generator to generate a "User" scaffold with "name:string" 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 paperclip generator to add a paperclip "attachment" to the "User" model
And I run a migration And I run a migration
And I add this snippet to the User model: And I attach :attachment with:
""" """
attr_accessible :name, :attachment if Rails::VERSION::MAJOR < 4 :path => ":rails_root/public/system/:attachment/:style/:filename"
has_attached_file :attachment, :path => ":rails_root/public/system/:attachment/:style/:filename"
""" """
Scenario: Paperclip refresh thumbnails task Scenario: Paperclip refresh thumbnails task
......
...@@ -15,8 +15,8 @@ Given /^I generate a new rails application$/ do ...@@ -15,8 +15,8 @@ Given /^I generate a new rails application$/ do
gem "gherkin" gem "gherkin"
gem "aws-sdk" gem "aws-sdk"
""" """
And I remove turbolinks if it exists And I remove turbolinks
And I empty the application.js file if it exists And I empty the application.js file
And I configure the application to use "paperclip" from this project And I configure the application to use "paperclip" from this project
And I reset Bundler environment variable And I reset Bundler environment variable
And I successfully run `bundle install --local` And I successfully run `bundle install --local`
...@@ -40,7 +40,7 @@ Given "I allow the attachment to be submitted" do ...@@ -40,7 +40,7 @@ Given "I allow the attachment to be submitted" do
end end
end end
Given "I remove turbolinks if it exists" do Given "I remove turbolinks" do
in_current_dir do in_current_dir do
transform_file("app/assets/javascripts/application.js") do |content| transform_file("app/assets/javascripts/application.js") do |content|
content.gsub("//= require turbolinks", "") content.gsub("//= require turbolinks", "")
...@@ -51,7 +51,32 @@ Given "I remove turbolinks if it exists" do ...@@ -51,7 +51,32 @@ Given "I remove turbolinks if it exists" do
end end
end end
Given "I empty the application.js file if it exists" do Given /^I attach :attachment$/ do
attach_attachment("attachment")
end
Given /^I attach :attachment with:$/ do |definition|
attach_attachment("attachment", definition)
end
def attach_attachment(name, definition = nil)
snippet = ""
if using_protected_attributes?
snippet += "attr_accessible :name, :#{name}\n"
end
snippet += "has_attached_file :#{name}"
if definition
snippet += ", \n"
snippet += definition
end
in_current_dir do
transform_file("app/models/user.rb") do |content|
content.sub(/end\Z/, "#{snippet}\nend")
end
end
end
Given "I empty the application.js file" do
in_current_dir do in_current_dir do
transform_file("app/assets/javascripts/application.js") do |content| transform_file("app/assets/javascripts/application.js") do |content|
"" ""
...@@ -139,13 +164,7 @@ end ...@@ -139,13 +164,7 @@ end
Then /^the file at "([^"]*)" should be the same as "([^"]*)"$/ do |web_file, path| Then /^the file at "([^"]*)" should be the same as "([^"]*)"$/ do |web_file, path|
expected = IO.read(path) expected = IO.read(path)
actual = if web_file.match %r{^https?://} actual = read_from_web(web_file)
Net::HTTP.get(URI.parse(web_file))
else
visit(web_file)
page.source
end
actual.force_encoding("UTF-8") if actual.respond_to?(:force_encoding)
actual.should == expected actual.should == expected
end end
......
...@@ -19,6 +19,16 @@ module FileHelpers ...@@ -19,6 +19,16 @@ module FileHelpers
File.open("Gemfile", 'w'){ |file| file.write(gemfile) } File.open("Gemfile", 'w'){ |file| file.write(gemfile) }
end end
end end
def read_from_web(url)
file = if url.match %r{^https?://}
Net::HTTP.get(URI.parse(url))
else
visit(url)
page.source
end
file.force_encoding("UTF-8") if file.respond_to?(:force_encoding)
end
end end
World(FileHelpers) World(FileHelpers)
...@@ -35,6 +35,10 @@ module RailsCommandHelpers ...@@ -35,6 +35,10 @@ module RailsCommandHelpers
framework_version.split(".").first.to_i framework_version.split(".").first.to_i
end end
def using_protected_attributes?
framework_major_version < 4
end
def new_application_command def new_application_command
"rails new" "rails new"
end end
......
...@@ -51,6 +51,10 @@ ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + "/debug.log") ...@@ -51,6 +51,10 @@ ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + "/debug.log")
ActiveRecord::Base.establish_connection(config['test']) ActiveRecord::Base.establish_connection(config['test'])
Paperclip.options[:logger] = ActiveRecord::Base.logger Paperclip.options[:logger] = ActiveRecord::Base.logger
def using_protected_attributes?
ActiveRecord::VERSION::MAJOR < 4
end
def require_everything_in_directory(directory_name) def require_everything_in_directory(directory_name)
Dir[File.join(File.dirname(__FILE__), directory_name, '*')].each do |f| Dir[File.join(File.dirname(__FILE__), directory_name, '*')].each do |f|
require f require f
......
...@@ -123,7 +123,7 @@ class PaperclipTest < Test::Unit::TestCase ...@@ -123,7 +123,7 @@ class PaperclipTest < Test::Unit::TestCase
end end
end end
if ActiveSupport::VERSION::MAJOR < 4 if using_protected_attributes?
context "that is attr_protected" do context "that is attr_protected" do
setup do setup do
Dummy.class_eval do Dummy.class_eval do
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment