Sha256: 51dffc8495f780d8df3be1b62d931d7ff515457883b2edae32313dc395af82c0

Contents?: true

Size: 1.49 KB

Versions: 7

Compression:

Stored size: 1.49 KB

Contents

# PaperTrail is not compatible with sinatra 2 yet. Contributions welcome.
if Gem::Version.new(Rack.release) < Gem::Version.new("2.0.0.alpha")
  require "test_helper"
  # require 'sinatra/main'

  # --- Tests for non-modular `Sinatra::Application` style ----
  module Sinatra
    class Application
      configs = YAML.load_file(File.expand_path("../../dummy/config/database.yml", __FILE__))
      ActiveRecord::Base.configurations = configs
      ActiveRecord::Base.establish_connection(:test)

      # We shouldn't actually need this line if I'm not mistaken but the tests
      # seem to fail without it ATM
      register PaperTrail::Sinatra

      get "/test" do
        Widget.create!(name: "bar")
        "Hai"
      end

      def current_user
        @current_user ||= OpenStruct.new(id: "raboof")
      end
    end
  end

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

    def app
      @app ||= Sinatra::Application
    end

    test "baseline" do
      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.last
        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
end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/paper_trail-5.2.3/test/functional/sinatra_test.rb
paper_trail-6.0.2 test/functional/sinatra_test.rb
paper_trail-6.0.1 test/functional/sinatra_test.rb
paper_trail-6.0.0 test/functional/sinatra_test.rb
paper_trail-5.2.3 test/functional/sinatra_test.rb
paper_trail-5.2.2 test/functional/sinatra_test.rb
paper_trail-5.2.1 test/functional/sinatra_test.rb