Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Begin testing against AR 5 #684

Merged
merged 2 commits into from
Jan 8, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
gemfiles/*.lock
NOTES
test/debug.log
test/paper_trail_plugin.sqlite3.db
Expand Down
14 changes: 11 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: ruby
rvm:
- 2.0.0
- 2.2.4
- 1.9.3
- jruby-19mode
env:
Expand All @@ -24,11 +24,19 @@ before_script:
- sh -c "if [ \"$DB\" = 'postgres' ]; then psql -c 'create database paper_trail_foo;' -U postgres; fi"

gemfile:
- Gemfile
- gemfiles/3.0.gemfile
- gemfiles/ar3.gemfile
- gemfiles/ar4.gemfile
- gemfiles/ar5.gemfile

matrix:
fast_finish: true
allow_failures:
- gemfile: gemfiles/ar5.gemfile
exclude:
- gemfile: gemfiles/ar5.gemfile
rvm: 1.9.3
- gemfile: gemfiles/ar5.gemfile
rvm: jruby-19mode

addons:
postgresql: "9.4"
45 changes: 45 additions & 0 deletions Appraisals
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Specify here only version constraints that differ from
# `paper_trail.gemspec`.
#
# > The dependencies in your Appraisals file are combined with dependencies in
# > your Gemfile, so you don"t need to repeat anything that"s the same for each
# > appraisal. If something is specified in both the Gemfile and an appraisal,
# > the version from the appraisal takes precedence.
# > https://github.com/thoughtbot/appraisal

appraise "ar3" do
gem "activerecord", "~> 3.2"
gem "i18n", "~> 0.6.11"
gem "request_store", "~> 1.1.0"

group :development, :test do
gem 'railties', '~> 3.0'
gem 'test-unit', '~> 3.0'
platforms :ruby do
gem 'mysql2', '~> 0.3.20'
gem 'pg', '~> 0.17.1'
end
platforms :jruby do
gem 'activerecord-jdbcsqlite3-adapter', '~> 1.3'
gem 'activerecord-jdbcpostgresql-adapter', '~> 1.3'
gem 'activerecord-jdbcmysql-adapter', '~> 1.3'
gem 'activerecord-jdbc-adapter', '1.3.15'
end
end
end

appraise "ar4" do
gem "activerecord", "~> 4.2"
end

appraise "ar5" do
gem "activerecord", "5.0.0.beta1"
gem "activemodel", "5.0.0.beta1"
gem "actionpack", "5.0.0.beta1"
gem "railties", "5.0.0.beta1"
gem "rspec-rails", github: "rspec/rspec-rails"
gem "rspec-core", github: "rspec/rspec-core"
gem "rspec-expectations", github: "rspec/rspec-expectations"
gem "rspec-mocks", github: "rspec/rspec-mocks"
gem "rspec-support", github: "rspec/rspec-support"
end
11 changes: 9 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,15 @@ Please use our [bug report template][1].

Testing is a little awkward because the test suite:

1. contains a rails app with three databases (test, foo, and bar)
1. supports three different RDBMS': sqlite, mysql, and postgres
1. Supports three major versions of rails: 3, 4, 5
1. Sontains a rails app with three databases (test, foo, and bar)
1. Supports three different RDBMS': sqlite, mysql, and postgres

Test against rails 3:

```
bundle exec appraisal ar3 rake
```

Run tests with sqlite:

Expand Down
40 changes: 0 additions & 40 deletions gemfiles/3.0.gemfile

This file was deleted.

26 changes: 26 additions & 0 deletions gemfiles/ar3.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "activerecord", "~> 3.2"
gem "i18n", "~> 0.6.11"
gem "request_store", "~> 1.1.0"

group :development, :test do
gem "railties", "~> 3.0"
gem "test-unit", "~> 3.0"

platforms :ruby do
gem "mysql2", "~> 0.3.20"
gem "pg", "~> 0.17.1"
end

platforms :jruby do
gem "activerecord-jdbcsqlite3-adapter", "~> 1.3"
gem "activerecord-jdbcpostgresql-adapter", "~> 1.3"
gem "activerecord-jdbcmysql-adapter", "~> 1.3"
gem "activerecord-jdbc-adapter", "1.3.15"
end
end

gemspec :path => "../"
7 changes: 7 additions & 0 deletions gemfiles/ar4.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "activerecord", "~> 4.2"

gemspec :path => "../"
15 changes: 15 additions & 0 deletions gemfiles/ar5.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "activerecord", "5.0.0.beta1"
gem "activemodel", "5.0.0.beta1"
gem "actionpack", "5.0.0.beta1"
gem "railties", "5.0.0.beta1"
gem "rspec-rails", :github => "rspec/rspec-rails"
gem "rspec-core", :github => "rspec/rspec-core"
gem "rspec-expectations", :github => "rspec/rspec-expectations"
gem "rspec-mocks", :github => "rspec/rspec-mocks"
gem "rspec-support", :github => "rspec/rspec-support"

gemspec :path => "../"
1 change: 1 addition & 0 deletions paper_trail.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Gem::Specification.new do |s|
s.add_dependency 'activesupport', ['>= 3.0', '< 6.0']
s.add_dependency 'request_store', '~> 1.1'

s.add_development_dependency 'appraisal', '~> 2.1'
s.add_development_dependency 'rake', '~> 10.4.2'
s.add_development_dependency 'shoulda', '~> 3.5'
s.add_development_dependency 'ffaker', '~> 2.1.0'
Expand Down
7 changes: 5 additions & 2 deletions test/dummy/app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
class ApplicationController < ActionController::Base
protect_from_forgery

# Rails 5 deprecates `before_filter`
name_of_before_callback = respond_to?(:before_action) ? :before_action : :before_filter

# Some applications and libraries modify `current_user`. Their changes need
# to be reflected in `whodunnit`, so the `set_paper_trail_whodunnit` below
# must happen after this.
before_filter :modify_current_user
send(name_of_before_callback, :modify_current_user)

# Going forward, we'll no longer add this `before_filter`, requiring people
# to do so themselves, allowing them to control the order in which this filter
# happens.
before_filter :set_paper_trail_whodunnit
send(name_of_before_callback, :set_paper_trail_whodunnit)

def rescue_action(e)
raise e
Expand Down
12 changes: 10 additions & 2 deletions test/dummy/app/models/song.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ def attributes_with_name
attributes_without_name
end
end
alias_method_chain :attributes, :name

# `alias_method_chain` is deprecated in rails 5, but we cannot use the
# suggested replacement, `Module#prepend`, because we still support ruby 1.9.
alias_method :attributes_without_name, :attributes
alias_method :attributes, :attributes_with_name

def changed_attributes_with_name
if name
Expand All @@ -28,5 +32,9 @@ def changed_attributes_with_name
changed_attributes_without_name
end
end
alias_method_chain :changed_attributes, :name

# `alias_method_chain` is deprecated in rails 5, but we cannot use the
# suggested replacement, `Module#prepend`, because we still support ruby 1.9.
alias_method :changed_attributes_without_name, :changed_attributes
alias_method :changed_attributes, :changed_attributes_with_name
end
16 changes: 12 additions & 4 deletions test/dummy/config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,25 @@ class Application < Rails::Application
# parameters by using an attr_accessible or attr_protected declaration.
config.active_record.whitelist_attributes = false if ::PaperTrail.active_record_protected_attributes?

# Enable the asset pipeline
config.assets.enabled = false
# `config.assets` is a `NoMethodError` in rails 5.
if config.respond_to?(:assets)
config.assets.enabled = false
end

# Version of your assets, change this if you want to expire all your assets
# config.assets.version = '1.0'

# Rails 4 key for generating secret key
config.secret_key_base = 'A fox regularly kicked the screaming pile of biscuits.'

# supress warnings about raises in transactional callbacks on AR 4.2+
config.active_record.raise_in_transactional_callbacks = true if ActiveRecord::VERSION::STRING >= '4.2'
# `raise_in_transactional_callbacks` was added in rails 4, then deprecated
# in rails 5. Oh, how fickle are the gods.
if ActiveRecord.respond_to?(:gem_version)
v = ActiveRecord.gem_version
if v >= Gem::Version.new("4.2") && v < Gem::Version.new("5.0.0.beta1")
config.active_record.raise_in_transactional_callbacks = true
end
end

# Set test order for Test::Unit if possible
config.active_support.test_order = :sorted if config.active_support.respond_to?(:test_order=)
Expand Down
14 changes: 11 additions & 3 deletions test/dummy/config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,21 @@
# Eager loads all registered namespaces
config.eager_load = true

# Configure static asset server for tests with Cache-Control for performance
if config.respond_to?(:serve_static_files=)
if config.respond_to?(:public_file_server)
config.public_file_server.enabled = true
elsif config.respond_to?(:serve_static_files=)
config.serve_static_files = true
else
config.serve_static_assets = true
end
config.static_cache_control = "public, max-age=3600"

if config.respond_to?(:public_file_server)
config.public_file_server.headers = {
'Cache-Control' => 'public, max-age=3600'
}
else
config.static_cache_control = "public, max-age=3600"
end

# Show full error reports and disable caching
config.consider_all_requests_local = true
Expand Down
76 changes: 43 additions & 33 deletions test/functional/modular_sinatra_test.rb
Original file line number Diff line number Diff line change
@@ -1,45 +1,55 @@
require 'test_helper'
require 'sinatra/base'
# Our ActiveRecord 5 gemfile (see `Appraisals`) must use `rack 2.0.0.alpha`
# which renames several files that sinatra 1 depended on. Until there is
# a released version of sinatra that supports `rack 2.0.0.alpha`, we
# must exclude sinatra from our test suite. This is done in two files:
#
# - test/functional/sinatra_test.rb
# - test/functional/modular_sinatra_test.rb
#
if Gem::Version.new(Rack.release) < Gem::Version.new("2.0.0.alpha")
require 'test_helper'
require 'sinatra/base'

# --- Tests for modular `Sinatra::Base` style ----
class BaseApp < Sinatra::Base
configs = YAML.load_file(File.expand_path('../../dummy/config/database.yml', __FILE__))
ActiveRecord::Base.configurations = configs
ActiveRecord::Base.establish_connection(:test)
register PaperTrail::Sinatra

get '/test' do
Widget.create!(:name => 'foo')
'Hello'
end
class BaseApp < Sinatra::Base
configs = YAML.load_file(File.expand_path('../../dummy/config/database.yml', __FILE__))
ActiveRecord::Base.configurations = configs
ActiveRecord::Base.establish_connection(:test)
register PaperTrail::Sinatra

get '/test' do
Widget.create!(:name => 'foo')
'Hello'
end

def current_user
@current_user ||= OpenStruct.new(id: 'foobar')
def current_user
@current_user ||= OpenStruct.new(id: 'foobar')
end
end
end

class ModularSinatraTest < ActionDispatch::IntegrationTest
include Rack::Test::Methods
class ModularSinatraTest < ActionDispatch::IntegrationTest
include Rack::Test::Methods

def app
@app ||= BaseApp
end
def app
@app ||= BaseApp
end

test 'baseline' do
assert_nil Widget.create.versions.first.whodunnit
end
test 'baseline' do
assert_nil Widget.create.versions.first.whodunnit
end

context "`PaperTrail::Sinatra` in a `Sinatra::Base` application" do
context "`PaperTrail::Sinatra` in a `Sinatra::Base` application" do

should "sets the `user_for_paper_trail` from the `current_user` method" do
get '/test'
assert_equal 'Hello', last_response.body
widget = Widget.last
assert_not_nil widget
assert_equal 'foo', widget.name
assert_equal 1, widget.versions.size
assert_equal 'foobar', widget.versions.first.whodunnit
end
should "sets the `user_for_paper_trail` from the `current_user` method" do
get '/test'
assert_equal 'Hello', last_response.body
widget = Widget.last
assert_not_nil widget
assert_equal 'foo', widget.name
assert_equal 1, widget.versions.size
assert_equal 'foobar', widget.versions.first.whodunnit
end

end
end
end
Loading