Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.

Commit

Permalink
Merge branch 'master' into interpolations_tuning
Browse files Browse the repository at this point in the history
  • Loading branch information
dgynn committed Jul 29, 2015
2 parents dee1f4c + c819d5d commit f3172b3
Show file tree
Hide file tree
Showing 11 changed files with 43 additions and 151 deletions.
9 changes: 3 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
rvm:
- 2.0
- 2.1
- 2.2.2
- jruby-19mode
- rbx-2
- 2.0.0
- 2.1.1
- 2.2.2

install:
- "travis_retry bundle install"

script: "bundle exec rake clean spec cucumber"

Expand Down
3 changes: 0 additions & 3 deletions Appraisals
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
appraise "3.2" do
gem "rails", "~> 3.2.0"
gem "paperclip", :path => "../"
end

appraise "4.1" do
gem "rails", "~> 4.1.0"
gem "paperclip", :path => "../"
end

appraise "4.2" do
gem "rails", "~> 4.2.0"
gem "paperclip", :path => "../"
end
40 changes: 20 additions & 20 deletions features/step_definitions/attachment_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def attachment_path(filename)
World(AttachmentHelpers)

When /^I modify my attachment definition to:$/ do |definition|
content = in_current_dir { File.read("app/models/user.rb") }
content = cd(".") { File.read("app/models/user.rb") }
name = content[/has_attached_file :\w+/][/:\w+/]
content.gsub!(/has_attached_file.+end/m, <<-FILE)
#{definition}
Expand All @@ -19,36 +19,36 @@ def attachment_path(filename)
FILE

write_file "app/models/user.rb", content
in_current_dir { FileUtils.rm_rf ".rbx" }
cd(".") { FileUtils.rm_rf ".rbx" }
end

When /^I upload the fixture "([^"]*)"$/ do |filename|
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|
in_current_dir do
cd(".") do
geometry = `identify -format "%wx%h" "#{attachment_path(filename)}"`.strip
geometry.should == dimension
expect(geometry).to eq(dimension)
end
end

Then /^the attachment "([^"]*)" should exist$/ do |filename|
in_current_dir do
File.exist?(attachment_path(filename)).should be
cd(".") do
expect(File.exist?(attachment_path(filename))).to be true
end
end

When /^I swap the attachment "([^"]*)" with the fixture "([^"]*)"$/ do |attachment_filename, fixture_filename|
in_current_dir do
cd(".") do
require 'fileutils'
FileUtils.rm_f attachment_path(attachment_filename)
FileUtils.cp fixture_path(fixture_filename), attachment_path(attachment_filename)
end
end

Then /^the attachment should have the same content type as the fixture "([^"]*)"$/ do |filename|
in_current_dir do
cd(".") do
begin
# Use mime/types/columnar if available, for reduced memory usage
require "mime/types/columnar"
Expand All @@ -57,46 +57,46 @@ def attachment_path(filename)
end

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
expected = MIME::Types.type_for(filename).first.content_type
expect(attachment_content_type).to eq(expected)
end
end

Then /^the attachment should have the same file name as the fixture "([^"]*)"$/ do |filename|
in_current_dir do
cd(".") do
attachment_file_name = `bundle exec #{runner_command} "puts User.last.attachment_file_name"`.strip
attachment_file_name.should == File.name(fixture_path(filename)).to_s
expect(attachment_file_name).to eq(File.name(fixture_path(filename)).to_s)
end
end

Then /^the attachment should have the same file size as the fixture "([^"]*)"$/ do |filename|
in_current_dir do
cd(".") do
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
expect(attachment_file_size).to eq(File.size(fixture_path(filename)).to_s)
end
end

Then /^the attachment file "([^"]*)" should (not )?exist$/ do |filename, not_exist|
in_current_dir do
check_file_presence([attachment_path(filename)], !not_exist)
cd(".") do
expect(attachment_path(filename)).not_to be_an_existing_file
end
end

Then /^I should have attachment columns for "([^"]*)"$/ do |attachment_name|
in_current_dir do
cd(".") do
columns = eval(`bundle exec #{runner_command} "puts User.columns.map{ |column| [column.name, column.type] }.inspect"`.strip)
expect_columns = [
["#{attachment_name}_file_name", :string],
["#{attachment_name}_content_type", :string],
["#{attachment_name}_file_size", :integer],
["#{attachment_name}_updated_at", :datetime]
]

