Skip to content

Commit

Permalink
Getting tests to run in Rails 4
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon Yurek committed Jul 30, 2013
1 parent 1f92b87 commit 3b40121
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 27 deletions.
4 changes: 0 additions & 4 deletions Gemfile
@@ -1,7 +1,3 @@
source "https://rubygems.org"

gemspec

gem "jruby-openssl", :platform => :jruby
gem "activerecord-jdbcsqlite3-adapter", :platform => :jruby
gem "sqlite3", :platform => :ruby
6 changes: 3 additions & 3 deletions features/basic_integration.feature
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion features/rake_tasks.feature
Expand Up @@ -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"
"""

Expand Down
22 changes: 22 additions & 0 deletions features/step_definitions/rails_steps.rb
Expand Up @@ -15,6 +15,7 @@
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`
Expand All @@ -29,6 +30,27 @@
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
Expand Down
16 changes: 14 additions & 2 deletions features/support/rails.rb
Expand Up @@ -31,16 +31,28 @@ def framework_version
@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)
36 changes: 19 additions & 17 deletions test/paperclip_test.rb
Expand Up @@ -123,28 +123,30 @@ class ::Four; end
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

Expand Down

0 comments on commit 3b40121

Please sign in to comment.