Commit 3b40121b by Jon Yurek

Getting tests to run in Rails 4

parent 1f92b87a
source "https://rubygems.org" source "https://rubygems.org"
gemspec gemspec
gem "jruby-openssl", :platform => :jruby
gem "activerecord-jdbcsqlite3-adapter", :platform => :jruby
gem "sqlite3", :platform => :ruby
...@@ -15,7 +15,7 @@ Feature: Rails integration ...@@ -15,7 +15,7 @@ Feature: Rails integration
""" """
Given I add this snippet to the User model: 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 has_attached_file :attachment
""" """
And I start the rails application And I start the rails application
...@@ -30,7 +30,7 @@ Feature: Rails integration ...@@ -30,7 +30,7 @@ Feature: Rails integration
Scenario: Filesystem integration test Scenario: Filesystem integration test
Given I add this snippet to the User model: 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" has_attached_file :attachment, :url => "/system/:attachment/:style/:filename"
""" """
And I start the rails application And I start the rails application
...@@ -45,7 +45,7 @@ Feature: Rails integration ...@@ -45,7 +45,7 @@ Feature: Rails integration
Scenario: S3 Integration test Scenario: S3 Integration test
Given I add this snippet to the User model: 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, has_attached_file :attachment,
:storage => :s3, :storage => :s3,
:path => "/:attachment/:style/:filename", :path => "/:attachment/:style/:filename",
......
...@@ -7,7 +7,7 @@ Feature: Rake tasks ...@@ -7,7 +7,7 @@ Feature: Rake tasks
And I run a migration And I run a migration
And I add this snippet to the User model: 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" has_attached_file :attachment, :path => ":rails_root/public/system/:attachment/:style/:filename"
""" """
......
...@@ -15,6 +15,7 @@ Given /^I generate a new rails application$/ do ...@@ -15,6 +15,7 @@ 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 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`
...@@ -29,6 +30,27 @@ Given "I fix the application.rb for 3.0.12" do ...@@ -29,6 +30,27 @@ Given "I fix the application.rb for 3.0.12" do
end end
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| 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}`] step %[I successfully run `bundle exec #{generator_command} scaffold #{model_name} #{attributes}`]
end end
......
...@@ -31,16 +31,28 @@ module RailsCommandHelpers ...@@ -31,16 +31,28 @@ module RailsCommandHelpers
@framework_version ||= `rails -v`[/^Rails (.+)$/, 1] @framework_version ||= `rails -v`[/^Rails (.+)$/, 1]
end end
def framework_major_version
framework_version.split(".").first.to_i
end
def new_application_command def new_application_command
"rails new" "rails new"
end end
def generator_command def generator_command
"script/rails generate" if framework_major_version >= 4
"rails generate"
else
"script/rails generate"
end
end end
def runner_command def runner_command
"script/rails runner" if framework_major_version >= 4
"rails runner"
else
"script/rails runner"
end
end end
end end
World(RailsCommandHelpers) World(RailsCommandHelpers)
...@@ -123,28 +123,30 @@ class PaperclipTest < Test::Unit::TestCase ...@@ -123,28 +123,30 @@ class PaperclipTest < Test::Unit::TestCase
end end
end end
context "that is attr_protected" do if ActiveSupport::VERSION::MAJOR < 4
setup do context "that is attr_protected" do
Dummy.class_eval do setup do
attr_protected :avatar Dummy.class_eval do
attr_protected :avatar
end
@dummy = Dummy.new
end end
@dummy = Dummy.new
end
should "not assign the avatar on mass-set" do should "not assign the avatar on mass-set" do
@dummy.attributes = { :other => "I'm set!", @dummy.attributes = { :other => "I'm set!",
:avatar => @file } :avatar => @file }
assert_equal "I'm set!", @dummy.other assert_equal "I'm set!", @dummy.other
assert ! @dummy.avatar? assert ! @dummy.avatar?
end end
should "still allow assigment on normal set" do should "still allow assigment on normal set" do
@dummy.other = "I'm set!" @dummy.other = "I'm set!"
@dummy.avatar = @file @dummy.avatar = @file
assert_equal "I'm set!", @dummy.other assert_equal "I'm set!", @dummy.other
assert @dummy.avatar? assert @dummy.avatar?
end
end 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