Sha256: 06a42034b2e6790b982cb576db7033d5e9721a73219345b2205d43d1cbb0990e

Contents?: true

Size: 1.17 KB

Versions: 2

Compression:

Stored size: 1.17 KB

Contents

require 'test_helper'
# require 'sinatra/main'

# --- Tests for non-modular `Sinatra::Application` style ----
class Sinatra::Application
  ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => File.expand_path('../../dummy/db/test.sqlite3', __FILE__))
  register Sinatra::PaperTrail # we shouldn't actually need this line if I'm not mistaken but the tests seem to fail without it ATM

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

  def current_user
    'raboof'
  end

end

class SinatraTest < ActionDispatch::IntegrationTest
  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'
      assert_equal 'Hai', last_response.body
      widget = Widget.first
      assert_not_nil widget
      assert_equal 'bar', widget.name
      assert_equal 1, widget.versions.size
      assert_equal 'raboof', widget.versions.first.whodunnit
    end

  end
end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
paper_trail_without_deprecated-3.0.0.beta1 test/functional/sinatra_test.rb
paper_trail-3.0.0.beta1 test/functional/sinatra_test.rb