From d2e6be1677b124b3eef5b3ebe0fd4a0d31d8a2bf Mon Sep 17 00:00:00 2001 From: Keenan Brock Date: Sat, 5 Dec 2015 20:23:12 -0500 Subject: introduce predicate {does_not_}matches_regexp --- test/visitors/test_postgres.rb | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'test/visitors') diff --git a/test/visitors/test_postgres.rb b/test/visitors/test_postgres.rb index 4209712e8e..5901c56968 100644 --- a/test/visitors/test_postgres.rb +++ b/test/visitors/test_postgres.rb @@ -114,21 +114,25 @@ module Arel describe "Nodes::Regexp" do it "should know how to visit" do - node = Arel::Nodes::Regexp.new(@table[:name], Nodes.build_quoted('foo.*')) + node = @table[:name].matches_regexp('foo.*') + node.must_be_kind_of Nodes::Regexp + node.case_sensitive.must_equal(true) compile(node).must_be_like %{ "users"."name" ~ 'foo.*' } end it "can handle case insensitive" do - node = Arel::Nodes::Regexp.new(@table[:name], Nodes.build_quoted('foo.*'), false) + node = @table[:name].matches_regexp('foo.*', false) + node.must_be_kind_of Nodes::Regexp + node.case_sensitive.must_equal(false) compile(node).must_be_like %{ "users"."name" ~* 'foo.*' } end it 'can handle subqueries' do - subquery = @table.project(:id).where(Arel::Nodes::Regexp.new(@table[:name], Nodes.build_quoted('foo.*'))) + subquery = @table.project(:id).where(@table[:name].matches_regexp('foo.*')) node = @attr.in subquery compile(node).must_be_like %{ "users"."id" IN (SELECT id FROM "users" WHERE "users"."name" ~ 'foo.*') @@ -138,21 +142,24 @@ module Arel describe "Nodes::NotRegexp" do it "should know how to visit" do - node = Arel::Nodes::NotRegexp.new(@table[:name], Nodes.build_quoted('foo.*')) + node = @table[:name].does_not_match_regexp('foo.*') + node.must_be_kind_of Nodes::NotRegexp + node.case_sensitive.must_equal(true) compile(node).must_be_like %{ "users"."name" !~ 'foo.*' } end it "can handle case insensitive" do - node = Arel::Nodes::NotRegexp.new(@table[:name], Nodes.build_quoted('foo.*'), false) + node = @table[:name].does_not_match_regexp('foo.*', false) + node.case_sensitive.must_equal(false) compile(node).must_be_like %{ "users"."name" !~* 'foo.*' } end it 'can handle subqueries' do - subquery = @table.project(:id).where(Arel::Nodes::NotRegexp.new(@table[:name], Nodes.build_quoted('foo.*'))) + subquery = @table.project(:id).where(@table[:name].does_not_match_regexp('foo.*')) node = @attr.in subquery compile(node).must_be_like %{ "users"."id" IN (SELECT id FROM "users" WHERE "users"."name" !~ 'foo.*') -- cgit v1.2.3