Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'test_helper' | ||
|
||
TeatApp::Application.initialize! | ||
|
||
require 'active_record' | ||
require 'sqlite3' | ||
|
||
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:') | ||
|
||
ActiveRecord::Base.connection.create_table(:users) do |t| | ||
t.string :name | ||
end | ||
|
||
ActiveRecord::Base.logger = Logger.new(LOGGER = StringIO.new) | ||
|
||
class User < ActiveRecord::Base; end | ||
|
||
describe PpSql do | ||
after { clear_logs! } | ||
|
||
it 'load with right 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 | ||
|
||
private | ||
|
||
def clear_logs! | ||
LOGGER.string.clear | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'test_helper' | ||
|
||
describe PpSql do | ||
class SubString < String | ||
include PpSql::ToSqlBeautify | ||
end | ||
|
||
let(:str) { SubString.new 'SELECT COUNT(*) FROM "users"' } | ||
|
||
after { PpSql.rewrite_to_sql_method = true } | ||
|
||
it 'will parse provided sql' do | ||
assert_equal str.to_sql.lines.count, 4 | ||
end | ||
|
||
it 'throw string as is' do | ||
PpSql.rewrite_to_sql_method = false | ||
assert_equal str.to_sql.lines.count, 1 | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
|
||
# frozen_string_literal: false | ||
|
||
require 'test_helper' | ||
|
||
using PpSql::ToSqlBeautifyRefinement | ||
|
||
module PpSql | ||
describe ToSqlBeautifyRefinement do | ||
let(:str) { 'SELECT COUNT(*) FROM "users"' } | ||
|
||
it 'will parse provided sql' do | ||
assert_equal str.to_sql.lines.count, 4 | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'minitest/autorun' | ||
require 'minitest/focus' | ||
require 'rails' | ||
require 'pp_sql' | ||
|
||
require 'minitest/reporters' | ||
Minitest::Reporters.use! | ||
|
||
ENV['RAILS_ENV'] = 'test' | ||
ENV['DATABASE'] = 'sqlite3://localhost/:memory:' | ||
|
||
module TeatApp | ||
class Application < Rails::Application | ||
config.eager_load = false | ||
end | ||
end |