未验证 提交 2e6d9af6 编写于 作者: R Ryuta Kamizono 提交者: GitHub

Merge pull request #36800 from jamespearson/matches_regex_mysql

Enabled matches_regex for MySql
* Allow matches_regex on MySQL
*James Pearson*
* Allow specifying fixtures to be ignored by setting `ignore` in YAML file's '_fixture' section.
*Tongfei Gao*
......
......@@ -48,6 +48,14 @@ def visit_Arel_Nodes_IsDistinctFrom(o, collector)
visit_Arel_Nodes_IsNotDistinctFrom o, collector
end
def visit_Arel_Nodes_Regexp(o, collector)
infix_value o, collector, " REGEXP "
end
def visit_Arel_Nodes_NotRegexp(o, collector)
infix_value o, collector, " NOT REGEXP "
end
# In the simple case, MySQL allows us to place JOINs directly into the UPDATE
# query. However, this does not allow for LIMIT, OFFSET and ORDER. To support
# these, we must use a subquery.
......
......@@ -104,6 +104,52 @@ def compile(node)
sql.must_be_like %{ NOT "users"."name" <=> NULL }
end
end
describe "Nodes::Regexp" do
before do
@table = Table.new(:users)
@attr = @table[:id]
end
it "should know how to visit" do
node = @table[:name].matches_regexp("foo.*")
node.must_be_kind_of Nodes::Regexp
compile(node).must_be_like %{
"users"."name" REGEXP 'foo.*'
}
end
it "can handle subqueries" do
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" REGEXP 'foo.*')
}
end
end
describe "Nodes::NotRegexp" do
before do
@table = Table.new(:users)
@attr = @table[:id]
end
it "should know how to visit" do
node = @table[:name].does_not_match_regexp("foo.*")
node.must_be_kind_of Nodes::NotRegexp
compile(node).must_be_like %{
"users"."name" NOT REGEXP 'foo.*'
}
end
it "can handle subqueries" do
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" NOT REGEXP 'foo.*')
}
end
end
end
end
end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册