Commit 3b40121b by Jon Yurek

Getting tests to run in Rails 4

parent 1f92b87a
source "https://rubygems.org"
gemspec
gem "jruby-openssl", :platform => :jruby
gem "activerecord-jdbcsqlite3-adapter", :platform => :jruby
gem "sqlite3", :platform => :ruby
......@@ -15,7 +15,7 @@ Feature: Rails integration
"""
Given I add this snippet to the User model:
"""
attr_accessible :name, :attachment
attr_accessible :name, :attachment if Rails::VERSION::MAJOR < 4
has_attached_file :attachment
"""
And I start the rails application
......@@ -30,7 +30,7 @@ Feature: Rails integration
Scenario: Filesystem integration test
Given I add this snippet to the User model:
"""
attr_accessible :name, :attachment
attr_accessible :name, :attachment if Rails::VERSION::MAJOR < 4
has_attached_file :attachment, :url => "/system/:attachment/:style/:filename"
"""
And I start the rails application
......@@ -45,7 +45,7 @@ Feature: Rails integration
Scenario: S3 Integration test
Given I add this snippet to the User model:
"""
attr_accessible :name, :attachment
attr_accessible :name, :attachment if Rails::VERSION::MAJOR < 4
has_attached_file :attachment,
:storage => :s3,
:path => "/:attachment/:style/:filename",
......
......@@ -7,7 +7,7 @@ Feature: Rake tasks
And I run a migration
And I add this snippet to the User model:
"""
attr_accessible :name, :attachment
attr_accessible :name, :attachment if Rails::VERSION::MAJOR < 4
has_attached_file :attachment, :path => ":rails_root/public/system/:attachment/:style/:filename"
"""
......
......@@ -15,6 +15,7 @@ Given /^I generate a new rails application$/ do
gem "gherkin"
gem "aws-sdk"
"""
And I remove turbolinks if it exists
And I configure the application to use "paperclip" from this project
And I reset Bundler environment variable
And I successfully run `bundle install --local`
......@@ -29,6 +30,27 @@ Given "I fix the application.rb for 3.0.12" do
end
end
def transform_file(filename)
content = File.read(filename)
File.open(filename, "w") do |f|
content = yield(content)
f.write(content)
end
end
Given "I remove turbolinks if it exists" do
if framework_major_version >= 4
in_current_dir do
transform_file("app/assets/javascripts/application.js") do |content|
content.gsub("//= require turbolinks", "")
end
transform_file("app/views/layouts/application.html.erb") do |content|
content.gsub(', "data-turbolinks-track" => true', "")
end
end
end
end
Given /^I run a rails generator to generate a "([^"]*)" scaffold with "([^"]*)"$/ do |model_name, attributes|
step %[I successfully run `bundle exec #{generator_command} scaffold #{model_name} #{attributes}`]
end
......
......@@ -31,16 +31,28 @@ module RailsCommandHelpers
@framework_version ||= `rails -v`[/^Rails (.+)$/, 1]
end
def framework_major_version
framework_version.split(".").first.to_i
end
def new_application_command
"rails new"
end
def generator_command
"script/rails generate"
if framework_major_version >= 4
"rails generate"
else
"script/rails generate"
end
end
def runner_command
"script/rails runner"
if framework_major_version >= 4
"rails runner"
else
"script/rails runner"
end
end
end
World(RailsCommandHelpers)
......@@ -123,28 +123,30 @@ class PaperclipTest < Test::Unit::TestCase
end
end
context "that is attr_protected" do
setup do
Dummy.class_eval do
attr_protected :avatar
if ActiveSupport::VERSION::MAJOR < 4
context "that is attr_protected" do
setup do
Dummy.class_eval do
attr_protected :avatar
end
@dummy = Dummy.new
end
@dummy = Dummy.new
end
should "not assign the avatar on mass-set" do
@dummy.attributes = { :other => "I'm set!",
:avatar => @file }
should "not assign the avatar on mass-set" do
@dummy.attributes = { :other => "I'm set!",
:avatar => @file }
assert_equal "I'm set!", @dummy.other
assert ! @dummy.avatar?
end
assert_equal "I'm set!", @dummy.other
assert ! @dummy.avatar?
end
should "still allow assigment on normal set" do
@dummy.other = "I'm set!"
@dummy.avatar = @file
should "still allow assigment on normal set" do
@dummy.other = "I'm set!"
@dummy.avatar = @file
assert_equal "I'm set!", @dummy.other
assert @dummy.avatar?
assert_equal "I'm set!", @dummy.other
assert @dummy.avatar?
end
end
end
......
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