Skip to content

Commit

Permalink
Responses to PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon Yurek committed Jul 31, 2013
1 parent f29f96b commit 0d04ae1
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 31 deletions.
23 changes: 8 additions & 15 deletions features/basic_integration.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand All @@ -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:
"""
Expand Down
5 changes: 2 additions & 3 deletions features/rake_tasks.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
41 changes: 30 additions & 11 deletions features/step_definitions/rails_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
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`
Expand All @@ -40,7 +40,7 @@
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", "")
Expand All @@ -51,7 +51,32 @@
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|
""
Expand Down Expand Up @@ -139,13 +164,7 @@

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

Expand Down
10 changes: 10 additions & 0 deletions features/support/file_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ def comment_out_gem_in_gemfile(gemname)
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)
4 changes: 4 additions & 0 deletions features/support/rails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ def framework_major_version
framework_version.split(".").first.to_i
end

def using_protected_attributes?
framework_major_version < 4
end

def new_application_command
"rails new"
end
Expand Down
2 changes: 1 addition & 1 deletion gemfiles/4.0.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ gem "sqlite3", :platform=>:ruby
gem "rails", "~> 4.0.0"
gem "paperclip", :path=>"../"

gemspec :path=>"../"
gemspec :path=>"../"
4 changes: 4 additions & 0 deletions test/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ def setup
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
Expand Down
2 changes: 1 addition & 1 deletion test/paperclip_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class ::Four; end
end
end

if ActiveSupport::VERSION::MAJOR < 4
if using_protected_attributes?
context "that is attr_protected" do
setup do
Dummy.class_eval do
Expand Down

0 comments on commit 0d04ae1

Please sign in to comment.