test/unit/relation_spy_tests.rb in ardb-0.29.1 vs test/unit/relation_spy_tests.rb in ardb-0.29.2
- old
+ new
@@ -1,5 +1,7 @@
+# frozen_string_literal: true
+
require "assert"
require "ardb/relation_spy"
class Ardb::RelationSpy
class UnitTests < Assert::Context
@@ -47,11 +49,12 @@
subject.select :column_a
assert_equal other_relation, subject
end
- should "build a fake sql string for its applied expressions using `to_sql`" do
+ 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(", ")
@@ -79,11 +82,11 @@
end
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
+ assert_equal [:column_a, :column_b], @applied.args
end
end
class FromTests < UnitTests
desc "from"
@@ -93,11 +96,11 @@
end
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
+ assert_equal ["some SQL"], @applied.args
end
end
class IncludesTests < UnitTests
desc "includes"
@@ -107,11 +110,11 @@
end
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
+ assert_equal [:table_a, :table_b], @applied.args
end
end
class JoinsTests < UnitTests
desc "joins"
@@ -121,25 +124,25 @@
end
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
+ assert_equal [:table_a, :table_b], @applied.args
end
end
class WhereTests < UnitTests
desc "where"
setup do
- @relation_spy.where :column_a => "some value"
+ @relation_spy.where column_a: "some value"
@applied = subject.applied.first
end
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
+ assert_equal [{ column_a: "some value" }], @applied.args
end
end
class OrderTests < UnitTests
desc "order"
@@ -149,11 +152,11 @@
end
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
+ assert_equal [:column_a, :column_b], @applied.args
end
end
class ReverseOrderTests < UnitTests
desc "reverse_order"
@@ -176,11 +179,11 @@
end
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
+ assert_equal [:column_a, :column_b], @applied.args
end
end
class HavingTests < UnitTests
desc "having"
@@ -190,11 +193,11 @@
end
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
+ assert_equal ["COUNT(column_a) > 0"], @applied.args
end
end
class ReadonlyTests < UnitTests
desc "readonly"
@@ -204,11 +207,11 @@
end
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
+ assert_equal [true], @applied.args
end
end
class LimitTests < UnitTests
desc "limit"
@@ -218,11 +221,11 @@
end
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
+ assert_equal [100], @applied.args
end
should "set it's limit value" do
assert_equal 100, subject.limit_value
end
@@ -236,22 +239,23 @@
end
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
+ assert_equal [100], @applied.args
end
should "set it's offset value" do
assert_equal 100, subject.offset_value
end
end
class MergeWithARelationSpyTests < UnitTests
desc "merge with a relation spy"
setup do
- @other_relation_spy = Ardb::RelationSpy.new.select("column").joins("table")
+ @other_relation_spy =
+ Ardb::RelationSpy.new.select("column").joins("table")
@relation_spy.merge @other_relation_spy
end
should "apply another relation's applied expressions using `merge`" do
@other_relation_spy.applied.each do |applied|
@@ -269,11 +273,11 @@
end
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
+ assert_equal [@fake_relation], @applied.args
end
end
class MergeWithSelfTests < UnitTests
desc "merge with itself"
@@ -288,11 +292,11 @@
end
class WithExpressionsTests < UnitTests
setup do
@relation_spy.select("column").includes("table").joins("table")
- @relation_spy.where(:column => "value").order("column")
+ @relation_spy.where(column: "value").order("column")
@relation_spy.group("column").having("count(*) > 1")
@relation_spy.limit(1).offset(1)
end
end
@@ -305,14 +309,14 @@
end
should "remove any applied expressions in the passed types" do
relation_spy = subject.except(:includes, :where, :group, :offset)
applied_types = relation_spy.applied.map(&:type)
- [ :select, :joins, :order, :having, :limit ].each do |type|
+ [:select, :joins, :order, :having, :limit].each do |type|
assert_includes type, applied_types
end
- [ :includes, :where, :group, :offset ].each do |type|
+ [:includes, :where, :group, :offset].each do |type|
assert_not_includes type, applied_types
end
end
should "unset the limit value if limit is included in the passed types" do
@@ -339,25 +343,27 @@
end
should "remove any applied expressions not in the passed types" do
relation_spy = subject.only(:includes, :where, :group, :offset)
applied_types = relation_spy.applied.map(&:type)
- [ :includes, :where, :group, :offset ].each do |type|
+ [:includes, :where, :group, :offset].each do |type|
assert_includes type, applied_types
end
- [ :select, :joins, :order, :having, :limit ].each do |type|
+ [:select, :joins, :order, :having, :limit].each do |type|
assert_not_includes type, applied_types
end
end
- should "unset the limit value if limit is not included in the passed types" do
+ should "unset the limit value if limit is not included in the passed "\
+ "types" do
relation_spy = subject.only(:limit)
assert_not_nil relation_spy.limit_value
relation_spy = subject.only(:select)
assert_nil relation_spy.limit_value
end
- should "unset the offset value if offset is not included in the passed types" do
+ should "unset the offset value if offset is not included in the passed "\
+ "types" do
relation_spy = subject.only(:offset)
assert_not_nil relation_spy.offset_value
relation_spy = subject.only(:select)
assert_nil relation_spy.offset_value
end