Commit 0d04ae1b by Jon Yurek

Responses to PR comments

parent f29f96b2
......@@ -14,11 +14,7 @@ Feature: Rails integration
"""
config.paperclip_defaults = {:url => "/paperclip/custom/:attachment/:style/:filename"}
"""
Given I add this snippet to the User model:
"""
attr_accessible :name, :attachment if Rails::VERSION::MAJOR < 4
has_attached_file :attachment
"""
And I attach :attachment
And I start the rails application
When I go to the new user page
And I fill in "Name" with "something"
......@@ -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"
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
has_attached_file :attachment, :url => "/system/:attachment/:style/:filename"
:url => "/system/:attachment/:style/:filename"
"""
And I start the rails application
When I go to the new user page
......@@ -44,14 +39,12 @@ Feature: Rails integration
And the file at "/system/attachments/original/5k.png" should be the same as "test/fixtures/5k.png"
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,
:path => "/:attachment/:style/:filename",
:s3_credentials => Rails.root.join("config/s3.yml"),
:styles => { :square => "100x100#" }
:storage => :s3,
:path => "/:attachment/:style/:filename",
:s3_credentials => Rails.root.join("config/s3.yml"),
:styles => { :square => "100x100#" }
"""
And I write to "config/s3.yml" with:
"""
......
......@@ -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 paperclip generator to add a paperclip "attachment" to the "User" model
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
has_attached_file :attachment, :path => ":rails_root/public/system/:attachment/:style/:filename"
:path => ":rails_root/public/system/:attachment/:style/:filename"
"""
Scenario: Paperclip refresh thumbnails task
......
......@@ -15,8 +15,8 @@ Given /^I generate a new rails application$/ do
gem "gherkin"
gem "aws-sdk"
"""
And I remove turbolinks if it exists
And I empty the application.js file if it exists
And I remove turbolinks
And I empty the application.js file
And I configure the application to use "paperclip" from this project
And I reset Bundler environment variable
And I successfully run `bundle install --local`
......@@ -40,7 +40,7 @@ Given "I allow the attachment to be submitted" do
end
end
Given "I remove turbolinks if it exists" do
Given "I remove turbolinks" do
in_current_dir do
transform_file("app/assets/javascripts/application.js") do |content|
content.gsub("//= require turbolinks", "")
......@@ -51,7 +51,32 @@ Given "I remove turbolinks if it exists" do
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
transform_file("app/assets/javascripts/application.js") do |content|
""
......@@ -139,13 +164,7 @@ 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?://}
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 = read_from_web(web_file)
actual.should == expected
end
......
......@@ -19,6 +19,16 @@ module FileHelpers
File.open("Gemfile", 'w'){ |file| file.write(gemfile) }
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
World(FileHelpers)
......@@ -35,6 +35,10 @@ module RailsCommandHelpers
framework_version.split(".").first.to_i
end
def using_protected_attributes?
framework_major_version < 4
end
def new_application_command
"rails new"
end
......
......@@ -8,4 +8,4 @@ gem "sqlite3", :platform=>:ruby
gem "rails", "~> 4.0.0"
gem "paperclip", :path=>"../"
gemspec :path=>"../"
\ No newline at end of file
gemspec :path=>"../"
......@@ -51,6 +51,10 @@ ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + "/debug.log")
ActiveRecord::Base.establish_connection(config['test'])
Paperclip.options[:logger] = ActiveRecord::Base.logger
def using_protected_attributes?
ActiveRecord::VERSION::MAJOR < 4
end
def require_everything_in_directory(directory_name)
Dir[File.join(File.dirname(__FILE__), directory_name, '*')].each do |f|
require f
......
......@@ -123,7 +123,7 @@ class PaperclipTest < Test::Unit::TestCase
end
end
if ActiveSupport::VERSION::MAJOR < 4
if using_protected_attributes?
context "that is attr_protected" do
setup 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