File: query_cache_test.rb

package info (click to toggle)
ruby-otr-activerecord 2.5.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 356 kB
  • sloc: ruby: 561; sh: 133; makefile: 6
file content (33 lines) | stat: -rw-r--r-- 941 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
require 'test_helper'

class QueryCacheTest < Minitest::Test
  def setup
    @db = Tempfile.create
    OTR::ActiveRecord.configure_from_hash!({adapter: "sqlite3", database: @db.path})
    OTR::ActiveRecord.establish_connection!
    Schema.load!
    @cat = Category.create!(name: "Foo")
    Widget.create!(category_id: @cat.id, name: "Spline")
  end

  def teardown
    ActiveRecord::Base.connection_handler.clear_all_connections!
    ActiveRecord::Base.connection_pool.disconnect!
    File.unlink @db.path
  end

  def test_returns_resp
    app = proc do |env|
      Widget.count
      body = "Testing"
      [200, {"Content-Type" => "text/plain", "Content-Length" => body.size.to_s}, [body]]
    end

    middleware = OTR::ActiveRecord::QueryCache.new(app)
    status, headers, body = middleware.call({})

    assert_equal 200, status
    assert_equal "text/plain", headers["Content-Type"]
    assert_equal ["Testing"], body.to_a
  end
end