aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/arel/nodes/sql_literal.rb4
-rw-r--r--test/nodes/test_sql_literal.rb8
2 files changed, 12 insertions, 0 deletions
diff --git a/lib/arel/nodes/sql_literal.rb b/lib/arel/nodes/sql_literal.rb
index 1bae8c9366..b43288b29c 100644
--- a/lib/arel/nodes/sql_literal.rb
+++ b/lib/arel/nodes/sql_literal.rb
@@ -5,6 +5,10 @@ module Arel
include Arel::Predications
include Arel::AliasPredication
include Arel::OrderPredications
+
+ def encode_with(coder)
+ coder.scalar = self.to_s
+ end
end
class BindParam < SqlLiteral
diff --git a/test/nodes/test_sql_literal.rb b/test/nodes/test_sql_literal.rb
index 9deb8e5d8d..085c5dad6b 100644
--- a/test/nodes/test_sql_literal.rb
+++ b/test/nodes/test_sql_literal.rb
@@ -1,4 +1,5 @@
require 'helper'
+require 'yaml'
module Arel
module Nodes
@@ -56,6 +57,13 @@ module Arel
@visitor.accept(node).must_be_like %{ (foo = 1 AND foo = 2) }
end
end
+
+ describe 'serialization' do
+ it 'serializes into YAML' do
+ yaml_literal = SqlLiteral.new('foo').to_yaml
+ assert_equal('foo', YAML.load(yaml_literal))
+ end
+ end
end
end
end