-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added LENGTH criteria function to String * Added REVERSE criteria function to String * Added ABS criteria function to Int * Added ABS criteria function to Float64 * Added CEIL criteria function to Float64 * Added FLOOR criteria function to Float64
- Loading branch information
Showing
8 changed files
with
91 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,33 @@ | ||
require "../spec_helper" | ||
|
||
private class QueryMe < BaseModel | ||
COLUMN_SQL = "purchases.id, purchases.created_at, purchases.updated_at, purchases.amount" | ||
|
||
table purchases do | ||
column amount : Float64 | ||
end | ||
end | ||
|
||
describe Float64::Lucky::Criteria do | ||
describe "abs" do | ||
it "uses ABS" do | ||
amount.abs.eq(39.99).to_sql.should eq ["SELECT #{QueryMe::COLUMN_SQL} FROM purchases WHERE ABS(purchases.amount) = $1", "39.99"] | ||
end | ||
end | ||
|
||
describe "ceil" do | ||
it "uses CEIL" do | ||
amount.ceil.eq(40.0).to_sql.should eq ["SELECT #{QueryMe::COLUMN_SQL} FROM purchases WHERE CEIL(purchases.amount) = $1", "40.0"] | ||
end | ||
end | ||
|
||
describe "floor" do | ||
it "uses FLOOR" do | ||
amount.floor.eq(39.0).to_sql.should eq ["SELECT #{QueryMe::COLUMN_SQL} FROM purchases WHERE FLOOR(purchases.amount) = $1", "39.0"] | ||
end | ||
end | ||
end | ||
|
||
private def amount | ||
QueryMe::BaseQuery.new.amount | ||
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,34 @@ | ||
require "../spec_helper" | ||
|
||
private class QueryMe < BaseModel | ||
COLUMN_SQL = "transactions.id, transactions.created_at, transactions.updated_at, transactions.small_amount, transactions.amount, transactions.big_amount" | ||
|
||
table transactions do | ||
column small_amount : Int16 | ||
column amount : Int32 | ||
column big_amount : Int64 | ||
end | ||
end | ||
|
||
# These specs handle all ints: Int16, Int32, Int64 | ||
describe "Int::Lucky::Criteria" do | ||
describe "abs" do | ||
it "uses ABS" do | ||
small_amount.abs.eq(4).to_sql.should eq ["SELECT #{QueryMe::COLUMN_SQL} FROM transactions WHERE ABS(transactions.small_amount) = $1", "4"] | ||
amount.abs.eq(400).to_sql.should eq ["SELECT #{QueryMe::COLUMN_SQL} FROM transactions WHERE ABS(transactions.amount) = $1", "400"] | ||
big_amount.abs.eq(40000).to_sql.should eq ["SELECT #{QueryMe::COLUMN_SQL} FROM transactions WHERE ABS(transactions.big_amount) = $1", "40000"] | ||
end | ||
end | ||
end | ||
|
||
private def small_amount | ||
QueryMe::BaseQuery.new.small_amount | ||
end | ||
|
||
private def amount | ||
QueryMe::BaseQuery.new.amount | ||
end | ||
|
||
private def big_amount | ||
QueryMe::BaseQuery.new.big_amount | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,6 +58,8 @@ struct Int16 | |
def select_sum! : Int64 | ||
select_sum || 0_i64 | ||
end | ||
|
||
define_function_criteria(abs, V) | ||
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 |
---|---|---|
|
@@ -59,6 +59,8 @@ struct Int32 | |
def select_sum! : Int64 | ||
select_sum || 0_i64 | ||
end | ||
|
||
define_function_criteria(abs, V) | ||
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 |
---|---|---|
|
@@ -57,6 +57,8 @@ struct Int64 | |
def select_sum! : Int64 | ||
select_sum || 0_i64 | ||
end | ||
|
||
define_function_criteria(abs, V) | ||
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