expect_columns.all?{ |column| columns.include? column }.should eq true
expect(columns).to include(*expect_columns)
end
end

Then /^I should not have attachment columns for "([^"]*)"$/ do |attachment_name|
in_current_dir do
cd(".") do
columns = eval(`bundle exec #{runner_command} "puts User.columns.map{ |column| [column.name, column.type] }.inspect"`.strip)
expect_columns = [
["#{attachment_name}_file_name", :string],
Expand All @@ -105,6 +105,6 @@ def attachment_path(filename)
["#{attachment_name}_updated_at", :datetime]
]

expect_columns.none?{ |column| columns.include? column }.should eq true
expect(columns).not_to include(*expect_columns)
end
end
4 changes: 2 additions & 2 deletions features/step_definitions/html_steps.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Then %r{I should see an image with a path of "([^"]*)"} do |path|
page.should have_css("img[src^='#{path}']")
expect(page).to have_css("img[src^='#{path}']")
end

Then %r{^the file at "([^"]*)" is the same as "([^"]*)"$} do |web_file, path|
Expand All @@ -11,5 +11,5 @@
page.body
end
actual.force_encoding("UTF-8") if actual.respond_to?(:force_encoding)
actual.should == expected
expect(actual).to eq(expected)
end
22 changes: 11 additions & 11 deletions features/step_definitions/rails_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@
end

Given "I fix the application.rb for 3.0.12" do
in_current_dir do
cd(".") do
File.open("config/application.rb", "a") do |f|
f << "ActionController::Base.config.relative_url_root = ''"
end
end
end

Given "I allow the attachment to be submitted" do
in_current_dir do
cd(".") do
transform_file("app/controllers/users_controller.rb") do |content|
content.gsub("params.require(:user).permit(:name)",
"params.require(:user).permit!")
Expand All @@ -41,7 +41,7 @@
end

Given "I remove turbolinks" do
in_current_dir do
cd(".") do
transform_file("app/assets/javascripts/application.js") do |content|
content.gsub("//= require turbolinks", "")
end
Expand Down Expand Up @@ -70,15 +70,15 @@ def attach_attachment(name, definition = nil)
snippet += definition
end
snippet += "\ndo_not_validate_attachment_file_type :#{name}\n"
in_current_dir do
cd(".") 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
cd(".") do
transform_file("app/assets/javascripts/application.js") do |content|
""
end
Expand Down Expand Up @@ -128,22 +128,22 @@ def attach_attachment(name, definition = nil)

Given /^I add this snippet to the User model:$/ do |snippet|
file_name = "app/models/user.rb"
in_current_dir do
cd(".") do
content = File.read(file_name)
File.open(file_name, 'w') { |f| f << content.sub(/end\Z/, "#{snippet}\nend") }
end
end

Given /^I add this snippet to config\/application.rb:$/ do |snippet|
file_name = "config/application.rb"
in_current_dir do
cd(".") do
content = File.read(file_name)
File.open(file_name, 'w') {|f| f << content.sub(/class Application < Rails::Application.*$/, "class Application < Rails::Application\n#{snippet}\n")}
end
end

Given /^I start the rails application$/ do
in_current_dir do
cd(".") do
require "./config/environment"
require "capybara/rails"
end
Expand All @@ -154,7 +154,7 @@ def attach_attachment(name, definition = nil)
end

When /^I turn off class caching$/ do
in_current_dir do
cd(".") do
file = "config/environments/test.rb"
config = IO.read(file)
config.gsub!(%r{^\s*config.cache_classes.*$},
Expand All @@ -166,7 +166,7 @@ def attach_attachment(name, definition = nil)
Then /^the file at "([^"]*)" should be the same as "([^"]*)"$/ do |web_file, path|
expected = IO.read(path)
actual = read_from_web(web_file)
actual.should == expected
expect(actual).to eq(expected)
end

When /^I configure the application to use "([^\"]+)" from this project$/ do |name|
Expand Down Expand Up @@ -198,7 +198,7 @@ def attach_attachment(name, definition = nil)

Given(/^I add a "(.*?)" processor in "(.*?)"$/) do |processor, directory|
filename = "#{directory}/#{processor}.rb"
in_current_dir do
cd(".") do
FileUtils.mkdir_p directory
File.open(filename, "w") do |f|
f.write(<<-CLASS)
Expand Down
104 changes: 1 addition & 103 deletions features/step_definitions/web_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,107 +103,5 @@ def with_scope(locator)
end

Then /^(?:|I )should see "([^"]*)"$/ do |text|
if page.respond_to? :should
page.should have_content(text)
else
assert page.has_content?(text)
end
end

