test/unit/relation_spy_tests.rb in ardb-0.21.0 vs test/unit/relation_spy_tests.rb in ardb-0.22.0
- old
+ new
@@ -11,11 +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 :to_sql, :reset!
should have_imeths :select
should have_imeths :from
should have_imeths :includes, :joins
should have_imeths :where
should have_imeths :order, :reverse_order
@@ -25,14 +25,14 @@
should have_imeths :merge, :only, :except
should have_imeths :find, :first, :first!, :last, :last!, :all
should have_imeths :count
should "default it's attributes" do
- assert_equal [], subject.applied
- assert_equal [], subject.results
- assert_equal nil, subject.limit_value
- assert_equal nil, subject.offset_value
+ assert_equal [], subject.applied
+ assert_equal [], subject.results
+ assert_nil subject.limit_value
+ assert_nil subject.offset_value
end
should "dup its applied and results arrays when copied" do
new_relation_spy = subject.dup
assert_not_same subject.applied, new_relation_spy.applied
@@ -55,20 +55,32 @@
expected = subject.applied.map(&:to_sql).join(', ')
assert_equal expected, subject.to_sql
end
+ should "be able to be reset" do
+ Factory.integer(3).times.each{ subject.applied << Factory.string }
+ Factory.integer(3).times.each{ subject.results << Factory.string }
+ subject.limit_value = Factory.integer
+ subject.offset_value = Factory.integer
+ subject.reset!
+ assert_equal [], subject.applied
+ assert_equal [], subject.results
+ assert_nil subject.limit_value
+ assert_nil subject.offset_value
+ end
+
end
class SelectTests < UnitTests
desc "select"
setup do
@relation_spy.select :column_a, :column_b
@applied = subject.applied.first
end
- should "have added a select applied expression with the passed args" do
+ should "add a select applied expression with the passed args" do
assert_instance_of AppliedExpression, @applied
assert_equal :select, @applied.type
assert_equal [ :column_a, :column_b ], @applied.args
end
@@ -79,11 +91,11 @@
setup do
@relation_spy.from "some SQL"
@applied = subject.applied.first
end
- should "have added a from applied expression with the passed args" do
+ should "add a from applied expression with the passed args" do
assert_instance_of AppliedExpression, @applied
assert_equal :from, @applied.type
assert_equal [ "some SQL" ], @applied.args
end
@@ -94,11 +106,11 @@
setup do
@relation_spy.includes :table_a, :table_b
@applied = subject.applied.first
end
- should "have added an includes applied expression with the passed args" do
+ should "add an includes applied expression with the passed args" do
assert_instance_of AppliedExpression, @applied
assert_equal :includes, @applied.type
assert_equal [ :table_a, :table_b ], @applied.args
end
@@ -109,11 +121,11 @@
setup do
@relation_spy.joins :table_a, :table_b
@applied = subject.applied.first
end
- should "have added a joins applied expression with the passed args" do
+ should "add a joins applied expression with the passed args" do
assert_instance_of AppliedExpression, @applied
assert_equal :joins, @applied.type
assert_equal [ :table_a, :table_b ], @applied.args
end
@@ -124,11 +136,11 @@
setup do
@relation_spy.where :column_a => 'some value'
@applied = subject.applied.first
end
- should "have added a where applied expression with the passed args" do
+ should "add a where applied expression with the passed args" do
assert_instance_of AppliedExpression, @applied
assert_equal :where, @applied.type
assert_equal [ { :column_a => 'some value' } ], @applied.args
end
@@ -139,11 +151,11 @@
setup do
@relation_spy.order :column_a, :column_b
@applied = subject.applied.first
end
- should "have added an order applied expression with the passed args" do
+ should "add an order applied expression with the passed args" do
assert_instance_of AppliedExpression, @applied
assert_equal :order, @applied.type
assert_equal [ :column_a, :column_b ], @applied.args
end
@@ -154,11 +166,11 @@
setup do
@relation_spy.reverse_order
@applied = subject.applied.first
end
- should "have added a reverse order applied expression with the passed args" do
+ should "add a reverse order applied expression with the passed args" do
assert_instance_of AppliedExpression, @applied
assert_equal :reverse_order, @applied.type
end
end
@@ -168,11 +180,11 @@
setup do
@relation_spy.group :column_a, :column_b
@applied = subject.applied.first
end
- should "have added a group applied expression with the passed args" do
+ should "add a group applied expression with the passed args" do
assert_instance_of AppliedExpression, @applied
assert_equal :group, @applied.type
assert_equal [ :column_a, :column_b ], @applied.args
end
@@ -183,11 +195,11 @@
setup do
@relation_spy.having 'COUNT(column_a) > 0'
@applied = subject.applied.first
end
- should "have added a having applied expression with the passed args" do
+ should "add a having applied expression with the passed args" do
assert_instance_of AppliedExpression, @applied
assert_equal :having, @applied.type
assert_equal [ 'COUNT(column_a) > 0' ], @applied.args
end
@@ -198,11 +210,11 @@
setup do
@relation_spy.readonly true
@applied = subject.applied.first
end
- should "have added a readonly applied expression with the passed args" do
+ should "add a readonly applied expression with the passed args" do
assert_instance_of AppliedExpression, @applied
assert_equal :readonly, @applied.type
assert_equal [ true ], @applied.args
end
@@ -213,11 +225,11 @@
setup do
@relation_spy.limit 100
@applied = subject.applied.first
end
- should "have added a limit applied expression with the passed args" do
+ should "add a limit applied expression with the passed args" do
assert_instance_of AppliedExpression, @applied
assert_equal :limit, @applied.type
assert_equal [ 100 ], @applied.args
end
@@ -232,11 +244,11 @@
setup do
@relation_spy.offset 100
@applied = subject.applied.first
end
- should "have added a offset applied expression with the passed args" do
+ should "add an offset applied expression with the passed args" do
assert_instance_of AppliedExpression, @applied
assert_equal :offset, @applied.type
assert_equal [ 100 ], @applied.args
end
@@ -267,10 +279,10 @@
@fake_relation = 'relation'
@relation_spy.merge @fake_relation
@applied = subject.applied.first
end
- should "have added a merge applied expression with the passed args" do
+ should "add a merge applied expression with the passed args" do
assert_instance_of AppliedExpression, @applied
assert_equal :merge, @applied.type
assert_equal [ @fake_relation ], @applied.args
end