-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce custom Rspec matcher comparing derived and expected SQL
- Loading branch information
nikola
committed
Jan 23, 2017
1 parent
5ab4ccc
commit 91f348b
Showing
6 changed files
with
95 additions
and
81 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
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 |
---|---|---|
@@ -1,20 +1,24 @@ | ||
require 'spec_helper' | ||
|
||
describe Dumbo::Cast do | ||
let(:cast) do | ||
oid = Dumbo::DB.exec("SELECT ca.oid | ||
FROM pg_cast ca | ||
JOIN pg_type st ON st.oid=castsource | ||
JOIN pg_type tt ON tt.oid=casttarget | ||
WHERE format_type(st.oid,NULL) = 'bigint' | ||
AND format_type(tt.oid,tt.typtypmod) = 'integer';").first['oid'] | ||
Dumbo::Cast.new(oid) | ||
sql = <<-SQL | ||
SELECT ca.oid | ||
FROM pg_cast ca | ||
JOIN pg_type st ON st.oid=castsource | ||
JOIN pg_type tt ON tt.oid=casttarget | ||
WHERE format_type(st.oid,NULL) = 'bigint' | ||
AND format_type(tt.oid,tt.typtypmod) = 'integer' | ||
SQL | ||
|
||
Dumbo::Cast.new(Dumbo::DB.exec(sql).first['oid']) | ||
end | ||
|
||
it 'should have a sql representation' do | ||
expect(cast.to_sql).to eq <<-SQL.gsub(/^ {6}/, '') | ||
expect(cast.to_sql).to eq_sql <<-SQL | ||
CREATE CAST (bigint AS integer) | ||
WITH FUNCTION int4(bigint) | ||
AS ASSIGNMENT; | ||
SQL | ||
end | ||
SQL | ||
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
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
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
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