Then /^(?:|I )should see \/([^\/]*)\/$/ do |regexp|
regexp = Regexp.new(regexp)

if page.respond_to? :should
page.should have_xpath('//*', :text => regexp)
else
assert page.has_xpath?('//*', :text => regexp)
end
end

Then /^(?:|I )should not see "([^"]*)"$/ do |text|
if page.respond_to? :should
page.should have_no_content(text)
else
assert page.has_no_content?(text)
end
end

Then /^(?:|I )should not see \/([^\/]*)\/$/ do |regexp|
regexp = Regexp.new(regexp)

if page.respond_to? :should
page.should have_no_xpath('//*', :text => regexp)
else
assert page.has_no_xpath?('//*', :text => regexp)
end
end

Then /^the "([^"]*)" field(?: within (.*))? should contain "([^"]*)"$/ do |field, parent, value|
with_scope(parent) do
field = find_field(field)
if field.value.respond_to? :should
field.value.should =~ /#{value}/
else
assert_match(/#{value}/, field.value)
end
end
end

Then /^the "([^"]*)" field(?: within (.*))? should not contain "([^"]*)"$/ do |field, parent, value|
with_scope(parent) do
field = find_field(field)
if field.value.respond_to? :should_not
field.value.should_not =~ /#{value}/
else
assert_no_match(/#{value}/, field.value)
end
end
end

Then /^the "([^"]*)" checkbox(?: within (.*))? should be checked$/ do |label, parent|
with_scope(parent) do
field_checked = find_field(label)['checked']
if field_checked.respond_to? :should
field_checked.should eq true
else
assert field_checked
end
end
end

Then /^the "([^"]*)" checkbox(?: within (.*))? should not be checked$/ do |label, parent|
with_scope(parent) do
field_checked = find_field(label)['checked']
if field_checked.respond_to? :should
field_checked.should eq false
else
assert !field_checked
end
end
end

Then /^(?:|I )should be on (.+)$/ do |page_name|
current_path = URI.parse(current_url).path
if current_path.respond_to? :should
current_path.should == path_to(page_name)
else
assert_equal path_to(page_name), current_path
end
end

Then /^(?:|I )should have the following query string:$/ do |expected_pairs|
query = URI.parse(current_url).query
actual_params = query ? CGI.parse(query) : {}
expected_params = {}
expected_pairs.rows_hash.each_pair{|k,v| expected_params[k] = v.split(',')}

if actual_params.respond_to? :should
actual_params.should == expected_params
else
assert_equal expected_params, actual_params
end
end

Then /^show me the page$/ do
save_and_open_page
expect(page).to have_content(text)
end
4 changes: 2 additions & 2 deletions features/support/file_helpers.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module FileHelpers
def append_to(path, contents)
in_current_dir do
cd(".") do
File.open(path, "a") do |file|
file.puts
file.puts contents
Expand All @@ -13,7 +13,7 @@ def append_to_gemfile(contents)
end

def comment_out_gem_in_gemfile(gemname)
in_current_dir do
cd(".") do
gemfile = File.read("Gemfile")
gemfile.sub!(/^(\s*)(gem\s*['"]#{gemname})/, "\\1# \\2")
File.open("Gemfile", 'w'){ |file| file.write(gemfile) }
Expand Down
3 changes: 1 addition & 2 deletions gemfiles/3.2.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ gem "activerecord-jdbcsqlite3-adapter", :platforms => :jruby
gem "rubysl", :platforms => :rbx
gem "racc", :platforms => :rbx
gem "pry"
gem "rails", "~> 3.2.15"
gem "paperclip", :path => "../"
gem "rails", "~> 3.2.0"

group :development, :test do
gem "mime-types", "~> 1.16"
Expand Down
Loading

0 comments on commit f3172b3

Please sign in to comment.