-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathpp_sql_rails_test.rb
More file actions
57 lines (46 loc) · 1.25 KB
/
pp_sql_rails_test.rb
File metadata and controls
57 lines (46 loc) · 1.25 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# frozen_string_literal: true
return if Gem::Specification.find_all_by_name('rails').empty?
require 'rails'
require 'test_helper'
require 'active_record'
require 'sqlite3'
ENV['RAILS_ENV'] = 'test'
module TeatApp
class Application < Rails::Application
config.eager_load = false
config.load_defaults Gem::Version.new(Rails.version).segments.first(2).join('.').to_f
initialize!
end
end
module ActiveRecord
class Base
establish_connection(adapter: 'sqlite3', database: ':memory:')
connection.create_table(:users) { |t| t.string :name }
self.logger = Logger.new(::LOGGER)
end
end
class User < ActiveRecord::Base; end
describe PpSql do
after { clear_logs! && set_default_config! }
it 'Rails & ActiveRecord with formatted output' do
User.create
assert(LOGGER.string.lines.detect { |line| line =~ /INTO\n/ })
clear_logs!
User.first
assert_equal LOGGER.string.lines.count, 6
end
it 'Rails & ActiveRecord with default output' do
PpSql.add_rails_logger_formatting = false
User.create
clear_logs!
User.first
assert_equal LOGGER.string.lines.count, 1
end
private
def clear_logs!
LOGGER.string.clear
end
def set_default_config!
PpSql.add_rails_logger_formatting = true
end
end