-
Notifications
You must be signed in to change notification settings - Fork 463
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
68 additions
and
2 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 |
---|---|---|
|
@@ -86,4 +86,4 @@ class << ActiveRecord::Base | |
alias_method :acts_as_tree, :has_ancestry | ||
end | ||
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,33 @@ | ||
require_relative '../environment' | ||
|
||
class ClassMethodsTest < ActiveSupport::TestCase | ||
def test_sql_concat | ||
AncestryTestDatabase.with_model do |model| | ||
result = model.send(:sql_concat, 'table_name.id', "'/'") | ||
|
||
case ActiveRecord::Base.connection.adapter_name.downcase.to_sym | ||
when :sqlite | ||
assert_equal result, "table_name.id || '/'" | ||
when :mysql | ||
assert_equal result, "CONCAT(table_name.id, '/')" | ||
when :postgresql | ||
assert_equal result, "CONCAT(table_name.id, '/')" | ||
end | ||
end | ||
end | ||
|
||
def text_sql_cast_as_text | ||
AncestryTestDatabase.with_model do |model| | ||
result = model.send(:sql_cast_as_text, 'table_name.id') | ||
|
||
case ActiveRecord::Base.connection.adapter_name.downcase.to_sym | ||
when :sqlite | ||
assert_equal result, 'CAST(table_name.id AS TEXT)' | ||
when :mysql | ||
assert_equal result, 'CAST(table_name.id AS CHAR)' | ||
when :postgresql | ||
assert_equal result, 'CAST(table_name.id AS TEXT)' | ||
end | ||
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