test/unit/relation_spy_tests.rb in ardb-0.19.0 vs test/unit/relation_spy_tests.rb in ardb-0.20.0
- old
+ new
@@ -11,10 +11,11 @@
subject{ @relation_spy }
should have_readers :applied
should have_accessors :results
should have_accessors :limit_value, :offset_value
+ should have_imeths :to_sql
should have_imeths :select
should have_imeths :from
should have_imeths :includes, :joins
should have_imeths :where
should have_imeths :order, :reverse_order
@@ -45,10 +46,19 @@
subject.select :column_a
assert_equal other_relation, subject
end
+ should "build a fake sql string for its applied expressions using `to_sql`" do
+ subject.select 'column'
+ subject.from 'table'
+ subject.joins 'my_table.my_column ON my_table.my_column = table.column'
+
+ expected = subject.applied.map(&:to_sql).join(', ')
+ assert_equal expected, subject.to_sql
+ end
+
end
class SelectTests < UnitTests
desc "select"
setup do
@@ -442,9 +452,26 @@
should "return the size of `all`" do
assert_equal subject.all.size, subject.count
subject.limit 2
assert_equal subject.all.size, subject.count
+ end
+
+ end
+
+ class AppliedExpressionTests < UnitTests
+ desc "AppliedExpression"
+ setup do
+ @applied_expression = AppliedExpression.new(:select, 'column')
+ end
+ subject{ @applied_expression }
+
+ should have_readers :type, :args
+ should have_imeths :to_sql
+
+ should "return a string representing the expression using `to_sql`" do
+ expected = "#{subject.type}: #{subject.args.inspect}"
+ assert_equal expected, subject.to_sql
end
end
Result = Struct.new(:id)