2013-08-13 17:10:41 -04:00
|
|
|
require 'test_helper'
|
2013-08-19 11:33:03 -04:00
|
|
|
# require 'sinatra/main'
|
2013-08-13 17:10:41 -04:00
|
|
|
|
|
|
|
# --- Tests for non-modular `Sinatra::Application` style ----
|
|
|
|
class Sinatra::Application
|
2013-08-13 18:02:46 -04:00
|
|
|
ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => File.expand_path('../../dummy/db/test.sqlite3', __FILE__))
|
2013-08-15 11:00:55 -04:00
|
|
|
register Sinatra::PaperTrail # we shouldn't actually need this line if I'm not mistaken but the tests seem to fail without it ATM
|
2013-08-13 17:10:41 -04:00
|
|
|
|
|
|
|
get '/test' do
|
2013-08-19 11:33:03 -04:00
|
|
|
Widget.create!(:name => 'bar')
|
2013-08-15 11:00:55 -04:00
|
|
|
'Hai'
|
2013-08-13 17:10:41 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def current_user
|
2013-08-13 18:02:46 -04:00
|
|
|
'raboof'
|
2013-08-13 17:10:41 -04:00
|
|
|
end
|
2013-08-15 11:00:55 -04:00
|
|
|
|
2013-08-13 17:10:41 -04:00
|
|
|
end
|
|
|
|
|
2013-08-19 11:33:03 -04:00
|
|
|
class SinatraTest < ActionDispatch::IntegrationTest
|
2013-08-13 17:10:41 -04:00
|
|
|
include Rack::Test::Methods
|
|
|
|
|
|
|
|
def app
|
|
|
|
@app ||= Sinatra::Application
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'baseline' do
|
|
|
|
assert_nil Widget.first
|
|
|
|
assert_nil Widget.create.versions.first.whodunnit
|
|
|
|
end
|
|
|
|
|
|
|
|
context "`PaperTrail::Sinatra` in a `Sinatra::Application` application" do
|
|
|
|
|
|
|
|
should "sets the `user_for_paper_trail` from the `current_user` method" do
|
|
|
|
get '/test'
|
2013-08-15 11:00:55 -04:00
|
|
|
assert_equal 'Hai', last_response.body
|
2013-08-13 17:10:41 -04:00
|
|
|
widget = Widget.first
|
|
|
|
assert_not_nil widget
|
2013-08-19 11:33:03 -04:00
|
|
|
assert_equal 'bar', widget.name
|
2013-08-13 17:10:41 -04:00
|
|
|
assert_equal 1, widget.versions.size
|
2013-08-13 18:02:46 -04:00
|
|
|
assert_equal 'raboof', widget.versions.first.whodunnit
|
2013-08-13 17:10:41 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|