diff options
author | Matthew Draper <matthew@trebex.net> | 2018-02-24 17:15:50 +1030 |
---|---|---|
committer | Matthew Draper <matthew@trebex.net> | 2018-02-24 17:16:13 +1030 |
commit | 4c0a3d48804a363c7e9272519665a21f601b5248 (patch) | |
tree | 6b1f6e28f85cfd69a0ce534856ef939c7079d5cf /activerecord/test/cases | |
parent | 17ca17072dcdff11b3702a6b45f2fb0c8f8fe9a4 (diff) | |
download | rails-4c0a3d48804a363c7e9272519665a21f601b5248.tar.gz rails-4c0a3d48804a363c7e9272519665a21f601b5248.tar.bz2 rails-4c0a3d48804a363c7e9272519665a21f601b5248.zip |
Arel: rubocop -a
Diffstat (limited to 'activerecord/test/cases')
60 files changed, 1263 insertions, 1218 deletions
diff --git a/activerecord/test/cases/arel/attributes/attribute_test.rb b/activerecord/test/cases/arel/attributes/attribute_test.rb index 802d6e743f..52573021a5 100644 --- a/activerecord/test/cases/arel/attributes/attribute_test.rb +++ b/activerecord/test/cases/arel/attributes/attribute_test.rb @@ -1,17 +1,18 @@ # frozen_string_literal: true -require_relative '../helper' -require 'ostruct' + +require_relative "../helper" +require "ostruct" module Arel module Attributes class AttributeTest < Arel::Spec - describe '#not_eq' do - it 'should create a NotEqual node' do + describe "#not_eq" do + it "should create a NotEqual node" do relation = Table.new(:users) relation[:id].not_eq(10).must_be_kind_of Nodes::NotEqual end - it 'should generate != in sql' do + it "should generate != in sql" do relation = Table.new(:users) mgr = relation.project relation[:id] mgr.where relation[:id].not_eq(10) @@ -20,7 +21,7 @@ module Arel } end - it 'should handle nil' do + it "should handle nil" do relation = Table.new(:users) mgr = relation.project relation[:id] mgr.where relation[:id].not_eq(nil) @@ -30,45 +31,45 @@ module Arel end end - describe '#not_eq_any' do - it 'should create a Grouping node' do + describe "#not_eq_any" do + it "should create a Grouping node" do relation = Table.new(:users) - relation[:id].not_eq_any([1,2]).must_be_kind_of Nodes::Grouping + relation[:id].not_eq_any([1, 2]).must_be_kind_of Nodes::Grouping end - it 'should generate ORs in sql' do + it "should generate ORs in sql" do relation = Table.new(:users) mgr = relation.project relation[:id] - mgr.where relation[:id].not_eq_any([1,2]) + mgr.where relation[:id].not_eq_any([1, 2]) mgr.to_sql.must_be_like %{ SELECT "users"."id" FROM "users" WHERE ("users"."id" != 1 OR "users"."id" != 2) } end end - describe '#not_eq_all' do - it 'should create a Grouping node' do + describe "#not_eq_all" do + it "should create a Grouping node" do relation = Table.new(:users) - relation[:id].not_eq_all([1,2]).must_be_kind_of Nodes::Grouping + relation[:id].not_eq_all([1, 2]).must_be_kind_of Nodes::Grouping end - it 'should generate ANDs in sql' do + it "should generate ANDs in sql" do relation = Table.new(:users) mgr = relation.project relation[:id] - mgr.where relation[:id].not_eq_all([1,2]) + mgr.where relation[:id].not_eq_all([1, 2]) mgr.to_sql.must_be_like %{ SELECT "users"."id" FROM "users" WHERE ("users"."id" != 1 AND "users"."id" != 2) } end end - describe '#gt' do - it 'should create a GreaterThan node' do + describe "#gt" do + it "should create a GreaterThan node" do relation = Table.new(:users) relation[:id].gt(10).must_be_kind_of Nodes::GreaterThan end - it 'should generate > in sql' do + it "should generate > in sql" do relation = Table.new(:users) mgr = relation.project relation[:id] mgr.where relation[:id].gt(10) @@ -77,7 +78,7 @@ module Arel } end - it 'should handle comparing with a subquery' do + it "should handle comparing with a subquery" do users = Table.new(:users) avg = users.project(users[:karma].average) @@ -88,10 +89,10 @@ module Arel } end - it 'should accept various data types.' do + it "should accept various data types." do relation = Table.new(:users) mgr = relation.project relation[:id] - mgr.where relation[:name].gt('fake_name') + mgr.where relation[:name].gt("fake_name") mgr.to_sql.must_match %{"users"."name" > 'fake_name'} current_time = ::Time.now @@ -100,45 +101,45 @@ module Arel end end - describe '#gt_any' do - it 'should create a Grouping node' do + describe "#gt_any" do + it "should create a Grouping node" do relation = Table.new(:users) - relation[:id].gt_any([1,2]).must_be_kind_of Nodes::Grouping + relation[:id].gt_any([1, 2]).must_be_kind_of Nodes::Grouping end - it 'should generate ORs in sql' do + it "should generate ORs in sql" do relation = Table.new(:users) mgr = relation.project relation[:id] - mgr.where relation[:id].gt_any([1,2]) + mgr.where relation[:id].gt_any([1, 2]) mgr.to_sql.must_be_like %{ SELECT "users"."id" FROM "users" WHERE ("users"."id" > 1 OR "users"."id" > 2) } end end - describe '#gt_all' do - it 'should create a Grouping node' do + describe "#gt_all" do + it "should create a Grouping node" do relation = Table.new(:users) - relation[:id].gt_all([1,2]).must_be_kind_of Nodes::Grouping + relation[:id].gt_all([1, 2]).must_be_kind_of Nodes::Grouping end - it 'should generate ANDs in sql' do + it "should generate ANDs in sql" do relation = Table.new(:users) mgr = relation.project relation[:id] - mgr.where relation[:id].gt_all([1,2]) + mgr.where relation[:id].gt_all([1, 2]) mgr.to_sql.must_be_like %{ SELECT "users"."id" FROM "users" WHERE ("users"."id" > 1 AND "users"."id" > 2) } end end - describe '#gteq' do - it 'should create a GreaterThanOrEqual node' do + describe "#gteq" do + it "should create a GreaterThanOrEqual node" do relation = Table.new(:users) relation[:id].gteq(10).must_be_kind_of Nodes::GreaterThanOrEqual end - it 'should generate >= in sql' do + it "should generate >= in sql" do relation = Table.new(:users) mgr = relation.project relation[:id] mgr.where relation[:id].gteq(10) @@ -147,10 +148,10 @@ module Arel } end - it 'should accept various data types.' do + it "should accept various data types." do relation = Table.new(:users) mgr = relation.project relation[:id] - mgr.where relation[:name].gteq('fake_name') + mgr.where relation[:name].gteq("fake_name") mgr.to_sql.must_match %{"users"."name" >= 'fake_name'} current_time = ::Time.now @@ -159,45 +160,45 @@ module Arel end end - describe '#gteq_any' do - it 'should create a Grouping node' do + describe "#gteq_any" do + it "should create a Grouping node" do relation = Table.new(:users) - relation[:id].gteq_any([1,2]).must_be_kind_of Nodes::Grouping + relation[:id].gteq_any([1, 2]).must_be_kind_of Nodes::Grouping end - it 'should generate ORs in sql' do + it "should generate ORs in sql" do relation = Table.new(:users) mgr = relation.project relation[:id] - mgr.where relation[:id].gteq_any([1,2]) + mgr.where relation[:id].gteq_any([1, 2]) mgr.to_sql.must_be_like %{ SELECT "users"."id" FROM "users" WHERE ("users"."id" >= 1 OR "users"."id" >= 2) } end end - describe '#gteq_all' do - it 'should create a Grouping node' do + describe "#gteq_all" do + it "should create a Grouping node" do relation = Table.new(:users) - relation[:id].gteq_all([1,2]).must_be_kind_of Nodes::Grouping + relation[:id].gteq_all([1, 2]).must_be_kind_of Nodes::Grouping end - it 'should generate ANDs in sql' do + it "should generate ANDs in sql" do relation = Table.new(:users) mgr = relation.project relation[:id] - mgr.where relation[:id].gteq_all([1,2]) + mgr.where relation[:id].gteq_all([1, 2]) mgr.to_sql.must_be_like %{ SELECT "users"."id" FROM "users" WHERE ("users"."id" >= 1 AND "users"."id" >= 2) } end end - describe '#lt' do - it 'should create a LessThan node' do + describe "#lt" do + it "should create a LessThan node" do relation = Table.new(:users) relation[:id].lt(10).must_be_kind_of Nodes::LessThan end - it 'should generate < in sql' do + it "should generate < in sql" do relation = Table.new(:users) mgr = relation.project relation[:id] mgr.where relation[:id].lt(10) @@ -206,10 +207,10 @@ module Arel } end - it 'should accept various data types.' do + it "should accept various data types." do relation = Table.new(:users) mgr = relation.project relation[:id] - mgr.where relation[:name].lt('fake_name') + mgr.where relation[:name].lt("fake_name") mgr.to_sql.must_match %{"users"."name" < 'fake_name'} current_time = ::Time.now @@ -218,45 +219,45 @@ module Arel end end - describe '#lt_any' do - it 'should create a Grouping node' do + describe "#lt_any" do + it "should create a Grouping node" do relation = Table.new(:users) - relation[:id].lt_any([1,2]).must_be_kind_of Nodes::Grouping + relation[:id].lt_any([1, 2]).must_be_kind_of Nodes::Grouping end - it 'should generate ORs in sql' do + it "should generate ORs in sql" do relation = Table.new(:users) mgr = relation.project relation[:id] - mgr.where relation[:id].lt_any([1,2]) + mgr.where relation[:id].lt_any([1, 2]) mgr.to_sql.must_be_like %{ SELECT "users"."id" FROM "users" WHERE ("users"."id" < 1 OR "users"."id" < 2) } end end - describe '#lt_all' do - it 'should create a Grouping node' do + describe "#lt_all" do + it "should create a Grouping node" do relation = Table.new(:users) - relation[:id].lt_all([1,2]).must_be_kind_of Nodes::Grouping + relation[:id].lt_all([1, 2]).must_be_kind_of Nodes::Grouping end - it 'should generate ANDs in sql' do + it "should generate ANDs in sql" do relation = Table.new(:users) mgr = relation.project relation[:id] - mgr.where relation[:id].lt_all([1,2]) + mgr.where relation[:id].lt_all([1, 2]) mgr.to_sql.must_be_like %{ SELECT "users"."id" FROM "users" WHERE ("users"."id" < 1 AND "users"."id" < 2) } end end - describe '#lteq' do - it 'should create a LessThanOrEqual node' do + describe "#lteq" do + it "should create a LessThanOrEqual node" do relation = Table.new(:users) relation[:id].lteq(10).must_be_kind_of Nodes::LessThanOrEqual end - it 'should generate <= in sql' do + it "should generate <= in sql" do relation = Table.new(:users) mgr = relation.project relation[:id] mgr.where relation[:id].lteq(10) @@ -265,10 +266,10 @@ module Arel } end - it 'should accept various data types.' do + it "should accept various data types." do relation = Table.new(:users) mgr = relation.project relation[:id] - mgr.where relation[:name].lteq('fake_name') + mgr.where relation[:name].lteq("fake_name") mgr.to_sql.must_match %{"users"."name" <= 'fake_name'} current_time = ::Time.now @@ -277,45 +278,45 @@ module Arel end end - describe '#lteq_any' do - it 'should create a Grouping node' do + describe "#lteq_any" do + it "should create a Grouping node" do relation = Table.new(:users) - relation[:id].lteq_any([1,2]).must_be_kind_of Nodes::Grouping + relation[:id].lteq_any([1, 2]).must_be_kind_of Nodes::Grouping end - it 'should generate ORs in sql' do + it "should generate ORs in sql" do relation = Table.new(:users) mgr = relation.project relation[:id] - mgr.where relation[:id].lteq_any([1,2]) + mgr.where relation[:id].lteq_any([1, 2]) mgr.to_sql.must_be_like %{ SELECT "users"."id" FROM "users" WHERE ("users"."id" <= 1 OR "users"."id" <= 2) } end end - describe '#lteq_all' do - it 'should create a Grouping node' do + describe "#lteq_all" do + it "should create a Grouping node" do relation = Table.new(:users) - relation[:id].lteq_all([1,2]).must_be_kind_of Nodes::Grouping + relation[:id].lteq_all([1, 2]).must_be_kind_of Nodes::Grouping end - it 'should generate ANDs in sql' do + it "should generate ANDs in sql" do relation = Table.new(:users) mgr = relation.project relation[:id] - mgr.where relation[:id].lteq_all([1,2]) + mgr.where relation[:id].lteq_all([1, 2]) mgr.to_sql.must_be_like %{ SELECT "users"."id" FROM "users" WHERE ("users"."id" <= 1 AND "users"."id" <= 2) } end end - describe '#average' do - it 'should create a AVG node' do + describe "#average" do + it "should create a AVG node" do relation = Table.new(:users) relation[:id].average.must_be_kind_of Nodes::Avg end - it 'should generate the proper SQL' do + it "should generate the proper SQL" do relation = Table.new(:users) mgr = relation.project relation[:id].average mgr.to_sql.must_be_like %{ @@ -325,13 +326,13 @@ module Arel end end - describe '#maximum' do - it 'should create a MAX node' do + describe "#maximum" do + it "should create a MAX node" do relation = Table.new(:users) relation[:id].maximum.must_be_kind_of Nodes::Max end - it 'should generate proper SQL' do + it "should generate proper SQL" do relation = Table.new(:users) mgr = relation.project relation[:id].maximum mgr.to_sql.must_be_like %{ @@ -341,13 +342,13 @@ module Arel end end - describe '#minimum' do - it 'should create a Min node' do + describe "#minimum" do + it "should create a Min node" do relation = Table.new(:users) relation[:id].minimum.must_be_kind_of Nodes::Min end - it 'should generate proper SQL' do + it "should generate proper SQL" do relation = Table.new(:users) mgr = relation.project relation[:id].minimum mgr.to_sql.must_be_like %{ @@ -357,13 +358,13 @@ module Arel end end - describe '#sum' do - it 'should create a SUM node' do + describe "#sum" do + it "should create a SUM node" do relation = Table.new(:users) relation[:id].sum.must_be_kind_of Nodes::Sum end - it 'should generate the proper SQL' do + it "should generate the proper SQL" do relation = Table.new(:users) mgr = relation.project relation[:id].sum mgr.to_sql.must_be_like %{ @@ -373,13 +374,13 @@ module Arel end end - describe '#count' do - it 'should return a count node' do + describe "#count" do + it "should return a count node" do relation = Table.new(:users) relation[:id].count.must_be_kind_of Nodes::Count end - it 'should take a distinct param' do + it "should take a distinct param" do relation = Table.new(:users) count = relation[:id].count(nil) count.must_be_kind_of Nodes::Count @@ -387,8 +388,8 @@ module Arel end end - describe '#eq' do - it 'should return an equality node' do + describe "#eq" do + it "should return an equality node" do attribute = Attribute.new nil, nil equality = attribute.eq 1 equality.left.must_equal attribute @@ -396,7 +397,7 @@ module Arel equality.must_be_kind_of Nodes::Equality end - it 'should generate = in sql' do + it "should generate = in sql" do relation = Table.new(:users) mgr = relation.project relation[:id] mgr.where relation[:id].eq(10) @@ -405,7 +406,7 @@ module Arel } end - it 'should handle nil' do + it "should handle nil" do relation = Table.new(:users) mgr = relation.project relation[:id] mgr.where relation[:id].eq(nil) @@ -415,152 +416,152 @@ module Arel end end - describe '#eq_any' do - it 'should create a Grouping node' do + describe "#eq_any" do + it "should create a Grouping node" do relation = Table.new(:users) - relation[:id].eq_any([1,2]).must_be_kind_of Nodes::Grouping + relation[:id].eq_any([1, 2]).must_be_kind_of Nodes::Grouping end - it 'should generate ORs in sql' do + it "should generate ORs in sql" do relation = Table.new(:users) mgr = relation.project relation[:id] - mgr.where relation[:id].eq_any([1,2]) + mgr.where relation[:id].eq_any([1, 2]) mgr.to_sql.must_be_like %{ SELECT "users"."id" FROM "users" WHERE ("users"."id" = 1 OR "users"."id" = 2) } end - it 'should not eat input' do + it "should not eat input" do relation = Table.new(:users) mgr = relation.project relation[:id] - values = [1,2] + values = [1, 2] mgr.where relation[:id].eq_any(values) - values.must_equal [1,2] + values.must_equal [1, 2] end end - describe '#eq_all' do - it 'should create a Grouping node' do + describe "#eq_all" do + it "should create a Grouping node" do relation = Table.new(:users) - relation[:id].eq_all([1,2]).must_be_kind_of Nodes::Grouping + relation[:id].eq_all([1, 2]).must_be_kind_of Nodes::Grouping end - it 'should generate ANDs in sql' do + it "should generate ANDs in sql" do relation = Table.new(:users) mgr = relation.project relation[:id] - mgr.where relation[:id].eq_all([1,2]) + mgr.where relation[:id].eq_all([1, 2]) mgr.to_sql.must_be_like %{ SELECT "users"."id" FROM "users" WHERE ("users"."id" = 1 AND "users"."id" = 2) } end - it 'should not eat input' do + it "should not eat input" do relation = Table.new(:users) mgr = relation.project relation[:id] - values = [1,2] + values = [1, 2] mgr.where relation[:id].eq_all(values) - values.must_equal [1,2] + values.must_equal [1, 2] end end - describe '#matches' do - it 'should create a Matches node' do + describe "#matches" do + it "should create a Matches node" do relation = Table.new(:users) - relation[:name].matches('%bacon%').must_be_kind_of Nodes::Matches + relation[:name].matches("%bacon%").must_be_kind_of Nodes::Matches end - it 'should generate LIKE in sql' do + it "should generate LIKE in sql" do relation = Table.new(:users) mgr = relation.project relation[:id] - mgr.where relation[:name].matches('%bacon%') + mgr.where relation[:name].matches("%bacon%") mgr.to_sql.must_be_like %{ SELECT "users"."id" FROM "users" WHERE "users"."name" LIKE '%bacon%' } end end - describe '#matches_any' do - it 'should create a Grouping node' do + describe "#matches_any" do + it "should create a Grouping node" do relation = Table.new(:users) - relation[:name].matches_any(['%chunky%','%bacon%']).must_be_kind_of Nodes::Grouping + relation[:name].matches_any(["%chunky%", "%bacon%"]).must_be_kind_of Nodes::Grouping end - it 'should generate ORs in sql' do + it "should generate ORs in sql" do relation = Table.new(:users) mgr = relation.project relation[:id] - mgr.where relation[:name].matches_any(['%chunky%','%bacon%']) + mgr.where relation[:name].matches_any(["%chunky%", "%bacon%"]) mgr.to_sql.must_be_like %{ SELECT "users"."id" FROM "users" WHERE ("users"."name" LIKE '%chunky%' OR "users"."name" LIKE '%bacon%') } end end - describe '#matches_all' do - it 'should create a Grouping node' do + describe "#matches_all" do + it "should create a Grouping node" do relation = Table.new(:users) - relation[:name].matches_all(['%chunky%','%bacon%']).must_be_kind_of Nodes::Grouping + relation[:name].matches_all(["%chunky%", "%bacon%"]).must_be_kind_of Nodes::Grouping end - it 'should generate ANDs in sql' do + it "should generate ANDs in sql" do relation = Table.new(:users) mgr = relation.project relation[:id] - mgr.where relation[:name].matches_all(['%chunky%','%bacon%']) + mgr.where relation[:name].matches_all(["%chunky%", "%bacon%"]) mgr.to_sql.must_be_like %{ SELECT "users"."id" FROM "users" WHERE ("users"."name" LIKE '%chunky%' AND "users"."name" LIKE '%bacon%') } end end - describe '#does_not_match' do - it 'should create a DoesNotMatch node' do + describe "#does_not_match" do + it "should create a DoesNotMatch node" do relation = Table.new(:users) - relation[:name].does_not_match('%bacon%').must_be_kind_of Nodes::DoesNotMatch + relation[:name].does_not_match("%bacon%").must_be_kind_of Nodes::DoesNotMatch end - it 'should generate NOT LIKE in sql' do + it "should generate NOT LIKE in sql" do relation = Table.new(:users) mgr = relation.project relation[:id] - mgr.where relation[:name].does_not_match('%bacon%') + mgr.where relation[:name].does_not_match("%bacon%") mgr.to_sql.must_be_like %{ SELECT "users"."id" FROM "users" WHERE "users"."name" NOT LIKE '%bacon%' } end end - describe '#does_not_match_any' do - it 'should create a Grouping node' do + describe "#does_not_match_any" do + it "should create a Grouping node" do relation = Table.new(:users) - relation[:name].does_not_match_any(['%chunky%','%bacon%']).must_be_kind_of Nodes::Grouping + relation[:name].does_not_match_any(["%chunky%", "%bacon%"]).must_be_kind_of Nodes::Grouping end - it 'should generate ORs in sql' do + it "should generate ORs in sql" do relation = Table.new(:users) mgr = relation.project relation[:id] - mgr.where relation[:name].does_not_match_any(['%chunky%','%bacon%']) + mgr.where relation[:name].does_not_match_any(["%chunky%", "%bacon%"]) mgr.to_sql.must_be_like %{ SELECT "users"."id" FROM "users" WHERE ("users"."name" NOT LIKE '%chunky%' OR "users"."name" NOT LIKE '%bacon%') } end end - describe '#does_not_match_all' do - it 'should create a Grouping node' do + describe "#does_not_match_all" do + it "should create a Grouping node" do relation = Table.new(:users) - relation[:name].does_not_match_all(['%chunky%','%bacon%']).must_be_kind_of Nodes::Grouping + relation[:name].does_not_match_all(["%chunky%", "%bacon%"]).must_be_kind_of Nodes::Grouping end - it 'should generate ANDs in sql' do + it "should generate ANDs in sql" do relation = Table.new(:users) mgr = relation.project relation[:id] - mgr.where relation[:name].does_not_match_all(['%chunky%','%bacon%']) + mgr.where relation[:name].does_not_match_all(["%chunky%", "%bacon%"]) mgr.to_sql.must_be_like %{ SELECT "users"."id" FROM "users" WHERE ("users"."name" NOT LIKE '%chunky%' AND "users"."name" NOT LIKE '%bacon%') } end end - describe 'with a range' do - it 'can be constructed with a standard range' do + describe "with a range" do + it "can be constructed with a standard range" do attribute = Attribute.new nil, nil node = attribute.between(1..3) @@ -573,7 +574,7 @@ module Arel ) end - it 'can be constructed with a range starting from -Infinity' do + it "can be constructed with a range starting from -Infinity" do attribute = Attribute.new nil, nil node = attribute.between(-::Float::INFINITY..3) @@ -583,7 +584,7 @@ module Arel ) end - it 'can be constructed with a quoted range starting from -Infinity' do + it "can be constructed with a quoted range starting from -Infinity" do attribute = Attribute.new nil, nil node = attribute.between(quoted_range(-::Float::INFINITY, 3, false)) @@ -593,7 +594,7 @@ module Arel ) end - it 'can be constructed with an exclusive range starting from -Infinity' do + it "can be constructed with an exclusive range starting from -Infinity" do attribute = Attribute.new nil, nil node = attribute.between(-::Float::INFINITY...3) @@ -603,7 +604,7 @@ module Arel ) end - it 'can be constructed with a quoted exclusive range starting from -Infinity' do + it "can be constructed with a quoted exclusive range starting from -Infinity" do attribute = Attribute.new nil, nil node = attribute.between(quoted_range(-::Float::INFINITY, 3, true)) @@ -613,14 +614,14 @@ module Arel ) end - it 'can be constructed with an infinite range' do + it "can be constructed with an infinite range" do attribute = Attribute.new nil, nil node = attribute.between(-::Float::INFINITY..::Float::INFINITY) node.must_equal Nodes::NotIn.new(attribute, []) end - it 'can be constructed with a quoted infinite range' do + it "can be constructed with a quoted infinite range" do attribute = Attribute.new nil, nil node = attribute.between(quoted_range(-::Float::INFINITY, ::Float::INFINITY, false)) @@ -628,7 +629,7 @@ module Arel end - it 'can be constructed with a range ending at Infinity' do + it "can be constructed with a range ending at Infinity" do attribute = Attribute.new nil, nil node = attribute.between(0..::Float::INFINITY) @@ -638,7 +639,7 @@ module Arel ) end - it 'can be constructed with a quoted range ending at Infinity' do + it "can be constructed with a quoted range ending at Infinity" do attribute = Attribute.new nil, nil node = attribute.between(quoted_range(0, ::Float::INFINITY, false)) @@ -648,7 +649,7 @@ module Arel ) end - it 'can be constructed with an exclusive range' do + it "can be constructed with an exclusive range" do attribute = Attribute.new nil, nil node = attribute.between(0...3) @@ -673,11 +674,11 @@ module Arel end end - describe '#in' do - it 'can be constructed with a subquery' do + describe "#in" do + it "can be constructed with a subquery" do relation = Table.new(:users) mgr = relation.project relation[:id] - mgr.where relation[:name].does_not_match_all(['%chunky%','%bacon%']) + mgr.where relation[:name].does_not_match_all(["%chunky%", "%bacon%"]) attribute = Attribute.new nil, nil node = attribute.in(mgr) @@ -685,7 +686,7 @@ module Arel node.must_equal Nodes::In.new(attribute, mgr.ast) end - it 'can be constructed with a list' do + it "can be constructed with a list" do attribute = Attribute.new nil, nil node = attribute.in([1, 2, 3]) @@ -699,7 +700,7 @@ module Arel ) end - it 'can be constructed with a random object' do + it "can be constructed with a random object" do attribute = Attribute.new nil, nil random_object = Object.new node = attribute.in(random_object) @@ -710,58 +711,58 @@ module Arel ) end - it 'should generate IN in sql' do + it "should generate IN in sql" do relation = Table.new(:users) mgr = relation.project relation[:id] - mgr.where relation[:id].in([1,2,3]) + mgr.where relation[:id].in([1, 2, 3]) mgr.to_sql.must_be_like %{ SELECT "users"."id" FROM "users" WHERE "users"."id" IN (1, 2, 3) } end end - describe '#in_any' do - it 'should create a Grouping node' do + describe "#in_any" do + it "should create a Grouping node" do relation = Table.new(:users) - relation[:id].in_any([1,2]).must_be_kind_of Nodes::Grouping + relation[:id].in_any([1, 2]).must_be_kind_of Nodes::Grouping end - it 'should generate ORs in sql' do + it "should generate ORs in sql" do relation = Table.new(:users) mgr = relation.project relation[:id] - mgr.where relation[:id].in_any([[1,2], [3,4]]) + mgr.where relation[:id].in_any([[1, 2], [3, 4]]) mgr.to_sql.must_be_like %{ SELECT "users"."id" FROM "users" WHERE ("users"."id" IN (1, 2) OR "users"."id" IN (3, 4)) } end end - describe '#in_all' do - it 'should create a Grouping node' do + describe "#in_all" do + it "should create a Grouping node" do relation = Table.new(:users) - relation[:id].in_all([1,2]).must_be_kind_of Nodes::Grouping + relation[:id].in_all([1, 2]).must_be_kind_of Nodes::Grouping end - it 'should generate ANDs in sql' do + it "should generate ANDs in sql" do relation = Table.new(:users) mgr = relation.project relation[:id] - mgr.where relation[:id].in_all([[1,2], [3,4]]) + mgr.where relation[:id].in_all([[1, 2], [3, 4]]) mgr.to_sql.must_be_like %{ SELECT "users"."id" FROM "users" WHERE ("users"."id" IN (1, 2) AND "users"."id" IN (3, 4)) } end end - describe 'with a range' do - it 'can be constructed with a standard range' do + describe "with a range" do + it "can be constructed with a standard range" do attribute = Attribute.new nil, nil node = attribute.not_between(1..3) node.must_equal Nodes::Grouping.new(Nodes::Or.new( - Nodes::LessThan.new( - attribute, - Nodes::Casted.new(1, attribute) - ), + Nodes::LessThan.new( + attribute, + Nodes::Casted.new(1, attribute) + ), Nodes::GreaterThan.new( attribute, Nodes::Casted.new(3, attribute) @@ -769,7 +770,7 @@ module Arel )) end - it 'can be constructed with a range starting from -Infinity' do + it "can be constructed with a range starting from -Infinity" do attribute = Attribute.new nil, nil node = attribute.not_between(-::Float::INFINITY..3) @@ -779,7 +780,7 @@ module Arel ) end - it 'can be constructed with an exclusive range starting from -Infinity' do + it "can be constructed with an exclusive range starting from -Infinity" do attribute = Attribute.new nil, nil node = attribute.not_between(-::Float::INFINITY...3) @@ -789,14 +790,14 @@ module Arel ) end - it 'can be constructed with an infinite range' do + it "can be constructed with an infinite range" do attribute = Attribute.new nil, nil node = attribute.not_between(-::Float::INFINITY..::Float::INFINITY) node.must_equal Nodes::In.new(attribute, []) end - it 'can be constructed with a range ending at Infinity' do + it "can be constructed with a range ending at Infinity" do attribute = Attribute.new nil, nil node = attribute.not_between(0..::Float::INFINITY) @@ -806,15 +807,15 @@ module Arel ) end - it 'can be constructed with an exclusive range' do + it "can be constructed with an exclusive range" do attribute = Attribute.new nil, nil node = attribute.not_between(0...3) node.must_equal Nodes::Grouping.new(Nodes::Or.new( - Nodes::LessThan.new( - attribute, - Nodes::Casted.new(0, attribute) - ), + Nodes::LessThan.new( + attribute, + Nodes::Casted.new(0, attribute) + ), Nodes::GreaterThanOrEqual.new( attribute, Nodes::Casted.new(3, attribute) @@ -823,11 +824,11 @@ module Arel end end - describe '#not_in' do - it 'can be constructed with a subquery' do + describe "#not_in" do + it "can be constructed with a subquery" do relation = Table.new(:users) mgr = relation.project relation[:id] - mgr.where relation[:name].does_not_match_all(['%chunky%','%bacon%']) + mgr.where relation[:name].does_not_match_all(["%chunky%", "%bacon%"]) attribute = Attribute.new nil, nil node = attribute.not_in(mgr) @@ -835,7 +836,7 @@ module Arel node.must_equal Nodes::NotIn.new(attribute, mgr.ast) end - it 'can be constructed with a Union' do + it "can be constructed with a Union" do relation = Table.new(:users) mgr1 = relation.project(relation[:id]) mgr2 = relation.project(relation[:id]) @@ -847,7 +848,7 @@ module Arel } end - it 'can be constructed with a list' do + it "can be constructed with a list" do attribute = Attribute.new nil, nil node = attribute.not_in([1, 2, 3]) @@ -861,7 +862,7 @@ module Arel ) end - it 'can be constructed with a random object' do + it "can be constructed with a random object" do attribute = Attribute.new nil, nil random_object = Object.new node = attribute.not_in(random_object) @@ -872,71 +873,71 @@ module Arel ) end - it 'should generate NOT IN in sql' do + it "should generate NOT IN in sql" do relation = Table.new(:users) mgr = relation.project relation[:id] - mgr.where relation[:id].not_in([1,2,3]) + mgr.where relation[:id].not_in([1, 2, 3]) mgr.to_sql.must_be_like %{ SELECT "users"."id" FROM "users" WHERE "users"."id" NOT IN (1, 2, 3) } end end - describe '#not_in_any' do - it 'should create a Grouping node' do + describe "#not_in_any" do + it "should create a Grouping node" do relation = Table.new(:users) - relation[:id].not_in_any([1,2]).must_be_kind_of Nodes::Grouping + relation[:id].not_in_any([1, 2]).must_be_kind_of Nodes::Grouping end - it 'should generate ORs in sql' do + it "should generate ORs in sql" do relation = Table.new(:users) mgr = relation.project relation[:id] - mgr.where relation[:id].not_in_any([[1,2], [3,4]]) + mgr.where relation[:id].not_in_any([[1, 2], [3, 4]]) mgr.to_sql.must_be_like %{ SELECT "users"."id" FROM "users" WHERE ("users"."id" NOT IN (1, 2) OR "users"."id" NOT IN (3, 4)) } end end - describe '#not_in_all' do - it 'should create a Grouping node' do + describe "#not_in_all" do + it "should create a Grouping node" do relation = Table.new(:users) - relation[:id].not_in_all([1,2]).must_be_kind_of Nodes::Grouping + relation[:id].not_in_all([1, 2]).must_be_kind_of Nodes::Grouping end - it 'should generate ANDs in sql' do + it "should generate ANDs in sql" do relation = Table.new(:users) mgr = relation.project relation[:id] - mgr.where relation[:id].not_in_all([[1,2], [3,4]]) + mgr.where relation[:id].not_in_all([[1, 2], [3, 4]]) mgr.to_sql.must_be_like %{ SELECT "users"."id" FROM "users" WHERE ("users"."id" NOT IN (1, 2) AND "users"."id" NOT IN (3, 4)) } end end - describe '#eq_all' do - it 'should create a Grouping node' do + describe "#eq_all" do + it "should create a Grouping node" do relation = Table.new(:users) - relation[:id].eq_all([1,2]).must_be_kind_of Nodes::Grouping + relation[:id].eq_all([1, 2]).must_be_kind_of Nodes::Grouping end - it 'should generate ANDs in sql' do + it "should generate ANDs in sql" do relation = Table.new(:users) mgr = relation.project relation[:id] - mgr.where relation[:id].eq_all([1,2]) + mgr.where relation[:id].eq_all([1, 2]) mgr.to_sql.must_be_like %{ SELECT "users"."id" FROM "users" WHERE ("users"."id" = 1 AND "users"."id" = 2) } end end - describe '#asc' do - it 'should create an Ascending node' do + describe "#asc" do + it "should create an Ascending node" do relation = Table.new(:users) relation[:id].asc.must_be_kind_of Nodes::Ascending end - it 'should generate ASC in sql' do + it "should generate ASC in sql" do relation = Table.new(:users) mgr = relation.project relation[:id] mgr.order relation[:id].asc @@ -946,13 +947,13 @@ module Arel end end - describe '#desc' do - it 'should create a Descending node' do + describe "#desc" do + it "should create a Descending node" do relation = Table.new(:users) relation[:id].desc.must_be_kind_of Nodes::Descending end - it 'should generate DESC in sql' do + it "should generate DESC in sql" do relation = Table.new(:users) mgr = relation.project relation[:id] mgr.order relation[:id].desc @@ -962,18 +963,18 @@ module Arel end end - describe 'equality' do - describe '#to_sql' do - it 'should produce sql' do + describe "equality" do + describe "#to_sql" do + it "should produce sql" do table = Table.new :users - condition = table['id'].eq 1 + condition = table["id"].eq 1 condition.to_sql.must_equal '"users"."id" = 1' end end end - describe 'type casting' do - it 'does not type cast by default' do + describe "type casting" do + it "does not type cast by default" do table = Table.new(:foo) condition = table["id"].eq("1") @@ -981,7 +982,7 @@ module Arel condition.to_sql.must_equal %("foo"."id" = '1') end - it 'type casts when given an explicit caster' do + it "type casts when given an explicit caster" do fake_caster = Object.new def fake_caster.type_cast_for_database(attr_name, value) if attr_name == "id" @@ -997,7 +998,7 @@ module Arel condition.to_sql.must_equal %("foo"."id" = 1 AND "foo"."other_id" = '2') end - it 'does not type cast SqlLiteral nodes' do + it "does not type cast SqlLiteral nodes" do fake_caster = Object.new def fake_caster.type_cast_for_database(attr_name, value) value.to_i diff --git a/activerecord/test/cases/arel/attributes_test.rb b/activerecord/test/cases/arel/attributes_test.rb index e17a6f5fd2..b00af4bd29 100644 --- a/activerecord/test/cases/arel/attributes_test.rb +++ b/activerecord/test/cases/arel/attributes_test.rb @@ -1,62 +1,63 @@ # frozen_string_literal: true -require_relative 'helper' + +require_relative "helper" module Arel - describe 'Attributes' do - it 'responds to lower' do + describe "Attributes" do + it "responds to lower" do relation = Table.new(:users) attribute = relation[:foo] node = attribute.lower - assert_equal 'LOWER', node.name + assert_equal "LOWER", node.name assert_equal [attribute], node.expressions end - describe 'equality' do - it 'is equal with equal ivars' do - array = [Attribute.new('foo', 'bar'), Attribute.new('foo', 'bar')] + describe "equality" do + it "is equal with equal ivars" do + array = [Attribute.new("foo", "bar"), Attribute.new("foo", "bar")] assert_equal 1, array.uniq.size end - it 'is not equal with different ivars' do - array = [Attribute.new('foo', 'bar'), Attribute.new('foo', 'baz')] + it "is not equal with different ivars" do + array = [Attribute.new("foo", "bar"), Attribute.new("foo", "baz")] assert_equal 2, array.uniq.size end end - describe 'for' do - it 'deals with unknown column types' do + describe "for" do + it "deals with unknown column types" do column = Struct.new(:type).new :crazy Attributes.for(column).must_equal Attributes::Undefined end - it 'returns the correct constant for strings' do + it "returns the correct constant for strings" do [:string, :text, :binary].each do |type| column = Struct.new(:type).new type Attributes.for(column).must_equal Attributes::String end end - it 'returns the correct constant for ints' do + it "returns the correct constant for ints" do column = Struct.new(:type).new :integer Attributes.for(column).must_equal Attributes::Integer end - it 'returns the correct constant for floats' do + it "returns the correct constant for floats" do column = Struct.new(:type).new :float Attributes.for(column).must_equal Attributes::Float end - it 'returns the correct constant for decimals' do + it "returns the correct constant for decimals" do column = Struct.new(:type).new :decimal Attributes.for(column).must_equal Attributes::Decimal end - it 'returns the correct constant for boolean' do + it "returns the correct constant for boolean" do column = Struct.new(:type).new :boolean Attributes.for(column).must_equal Attributes::Boolean end - it 'returns the correct constant for time' do + it "returns the correct constant for time" do [:date, :datetime, :timestamp, :time].each do |type| column = Struct.new(:type).new type Attributes.for(column).must_equal Attributes::Time diff --git a/activerecord/test/cases/arel/collectors/bind_test.rb b/activerecord/test/cases/arel/collectors/bind_test.rb index febc7290a7..9123a70c3e 100644 --- a/activerecord/test/cases/arel/collectors/bind_test.rb +++ b/activerecord/test/cases/arel/collectors/bind_test.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true -require_relative '../helper' + +require_relative "../helper" module Arel module Collectors @@ -10,15 +11,15 @@ module Arel super end - def collect node + def collect(node) @visitor.accept(node, Collectors::Bind.new) end - def compile node + def compile(node) collect(node).value end - def ast_with_binds bvs + def ast_with_binds(bvs) table = Table.new(:users) manager = Arel::SelectManager.new table manager.where(table[:age].eq(Nodes::BindParam.new(bvs.shift))) diff --git a/activerecord/test/cases/arel/collectors/composite_test.rb b/activerecord/test/cases/arel/collectors/composite_test.rb index e330cae7a6..545637496f 100644 --- a/activerecord/test/cases/arel/collectors/composite_test.rb +++ b/activerecord/test/cases/arel/collectors/composite_test.rb @@ -1,8 +1,9 @@ # frozen_string_literal: true -require_relative '../helper' -require 'arel/collectors/bind' -require 'arel/collectors/composite' +require_relative "../helper" + +require "arel/collectors/bind" +require "arel/collectors/composite" module Arel module Collectors @@ -13,18 +14,18 @@ module Arel super end - def collect node + def collect(node) sql_collector = Collectors::SQLString.new bind_collector = Collectors::Bind.new collector = Collectors::Composite.new(sql_collector, bind_collector) @visitor.accept(node, collector) end - def compile node + def compile(node) collect(node).value end - def ast_with_binds bvs + def ast_with_binds(bvs) table = Table.new(:users) manager = Arel::SelectManager.new table manager.where(table[:age].eq(Nodes::BindParam.new(bvs.shift))) diff --git a/activerecord/test/cases/arel/collectors/sql_string_test.rb b/activerecord/test/cases/arel/collectors/sql_string_test.rb index a8ed3eb625..380573494d 100644 --- a/activerecord/test/cases/arel/collectors/sql_string_test.rb +++ b/activerecord/test/cases/arel/collectors/sql_string_test.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true -require_relative '../helper' + +require_relative "../helper" module Arel module Collectors @@ -10,15 +11,15 @@ module Arel super end - def collect node + def collect(node) @visitor.accept(node, Collectors::SQLString.new) end - def compile node + def compile(node) collect(node).value end - def ast_with_binds bv + def ast_with_binds(bv) table = Table.new(:users) manager = Arel::SelectManager.new table manager.where(table[:age].eq(bv)) diff --git a/activerecord/test/cases/arel/collectors/substitute_bind_collector_test.rb b/activerecord/test/cases/arel/collectors/substitute_bind_collector_test.rb index 18f0ac14de..255c8e79e9 100644 --- a/activerecord/test/cases/arel/collectors/substitute_bind_collector_test.rb +++ b/activerecord/test/cases/arel/collectors/substitute_bind_collector_test.rb @@ -1,7 +1,8 @@ # frozen_string_literal: true -require_relative '../helper' -require 'arel/collectors/substitute_binds' -require 'arel/collectors/sql_string' + +require_relative "../helper" +require "arel/collectors/substitute_binds" +require "arel/collectors/sql_string" module Arel module Collectors diff --git a/activerecord/test/cases/arel/crud_test.rb b/activerecord/test/cases/arel/crud_test.rb index 38a956b9dd..f3cdd8927f 100644 --- a/activerecord/test/cases/arel/crud_test.rb +++ b/activerecord/test/cases/arel/crud_test.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true -require_relative 'helper' + +require_relative "helper" module Arel class FakeCrudder < SelectManager @@ -10,12 +11,12 @@ module Arel @calls = [] @connection_pool = self @spec = self - @config = { :adapter => 'sqlite3' } + @config = { adapter: "sqlite3" } end def connection; self end - def method_missing name, *args + def method_missing(name, *args) @calls << [name, args] end end @@ -25,34 +26,34 @@ module Arel attr_reader :engine attr_accessor :ctx - def initialize engine = FakeEngine.new + def initialize(engine = FakeEngine.new) super end end - describe 'crud' do - describe 'insert' do - it 'should call insert on the connection' do + describe "crud" do + describe "insert" do + it "should call insert on the connection" do table = Table.new :users fc = FakeCrudder.new fc.from table - im = fc.compile_insert [[table[:id], 'foo']] + im = fc.compile_insert [[table[:id], "foo"]] assert_instance_of Arel::InsertManager, im end end - describe 'update' do - it 'should call update on the connection' do + describe "update" do + it "should call update on the connection" do table = Table.new :users fc = FakeCrudder.new fc.from table - stmt = fc.compile_update [[table[:id], 'foo']], Arel::Attributes::Attribute.new(table, 'id') + stmt = fc.compile_update [[table[:id], "foo"]], Arel::Attributes::Attribute.new(table, "id") assert_instance_of Arel::UpdateManager, stmt end end - describe 'delete' do - it 'should call delete on the connection' do + describe "delete" do + it "should call delete on the connection" do table = Table.new :users fc = FakeCrudder.new fc.from table diff --git a/activerecord/test/cases/arel/delete_manager_test.rb b/activerecord/test/cases/arel/delete_manager_test.rb index 36d482f10b..17a5271039 100644 --- a/activerecord/test/cases/arel/delete_manager_test.rb +++ b/activerecord/test/cases/arel/delete_manager_test.rb @@ -1,15 +1,16 @@ # frozen_string_literal: true -require_relative 'helper' + +require_relative "helper" module Arel class DeleteManagerTest < Arel::Spec - describe 'new' do - it 'takes an engine' do + describe "new" do + it "takes an engine" do Arel::DeleteManager.new end end - it 'handles limit properly' do + it "handles limit properly" do table = Table.new(:users) dm = Arel::DeleteManager.new dm.take 10 @@ -17,23 +18,23 @@ module Arel assert_match(/LIMIT 10/, dm.to_sql) end - describe 'from' do - it 'uses from' do + describe "from" do + it "uses from" do table = Table.new(:users) dm = Arel::DeleteManager.new dm.from table dm.to_sql.must_be_like %{ DELETE FROM "users" } end - it 'chains' do + it "chains" do table = Table.new(:users) dm = Arel::DeleteManager.new dm.from(table).must_equal dm end end - describe 'where' do - it 'uses where values' do + describe "where" do + it "uses where values" do table = Table.new(:users) dm = Arel::DeleteManager.new dm.from table @@ -41,7 +42,7 @@ module Arel dm.to_sql.must_be_like %{ DELETE FROM "users" WHERE "users"."id" = 10} end - it 'chains' do + it "chains" do table = Table.new(:users) dm = Arel::DeleteManager.new dm.where(table[:id].eq(10)).must_equal dm diff --git a/activerecord/test/cases/arel/factory_methods_test.rb b/activerecord/test/cases/arel/factory_methods_test.rb index 2600b81e31..26d2cdd08d 100644 --- a/activerecord/test/cases/arel/factory_methods_test.rb +++ b/activerecord/test/cases/arel/factory_methods_test.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true -require_relative 'helper' + +require_relative "helper" module Arel module FactoryMethods @@ -37,7 +38,7 @@ module Arel def test_lower lower = @factory.lower :one assert_instance_of Nodes::NamedFunction, lower - assert_equal 'LOWER', lower.name + assert_equal "LOWER", lower.name assert_equal [:one], lower.expressions.map(&:expr) end end diff --git a/activerecord/test/cases/arel/helper.rb b/activerecord/test/cases/arel/helper.rb index b716ee833f..1f8612f799 100644 --- a/activerecord/test/cases/arel/helper.rb +++ b/activerecord/test/cases/arel/helper.rb @@ -1,13 +1,14 @@ # frozen_string_literal: true -require 'rubygems' -require 'minitest/autorun' -require 'arel' -require_relative 'support/fake_record' +require "rubygems" +require "minitest/autorun" +require "arel" + +require_relative "support/fake_record" class Object - def must_be_like other - gsub(/\s+/, ' ').strip.must_equal other.gsub(/\s+/, ' ').strip + def must_be_like(other) + gsub(/\s+/, " ").strip.must_equal other.gsub(/\s+/, " ").strip end end @@ -24,9 +25,9 @@ module Arel super end - def assert_like expected, actual - assert_equal expected.gsub(/\s+/, ' ').strip, - actual.gsub(/\s+/, ' ').strip + def assert_like(expected, actual) + assert_equal expected.gsub(/\s+/, " ").strip, + actual.gsub(/\s+/, " ").strip end end diff --git a/activerecord/test/cases/arel/insert_manager_test.rb b/activerecord/test/cases/arel/insert_manager_test.rb index 33fab63fbc..ae10ccf56c 100644 --- a/activerecord/test/cases/arel/insert_manager_test.rb +++ b/activerecord/test/cases/arel/insert_manager_test.rb @@ -1,16 +1,17 @@ # frozen_string_literal: true -require_relative 'helper' + +require_relative "helper" module Arel class InsertManagerTest < Arel::Spec - describe 'new' do - it 'takes an engine' do + describe "new" do + it "takes an engine" do Arel::InsertManager.new end end - describe 'insert' do - it 'can create a Values node' do + describe "insert" do + it "can create a Values node" do manager = Arel::InsertManager.new values = manager.create_values %w{ a b }, %w{ c d } @@ -19,16 +20,16 @@ module Arel assert_equal %w{ c d }, values.right end - it 'allows sql literals' do - manager = Arel::InsertManager.new + it "allows sql literals" do + manager = Arel::InsertManager.new manager.into Table.new(:users) - manager.values = manager.create_values [Arel.sql('*')], %w{ a } + manager.values = manager.create_values [Arel.sql("*")], %w{ a } manager.to_sql.must_be_like %{ INSERT INTO \"users\" VALUES (*) } end - it 'works with multiple values' do + it "works with multiple values" do table = Table.new(:users) manager = Arel::InsertManager.new manager.into table @@ -39,7 +40,7 @@ module Arel manager.values = manager.create_values_list([ %w{1 david}, %w{2 kir}, - ["3", Arel.sql('DEFAULT')], + ["3", Arel.sql("DEFAULT")], ]) manager.to_sql.must_be_like %{ @@ -47,7 +48,7 @@ module Arel } end - it 'literals in multiple values are not escaped' do + it "literals in multiple values are not escaped" do table = Table.new(:users) manager = Arel::InsertManager.new manager.into table @@ -55,8 +56,8 @@ module Arel manager.columns << table[:name] manager.values = manager.create_values_list([ - [Arel.sql('*')], - [Arel.sql('DEFAULT')], + [Arel.sql("*")], + [Arel.sql("DEFAULT")], ]) manager.to_sql.must_be_like %{ @@ -64,7 +65,7 @@ module Arel } end - it 'works with multiple single values' do + it "works with multiple single values" do table = Table.new(:users) manager = Arel::InsertManager.new manager.into table @@ -74,7 +75,7 @@ module Arel manager.values = manager.create_values_list([ %w{david}, %w{kir}, - [Arel.sql('DEFAULT')], + [Arel.sql("DEFAULT")], ]) manager.to_sql.must_be_like %{ @@ -114,26 +115,26 @@ module Arel } end - it 'takes a list of lists' do + it "takes a list of lists" do table = Table.new(:users) manager = Arel::InsertManager.new manager.into table - manager.insert [[table[:id], 1], [table[:name], 'aaron']] + manager.insert [[table[:id], 1], [table[:name], "aaron"]] manager.to_sql.must_be_like %{ INSERT INTO "users" ("id", "name") VALUES (1, 'aaron') } end - it 'defaults the table' do + it "defaults the table" do table = Table.new(:users) manager = Arel::InsertManager.new - manager.insert [[table[:id], 1], [table[:name], 'aaron']] + manager.insert [[table[:id], 1], [table[:name], "aaron"]] manager.to_sql.must_be_like %{ INSERT INTO "users" ("id", "name") VALUES (1, 'aaron') } end - it 'noop for empty list' do + it "noop for empty list" do table = Table.new(:users) manager = Arel::InsertManager.new manager.insert [[table[:id], 1]] @@ -143,21 +144,21 @@ module Arel } end - it 'is chainable' do + it "is chainable" do table = Table.new(:users) manager = Arel::InsertManager.new - insert_result = manager.insert [[table[:id],1]] + insert_result = manager.insert [[table[:id], 1]] assert_equal manager, insert_result end end - describe 'into' do - it 'takes a Table and chains' do + describe "into" do + it "takes a Table and chains" do manager = Arel::InsertManager.new manager.into(Table.new(:users)).must_equal manager end - it 'converts to sql' do + it "converts to sql" do table = Table.new :users manager = Arel::InsertManager.new manager.into table @@ -167,7 +168,7 @@ module Arel end end - describe 'columns' do + describe "columns" do it "converts to sql" do table = Table.new :users manager = Arel::InsertManager.new @@ -209,7 +210,7 @@ module Arel manager = Arel::InsertManager.new manager.into table - manager.values = Nodes::Values.new [1, 'aaron'] + manager.values = Nodes::Values.new [1, "aaron"] manager.columns << table[:id] manager.columns << table[:name] manager.to_sql.must_be_like %{ @@ -227,7 +228,7 @@ module Arel manager.into table select = Arel::SelectManager.new - select.project Arel.sql('1') + select.project Arel.sql("1") select.project Arel.sql('"aaron"') manager.select select @@ -239,6 +240,5 @@ module Arel end end - end end diff --git a/activerecord/test/cases/arel/nodes/and_test.rb b/activerecord/test/cases/arel/nodes/and_test.rb index de63e0bb31..eff54abd91 100644 --- a/activerecord/test/cases/arel/nodes/and_test.rb +++ b/activerecord/test/cases/arel/nodes/and_test.rb @@ -1,21 +1,21 @@ # frozen_string_literal: true -require_relative '../helper' + +require_relative "../helper" module Arel module Nodes - describe 'And' do - describe 'equality' do - it 'is equal with equal ivars' do - array = [And.new(['foo', 'bar']), And.new(['foo', 'bar'])] + describe "And" do + describe "equality" do + it "is equal with equal ivars" do + array = [And.new(["foo", "bar"]), And.new(["foo", "bar"])] assert_equal 1, array.uniq.size end - it 'is not equal with different ivars' do - array = [And.new(['foo', 'bar']), And.new(['foo', 'baz'])] + it "is not equal with different ivars" do + array = [And.new(["foo", "bar"]), And.new(["foo", "baz"])] assert_equal 2, array.uniq.size end end end end end - diff --git a/activerecord/test/cases/arel/nodes/as_test.rb b/activerecord/test/cases/arel/nodes/as_test.rb index 09c8aa8d62..1169ea11c9 100644 --- a/activerecord/test/cases/arel/nodes/as_test.rb +++ b/activerecord/test/cases/arel/nodes/as_test.rb @@ -1,32 +1,33 @@ # frozen_string_literal: true -require_relative '../helper' + +require_relative "../helper" module Arel module Nodes - describe 'As' do - describe '#as' do - it 'makes an AS node' do + describe "As" do + describe "#as" do + it "makes an AS node" do attr = Table.new(:users)[:id] - as = attr.as(Arel.sql('foo')) + as = attr.as(Arel.sql("foo")) assert_equal attr, as.left - assert_equal 'foo', as.right + assert_equal "foo", as.right end - it 'converts right to SqlLiteral if a string' do + it "converts right to SqlLiteral if a string" do attr = Table.new(:users)[:id] - as = attr.as('foo') + as = attr.as("foo") assert_kind_of Arel::Nodes::SqlLiteral, as.right end end - describe 'equality' do - it 'is equal with equal ivars' do - array = [As.new('foo', 'bar'), As.new('foo', 'bar')] + describe "equality" do + it "is equal with equal ivars" do + array = [As.new("foo", "bar"), As.new("foo", "bar")] assert_equal 1, array.uniq.size end - it 'is not equal with different ivars' do - array = [As.new('foo', 'bar'), As.new('foo', 'baz')] + it "is not equal with different ivars" do + array = [As.new("foo", "bar"), As.new("foo", "baz")] assert_equal 2, array.uniq.size end end diff --git a/activerecord/test/cases/arel/nodes/ascending_test.rb b/activerecord/test/cases/arel/nodes/ascending_test.rb index 5c73e69fa5..1efb16222a 100644 --- a/activerecord/test/cases/arel/nodes/ascending_test.rb +++ b/activerecord/test/cases/arel/nodes/ascending_test.rb @@ -1,43 +1,44 @@ # frozen_string_literal: true -require_relative '../helper' + +require_relative "../helper" module Arel module Nodes class TestAscending < Arel::Test def test_construct - ascending = Ascending.new 'zomg' - assert_equal 'zomg', ascending.expr + ascending = Ascending.new "zomg" + assert_equal "zomg", ascending.expr end def test_reverse - ascending = Ascending.new 'zomg' + ascending = Ascending.new "zomg" descending = ascending.reverse assert_kind_of Descending, descending assert_equal ascending.expr, descending.expr end def test_direction - ascending = Ascending.new 'zomg' + ascending = Ascending.new "zomg" assert_equal :asc, ascending.direction end def test_ascending? - ascending = Ascending.new 'zomg' + ascending = Ascending.new "zomg" assert ascending.ascending? end def test_descending? - ascending = Ascending.new 'zomg' + ascending = Ascending.new "zomg" assert !ascending.descending? end def test_equality_with_same_ivars - array = [Ascending.new('zomg'), Ascending.new('zomg')] + array = [Ascending.new("zomg"), Ascending.new("zomg")] assert_equal 1, array.uniq.size end def test_inequality_with_different_ivars - array = [Ascending.new('zomg'), Ascending.new('zomg!')] + array = [Ascending.new("zomg"), Ascending.new("zomg!")] assert_equal 2, array.uniq.size end end diff --git a/activerecord/test/cases/arel/nodes/bin_test.rb b/activerecord/test/cases/arel/nodes/bin_test.rb index 923a296adf..ee2ec3cf2f 100644 --- a/activerecord/test/cases/arel/nodes/bin_test.rb +++ b/activerecord/test/cases/arel/nodes/bin_test.rb @@ -1,32 +1,33 @@ # frozen_string_literal: true -require_relative '../helper' + +require_relative "../helper" module Arel module Nodes class TestBin < Arel::Test def test_new - assert Arel::Nodes::Bin.new('zomg') + assert Arel::Nodes::Bin.new("zomg") end def test_default_to_sql viz = Arel::Visitors::ToSql.new Table.engine.connection_pool - node = Arel::Nodes::Bin.new(Arel.sql('zomg')) - assert_equal 'zomg', viz.accept(node, Collectors::SQLString.new).value + node = Arel::Nodes::Bin.new(Arel.sql("zomg")) + assert_equal "zomg", viz.accept(node, Collectors::SQLString.new).value end def test_mysql_to_sql viz = Arel::Visitors::MySQL.new Table.engine.connection_pool - node = Arel::Nodes::Bin.new(Arel.sql('zomg')) - assert_equal 'BINARY zomg', viz.accept(node, Collectors::SQLString.new).value + node = Arel::Nodes::Bin.new(Arel.sql("zomg")) + assert_equal "BINARY zomg", viz.accept(node, Collectors::SQLString.new).value end def test_equality_with_same_ivars - array = [Bin.new('zomg'), Bin.new('zomg')] + array = [Bin.new("zomg"), Bin.new("zomg")] assert_equal 1, array.uniq.size end def test_inequality_with_different_ivars - array = [Bin.new('zomg'), Bin.new('zomg!')] + array = [Bin.new("zomg"), Bin.new("zomg!")] assert_equal 2, array.uniq.size end end diff --git a/activerecord/test/cases/arel/nodes/binary_test.rb b/activerecord/test/cases/arel/nodes/binary_test.rb index 0bea35f7dd..9bc55a155b 100644 --- a/activerecord/test/cases/arel/nodes/binary_test.rb +++ b/activerecord/test/cases/arel/nodes/binary_test.rb @@ -1,22 +1,23 @@ # frozen_string_literal: true -require_relative '../helper' + +require_relative "../helper" module Arel module Nodes - describe 'Binary' do - describe '#hash' do - it 'generates a hash based on its value' do - eq = Equality.new('foo', 'bar') - eq2 = Equality.new('foo', 'bar') - eq3 = Equality.new('bar', 'baz') + describe "Binary" do + describe "#hash" do + it "generates a hash based on its value" do + eq = Equality.new("foo", "bar") + eq2 = Equality.new("foo", "bar") + eq3 = Equality.new("bar", "baz") assert_equal eq.hash, eq2.hash refute_equal eq.hash, eq3.hash end - it 'generates a hash specific to its class' do - eq = Equality.new('foo', 'bar') - neq = NotEqual.new('foo', 'bar') + it "generates a hash specific to its class" do + eq = Equality.new("foo", "bar") + neq = NotEqual.new("foo", "bar") refute_equal eq.hash, neq.hash end diff --git a/activerecord/test/cases/arel/nodes/bind_param_test.rb b/activerecord/test/cases/arel/nodes/bind_param_test.rb index 665581edce..37a362ece4 100644 --- a/activerecord/test/cases/arel/nodes/bind_param_test.rb +++ b/activerecord/test/cases/arel/nodes/bind_param_test.rb @@ -1,19 +1,20 @@ # frozen_string_literal: true -require_relative '../helper' + +require_relative "../helper" module Arel module Nodes - describe 'BindParam' do - it 'is equal to other bind params with the same value' do + describe "BindParam" do + it "is equal to other bind params with the same value" do BindParam.new(1).must_equal(BindParam.new(1)) BindParam.new("foo").must_equal(BindParam.new("foo")) end - it 'is not equal to other nodes' do + it "is not equal to other nodes" do BindParam.new(nil).wont_equal(Node.new) end - it 'is not equal to bind params with different values' do + it "is not equal to bind params with different values" do BindParam.new(1).wont_equal(BindParam.new(2)) end end diff --git a/activerecord/test/cases/arel/nodes/case_test.rb b/activerecord/test/cases/arel/nodes/case_test.rb index 70364fe6ab..2c087e624e 100644 --- a/activerecord/test/cases/arel/nodes/case_test.rb +++ b/activerecord/test/cases/arel/nodes/case_test.rb @@ -1,26 +1,27 @@ # frozen_string_literal: true -require_relative '../helper' + +require_relative "../helper" module Arel module Nodes - describe 'Case' do - describe '#initialize' do - it 'sets case expression from first argument' do - node = Case.new 'foo' + describe "Case" do + describe "#initialize" do + it "sets case expression from first argument" do + node = Case.new "foo" - assert_equal 'foo', node.case + assert_equal "foo", node.case end - it 'sets default case from second argument' do - node = Case.new nil, 'bar' + it "sets default case from second argument" do + node = Case.new nil, "bar" - assert_equal 'bar', node.default + assert_equal "bar", node.default end end - describe '#clone' do - it 'clones case, conditions and default' do - foo = Nodes.build_quoted 'foo' + describe "#clone" do + it "clones case, conditions and default" do + foo = Nodes.build_quoted "foo" node = Case.new node.case = foo @@ -40,9 +41,9 @@ module Arel end end - describe 'equality' do - it 'is equal with equal ivars' do - foo = Nodes.build_quoted 'foo' + describe "equality" do + it "is equal with equal ivars" do + foo = Nodes.build_quoted "foo" one = Nodes.build_quoted 1 zero = Nodes.build_quoted 0 @@ -59,9 +60,9 @@ module Arel assert_equal 1, array.uniq.size end - it 'is not equal with different ivars' do - foo = Nodes.build_quoted 'foo' - bar = Nodes.build_quoted 'bar' + it "is not equal with different ivars" do + foo = Nodes.build_quoted "foo" + bar = Nodes.build_quoted "bar" one = Nodes.build_quoted 1 zero = Nodes.build_quoted 0 diff --git a/activerecord/test/cases/arel/nodes/casted_test.rb b/activerecord/test/cases/arel/nodes/casted_test.rb index a6e2dd2294..e27f58a4e2 100644 --- a/activerecord/test/cases/arel/nodes/casted_test.rb +++ b/activerecord/test/cases/arel/nodes/casted_test.rb @@ -1,11 +1,12 @@ # frozen_string_literal: true -require_relative '../helper' + +require_relative "../helper" module Arel module Nodes describe Casted do - describe '#hash' do - it 'is equal when eql? returns true' do + describe "#hash" do + it "is equal when eql? returns true" do one = Casted.new 1, 2 also_one = Casted.new 1, 2 diff --git a/activerecord/test/cases/arel/nodes/count_test.rb b/activerecord/test/cases/arel/nodes/count_test.rb index 28d8481993..3107659e77 100644 --- a/activerecord/test/cases/arel/nodes/count_test.rb +++ b/activerecord/test/cases/arel/nodes/count_test.rb @@ -1,11 +1,12 @@ # frozen_string_literal: true -require_relative '../helper' + +require_relative "../helper" class Arel::Nodes::CountTest < Arel::Spec describe "as" do - it 'should alias the count' do + it "should alias the count" do table = Arel::Table.new :users - table[:id].count.as('foo').to_sql.must_be_like %{ + table[:id].count.as("foo").to_sql.must_be_like %{ COUNT("users"."id") AS foo } end @@ -20,20 +21,20 @@ class Arel::Nodes::CountTest < Arel::Spec end end - describe 'equality' do - it 'is equal with equal ivars' do - array = [Arel::Nodes::Count.new('foo'), Arel::Nodes::Count.new('foo')] + describe "equality" do + it "is equal with equal ivars" do + array = [Arel::Nodes::Count.new("foo"), Arel::Nodes::Count.new("foo")] assert_equal 1, array.uniq.size end - it 'is not equal with different ivars' do - array = [Arel::Nodes::Count.new('foo'), Arel::Nodes::Count.new('foo!')] + it "is not equal with different ivars" do + array = [Arel::Nodes::Count.new("foo"), Arel::Nodes::Count.new("foo!")] assert_equal 2, array.uniq.size end end - describe 'math' do - it 'allows mathematical functions' do + describe "math" do + it "allows mathematical functions" do table = Arel::Table.new :users (table[:id].count + 1).to_sql.must_be_like %{ (COUNT("users"."id") + 1) diff --git a/activerecord/test/cases/arel/nodes/delete_statement_test.rb b/activerecord/test/cases/arel/nodes/delete_statement_test.rb index ada8964646..3f078063a4 100644 --- a/activerecord/test/cases/arel/nodes/delete_statement_test.rb +++ b/activerecord/test/cases/arel/nodes/delete_statement_test.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true -require_relative '../helper' + +require_relative "../helper" describe Arel::Nodes::DeleteStatement do describe "#clone" do @@ -13,8 +14,8 @@ describe Arel::Nodes::DeleteStatement do end end - describe 'equality' do - it 'is equal with equal ivars' do + describe "equality" do + it "is equal with equal ivars" do statement1 = Arel::Nodes::DeleteStatement.new statement1.wheres = %w[a b c] statement2 = Arel::Nodes::DeleteStatement.new @@ -23,7 +24,7 @@ describe Arel::Nodes::DeleteStatement do assert_equal 1, array.uniq.size end - it 'is not equal with different ivars' do + it "is not equal with different ivars" do statement1 = Arel::Nodes::DeleteStatement.new statement1.wheres = %w[a b c] statement2 = Arel::Nodes::DeleteStatement.new diff --git a/activerecord/test/cases/arel/nodes/descending_test.rb b/activerecord/test/cases/arel/nodes/descending_test.rb index 5fe0ba62b0..45e22de17b 100644 --- a/activerecord/test/cases/arel/nodes/descending_test.rb +++ b/activerecord/test/cases/arel/nodes/descending_test.rb @@ -1,43 +1,44 @@ # frozen_string_literal: true -require_relative '../helper' + +require_relative "../helper" module Arel module Nodes class TestDescending < Arel::Test def test_construct - descending = Descending.new 'zomg' - assert_equal 'zomg', descending.expr + descending = Descending.new "zomg" + assert_equal "zomg", descending.expr end def test_reverse - descending = Descending.new 'zomg' + descending = Descending.new "zomg" ascending = descending.reverse assert_kind_of Ascending, ascending assert_equal descending.expr, ascending.expr end def test_direction - descending = Descending.new 'zomg' + descending = Descending.new "zomg" assert_equal :desc, descending.direction end def test_ascending? - descending = Descending.new 'zomg' + descending = Descending.new "zomg" assert !descending.ascending? end def test_descending? - descending = Descending.new 'zomg' + descending = Descending.new "zomg" assert descending.descending? end def test_equality_with_same_ivars - array = [Descending.new('zomg'), Descending.new('zomg')] + array = [Descending.new("zomg"), Descending.new("zomg")] assert_equal 1, array.uniq.size end def test_inequality_with_different_ivars - array = [Descending.new('zomg'), Descending.new('zomg!')] + array = [Descending.new("zomg"), Descending.new("zomg!")] assert_equal 2, array.uniq.size end end diff --git a/activerecord/test/cases/arel/nodes/distinct_test.rb b/activerecord/test/cases/arel/nodes/distinct_test.rb index 465700118e..de5f0ee588 100644 --- a/activerecord/test/cases/arel/nodes/distinct_test.rb +++ b/activerecord/test/cases/arel/nodes/distinct_test.rb @@ -1,16 +1,17 @@ # frozen_string_literal: true -require_relative '../helper' + +require_relative "../helper" module Arel module Nodes - describe 'Distinct' do - describe 'equality' do - it 'is equal to other distinct nodes' do + describe "Distinct" do + describe "equality" do + it "is equal to other distinct nodes" do array = [Distinct.new, Distinct.new] assert_equal 1, array.uniq.size end - it 'is not equal with other nodes' do + it "is not equal with other nodes" do array = [Distinct.new, Node.new] assert_equal 2, array.uniq.size end @@ -18,4 +19,3 @@ module Arel end end end - diff --git a/activerecord/test/cases/arel/nodes/equality_test.rb b/activerecord/test/cases/arel/nodes/equality_test.rb index 28a74de321..e173720e86 100644 --- a/activerecord/test/cases/arel/nodes/equality_test.rb +++ b/activerecord/test/cases/arel/nodes/equality_test.rb @@ -1,37 +1,38 @@ # frozen_string_literal: true -require_relative '../helper' + +require_relative "../helper" module Arel module Nodes - describe 'equality' do + describe "equality" do # FIXME: backwards compat - describe 'backwards compat' do - describe 'operator' do - it 'returns :==' do + describe "backwards compat" do + describe "operator" do + it "returns :==" do attr = Table.new(:users)[:id] - left = attr.eq(10) + left = attr.eq(10) left.operator.must_equal :== end end - describe 'operand1' do + describe "operand1" do it "should equal left" do attr = Table.new(:users)[:id] - left = attr.eq(10) + left = attr.eq(10) left.left.must_equal left.operand1 end end - describe 'operand2' do + describe "operand2" do it "should equal right" do attr = Table.new(:users)[:id] - left = attr.eq(10) + left = attr.eq(10) left.right.must_equal left.operand2 end end - describe 'to_sql' do - it 'takes an engine' do + describe "to_sql" do + it "takes an engine" do engine = FakeRecord::Base.new engine.connection.extend Module.new { attr_accessor :quote_count @@ -49,8 +50,8 @@ module Arel end end - describe 'or' do - it 'makes an OR node' do + describe "or" do + it "makes an OR node" do attr = Table.new(:users)[:id] left = attr.eq(10) right = attr.eq(11) @@ -60,8 +61,8 @@ module Arel end end - describe 'and' do - it 'makes and AND node' do + describe "and" do + it "makes and AND node" do attr = Table.new(:users)[:id] left = attr.eq(10) right = attr.eq(11) @@ -71,13 +72,13 @@ module Arel end end - it 'is equal with equal ivars' do - array = [Equality.new('foo', 'bar'), Equality.new('foo', 'bar')] + it "is equal with equal ivars" do + array = [Equality.new("foo", "bar"), Equality.new("foo", "bar")] assert_equal 1, array.uniq.size end - it 'is not equal with different ivars' do - array = [Equality.new('foo', 'bar'), Equality.new('foo', 'baz')] + it "is not equal with different ivars" do + array = [Equality.new("foo", "bar"), Equality.new("foo", "baz")] assert_equal 2, array.uniq.size end end diff --git a/activerecord/test/cases/arel/nodes/extract_test.rb b/activerecord/test/cases/arel/nodes/extract_test.rb index f6dc1626a4..8fc1e04d67 100644 --- a/activerecord/test/cases/arel/nodes/extract_test.rb +++ b/activerecord/test/cases/arel/nodes/extract_test.rb @@ -1,41 +1,42 @@ # frozen_string_literal: true -require_relative '../helper' + +require_relative "../helper" class Arel::Nodes::ExtractTest < Arel::Spec it "should extract field" do table = Arel::Table.new :users - table[:timestamp].extract('date').to_sql.must_be_like %{ + table[:timestamp].extract("date").to_sql.must_be_like %{ EXTRACT(DATE FROM "users"."timestamp") } end describe "as" do - it 'should alias the extract' do + it "should alias the extract" do table = Arel::Table.new :users - table[:timestamp].extract('date').as('foo').to_sql.must_be_like %{ + table[:timestamp].extract("date").as("foo").to_sql.must_be_like %{ EXTRACT(DATE FROM "users"."timestamp") AS foo } end - it 'should not mutate the extract' do + it "should not mutate the extract" do table = Arel::Table.new :users - extract = table[:timestamp].extract('date') + extract = table[:timestamp].extract("date") before = extract.dup - extract.as('foo') + extract.as("foo") assert_equal extract, before end end - describe 'equality' do - it 'is equal with equal ivars' do + describe "equality" do + it "is equal with equal ivars" do table = Arel::Table.new :users - array = [table[:attr].extract('foo'), table[:attr].extract('foo')] + array = [table[:attr].extract("foo"), table[:attr].extract("foo")] assert_equal 1, array.uniq.size end - it 'is not equal with different ivars' do + it "is not equal with different ivars" do table = Arel::Table.new :users - array = [table[:attr].extract('foo'), table[:attr].extract('bar')] + array = [table[:attr].extract("foo"), table[:attr].extract("bar")] assert_equal 2, array.uniq.size end end diff --git a/activerecord/test/cases/arel/nodes/false_test.rb b/activerecord/test/cases/arel/nodes/false_test.rb index 8b91dc227c..4ecf8e332e 100644 --- a/activerecord/test/cases/arel/nodes/false_test.rb +++ b/activerecord/test/cases/arel/nodes/false_test.rb @@ -1,16 +1,17 @@ # frozen_string_literal: true -require_relative '../helper' + +require_relative "../helper" module Arel module Nodes - describe 'False' do - describe 'equality' do - it 'is equal to other false nodes' do + describe "False" do + describe "equality" do + it "is equal to other false nodes" do array = [False.new, False.new] assert_equal 1, array.uniq.size end - it 'is not equal with other nodes' do + it "is not equal with other nodes" do array = [False.new, Node.new] assert_equal 2, array.uniq.size end @@ -18,4 +19,3 @@ module Arel end end end - diff --git a/activerecord/test/cases/arel/nodes/grouping_test.rb b/activerecord/test/cases/arel/nodes/grouping_test.rb index 7ad1584f0f..03d5c142d5 100644 --- a/activerecord/test/cases/arel/nodes/grouping_test.rb +++ b/activerecord/test/cases/arel/nodes/grouping_test.rb @@ -1,26 +1,26 @@ # frozen_string_literal: true -require_relative '../helper' + +require_relative "../helper" module Arel module Nodes class GroupingTest < Arel::Spec - it 'should create Equality nodes' do - grouping = Grouping.new(Nodes.build_quoted('foo')) - grouping.eq('foo').to_sql.must_be_like %q{('foo') = 'foo'} + it "should create Equality nodes" do + grouping = Grouping.new(Nodes.build_quoted("foo")) + grouping.eq("foo").to_sql.must_be_like "('foo') = 'foo'" end - describe 'equality' do - it 'is equal with equal ivars' do - array = [Grouping.new('foo'), Grouping.new('foo')] + describe "equality" do + it "is equal with equal ivars" do + array = [Grouping.new("foo"), Grouping.new("foo")] assert_equal 1, array.uniq.size end - it 'is not equal with different ivars' do - array = [Grouping.new('foo'), Grouping.new('bar')] + it "is not equal with different ivars" do + array = [Grouping.new("foo"), Grouping.new("bar")] assert_equal 2, array.uniq.size end end end end end - diff --git a/activerecord/test/cases/arel/nodes/infix_operation_test.rb b/activerecord/test/cases/arel/nodes/infix_operation_test.rb index 28a4710dc0..dcf2200c12 100644 --- a/activerecord/test/cases/arel/nodes/infix_operation_test.rb +++ b/activerecord/test/cases/arel/nodes/infix_operation_test.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true -require_relative '../helper' + +require_relative "../helper" module Arel module Nodes @@ -13,10 +14,10 @@ module Arel def test_operation_alias operation = InfixOperation.new :+, 1, 2 - aliaz = operation.as('zomg') + aliaz = operation.as("zomg") assert_kind_of As, aliaz assert_equal operation, aliaz.left - assert_equal 'zomg', aliaz.right + assert_equal "zomg", aliaz.right end def test_operation_ordering diff --git a/activerecord/test/cases/arel/nodes/insert_statement_test.rb b/activerecord/test/cases/arel/nodes/insert_statement_test.rb index 87f9d83a32..252a0d0d0b 100644 --- a/activerecord/test/cases/arel/nodes/insert_statement_test.rb +++ b/activerecord/test/cases/arel/nodes/insert_statement_test.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true -require_relative '../helper' + +require_relative "../helper" describe Arel::Nodes::InsertStatement do describe "#clone" do @@ -17,8 +18,8 @@ describe Arel::Nodes::InsertStatement do end end - describe 'equality' do - it 'is equal with equal ivars' do + describe "equality" do + it "is equal with equal ivars" do statement1 = Arel::Nodes::InsertStatement.new statement1.columns = %w[a b c] statement1.values = %w[x y z] @@ -29,7 +30,7 @@ describe Arel::Nodes::InsertStatement do assert_equal 1, array.uniq.size end - it 'is not equal with different ivars' do + it "is not equal with different ivars" do statement1 = Arel::Nodes::InsertStatement.new statement1.columns = %w[a b c] statement1.values = %w[x y z] diff --git a/activerecord/test/cases/arel/nodes/named_function_test.rb b/activerecord/test/cases/arel/nodes/named_function_test.rb index 30f6dac595..dbd7ae43be 100644 --- a/activerecord/test/cases/arel/nodes/named_function_test.rb +++ b/activerecord/test/cases/arel/nodes/named_function_test.rb @@ -1,44 +1,45 @@ # frozen_string_literal: true -require_relative '../helper' + +require_relative "../helper" module Arel module Nodes class TestNamedFunction < Arel::Test def test_construct - function = NamedFunction.new 'omg', 'zomg' - assert_equal 'omg', function.name - assert_equal 'zomg', function.expressions + function = NamedFunction.new "omg", "zomg" + assert_equal "omg", function.name + assert_equal "zomg", function.expressions end def test_function_alias - function = NamedFunction.new 'omg', 'zomg' - function = function.as('wth') - assert_equal 'omg', function.name - assert_equal 'zomg', function.expressions + function = NamedFunction.new "omg", "zomg" + function = function.as("wth") + assert_equal "omg", function.name + assert_equal "zomg", function.expressions assert_kind_of SqlLiteral, function.alias - assert_equal 'wth', function.alias + assert_equal "wth", function.alias end def test_construct_with_alias - function = NamedFunction.new 'omg', 'zomg', 'wth' - assert_equal 'omg', function.name - assert_equal 'zomg', function.expressions + function = NamedFunction.new "omg", "zomg", "wth" + assert_equal "omg", function.name + assert_equal "zomg", function.expressions assert_kind_of SqlLiteral, function.alias - assert_equal 'wth', function.alias + assert_equal "wth", function.alias end def test_equality_with_same_ivars array = [ - NamedFunction.new('omg', 'zomg', 'wth'), - NamedFunction.new('omg', 'zomg', 'wth') + NamedFunction.new("omg", "zomg", "wth"), + NamedFunction.new("omg", "zomg", "wth") ] assert_equal 1, array.uniq.size end def test_inequality_with_different_ivars array = [ - NamedFunction.new('omg', 'zomg', 'wth'), - NamedFunction.new('zomg', 'zomg', 'wth') + NamedFunction.new("omg", "zomg", "wth"), + NamedFunction.new("zomg", "zomg", "wth") ] assert_equal 2, array.uniq.size end diff --git a/activerecord/test/cases/arel/nodes/node_test.rb b/activerecord/test/cases/arel/nodes/node_test.rb index c1d3a01d1c..f4f07ef2c5 100644 --- a/activerecord/test/cases/arel/nodes/node_test.rb +++ b/activerecord/test/cases/arel/nodes/node_test.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true -require_relative '../helper' + +require_relative "../helper" module Arel class TestNode < Arel::Test diff --git a/activerecord/test/cases/arel/nodes/not_test.rb b/activerecord/test/cases/arel/nodes/not_test.rb index 15f94a6f10..481e678700 100644 --- a/activerecord/test/cases/arel/nodes/not_test.rb +++ b/activerecord/test/cases/arel/nodes/not_test.rb @@ -1,11 +1,12 @@ # frozen_string_literal: true -require_relative '../helper' + +require_relative "../helper" module Arel module Nodes - describe 'not' do - describe '#not' do - it 'makes a NOT node' do + describe "not" do + describe "#not" do + it "makes a NOT node" do attr = Table.new(:users)[:id] expr = attr.eq(10) node = expr.not @@ -14,14 +15,14 @@ module Arel end end - describe 'equality' do - it 'is equal with equal ivars' do - array = [Not.new('foo'), Not.new('foo')] + describe "equality" do + it "is equal with equal ivars" do + array = [Not.new("foo"), Not.new("foo")] assert_equal 1, array.uniq.size end - it 'is not equal with different ivars' do - array = [Not.new('foo'), Not.new('baz')] + it "is not equal with different ivars" do + array = [Not.new("foo"), Not.new("baz")] assert_equal 2, array.uniq.size end end diff --git a/activerecord/test/cases/arel/nodes/or_test.rb b/activerecord/test/cases/arel/nodes/or_test.rb index 4f8d56d165..93f826740d 100644 --- a/activerecord/test/cases/arel/nodes/or_test.rb +++ b/activerecord/test/cases/arel/nodes/or_test.rb @@ -1,11 +1,12 @@ # frozen_string_literal: true -require_relative '../helper' + +require_relative "../helper" module Arel module Nodes - describe 'or' do - describe '#or' do - it 'makes an OR node' do + describe "or" do + describe "#or" do + it "makes an OR node" do attr = Table.new(:users)[:id] left = attr.eq(10) right = attr.eq(11) @@ -19,14 +20,14 @@ module Arel end end - describe 'equality' do - it 'is equal with equal ivars' do - array = [Or.new('foo', 'bar'), Or.new('foo', 'bar')] + describe "equality" do + it "is equal with equal ivars" do + array = [Or.new("foo", "bar"), Or.new("foo", "bar")] assert_equal 1, array.uniq.size end - it 'is not equal with different ivars' do - array = [Or.new('foo', 'bar'), Or.new('foo', 'baz')] + it "is not equal with different ivars" do + array = [Or.new("foo", "bar"), Or.new("foo", "baz")] assert_equal 2, array.uniq.size end end diff --git a/activerecord/test/cases/arel/nodes/over_test.rb b/activerecord/test/cases/arel/nodes/over_test.rb index c9804c395f..981ec2e34b 100644 --- a/activerecord/test/cases/arel/nodes/over_test.rb +++ b/activerecord/test/cases/arel/nodes/over_test.rb @@ -1,36 +1,37 @@ # frozen_string_literal: true -require_relative '../helper' + +require_relative "../helper" class Arel::Nodes::OverTest < Arel::Spec - describe 'as' do - it 'should alias the expression' do + describe "as" do + it "should alias the expression" do table = Arel::Table.new :users - table[:id].count.over.as('foo').to_sql.must_be_like %{ + table[:id].count.over.as("foo").to_sql.must_be_like %{ COUNT("users"."id") OVER () AS foo } end end - describe 'with literal' do - it 'should reference the window definition by name' do + describe "with literal" do + it "should reference the window definition by name" do table = Arel::Table.new :users - table[:id].count.over('foo').to_sql.must_be_like %{ + table[:id].count.over("foo").to_sql.must_be_like %{ COUNT("users"."id") OVER "foo" } end end - describe 'with SQL literal' do - it 'should reference the window definition by name' do + describe "with SQL literal" do + it "should reference the window definition by name" do table = Arel::Table.new :users - table[:id].count.over(Arel.sql('foo')).to_sql.must_be_like %{ + table[:id].count.over(Arel.sql("foo")).to_sql.must_be_like %{ COUNT("users"."id") OVER foo } end end - describe 'with no expression' do - it 'should use empty definition' do + describe "with no expression" do + it "should use empty definition" do table = Arel::Table.new :users table[:id].count.over.to_sql.must_be_like %{ COUNT("users"."id") OVER () @@ -38,29 +39,29 @@ class Arel::Nodes::OverTest < Arel::Spec end end - describe 'with expression' do - it 'should use definition in sub-expression' do + describe "with expression" do + it "should use definition in sub-expression" do table = Arel::Table.new :users - window = Arel::Nodes::Window.new.order(table['foo']) + window = Arel::Nodes::Window.new.order(table["foo"]) table[:id].count.over(window).to_sql.must_be_like %{ COUNT("users"."id") OVER (ORDER BY \"users\".\"foo\") } end end - describe 'equality' do - it 'is equal with equal ivars' do + describe "equality" do + it "is equal with equal ivars" do array = [ - Arel::Nodes::Over.new('foo', 'bar'), - Arel::Nodes::Over.new('foo', 'bar') + Arel::Nodes::Over.new("foo", "bar"), + Arel::Nodes::Over.new("foo", "bar") ] assert_equal 1, array.uniq.size end - it 'is not equal with different ivars' do + it "is not equal with different ivars" do array = [ - Arel::Nodes::Over.new('foo', 'bar'), - Arel::Nodes::Over.new('foo', 'baz') + Arel::Nodes::Over.new("foo", "bar"), + Arel::Nodes::Over.new("foo", "baz") ] assert_equal 2, array.uniq.size end diff --git a/activerecord/test/cases/arel/nodes/select_core_test.rb b/activerecord/test/cases/arel/nodes/select_core_test.rb index bbb06666b6..1cdc7a2360 100644 --- a/activerecord/test/cases/arel/nodes/select_core_test.rb +++ b/activerecord/test/cases/arel/nodes/select_core_test.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true -require_relative '../helper' + +require_relative "../helper" module Arel module Nodes @@ -25,7 +26,7 @@ module Arel core = Arel::Nodes::SelectCore.new core.set_quantifier = Arel::Nodes::Distinct.new viz = Arel::Visitors::ToSql.new Table.engine.connection_pool - assert_match 'DISTINCT', viz.accept(core, Collectors::SQLString.new).value + assert_match "DISTINCT", viz.accept(core, Collectors::SQLString.new).value end def test_equality_with_same_ivars diff --git a/activerecord/test/cases/arel/nodes/select_statement_test.rb b/activerecord/test/cases/arel/nodes/select_statement_test.rb index 5e313e03fa..a91605de3e 100644 --- a/activerecord/test/cases/arel/nodes/select_statement_test.rb +++ b/activerecord/test/cases/arel/nodes/select_statement_test.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true -require_relative '../helper' + +require_relative "../helper" describe Arel::Nodes::SelectStatement do describe "#clone" do @@ -12,37 +13,37 @@ describe Arel::Nodes::SelectStatement do end end - describe 'equality' do - it 'is equal with equal ivars' do + describe "equality" do + it "is equal with equal ivars" do statement1 = Arel::Nodes::SelectStatement.new %w[a b c] statement1.offset = 1 statement1.limit = 2 statement1.lock = false statement1.orders = %w[x y z] - statement1.with = 'zomg' + statement1.with = "zomg" statement2 = Arel::Nodes::SelectStatement.new %w[a b c] statement2.offset = 1 statement2.limit = 2 statement2.lock = false statement2.orders = %w[x y z] - statement2.with = 'zomg' + statement2.with = "zomg" array = [statement1, statement2] assert_equal 1, array.uniq.size end - it 'is not equal with different ivars' do + it "is not equal with different ivars" do statement1 = Arel::Nodes::SelectStatement.new %w[a b c] statement1.offset = 1 statement1.limit = 2 statement1.lock = false statement1.orders = %w[x y z] - statement1.with = 'zomg' + statement1.with = "zomg" statement2 = Arel::Nodes::SelectStatement.new %w[a b c] statement2.offset = 1 statement2.limit = 2 statement2.lock = false statement2.orders = %w[x y z] - statement2.with = 'wth' + statement2.with = "wth" array = [statement1, statement2] assert_equal 2, array.uniq.size end diff --git a/activerecord/test/cases/arel/nodes/sql_literal_test.rb b/activerecord/test/cases/arel/nodes/sql_literal_test.rb index 0c4f23be78..3b95fed1f4 100644 --- a/activerecord/test/cases/arel/nodes/sql_literal_test.rb +++ b/activerecord/test/cases/arel/nodes/sql_literal_test.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true -require_relative '../helper' -require 'yaml' + +require_relative "../helper" +require "yaml" module Arel module Nodes @@ -9,64 +10,64 @@ module Arel @visitor = Visitors::ToSql.new Table.engine.connection end - def compile node + def compile(node) @visitor.accept(node, Collectors::SQLString.new).value end - describe 'sql' do - it 'makes a sql literal node' do - sql = Arel.sql 'foo' + describe "sql" do + it "makes a sql literal node" do + sql = Arel.sql "foo" sql.must_be_kind_of Arel::Nodes::SqlLiteral end end - describe 'count' do - it 'makes a count node' do - node = SqlLiteral.new('*').count + describe "count" do + it "makes a count node" do + node = SqlLiteral.new("*").count compile(node).must_be_like %{ COUNT(*) } end - it 'makes a distinct node' do - node = SqlLiteral.new('*').count true + it "makes a distinct node" do + node = SqlLiteral.new("*").count true compile(node).must_be_like %{ COUNT(DISTINCT *) } end end - describe 'equality' do - it 'makes an equality node' do - node = SqlLiteral.new('foo').eq(1) + describe "equality" do + it "makes an equality node" do + node = SqlLiteral.new("foo").eq(1) compile(node).must_be_like %{ foo = 1 } end - it 'is equal with equal contents' do - array = [SqlLiteral.new('foo'), SqlLiteral.new('foo')] + it "is equal with equal contents" do + array = [SqlLiteral.new("foo"), SqlLiteral.new("foo")] assert_equal 1, array.uniq.size end - it 'is not equal with different contents' do - array = [SqlLiteral.new('foo'), SqlLiteral.new('bar')] + it "is not equal with different contents" do + array = [SqlLiteral.new("foo"), SqlLiteral.new("bar")] assert_equal 2, array.uniq.size end end describe 'grouped "or" equality' do - it 'makes a grouping node with an or node' do - node = SqlLiteral.new('foo').eq_any([1,2]) + it "makes a grouping node with an or node" do + node = SqlLiteral.new("foo").eq_any([1, 2]) compile(node).must_be_like %{ (foo = 1 OR foo = 2) } end end describe 'grouped "and" equality' do - it 'makes a grouping node with an and node' do - node = SqlLiteral.new('foo').eq_all([1,2]) + it "makes a grouping node with an and node" do + node = SqlLiteral.new("foo").eq_all([1, 2]) compile(node).must_be_like %{ (foo = 1 AND foo = 2) } end end - describe 'serialization' do - it 'serializes into YAML' do - yaml_literal = SqlLiteral.new('foo').to_yaml - assert_equal('foo', YAML.load(yaml_literal)) + describe "serialization" do + it "serializes into YAML" do + yaml_literal = SqlLiteral.new("foo").to_yaml + assert_equal("foo", YAML.load(yaml_literal)) end end end diff --git a/activerecord/test/cases/arel/nodes/sum_test.rb b/activerecord/test/cases/arel/nodes/sum_test.rb index 46c908d872..5015964951 100644 --- a/activerecord/test/cases/arel/nodes/sum_test.rb +++ b/activerecord/test/cases/arel/nodes/sum_test.rb @@ -1,30 +1,31 @@ # frozen_string_literal: true -require_relative '../helper' + +require_relative "../helper" class Arel::Nodes::SumTest < Arel::Spec describe "as" do - it 'should alias the sum' do + it "should alias the sum" do table = Arel::Table.new :users - table[:id].sum.as('foo').to_sql.must_be_like %{ + table[:id].sum.as("foo").to_sql.must_be_like %{ SUM("users"."id") AS foo } end end - describe 'equality' do - it 'is equal with equal ivars' do - array = [Arel::Nodes::Sum.new('foo'), Arel::Nodes::Sum.new('foo')] + describe "equality" do + it "is equal with equal ivars" do + array = [Arel::Nodes::Sum.new("foo"), Arel::Nodes::Sum.new("foo")] assert_equal 1, array.uniq.size end - it 'is not equal with different ivars' do - array = [Arel::Nodes::Sum.new('foo'), Arel::Nodes::Sum.new('foo!')] + it "is not equal with different ivars" do + array = [Arel::Nodes::Sum.new("foo"), Arel::Nodes::Sum.new("foo!")] assert_equal 2, array.uniq.size end end - - describe 'order' do - it 'should order the sum' do + + describe "order" do + it "should order the sum" do table = Arel::Table.new :users table[:id].sum.desc.to_sql.must_be_like %{ SUM("users"."id") DESC diff --git a/activerecord/test/cases/arel/nodes/table_alias_test.rb b/activerecord/test/cases/arel/nodes/table_alias_test.rb index b1b49919d5..c661b6771e 100644 --- a/activerecord/test/cases/arel/nodes/table_alias_test.rb +++ b/activerecord/test/cases/arel/nodes/table_alias_test.rb @@ -1,11 +1,12 @@ # frozen_string_literal: true -require_relative '../helper' + +require_relative "../helper" module Arel module Nodes - describe 'table alias' do - describe 'equality' do - it 'is equal with equal ivars' do + describe "table alias" do + describe "equality" do + it "is equal with equal ivars" do relation1 = Table.new(:users) node1 = TableAlias.new relation1, :foo relation2 = Table.new(:users) @@ -14,7 +15,7 @@ module Arel assert_equal 1, array.uniq.size end - it 'is not equal with different ivars' do + it "is not equal with different ivars" do relation1 = Table.new(:users) node1 = TableAlias.new relation1, :foo relation2 = Table.new(:users) diff --git a/activerecord/test/cases/arel/nodes/true_test.rb b/activerecord/test/cases/arel/nodes/true_test.rb index 198e7b1aa4..1e85fe7d48 100644 --- a/activerecord/test/cases/arel/nodes/true_test.rb +++ b/activerecord/test/cases/arel/nodes/true_test.rb @@ -1,16 +1,17 @@ # frozen_string_literal: true -require_relative '../helper' + +require_relative "../helper" module Arel module Nodes - describe 'True' do - describe 'equality' do - it 'is equal to other true nodes' do + describe "True" do + describe "equality" do + it "is equal to other true nodes" do array = [True.new, True.new] assert_equal 1, array.uniq.size end - it 'is not equal with other nodes' do + it "is not equal with other nodes" do array = [True.new, Node.new] assert_equal 2, array.uniq.size end @@ -18,5 +19,3 @@ module Arel end end end - - diff --git a/activerecord/test/cases/arel/nodes/unary_operation_test.rb b/activerecord/test/cases/arel/nodes/unary_operation_test.rb index e76b59c8e1..f0dd0c625c 100644 --- a/activerecord/test/cases/arel/nodes/unary_operation_test.rb +++ b/activerecord/test/cases/arel/nodes/unary_operation_test.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true -require_relative '../helper' + +require_relative "../helper" module Arel module Nodes @@ -12,10 +13,10 @@ module Arel def test_operation_alias operation = UnaryOperation.new :-, 1 - aliaz = operation.as('zomg') + aliaz = operation.as("zomg") assert_kind_of As, aliaz assert_equal operation, aliaz.left - assert_equal 'zomg', aliaz.right + assert_equal "zomg", aliaz.right end def test_operation_ordering diff --git a/activerecord/test/cases/arel/nodes/update_statement_test.rb b/activerecord/test/cases/arel/nodes/update_statement_test.rb index 3a635f75d6..a83ce32f68 100644 --- a/activerecord/test/cases/arel/nodes/update_statement_test.rb +++ b/activerecord/test/cases/arel/nodes/update_statement_test.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true -require_relative '../helper' + +require_relative "../helper" describe Arel::Nodes::UpdateStatement do describe "#clone" do @@ -17,41 +18,41 @@ describe Arel::Nodes::UpdateStatement do end end - describe 'equality' do - it 'is equal with equal ivars' do + describe "equality" do + it "is equal with equal ivars" do statement1 = Arel::Nodes::UpdateStatement.new - statement1.relation = 'zomg' + statement1.relation = "zomg" statement1.wheres = 2 statement1.values = false statement1.orders = %w[x y z] statement1.limit = 42 - statement1.key = 'zomg' + statement1.key = "zomg" statement2 = Arel::Nodes::UpdateStatement.new - statement2.relation = 'zomg' + statement2.relation = "zomg" statement2.wheres = 2 statement2.values = false statement2.orders = %w[x y z] statement2.limit = 42 - statement2.key = 'zomg' + statement2.key = "zomg" array = [statement1, statement2] assert_equal 1, array.uniq.size end - it 'is not equal with different ivars' do + it "is not equal with different ivars" do statement1 = Arel::Nodes::UpdateStatement.new - statement1.relation = 'zomg' + statement1.relation = "zomg" statement1.wheres = 2 statement1.values = false statement1.orders = %w[x y z] statement1.limit = 42 - statement1.key = 'zomg' + statement1.key = "zomg" statement2 = Arel::Nodes::UpdateStatement.new - statement2.relation = 'zomg' + statement2.relation = "zomg" statement2.wheres = 2 statement2.values = false statement2.orders = %w[x y z] statement2.limit = 42 - statement2.key = 'wth' + statement2.key = "wth" array = [statement1, statement2] assert_equal 2, array.uniq.size end diff --git a/activerecord/test/cases/arel/nodes/window_test.rb b/activerecord/test/cases/arel/nodes/window_test.rb index 81ecd5ced8..729b0556a4 100644 --- a/activerecord/test/cases/arel/nodes/window_test.rb +++ b/activerecord/test/cases/arel/nodes/window_test.rb @@ -1,11 +1,12 @@ # frozen_string_literal: true -require_relative '../helper' + +require_relative "../helper" module Arel module Nodes - describe 'Window' do - describe 'equality' do - it 'is equal with equal ivars' do + describe "Window" do + describe "equality" do + it "is equal with equal ivars" do window1 = Window.new window1.orders = [1, 2] window1.partitions = [1] @@ -18,7 +19,7 @@ module Arel assert_equal 1, array.uniq.size end - it 'is not equal with different ivars' do + it "is not equal with different ivars" do window1 = Window.new window1.orders = [1, 2] window1.partitions = [1] @@ -33,14 +34,14 @@ module Arel end end - describe 'NamedWindow' do - describe 'equality' do - it 'is equal with equal ivars' do - window1 = NamedWindow.new 'foo' + describe "NamedWindow" do + describe "equality" do + it "is equal with equal ivars" do + window1 = NamedWindow.new "foo" window1.orders = [1, 2] window1.partitions = [1] window1.frame 3 - window2 = NamedWindow.new 'foo' + window2 = NamedWindow.new "foo" window2.orders = [1, 2] window2.partitions = [1] window2.frame 3 @@ -48,12 +49,12 @@ module Arel assert_equal 1, array.uniq.size end - it 'is not equal with different ivars' do - window1 = NamedWindow.new 'foo' + it "is not equal with different ivars" do + window1 = NamedWindow.new "foo" window1.orders = [1, 2] window1.partitions = [1] window1.frame 3 - window2 = NamedWindow.new 'bar' + window2 = NamedWindow.new "bar" window2.orders = [1, 2] window2.partitions = [1] window2.frame 3 @@ -63,14 +64,14 @@ module Arel end end - describe 'CurrentRow' do - describe 'equality' do - it 'is equal to other current row nodes' do + describe "CurrentRow" do + describe "equality" do + it "is equal to other current row nodes" do array = [CurrentRow.new, CurrentRow.new] assert_equal 1, array.uniq.size end - it 'is not equal with other nodes' do + it "is not equal with other nodes" do array = [CurrentRow.new, Node.new] assert_equal 2, array.uniq.size end diff --git a/activerecord/test/cases/arel/nodes_test.rb b/activerecord/test/cases/arel/nodes_test.rb index 1934ef4c3b..9021de0d20 100644 --- a/activerecord/test/cases/arel/nodes_test.rb +++ b/activerecord/test/cases/arel/nodes_test.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true -require_relative 'helper' + +require_relative "helper" module Arel module Nodes @@ -24,12 +25,10 @@ module Arel eqeq_owner == hash_owner end - problem_msg = 'Some subclasses of Arel::Nodes::Node do not have a' \ - ' #== or #eql? or #hash defined from the same class as the others' + problem_msg = "Some subclasses of Arel::Nodes::Node do not have a" \ + " #== or #eql? or #hash defined from the same class as the others" assert_empty bad_node_descendants, problem_msg end - - end end end diff --git a/activerecord/test/cases/arel/select_manager_test.rb b/activerecord/test/cases/arel/select_manager_test.rb index e9056953d8..1bc9f6abf2 100644 --- a/activerecord/test/cases/arel/select_manager_test.rb +++ b/activerecord/test/cases/arel/select_manager_test.rb @@ -1,18 +1,18 @@ # frozen_string_literal: true -require_relative 'helper' -module Arel +require_relative "helper" +module Arel class SelectManagerTest < Arel::Spec def test_join_sources manager = Arel::SelectManager.new - manager.join_sources << Arel::Nodes::StringJoin.new(Nodes.build_quoted('foo')) + manager.join_sources << Arel::Nodes::StringJoin.new(Nodes.build_quoted("foo")) assert_equal "SELECT FROM 'foo'", manager.to_sql end - describe 'backwards compatibility' do - describe 'project' do - it 'accepts symbols as sql literals' do + describe "backwards compatibility" do + describe "project" do + it "accepts symbols as sql literals" do table = Table.new :users manager = Arel::SelectManager.new manager.project :id @@ -23,19 +23,19 @@ module Arel end end - describe 'order' do - it 'accepts symbols' do + describe "order" do + it "accepts symbols" do table = Table.new :users manager = Arel::SelectManager.new - manager.project Nodes::SqlLiteral.new '*' + manager.project Nodes::SqlLiteral.new "*" manager.from table manager.order :foo manager.to_sql.must_be_like %{ SELECT * FROM "users" ORDER BY foo } end end - describe 'group' do - it 'takes a symbol' do + describe "group" do + it "takes a symbol" do table = Table.new :users manager = Arel::SelectManager.new manager.from table @@ -44,55 +44,55 @@ module Arel end end - describe 'as' do - it 'makes an AS node by grouping the AST' do + describe "as" do + it "makes an AS node by grouping the AST" do manager = Arel::SelectManager.new - as = manager.as(Arel.sql('foo')) + as = manager.as(Arel.sql("foo")) assert_kind_of Arel::Nodes::Grouping, as.left assert_equal manager.ast, as.left.expr - assert_equal 'foo', as.right + assert_equal "foo", as.right end - it 'converts right to SqlLiteral if a string' do + it "converts right to SqlLiteral if a string" do manager = Arel::SelectManager.new - as = manager.as('foo') + as = manager.as("foo") assert_kind_of Arel::Nodes::SqlLiteral, as.right end - it 'can make a subselect' do + it "can make a subselect" do manager = Arel::SelectManager.new manager.project Arel.star - manager.from Arel.sql('zomg') - as = manager.as(Arel.sql('foo')) + manager.from Arel.sql("zomg") + as = manager.as(Arel.sql("foo")) manager = Arel::SelectManager.new - manager.project Arel.sql('name') + manager.project Arel.sql("name") manager.from as manager.to_sql.must_be_like "SELECT name FROM (SELECT * FROM zomg) foo" end end - describe 'from' do - it 'ignores strings when table of same name exists' do + describe "from" do + it "ignores strings when table of same name exists" do table = Table.new :users manager = Arel::SelectManager.new manager.from table - manager.from 'users' - manager.project table['id'] + manager.from "users" + manager.project table["id"] manager.to_sql.must_be_like 'SELECT "users"."id" FROM users' end - it 'should support any ast' do - table = Table.new :users + it "should support any ast" do + table = Table.new :users manager1 = Arel::SelectManager.new manager2 = Arel::SelectManager.new - manager2.project(Arel.sql('*')) + manager2.project(Arel.sql("*")) manager2.from table - manager1.project Arel.sql('lol') - as = manager2.as Arel.sql('omg') + manager1.project Arel.sql("lol") + as = manager2.as Arel.sql("omg") manager1.from(as) manager1.to_sql.must_be_like %{ @@ -101,32 +101,32 @@ module Arel end end - describe 'having' do - it 'converts strings to SQLLiterals' do - table = Table.new :users + describe "having" do + it "converts strings to SQLLiterals" do + table = Table.new :users mgr = table.from - mgr.having Arel.sql('foo') + mgr.having Arel.sql("foo") mgr.to_sql.must_be_like %{ SELECT FROM "users" HAVING foo } end - it 'can have multiple items specified separately' do + it "can have multiple items specified separately" do table = Table.new :users mgr = table.from - mgr.having Arel.sql('foo') - mgr.having Arel.sql('bar') + mgr.having Arel.sql("foo") + mgr.having Arel.sql("bar") mgr.to_sql.must_be_like %{ SELECT FROM "users" HAVING foo AND bar } end - it 'can receive any node' do + it "can receive any node" do table = Table.new :users mgr = table.from - mgr.having Arel::Nodes::And.new([Arel.sql('foo'), Arel.sql('bar')]) + mgr.having Arel::Nodes::And.new([Arel.sql("foo"), Arel.sql("bar")]) mgr.to_sql.must_be_like %{ SELECT FROM "users" HAVING foo AND bar } end end - describe 'on' do - it 'converts to sqlliterals' do + describe "on" do + it "converts to sqlliterals" do table = Table.new :users right = table.alias mgr = table.from @@ -134,7 +134,7 @@ module Arel mgr.to_sql.must_be_like %{ SELECT FROM "users" INNER JOIN "users" "users_2" ON omg } end - it 'converts to sqlliterals with multiple items' do + it "converts to sqlliterals with multiple items" do table = Table.new :users right = table.alias mgr = table.from @@ -144,17 +144,17 @@ module Arel end end - describe 'clone' do - it 'creates new cores' do - table = Table.new :users, :as => 'foo' + describe "clone" do + it "creates new cores" do + table = Table.new :users, as: "foo" mgr = table.from m2 = mgr.clone m2.project "foo" mgr.to_sql.wont_equal m2.to_sql end - it 'makes updates to the correct copy' do - table = Table.new :users, :as => 'foo' + it "makes updates to the correct copy" do + table = Table.new :users, as: "foo" mgr = table.from m2 = mgr.clone m3 = m2.clone @@ -164,40 +164,40 @@ module Arel end end - describe 'initialize' do - it 'uses alias in sql' do - table = Table.new :users, :as => 'foo' + describe "initialize" do + it "uses alias in sql" do + table = Table.new :users, as: "foo" mgr = table.from mgr.skip 10 mgr.to_sql.must_be_like %{ SELECT FROM "users" "foo" OFFSET 10 } end end - describe 'skip' do - it 'should add an offset' do - table = Table.new :users + describe "skip" do + it "should add an offset" do + table = Table.new :users mgr = table.from mgr.skip 10 mgr.to_sql.must_be_like %{ SELECT FROM "users" OFFSET 10 } end - it 'should chain' do - table = Table.new :users + it "should chain" do + table = Table.new :users mgr = table.from mgr.skip(10).to_sql.must_be_like %{ SELECT FROM "users" OFFSET 10 } end end - describe 'offset' do - it 'should add an offset' do - table = Table.new :users + describe "offset" do + it "should add an offset" do + table = Table.new :users mgr = table.from mgr.offset = 10 mgr.to_sql.must_be_like %{ SELECT FROM "users" OFFSET 10 } end - it 'should remove an offset' do - table = Table.new :users + it "should remove an offset" do + table = Table.new :users mgr = table.from mgr.offset = 10 mgr.to_sql.must_be_like %{ SELECT FROM "users" OFFSET 10 } @@ -206,35 +206,35 @@ module Arel mgr.to_sql.must_be_like %{ SELECT FROM "users" } end - it 'should return the offset' do - table = Table.new :users + it "should return the offset" do + table = Table.new :users mgr = table.from mgr.offset = 10 assert_equal 10, mgr.offset end end - describe 'exists' do - it 'should create an exists clause' do + describe "exists" do + it "should create an exists clause" do table = Table.new(:users) manager = Arel::SelectManager.new table - manager.project Nodes::SqlLiteral.new '*' + manager.project Nodes::SqlLiteral.new "*" m2 = Arel::SelectManager.new m2.project manager.exists m2.to_sql.must_be_like %{ SELECT EXISTS (#{manager.to_sql}) } end - it 'can be aliased' do + it "can be aliased" do table = Table.new(:users) manager = Arel::SelectManager.new table - manager.project Nodes::SqlLiteral.new '*' + manager.project Nodes::SqlLiteral.new "*" m2 = Arel::SelectManager.new - m2.project manager.exists.as('foo') + m2.project manager.exists.as("foo") m2.to_sql.must_be_like %{ SELECT EXISTS (#{manager.to_sql}) AS foo } end end - describe 'union' do + describe "union" do before do table = Table.new :users @m1 = Arel::SelectManager.new table @@ -248,7 +248,7 @@ module Arel end - it 'should union two managers' do + it "should union two managers" do # FIXME should this union "managers" or "statements" ? # FIXME this probably shouldn't return a node node = @m1.union @m2 @@ -259,7 +259,7 @@ module Arel } end - it 'should union all' do + it "should union all" do node = @m1.union :all, @m2 node.to_sql.must_be_like %{ @@ -269,7 +269,7 @@ module Arel end - describe 'intersect' do + describe "intersect" do before do table = Table.new :users @m1 = Arel::SelectManager.new table @@ -283,7 +283,7 @@ module Arel end - it 'should interect two managers' do + it "should interect two managers" do # FIXME should this intersect "managers" or "statements" ? # FIXME this probably shouldn't return a node node = @m1.intersect @m2 @@ -296,7 +296,7 @@ module Arel end - describe 'except' do + describe "except" do before do table = Table.new :users @m1 = Arel::SelectManager.new table @@ -308,7 +308,7 @@ module Arel @m2.where(table[:age].between(40..99)) end - it 'should except two managers' do + it "should except two managers" do # FIXME should this except "managers" or "statements" ? # FIXME this probably shouldn't return a node node = @m1.except @m2 @@ -321,8 +321,8 @@ module Arel end - describe 'with' do - it 'should support basic WITH' do + describe "with" do + it "should support basic WITH" do users = Table.new(:users) users_top = Table.new(:users_top) comments = Table.new(:comments) @@ -370,43 +370,43 @@ module Arel end end - describe 'ast' do - it 'should return the ast' do - table = Table.new :users + describe "ast" do + it "should return the ast" do + table = Table.new :users mgr = table.from assert mgr.ast end - it 'should allow orders to work when the ast is grepped' do - table = Table.new :users + it "should allow orders to work when the ast is grepped" do + table = Table.new :users mgr = table.from - mgr.project Arel.sql '*' + mgr.project Arel.sql "*" mgr.from table - mgr.orders << Arel::Nodes::Ascending.new(Arel.sql('foo')) + mgr.orders << Arel::Nodes::Ascending.new(Arel.sql("foo")) mgr.ast.grep(Arel::Nodes::OuterJoin) mgr.to_sql.must_be_like %{ SELECT * FROM "users" ORDER BY foo ASC } end end - describe 'taken' do - it 'should return limit' do + describe "taken" do + it "should return limit" do manager = Arel::SelectManager.new manager.take 10 manager.taken.must_equal 10 end end - describe 'lock' do + describe "lock" do # This should fail on other databases - it 'adds a lock node' do - table = Table.new :users + it "adds a lock node" do + table = Table.new :users mgr = table.from mgr.lock.to_sql.must_be_like %{ SELECT FROM "users" FOR UPDATE } end end - describe 'orders' do - it 'returns order clauses' do + describe "orders" do + it "returns order clauses" do table = Table.new :users manager = Arel::SelectManager.new order = table[:id] @@ -415,11 +415,11 @@ module Arel end end - describe 'order' do - it 'generates order clauses' do + describe "order" do + it "generates order clauses" do table = Table.new :users manager = Arel::SelectManager.new - manager.project Nodes::SqlLiteral.new '*' + manager.project Nodes::SqlLiteral.new "*" manager.from table manager.order table[:id] manager.to_sql.must_be_like %{ @@ -428,10 +428,10 @@ module Arel end # FIXME: I would like to deprecate this - it 'takes *args' do + it "takes *args" do table = Table.new :users manager = Arel::SelectManager.new - manager.project Nodes::SqlLiteral.new '*' + manager.project Nodes::SqlLiteral.new "*" manager.from table manager.order table[:id], table[:name] manager.to_sql.must_be_like %{ @@ -439,16 +439,16 @@ module Arel } end - it 'chains' do + it "chains" do table = Table.new :users manager = Arel::SelectManager.new manager.order(table[:id]).must_equal manager end - it 'has order attributes' do + it "has order attributes" do table = Table.new :users manager = Arel::SelectManager.new - manager.project Nodes::SqlLiteral.new '*' + manager.project Nodes::SqlLiteral.new "*" manager.from table manager.order table[:id].desc manager.to_sql.must_be_like %{ @@ -457,8 +457,8 @@ module Arel end end - describe 'on' do - it 'takes two params' do + describe "on" do + it "takes two params" do left = Table.new :users right = left.alias predicate = left[:id].eq(right[:id]) @@ -474,7 +474,7 @@ module Arel } end - it 'takes three params' do + it "takes three params" do left = Table.new :users right = left.alias predicate = left[:id].eq(right[:id]) @@ -496,59 +496,59 @@ module Arel end end - it 'should hand back froms' do + it "should hand back froms" do relation = Arel::SelectManager.new assert_equal [], relation.froms end - it 'should create and nodes' do + it "should create and nodes" do relation = Arel::SelectManager.new - children = ['foo', 'bar', 'baz'] + children = ["foo", "bar", "baz"] clause = relation.create_and children assert_kind_of Arel::Nodes::And, clause assert_equal children, clause.children end - it 'should create insert managers' do + it "should create insert managers" do relation = Arel::SelectManager.new insert = relation.create_insert assert_kind_of Arel::InsertManager, insert end - it 'should create join nodes' do + it "should create join nodes" do relation = Arel::SelectManager.new - join = relation.create_join 'foo', 'bar' + join = relation.create_join "foo", "bar" assert_kind_of Arel::Nodes::InnerJoin, join - assert_equal 'foo', join.left - assert_equal 'bar', join.right + assert_equal "foo", join.left + assert_equal "bar", join.right end - it 'should create join nodes with a full outer join klass' do + it "should create join nodes with a full outer join klass" do relation = Arel::SelectManager.new - join = relation.create_join 'foo', 'bar', Arel::Nodes::FullOuterJoin + join = relation.create_join "foo", "bar", Arel::Nodes::FullOuterJoin assert_kind_of Arel::Nodes::FullOuterJoin, join - assert_equal 'foo', join.left - assert_equal 'bar', join.right + assert_equal "foo", join.left + assert_equal "bar", join.right end - it 'should create join nodes with a outer join klass' do + it "should create join nodes with a outer join klass" do relation = Arel::SelectManager.new - join = relation.create_join 'foo', 'bar', Arel::Nodes::OuterJoin + join = relation.create_join "foo", "bar", Arel::Nodes::OuterJoin assert_kind_of Arel::Nodes::OuterJoin, join - assert_equal 'foo', join.left - assert_equal 'bar', join.right + assert_equal "foo", join.left + assert_equal "bar", join.right end - it 'should create join nodes with a right outer join klass' do + it "should create join nodes with a right outer join klass" do relation = Arel::SelectManager.new - join = relation.create_join 'foo', 'bar', Arel::Nodes::RightOuterJoin + join = relation.create_join "foo", "bar", Arel::Nodes::RightOuterJoin assert_kind_of Arel::Nodes::RightOuterJoin, join - assert_equal 'foo', join.left - assert_equal 'bar', join.right + assert_equal "foo", join.left + assert_equal "bar", join.right end - describe 'join' do - it 'responds to join' do + describe "join" do + it "responds to join" do left = Table.new :users right = left.alias predicate = left[:id].eq(right[:id]) @@ -563,7 +563,7 @@ module Arel } end - it 'takes a class' do + it "takes a class" do left = Table.new :users right = left.alias predicate = left[:id].eq(right[:id]) @@ -578,7 +578,7 @@ module Arel } end - it 'takes the full outer join class' do + it "takes the full outer join class" do left = Table.new :users right = left.alias predicate = left[:id].eq(right[:id]) @@ -593,7 +593,7 @@ module Arel } end - it 'takes the right outer join class' do + it "takes the right outer join class" do left = Table.new :users right = left.alias predicate = left[:id].eq(right[:id]) @@ -608,12 +608,12 @@ module Arel } end - it 'noops on nil' do - manager = Arel::SelectManager.new + it "noops on nil" do + manager = Arel::SelectManager.new manager.join(nil).must_equal manager end - it 'raises EmptyJoinError on empty' do + it "raises EmptyJoinError on empty" do left = Table.new :users manager = Arel::SelectManager.new @@ -624,8 +624,8 @@ module Arel end end - describe 'outer join' do - it 'responds to join' do + describe "outer join" do + it "responds to join" do left = Table.new :users right = left.alias predicate = left[:id].eq(right[:id]) @@ -640,15 +640,15 @@ module Arel } end - it 'noops on nil' do - manager = Arel::SelectManager.new + it "noops on nil" do + manager = Arel::SelectManager.new manager.outer_join(nil).must_equal manager end end - describe 'joins' do + describe "joins" do - it 'returns inner join sql' do + it "returns inner join sql" do table = Table.new :users aliaz = table.alias manager = Arel::SelectManager.new @@ -657,7 +657,7 @@ module Arel manager.to_sql end - it 'returns outer join sql' do + it "returns outer join sql" do table = Table.new :users aliaz = table.alias manager = Arel::SelectManager.new @@ -666,7 +666,7 @@ module Arel manager.to_sql end - it 'can have a non-table alias as relation name' do + it "can have a non-table alias as relation name" do users = Table.new :users comments = Table.new :comments @@ -678,7 +678,7 @@ module Arel ).as("counts") joins = users.join(counts).on(counts[:user_id].eq(10)) - joins.to_sql.must_be_like %{ + joins.to_sql.must_be_like %{ SELECT FROM "users" INNER JOIN (SELECT "comments"."user_id" AS user_id, COUNT("comments"."user_id") AS count FROM "comments" GROUP BY "comments"."user_id") counts ON counts."user_id" = 10 } end @@ -689,7 +689,7 @@ module Arel predicate = left[:id].eq(right[:id]) mgr = left.join(right) - mgr.project Nodes::SqlLiteral.new('*') + mgr.project Nodes::SqlLiteral.new("*") mgr.on(predicate).must_equal mgr mgr.to_sql.must_be_like %{ @@ -699,15 +699,15 @@ module Arel } end - it 'returns string join sql' do + it "returns string join sql" do manager = Arel::SelectManager.new - manager.from Nodes::StringJoin.new(Nodes.build_quoted('hello')) + manager.from Nodes::StringJoin.new(Nodes.build_quoted("hello")) assert_match "'hello'", manager.to_sql end end - describe 'group' do - it 'takes an attribute' do + describe "group" do + it "takes an attribute" do table = Table.new :users manager = Arel::SelectManager.new manager.from table @@ -717,13 +717,13 @@ module Arel } end - it 'chains' do + it "chains" do table = Table.new :users manager = Arel::SelectManager.new manager.group(table[:id]).must_equal manager end - it 'takes multiple args' do + it "takes multiple args" do table = Table.new :users manager = Arel::SelectManager.new manager.from table @@ -734,132 +734,132 @@ module Arel end # FIXME: backwards compat - it 'makes strings literals' do + it "makes strings literals" do table = Table.new :users manager = Arel::SelectManager.new manager.from table - manager.group 'foo' + manager.group "foo" manager.to_sql.must_be_like %{ SELECT FROM "users" GROUP BY foo } end end - describe 'window definition' do - it 'can be empty' do + describe "window definition" do + it "can be empty" do table = Table.new :users manager = Arel::SelectManager.new manager.from table - manager.window('a_window') + manager.window("a_window") manager.to_sql.must_be_like %{ SELECT FROM "users" WINDOW "a_window" AS () } end - it 'takes an order' do + it "takes an order" do table = Table.new :users manager = Arel::SelectManager.new manager.from table - manager.window('a_window').order(table['foo'].asc) + manager.window("a_window").order(table["foo"].asc) manager.to_sql.must_be_like %{ SELECT FROM "users" WINDOW "a_window" AS (ORDER BY "users"."foo" ASC) } end - it 'takes an order with multiple columns' do + it "takes an order with multiple columns" do table = Table.new :users manager = Arel::SelectManager.new manager.from table - manager.window('a_window').order(table['foo'].asc, table['bar'].desc) + manager.window("a_window").order(table["foo"].asc, table["bar"].desc) manager.to_sql.must_be_like %{ SELECT FROM "users" WINDOW "a_window" AS (ORDER BY "users"."foo" ASC, "users"."bar" DESC) } end - it 'takes a partition' do + it "takes a partition" do table = Table.new :users manager = Arel::SelectManager.new manager.from table - manager.window('a_window').partition(table['bar']) + manager.window("a_window").partition(table["bar"]) manager.to_sql.must_be_like %{ SELECT FROM "users" WINDOW "a_window" AS (PARTITION BY "users"."bar") } end - it 'takes a partition and an order' do + it "takes a partition and an order" do table = Table.new :users manager = Arel::SelectManager.new manager.from table - manager.window('a_window').partition(table['foo']).order(table['foo'].asc) + manager.window("a_window").partition(table["foo"]).order(table["foo"].asc) manager.to_sql.must_be_like %{ SELECT FROM "users" WINDOW "a_window" AS (PARTITION BY "users"."foo" ORDER BY "users"."foo" ASC) } end - it 'takes a partition with multiple columns' do + it "takes a partition with multiple columns" do table = Table.new :users manager = Arel::SelectManager.new manager.from table - manager.window('a_window').partition(table['bar'], table['baz']) + manager.window("a_window").partition(table["bar"], table["baz"]) manager.to_sql.must_be_like %{ SELECT FROM "users" WINDOW "a_window" AS (PARTITION BY "users"."bar", "users"."baz") } end - it 'takes a rows frame, unbounded preceding' do + it "takes a rows frame, unbounded preceding" do table = Table.new :users manager = Arel::SelectManager.new manager.from table - manager.window('a_window').rows(Arel::Nodes::Preceding.new) + manager.window("a_window").rows(Arel::Nodes::Preceding.new) manager.to_sql.must_be_like %{ SELECT FROM "users" WINDOW "a_window" AS (ROWS UNBOUNDED PRECEDING) } end - it 'takes a rows frame, bounded preceding' do + it "takes a rows frame, bounded preceding" do table = Table.new :users manager = Arel::SelectManager.new manager.from table - manager.window('a_window').rows(Arel::Nodes::Preceding.new(5)) + manager.window("a_window").rows(Arel::Nodes::Preceding.new(5)) manager.to_sql.must_be_like %{ SELECT FROM "users" WINDOW "a_window" AS (ROWS 5 PRECEDING) } end - it 'takes a rows frame, unbounded following' do + it "takes a rows frame, unbounded following" do table = Table.new :users manager = Arel::SelectManager.new manager.from table - manager.window('a_window').rows(Arel::Nodes::Following.new) + manager.window("a_window").rows(Arel::Nodes::Following.new) manager.to_sql.must_be_like %{ SELECT FROM "users" WINDOW "a_window" AS (ROWS UNBOUNDED FOLLOWING) } end - it 'takes a rows frame, bounded following' do + it "takes a rows frame, bounded following" do table = Table.new :users manager = Arel::SelectManager.new manager.from table - manager.window('a_window').rows(Arel::Nodes::Following.new(5)) + manager.window("a_window").rows(Arel::Nodes::Following.new(5)) manager.to_sql.must_be_like %{ SELECT FROM "users" WINDOW "a_window" AS (ROWS 5 FOLLOWING) } end - it 'takes a rows frame, current row' do + it "takes a rows frame, current row" do table = Table.new :users manager = Arel::SelectManager.new manager.from table - manager.window('a_window').rows(Arel::Nodes::CurrentRow.new) + manager.window("a_window").rows(Arel::Nodes::CurrentRow.new) manager.to_sql.must_be_like %{ SELECT FROM "users" WINDOW "a_window" AS (ROWS CURRENT ROW) } end - it 'takes a rows frame, between two delimiters' do + it "takes a rows frame, between two delimiters" do table = Table.new :users manager = Arel::SelectManager.new manager.from table - window = manager.window('a_window') + window = manager.window("a_window") window.frame( Arel::Nodes::Between.new( window.rows, @@ -872,61 +872,61 @@ module Arel } end - it 'takes a range frame, unbounded preceding' do + it "takes a range frame, unbounded preceding" do table = Table.new :users manager = Arel::SelectManager.new manager.from table - manager.window('a_window').range(Arel::Nodes::Preceding.new) + manager.window("a_window").range(Arel::Nodes::Preceding.new) manager.to_sql.must_be_like %{ SELECT FROM "users" WINDOW "a_window" AS (RANGE UNBOUNDED PRECEDING) } end - it 'takes a range frame, bounded preceding' do + it "takes a range frame, bounded preceding" do table = Table.new :users manager = Arel::SelectManager.new manager.from table - manager.window('a_window').range(Arel::Nodes::Preceding.new(5)) + manager.window("a_window").range(Arel::Nodes::Preceding.new(5)) manager.to_sql.must_be_like %{ SELECT FROM "users" WINDOW "a_window" AS (RANGE 5 PRECEDING) } end - it 'takes a range frame, unbounded following' do + it "takes a range frame, unbounded following" do table = Table.new :users manager = Arel::SelectManager.new manager.from table - manager.window('a_window').range(Arel::Nodes::Following.new) + manager.window("a_window").range(Arel::Nodes::Following.new) manager.to_sql.must_be_like %{ SELECT FROM "users" WINDOW "a_window" AS (RANGE UNBOUNDED FOLLOWING) } end - it 'takes a range frame, bounded following' do + it "takes a range frame, bounded following" do table = Table.new :users manager = Arel::SelectManager.new manager.from table - manager.window('a_window').range(Arel::Nodes::Following.new(5)) + manager.window("a_window").range(Arel::Nodes::Following.new(5)) manager.to_sql.must_be_like %{ SELECT FROM "users" WINDOW "a_window" AS (RANGE 5 FOLLOWING) } end - it 'takes a range frame, current row' do + it "takes a range frame, current row" do table = Table.new :users manager = Arel::SelectManager.new manager.from table - manager.window('a_window').range(Arel::Nodes::CurrentRow.new) + manager.window("a_window").range(Arel::Nodes::CurrentRow.new) manager.to_sql.must_be_like %{ SELECT FROM "users" WINDOW "a_window" AS (RANGE CURRENT ROW) } end - it 'takes a range frame, between two delimiters' do + it "takes a range frame, between two delimiters" do table = Table.new :users manager = Arel::SelectManager.new manager.from table - window = manager.window('a_window') + window = manager.window("a_window") window.frame( Arel::Nodes::Between.new( window.range, @@ -940,7 +940,7 @@ module Arel end end - describe 'delete' do + describe "delete" do it "copies from" do table = Table.new :users manager = Arel::SelectManager.new @@ -963,8 +963,8 @@ module Arel end end - describe 'where_sql' do - it 'gives me back the where sql' do + describe "where_sql" do + it "gives me back the where sql" do table = Table.new :users manager = Arel::SelectManager.new manager.from table @@ -972,7 +972,7 @@ module Arel manager.where_sql.must_be_like %{ WHERE "users"."id" = 10 } end - it 'joins wheres with AND' do + it "joins wheres with AND" do table = Table.new :users manager = Arel::SelectManager.new manager.from table @@ -981,19 +981,19 @@ module Arel manager.where_sql.must_be_like %{ WHERE "users"."id" = 10 AND "users"."id" = 11} end - it 'handles database specific statements' do + it "handles database specific statements" do old_visitor = Table.engine.connection.visitor Table.engine.connection.visitor = Visitors::PostgreSQL.new Table.engine.connection table = Table.new :users manager = Arel::SelectManager.new manager.from table manager.where table[:id].eq 10 - manager.where table[:name].matches 'foo%' + manager.where table[:name].matches "foo%" manager.where_sql.must_be_like %{ WHERE "users"."id" = 10 AND "users"."name" ILIKE 'foo%' } Table.engine.connection.visitor = old_visitor end - it 'returns nil when there are no wheres' do + it "returns nil when there are no wheres" do table = Table.new :users manager = Arel::SelectManager.new manager.from table @@ -1001,35 +1001,35 @@ module Arel end end - describe 'update' do + describe "update" do - it 'creates an update statement' do + it "creates an update statement" do table = Table.new :users manager = Arel::SelectManager.new manager.from table - stmt = manager.compile_update({table[:id] => 1}, Arel::Attributes::Attribute.new(table, 'id')) + stmt = manager.compile_update({ table[:id] => 1 }, Arel::Attributes::Attribute.new(table, "id")) stmt.to_sql.must_be_like %{ UPDATE "users" SET "id" = 1 } end - it 'takes a string' do + it "takes a string" do table = Table.new :users manager = Arel::SelectManager.new manager.from table - stmt = manager.compile_update(Nodes::SqlLiteral.new('foo = bar'), Arel::Attributes::Attribute.new(table, 'id')) + stmt = manager.compile_update(Nodes::SqlLiteral.new("foo = bar"), Arel::Attributes::Attribute.new(table, "id")) stmt.to_sql.must_be_like %{ UPDATE "users" SET foo = bar } end - it 'copies limits' do + it "copies limits" do table = Table.new :users manager = Arel::SelectManager.new manager.from table manager.take 1 - stmt = manager.compile_update(Nodes::SqlLiteral.new('foo = bar'), Arel::Attributes::Attribute.new(table, 'id')) - stmt.key = table['id'] + stmt = manager.compile_update(Nodes::SqlLiteral.new("foo = bar"), Arel::Attributes::Attribute.new(table, "id")) + stmt.key = table["id"] stmt.to_sql.must_be_like %{ UPDATE "users" SET foo = bar @@ -1037,13 +1037,13 @@ module Arel } end - it 'copies order' do + it "copies order" do table = Table.new :users manager = Arel::SelectManager.new manager.from table manager.order :foo - stmt = manager.compile_update(Nodes::SqlLiteral.new('foo = bar'), Arel::Attributes::Attribute.new(table, 'id')) - stmt.key = table['id'] + stmt = manager.compile_update(Nodes::SqlLiteral.new("foo = bar"), Arel::Attributes::Attribute.new(table, "id")) + stmt.key = table["id"] stmt.to_sql.must_be_like %{ UPDATE "users" SET foo = bar @@ -1051,25 +1051,25 @@ module Arel } end - it 'copies where clauses' do + it "copies where clauses" do table = Table.new :users manager = Arel::SelectManager.new manager.where table[:id].eq 10 manager.from table - stmt = manager.compile_update({table[:id] => 1}, Arel::Attributes::Attribute.new(table, 'id')) + stmt = manager.compile_update({ table[:id] => 1 }, Arel::Attributes::Attribute.new(table, "id")) stmt.to_sql.must_be_like %{ UPDATE "users" SET "id" = 1 WHERE "users"."id" = 10 } end - it 'copies where clauses when nesting is triggered' do + it "copies where clauses when nesting is triggered" do table = Table.new :users manager = Arel::SelectManager.new manager.where table[:foo].eq 10 manager.take 42 manager.from table - stmt = manager.compile_update({table[:id] => 1}, Arel::Attributes::Attribute.new(table, 'id')) + stmt = manager.compile_update({ table[:id] => 1 }, Arel::Attributes::Attribute.new(table, "id")) stmt.to_sql.must_be_like %{ UPDATE "users" SET "id" = 1 WHERE "users"."id" IN (SELECT "users"."id" FROM "users" WHERE "users"."foo" = 10 LIMIT 42) @@ -1078,51 +1078,51 @@ module Arel end - describe 'project' do + describe "project" do it "takes sql literals" do manager = Arel::SelectManager.new - manager.project Nodes::SqlLiteral.new '*' + manager.project Nodes::SqlLiteral.new "*" manager.to_sql.must_be_like %{ SELECT * } end - it 'takes multiple args' do + it "takes multiple args" do manager = Arel::SelectManager.new - manager.project Nodes::SqlLiteral.new('foo'), - Nodes::SqlLiteral.new('bar') + manager.project Nodes::SqlLiteral.new("foo"), + Nodes::SqlLiteral.new("bar") manager.to_sql.must_be_like %{ SELECT foo, bar } end - it 'takes strings' do + it "takes strings" do manager = Arel::SelectManager.new - manager.project '*' + manager.project "*" manager.to_sql.must_be_like %{ SELECT * } end end - describe 'projections' do - it 'reads projections' do + describe "projections" do + it "reads projections" do manager = Arel::SelectManager.new - manager.project Arel.sql('foo'), Arel.sql('bar') - manager.projections.must_equal [Arel.sql('foo'), Arel.sql('bar')] + manager.project Arel.sql("foo"), Arel.sql("bar") + manager.projections.must_equal [Arel.sql("foo"), Arel.sql("bar")] end end - describe 'projections=' do - it 'overwrites projections' do + describe "projections=" do + it "overwrites projections" do manager = Arel::SelectManager.new - manager.project Arel.sql('foo') - manager.projections = [Arel.sql('bar')] + manager.project Arel.sql("foo") + manager.projections = [Arel.sql("bar")] manager.to_sql.must_be_like %{ SELECT bar } end end - describe 'take' do + describe "take" do it "knows take" do table = Table.new :users manager = Arel::SelectManager.new - manager.from(table).project(table['id']) - manager.where(table['id'].eq(1)) + manager.from(table).project(table["id"]) + manager.where(table["id"].eq(1)) manager.take 1 manager.to_sql.must_be_like %{ @@ -1138,22 +1138,22 @@ module Arel manager.take(1).must_equal manager end - it 'removes LIMIT when nil is passed' do + it "removes LIMIT when nil is passed" do manager = Arel::SelectManager.new manager.limit = 10 - assert_match('LIMIT', manager.to_sql) + assert_match("LIMIT", manager.to_sql) manager.limit = nil - refute_match('LIMIT', manager.to_sql) + refute_match("LIMIT", manager.to_sql) end end - describe 'where' do + describe "where" do it "knows where" do table = Table.new :users manager = Arel::SelectManager.new - manager.from(table).project(table['id']) - manager.where(table['id'].eq(1)) + manager.from(table).project(table["id"]) + manager.where(table["id"].eq(1)) manager.to_sql.must_be_like %{ SELECT "users"."id" FROM "users" @@ -1165,37 +1165,37 @@ module Arel table = Table.new :users manager = Arel::SelectManager.new manager.from(table) - manager.project(table['id']).where(table['id'].eq 1).must_equal manager + manager.project(table["id"]).where(table["id"].eq 1).must_equal manager end end - describe 'from' do + describe "from" do it "makes sql" do table = Table.new :users manager = Arel::SelectManager.new manager.from table - manager.project table['id'] + manager.project table["id"] manager.to_sql.must_be_like 'SELECT "users"."id" FROM "users"' end it "chains" do table = Table.new :users manager = Arel::SelectManager.new - manager.from(table).project(table['id']).must_equal manager + manager.from(table).project(table["id"]).must_equal manager manager.to_sql.must_be_like 'SELECT "users"."id" FROM "users"' end end - describe 'source' do - it 'returns the join source of the select core' do + describe "source" do + it "returns the join source of the select core" do manager = Arel::SelectManager.new manager.source.must_equal manager.ast.cores.last.source end end - describe 'distinct' do - it 'sets the quantifier' do + describe "distinct" do + it "sets the quantifier" do manager = Arel::SelectManager.new manager.distinct @@ -1212,13 +1212,13 @@ module Arel end end - describe 'distinct_on' do - it 'sets the quantifier' do + describe "distinct_on" do + it "sets the quantifier" do manager = Arel::SelectManager.new table = Table.new :users - manager.distinct_on(table['id']) - manager.ast.cores.last.set_quantifier.must_equal Arel::Nodes::DistinctOn.new(table['id']) + manager.distinct_on(table["id"]) + manager.ast.cores.last.set_quantifier.must_equal Arel::Nodes::DistinctOn.new(table["id"]) manager.distinct_on(false) manager.ast.cores.last.set_quantifier.must_be_nil @@ -1228,7 +1228,7 @@ module Arel manager = Arel::SelectManager.new table = Table.new :users - manager.distinct_on(table['id']).must_equal manager + manager.distinct_on(table["id"]).must_equal manager manager.distinct_on(false).must_equal manager end end diff --git a/activerecord/test/cases/arel/support/fake_record.rb b/activerecord/test/cases/arel/support/fake_record.rb index 75ac1e072f..8620d6fd34 100644 --- a/activerecord/test/cases/arel/support/fake_record.rb +++ b/activerecord/test/cases/arel/support/fake_record.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'date' +require "date" module FakeRecord class Column < Struct.new(:name, :type) end @@ -12,49 +12,49 @@ module FakeRecord def initialize(visitor = nil) @tables = %w{ users photos developers products} @columns = { - 'users' => [ - Column.new('id', :integer), - Column.new('name', :string), - Column.new('bool', :boolean), - Column.new('created_at', :date) + "users" => [ + Column.new("id", :integer), + Column.new("name", :string), + Column.new("bool", :boolean), + Column.new("created_at", :date) ], - 'products' => [ - Column.new('id', :integer), - Column.new('price', :decimal) + "products" => [ + Column.new("id", :integer), + Column.new("price", :decimal) ] } @columns_hash = { - 'users' => Hash[@columns['users'].map { |x| [x.name, x] }], - 'products' => Hash[@columns['products'].map { |x| [x.name, x] }] + "users" => Hash[@columns["users"].map { |x| [x.name, x] }], + "products" => Hash[@columns["products"].map { |x| [x.name, x] }] } @primary_keys = { - 'users' => 'id', - 'products' => 'id' + "users" => "id", + "products" => "id" } @visitor = visitor end - def columns_hash table_name + def columns_hash(table_name) @columns_hash[table_name] end - def primary_key name + def primary_key(name) @primary_keys[name.to_s] end - def data_source_exists? name + def data_source_exists?(name) @tables.include? name.to_s end - def columns name, message = nil + def columns(name, message = nil) @columns[name.to_s] end - def quote_table_name name + def quote_table_name(name) "\"#{name.to_s}\"" end - def quote_column_name name + def quote_column_name(name) "\"#{name.to_s}\"" end @@ -62,7 +62,7 @@ module FakeRecord self end - def quote thing + def quote(thing) case thing when DateTime "'#{thing.strftime("%Y-%m-%d %H:%M:%S")}'" @@ -73,7 +73,7 @@ module FakeRecord when false "'f'" when nil - 'NULL' + "NULL" when Numeric thing else @@ -89,7 +89,7 @@ module FakeRecord attr_reader :spec, :connection def initialize - @spec = Spec.new(:adapter => 'america') + @spec = Spec.new(adapter: "america") @connection = Connection.new @connection.visitor = Arel::Visitors::ToSql.new(connection) end @@ -98,7 +98,7 @@ module FakeRecord yield connection end - def table_exists? name + def table_exists?(name) connection.tables.include? name.to_s end @@ -110,7 +110,7 @@ module FakeRecord connection end - def quote thing + def quote(thing) connection.quote thing end end diff --git a/activerecord/test/cases/arel/table_test.rb b/activerecord/test/cases/arel/table_test.rb index ccb3ab302f..91b7a5a480 100644 --- a/activerecord/test/cases/arel/table_test.rb +++ b/activerecord/test/cases/arel/table_test.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true -require_relative 'helper' + +require_relative "helper" module Arel class TableTest < Arel::Spec @@ -7,56 +8,56 @@ module Arel @relation = Table.new(:users) end - it 'should create join nodes' do - join = @relation.create_string_join 'foo' + it "should create join nodes" do + join = @relation.create_string_join "foo" assert_kind_of Arel::Nodes::StringJoin, join - assert_equal 'foo', join.left + assert_equal "foo", join.left end - it 'should create join nodes' do - join = @relation.create_join 'foo', 'bar' + it "should create join nodes" do + join = @relation.create_join "foo", "bar" assert_kind_of Arel::Nodes::InnerJoin, join - assert_equal 'foo', join.left - assert_equal 'bar', join.right + assert_equal "foo", join.left + assert_equal "bar", join.right end - it 'should create join nodes with a klass' do - join = @relation.create_join 'foo', 'bar', Arel::Nodes::FullOuterJoin + it "should create join nodes with a klass" do + join = @relation.create_join "foo", "bar", Arel::Nodes::FullOuterJoin assert_kind_of Arel::Nodes::FullOuterJoin, join - assert_equal 'foo', join.left - assert_equal 'bar', join.right + assert_equal "foo", join.left + assert_equal "bar", join.right end - it 'should create join nodes with a klass' do - join = @relation.create_join 'foo', 'bar', Arel::Nodes::OuterJoin + it "should create join nodes with a klass" do + join = @relation.create_join "foo", "bar", Arel::Nodes::OuterJoin assert_kind_of Arel::Nodes::OuterJoin, join - assert_equal 'foo', join.left - assert_equal 'bar', join.right + assert_equal "foo", join.left + assert_equal "bar", join.right end - it 'should create join nodes with a klass' do - join = @relation.create_join 'foo', 'bar', Arel::Nodes::RightOuterJoin + it "should create join nodes with a klass" do + join = @relation.create_join "foo", "bar", Arel::Nodes::RightOuterJoin assert_kind_of Arel::Nodes::RightOuterJoin, join - assert_equal 'foo', join.left - assert_equal 'bar', join.right + assert_equal "foo", join.left + assert_equal "bar", join.right end - it 'should return an insert manager' do - im = @relation.compile_insert 'VALUES(NULL)' + it "should return an insert manager" do + im = @relation.compile_insert "VALUES(NULL)" assert_kind_of Arel::InsertManager, im im.into Table.new(:users) assert_equal "INSERT INTO \"users\" VALUES(NULL)", im.to_sql end - describe 'skip' do - it 'should add an offset' do + describe "skip" do + it "should add an offset" do sm = @relation.skip 2 sm.to_sql.must_be_like "SELECT FROM \"users\" OFFSET 2" end end - describe 'having' do - it 'adds a having clause' do + describe "having" do + it "adds a having clause" do mgr = @relation.having @relation[:id].eq(10) mgr.to_sql.must_be_like %{ SELECT FROM "users" HAVING "users"."id" = 10 @@ -64,21 +65,21 @@ module Arel end end - describe 'backwards compat' do - describe 'join' do - it 'noops on nil' do + describe "backwards compat" do + describe "join" do + it "noops on nil" do mgr = @relation.join nil mgr.to_sql.must_be_like %{ SELECT FROM "users" } end - it 'raises EmptyJoinError on empty' do + it "raises EmptyJoinError on empty" do assert_raises(EmptyJoinError) do @relation.join "" end end - it 'takes a second argument for join type' do + it "takes a second argument for join type" do right = @relation.alias predicate = @relation[:id].eq(right[:id]) mgr = @relation.join(right, Nodes::OuterJoin).on(predicate) @@ -91,8 +92,8 @@ module Arel end end - describe 'join' do - it 'creates an outer join' do + describe "join" do + it "creates an outer join" do right = @relation.alias predicate = @relation[:id].eq(right[:id]) mgr = @relation.outer_join(right).on(predicate) @@ -106,8 +107,8 @@ module Arel end end - describe 'group' do - it 'should create a group' do + describe "group" do + it "should create a group" do manager = @relation.group @relation[:id] manager.to_sql.must_be_like %{ SELECT FROM "users" GROUP BY "users"."id" @@ -115,54 +116,54 @@ module Arel end end - describe 'alias' do - it 'should create a node that proxies to a table' do + describe "alias" do + it "should create a node that proxies to a table" do node = @relation.alias - node.name.must_equal 'users_2' + node.name.must_equal "users_2" node[:id].relation.must_equal node end end - describe 'new' do - it 'should accept a hash' do - rel = Table.new :users, :as => 'foo' - rel.table_alias.must_equal 'foo' + describe "new" do + it "should accept a hash" do + rel = Table.new :users, as: "foo" + rel.table_alias.must_equal "foo" end - it 'ignores as if it equals name' do - rel = Table.new :users, :as => 'users' + it "ignores as if it equals name" do + rel = Table.new :users, as: "users" rel.table_alias.must_be_nil end end - describe 'order' do + describe "order" do it "should take an order" do manager = @relation.order "foo" manager.to_sql.must_be_like %{ SELECT FROM "users" ORDER BY foo } end end - describe 'take' do + describe "take" do it "should add a limit" do manager = @relation.take 1 - manager.project Nodes::SqlLiteral.new '*' + manager.project Nodes::SqlLiteral.new "*" manager.to_sql.must_be_like %{ SELECT * FROM "users" LIMIT 1 } end end - describe 'project' do - it 'can project' do - manager = @relation.project Nodes::SqlLiteral.new '*' + describe "project" do + it "can project" do + manager = @relation.project Nodes::SqlLiteral.new "*" manager.to_sql.must_be_like %{ SELECT * FROM "users" } end - it 'takes multiple parameters' do - manager = @relation.project Nodes::SqlLiteral.new('*'), Nodes::SqlLiteral.new('*') + it "takes multiple parameters" do + manager = @relation.project Nodes::SqlLiteral.new("*"), Nodes::SqlLiteral.new("*") manager.to_sql.must_be_like %{ SELECT *, * FROM "users" } end end - describe 'where' do + describe "where" do it "returns a tree manager" do manager = @relation.where @relation[:id].eq 1 manager.project @relation[:id] @@ -176,15 +177,15 @@ module Arel end it "should have a name" do - @relation.name.must_equal 'users' + @relation.name.must_equal "users" end it "should have a table name" do - @relation.table_name.must_equal 'users' + @relation.table_name.must_equal "users" end - describe '[]' do - describe 'when given a Symbol' do + describe "[]" do + describe "when given a Symbol" do it "manufactures an attribute if the symbol names an attribute within the relation" do column = @relation[:id] column.name.must_equal :id @@ -192,21 +193,21 @@ module Arel end end - describe 'equality' do - it 'is equal with equal ivars' do + describe "equality" do + it "is equal with equal ivars" do relation1 = Table.new(:users) - relation1.table_alias = 'zomg' + relation1.table_alias = "zomg" relation2 = Table.new(:users) - relation2.table_alias = 'zomg' + relation2.table_alias = "zomg" array = [relation1, relation2] assert_equal 1, array.uniq.size end - it 'is not equal with different ivars' do + it "is not equal with different ivars" do relation1 = Table.new(:users) - relation1.table_alias = 'zomg' + relation1.table_alias = "zomg" relation2 = Table.new(:users) - relation2.table_alias = 'zomg2' + relation2.table_alias = "zomg2" array = [relation1, relation2] assert_equal 2, array.uniq.size end diff --git a/activerecord/test/cases/arel/update_manager_test.rb b/activerecord/test/cases/arel/update_manager_test.rb index 91118c5e9f..cc1b9ac5b3 100644 --- a/activerecord/test/cases/arel/update_manager_test.rb +++ b/activerecord/test/cases/arel/update_manager_test.rb @@ -1,10 +1,11 @@ # frozen_string_literal: true -require_relative 'helper' + +require_relative "helper" module Arel class UpdateManagerTest < Arel::Spec - describe 'new' do - it 'takes an engine' do + describe "new" do + it "takes an engine" do Arel::UpdateManager.new end end @@ -17,17 +18,17 @@ module Arel um.to_sql.must_be_like %{ UPDATE "users" SET "name" = ? } end - it 'handles limit properly' do + it "handles limit properly" do table = Table.new(:users) um = Arel::UpdateManager.new - um.key = 'id' + um.key = "id" um.take 10 um.table table um.set [[table[:name], nil]] assert_match(/LIMIT 10/, um.to_sql) end - describe 'set' do + describe "set" do it "updates with null" do table = Table.new(:users) um = Arel::UpdateManager.new @@ -36,7 +37,7 @@ module Arel um.to_sql.must_be_like %{ UPDATE "users" SET "name" = NULL } end - it 'takes a string' do + it "takes a string" do table = Table.new(:users) um = Arel::UpdateManager.new um.table table @@ -44,36 +45,36 @@ module Arel um.to_sql.must_be_like %{ UPDATE "users" SET foo = bar } end - it 'takes a list of lists' do + it "takes a list of lists" do table = Table.new(:users) um = Arel::UpdateManager.new um.table table - um.set [[table[:id], 1], [table[:name], 'hello']] + um.set [[table[:id], 1], [table[:name], "hello"]] um.to_sql.must_be_like %{ UPDATE "users" SET "id" = 1, "name" = 'hello' } end - it 'chains' do + it "chains" do table = Table.new(:users) um = Arel::UpdateManager.new - um.set([[table[:id], 1], [table[:name], 'hello']]).must_equal um + um.set([[table[:id], 1], [table[:name], "hello"]]).must_equal um end end - describe 'table' do - it 'generates an update statement' do + describe "table" do + it "generates an update statement" do um = Arel::UpdateManager.new um.table Table.new(:users) um.to_sql.must_be_like %{ UPDATE "users" } end - it 'chains' do + it "chains" do um = Arel::UpdateManager.new um.table(Table.new(:users)).must_equal um end - it 'generates an update statement with joins' do + it "generates an update statement with joins" do um = Arel::UpdateManager.new table = Table.new(:users) @@ -87,8 +88,8 @@ module Arel end end - describe 'where' do - it 'generates a where clause' do + describe "where" do + it "generates a where clause" do table = Table.new :users um = Arel::UpdateManager.new um.table table @@ -98,7 +99,7 @@ module Arel } end - it 'chains' do + it "chains" do table = Table.new :users um = Arel::UpdateManager.new um.table table @@ -106,18 +107,18 @@ module Arel end end - describe 'key' do + describe "key" do before do @table = Table.new :users @um = Arel::UpdateManager.new @um.key = @table[:foo] end - it 'can be set' do + it "can be set" do @um.ast.key.must_equal @table[:foo] end - it 'can be accessed' do + it "can be accessed" do @um.key.must_equal @table[:foo] end end diff --git a/activerecord/test/cases/arel/visitors/depth_first_test.rb b/activerecord/test/cases/arel/visitors/depth_first_test.rb index b841d119d2..3baccc7316 100644 --- a/activerecord/test/cases/arel/visitors/depth_first_test.rb +++ b/activerecord/test/cases/arel/visitors/depth_first_test.rb @@ -1,11 +1,12 @@ # frozen_string_literal: true -require_relative '../helper' + +require_relative "../helper" module Arel module Visitors class TestDepthFirst < Arel::Test Collector = Struct.new(:calls) do - def call object + def call(object) calls << object end end @@ -164,7 +165,7 @@ module Arel def test_table relation = Arel::Table.new(:users) @visitor.accept relation - assert_equal ['users', relation], @collector.calls + assert_equal ["users", relation], @collector.calls end def test_array diff --git a/activerecord/test/cases/arel/visitors/dispatch_contamination_test.rb b/activerecord/test/cases/arel/visitors/dispatch_contamination_test.rb index eb278cde4c..a07a1a050a 100644 --- a/activerecord/test/cases/arel/visitors/dispatch_contamination_test.rb +++ b/activerecord/test/cases/arel/visitors/dispatch_contamination_test.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true -require_relative '../helper' -require 'concurrent' + +require_relative "../helper" +require "concurrent" module Arel module Visitors @@ -10,14 +11,14 @@ module Arel @barrier = Concurrent::CyclicBarrier.new(2) end - def visit_Arel_Visitors_DummySuperNode node + def visit_Arel_Visitors_DummySuperNode(node) 42 end # This is terrible, but it's the only way to reliably reproduce # the possible race where two threads attempt to correct the # dispatch hash at the same time. - def send *args + def send(*args) super rescue # Both threads try (and fail) to dispatch to the subclass's name @@ -43,7 +44,7 @@ module Arel @table = Table.new(:users) end - it 'dispatches properly after failing upwards' do + it "dispatches properly after failing upwards" do node = Nodes::Union.new(Nodes::True.new, Nodes::False.new) assert_equal "( TRUE UNION FALSE )", node.to_sql @@ -52,7 +53,7 @@ module Arel assert_equal "( TRUE UNION FALSE )", node.to_sql end - it 'is threadsafe when implementing superclass fallback' do + it "is threadsafe when implementing superclass fallback" do visitor = DummyVisitor.new main_thread_finished = Concurrent::Event.new @@ -69,4 +70,3 @@ module Arel end end end - diff --git a/activerecord/test/cases/arel/visitors/dot_test.rb b/activerecord/test/cases/arel/visitors/dot_test.rb index 048482c3ca..98f3bab620 100644 --- a/activerecord/test/cases/arel/visitors/dot_test.rb +++ b/activerecord/test/cases/arel/visitors/dot_test.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true -require_relative '../helper' + +require_relative "../helper" module Arel module Visitors @@ -23,7 +24,7 @@ module Arel end def test_named_function - func = Nodes::NamedFunction.new 'omg', 'omg' + func = Nodes::NamedFunction.new "omg", "omg" @visitor.accept func, Collectors::PlainString.new end diff --git a/activerecord/test/cases/arel/visitors/ibm_db_test.rb b/activerecord/test/cases/arel/visitors/ibm_db_test.rb index d7569eedc3..7163cb34d3 100644 --- a/activerecord/test/cases/arel/visitors/ibm_db_test.rb +++ b/activerecord/test/cases/arel/visitors/ibm_db_test.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true -require_relative '../helper' + +require_relative "../helper" module Arel module Visitors @@ -8,18 +9,18 @@ module Arel @visitor = IBM_DB.new Table.engine.connection end - def compile node + def compile(node) @visitor.accept(node, Collectors::SQLString.new).value end - it 'uses FETCH FIRST n ROWS to limit results' do + it "uses FETCH FIRST n ROWS to limit results" do stmt = Nodes::SelectStatement.new stmt.limit = Nodes::Limit.new(1) sql = compile(stmt) sql.must_be_like "SELECT FETCH FIRST 1 ROWS ONLY" end - it 'uses FETCH FIRST n ROWS in updates with a limit' do + it "uses FETCH FIRST n ROWS in updates with a limit" do table = Table.new(:users) stmt = Nodes::UpdateStatement.new stmt.relation = table @@ -28,7 +29,6 @@ module Arel sql = compile(stmt) sql.must_be_like "UPDATE \"users\" WHERE \"users\".\"id\" IN (SELECT \"users\".\"id\" FROM \"users\" FETCH FIRST 1 ROWS ONLY)" end - end end end diff --git a/activerecord/test/cases/arel/visitors/informix_test.rb b/activerecord/test/cases/arel/visitors/informix_test.rb index bb6ff42f05..b0b031cca3 100644 --- a/activerecord/test/cases/arel/visitors/informix_test.rb +++ b/activerecord/test/cases/arel/visitors/informix_test.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true -require_relative '../helper' + +require_relative "../helper" module Arel module Visitors @@ -8,18 +9,18 @@ module Arel @visitor = Informix.new Table.engine.connection end - def compile node + def compile(node) @visitor.accept(node, Collectors::SQLString.new).value end - it 'uses FIRST n to limit results' do + it "uses FIRST n to limit results" do stmt = Nodes::SelectStatement.new stmt.limit = Nodes::Limit.new(1) sql = compile(stmt) sql.must_be_like "SELECT FIRST 1" end - it 'uses FIRST n in updates with a limit' do + it "uses FIRST n in updates with a limit" do table = Table.new(:users) stmt = Nodes::UpdateStatement.new stmt.relation = table @@ -29,14 +30,14 @@ module Arel sql.must_be_like "UPDATE \"users\" WHERE \"users\".\"id\" IN (SELECT FIRST 1 \"users\".\"id\" FROM \"users\")" end - it 'uses SKIP n to jump results' do + it "uses SKIP n to jump results" do stmt = Nodes::SelectStatement.new stmt.offset = Nodes::Offset.new(10) sql = compile(stmt) sql.must_be_like "SELECT SKIP 10" end - it 'uses SKIP before FIRST' do + it "uses SKIP before FIRST" do stmt = Nodes::SelectStatement.new stmt.limit = Nodes::Limit.new(1) stmt.offset = Nodes::Offset.new(1) @@ -44,7 +45,7 @@ module Arel sql.must_be_like "SELECT SKIP 1 FIRST 1" end - it 'uses INNER JOIN to perform joins' do + it "uses INNER JOIN to perform joins" do core = Nodes::SelectCore.new table = Table.new(:posts) core.source = Nodes::JoinSource.new(table, [table.create_join(Table.new(:comments))]) @@ -53,7 +54,6 @@ module Arel sql = compile(stmt) sql.must_be_like 'SELECT FROM "posts" INNER JOIN "comments"' end - end end end diff --git a/activerecord/test/cases/arel/visitors/mssql_test.rb b/activerecord/test/cases/arel/visitors/mssql_test.rb index 4e81678813..340376c3d6 100644 --- a/activerecord/test/cases/arel/visitors/mssql_test.rb +++ b/activerecord/test/cases/arel/visitors/mssql_test.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true -require_relative '../helper' + +require_relative "../helper" module Arel module Visitors @@ -9,17 +10,17 @@ module Arel @table = Arel::Table.new "users" end - def compile node + def compile(node) @visitor.accept(node, Collectors::SQLString.new).value end - it 'should not modify query if no offset or limit' do + it "should not modify query if no offset or limit" do stmt = Nodes::SelectStatement.new sql = compile(stmt) sql.must_be_like "SELECT" end - it 'should go over table PK if no .order() or .group()' do + it "should go over table PK if no .order() or .group()" do stmt = Nodes::SelectStatement.new stmt.cores.first.from = @table stmt.limit = Nodes::Limit.new(10) @@ -27,7 +28,7 @@ module Arel sql.must_be_like "SELECT _t.* FROM (SELECT ROW_NUMBER() OVER (ORDER BY \"users\".\"id\") as _row_num FROM \"users\") as _t WHERE _row_num BETWEEN 1 AND 10" end - it 'caches the PK lookup for order' do + it "caches the PK lookup for order" do connection = Minitest::Mock.new connection.expect(:primary_key, ["id"], ["users"]) @@ -46,7 +47,7 @@ module Arel connection.verify end - it 'should use TOP for limited deletes' do + it "should use TOP for limited deletes" do stmt = Nodes::DeleteStatement.new stmt.relation = @table stmt.limit = Nodes::Limit.new(10) @@ -55,23 +56,23 @@ module Arel sql.must_be_like "DELETE TOP (10) FROM \"users\"" end - it 'should go over query ORDER BY if .order()' do + it "should go over query ORDER BY if .order()" do stmt = Nodes::SelectStatement.new stmt.limit = Nodes::Limit.new(10) - stmt.orders << Nodes::SqlLiteral.new('order_by') + stmt.orders << Nodes::SqlLiteral.new("order_by") sql = compile(stmt) sql.must_be_like "SELECT _t.* FROM (SELECT ROW_NUMBER() OVER (ORDER BY order_by) as _row_num) as _t WHERE _row_num BETWEEN 1 AND 10" end - it 'should go over query GROUP BY if no .order() and there is .group()' do + it "should go over query GROUP BY if no .order() and there is .group()" do stmt = Nodes::SelectStatement.new - stmt.cores.first.groups << Nodes::SqlLiteral.new('group_by') + stmt.cores.first.groups << Nodes::SqlLiteral.new("group_by") stmt.limit = Nodes::Limit.new(10) sql = compile(stmt) sql.must_be_like "SELECT _t.* FROM (SELECT ROW_NUMBER() OVER (ORDER BY group_by) as _row_num GROUP BY group_by) as _t WHERE _row_num BETWEEN 1 AND 10" end - it 'should use BETWEEN if both .limit() and .offset' do + it "should use BETWEEN if both .limit() and .offset" do stmt = Nodes::SelectStatement.new stmt.limit = Nodes::Limit.new(10) stmt.offset = Nodes::Offset.new(20) @@ -79,21 +80,20 @@ module Arel sql.must_be_like "SELECT _t.* FROM (SELECT ROW_NUMBER() OVER (ORDER BY ) as _row_num) as _t WHERE _row_num BETWEEN 21 AND 30" end - it 'should use >= if only .offset' do + it "should use >= if only .offset" do stmt = Nodes::SelectStatement.new stmt.offset = Nodes::Offset.new(20) sql = compile(stmt) sql.must_be_like "SELECT _t.* FROM (SELECT ROW_NUMBER() OVER (ORDER BY ) as _row_num) as _t WHERE _row_num >= 21" end - it 'should generate subquery for .count' do + it "should generate subquery for .count" do stmt = Nodes::SelectStatement.new stmt.limit = Nodes::Limit.new(10) - stmt.cores.first.projections << Nodes::Count.new('*') + stmt.cores.first.projections << Nodes::Count.new("*") sql = compile(stmt) sql.must_be_like "SELECT COUNT(1) as count_id FROM (SELECT _t.* FROM (SELECT ROW_NUMBER() OVER (ORDER BY ) as _row_num) as _t WHERE _row_num BETWEEN 1 AND 10) AS subquery" end - end end end diff --git a/activerecord/test/cases/arel/visitors/mysql_test.rb b/activerecord/test/cases/arel/visitors/mysql_test.rb index f9b468b1d2..9d3bad8516 100644 --- a/activerecord/test/cases/arel/visitors/mysql_test.rb +++ b/activerecord/test/cases/arel/visitors/mysql_test.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true -require_relative '../helper' + +require_relative "../helper" module Arel module Visitors @@ -8,24 +9,24 @@ module Arel @visitor = MySQL.new Table.engine.connection end - def compile node + def compile(node) @visitor.accept(node, Collectors::SQLString.new).value end - it 'squashes parenthesis on multiple unions' do - subnode = Nodes::Union.new Arel.sql('left'), Arel.sql('right') - node = Nodes::Union.new subnode, Arel.sql('topright') - assert_equal 1, compile(node).scan('(').length + it "squashes parenthesis on multiple unions" do + subnode = Nodes::Union.new Arel.sql("left"), Arel.sql("right") + node = Nodes::Union.new subnode, Arel.sql("topright") + assert_equal 1, compile(node).scan("(").length - subnode = Nodes::Union.new Arel.sql('left'), Arel.sql('right') - node = Nodes::Union.new Arel.sql('topleft'), subnode - assert_equal 1, compile(node).scan('(').length + subnode = Nodes::Union.new Arel.sql("left"), Arel.sql("right") + node = Nodes::Union.new Arel.sql("topleft"), subnode + assert_equal 1, compile(node).scan("(").length end ### # :'( # http://dev.mysql.com/doc/refman/5.0/en/select.html#id3482214 - it 'defaults limit to 18446744073709551615' do + it "defaults limit to 18446744073709551615" do stmt = Nodes::SelectStatement.new stmt.offset = Nodes::Offset.new(1) sql = compile(stmt) @@ -39,20 +40,20 @@ module Arel assert_equal("UPDATE \"users\" LIMIT 'omg'", compile(sc)) end - it 'uses DUAL for empty from' do + it "uses DUAL for empty from" do stmt = Nodes::SelectStatement.new sql = compile(stmt) sql.must_be_like "SELECT FROM DUAL" end - describe 'locking' do - it 'defaults to FOR UPDATE when locking' do - node = Nodes::Lock.new(Arel.sql('FOR UPDATE')) + describe "locking" do + it "defaults to FOR UPDATE when locking" do + node = Nodes::Lock.new(Arel.sql("FOR UPDATE")) compile(node).must_be_like "FOR UPDATE" end - it 'allows a custom string to be used as a lock' do - node = Nodes::Lock.new(Arel.sql('LOCK IN SHARE MODE')) + it "allows a custom string to be used as a lock" do + node = Nodes::Lock.new(Arel.sql("LOCK IN SHARE MODE")) compile(node).must_be_like "LOCK IN SHARE MODE" end end @@ -68,7 +69,7 @@ module Arel it "concats a string" do @table = Table.new(:users) - query = @table[:name].concat(Nodes.build_quoted('abc')) + query = @table[:name].concat(Nodes.build_quoted("abc")) compile(query).must_be_like %{ CONCAT("users"."name", 'abc') } diff --git a/activerecord/test/cases/arel/visitors/oracle12_test.rb b/activerecord/test/cases/arel/visitors/oracle12_test.rb index ef2050b7c9..83a2ee36ca 100644 --- a/activerecord/test/cases/arel/visitors/oracle12_test.rb +++ b/activerecord/test/cases/arel/visitors/oracle12_test.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true -require_relative '../helper' + +require_relative "../helper" module Arel module Visitors @@ -9,11 +10,11 @@ module Arel @table = Table.new(:users) end - def compile node + def compile(node) @visitor.accept(node, Collectors::SQLString.new).value end - it 'modified except to be minus' do + it "modified except to be minus" do left = Nodes::SqlLiteral.new("SELECT * FROM users WHERE age > 10") right = Nodes::SqlLiteral.new("SELECT * FROM users WHERE age > 20") sql = compile Nodes::Except.new(left, right) @@ -22,7 +23,7 @@ module Arel } end - it 'generates select options offset then limit' do + it "generates select options offset then limit" do stmt = Nodes::SelectStatement.new stmt.offset = Nodes::Offset.new(1) stmt.limit = Nodes::Limit.new(10) @@ -30,18 +31,18 @@ module Arel sql.must_be_like "SELECT OFFSET 1 ROWS FETCH FIRST 10 ROWS ONLY" end - describe 'locking' do - it 'generates ArgumentError if limit and lock are used' do + describe "locking" do + it "generates ArgumentError if limit and lock are used" do stmt = Nodes::SelectStatement.new stmt.limit = Nodes::Limit.new(10) - stmt.lock = Nodes::Lock.new(Arel.sql('FOR UPDATE')) + stmt.lock = Nodes::Lock.new(Arel.sql("FOR UPDATE")) assert_raises ArgumentError do compile(stmt) end end - it 'defaults to FOR UPDATE when locking' do - node = Nodes::Lock.new(Arel.sql('FOR UPDATE')) + it "defaults to FOR UPDATE when locking" do + node = Nodes::Lock.new(Arel.sql("FOR UPDATE")) compile(node).must_be_like "FOR UPDATE" end end diff --git a/activerecord/test/cases/arel/visitors/oracle_test.rb b/activerecord/test/cases/arel/visitors/oracle_test.rb index 0737774fbf..e1dfe40cf9 100644 --- a/activerecord/test/cases/arel/visitors/oracle_test.rb +++ b/activerecord/test/cases/arel/visitors/oracle_test.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true -require_relative '../helper' + +require_relative "../helper" module Arel module Visitors @@ -9,79 +10,79 @@ module Arel @table = Table.new(:users) end - def compile node + def compile(node) @visitor.accept(node, Collectors::SQLString.new).value end - it 'modifies order when there is distinct and first value' do + it "modifies order when there is distinct and first value" do # *sigh* select = "DISTINCT foo.id, FIRST_VALUE(projects.name) OVER (foo) AS alias_0__" stmt = Nodes::SelectStatement.new stmt.cores.first.projections << Nodes::SqlLiteral.new(select) - stmt.orders << Nodes::SqlLiteral.new('foo') + stmt.orders << Nodes::SqlLiteral.new("foo") sql = compile(stmt) sql.must_be_like %{ SELECT #{select} ORDER BY alias_0__ } end - it 'is idempotent with crazy query' do + it "is idempotent with crazy query" do # *sigh* select = "DISTINCT foo.id, FIRST_VALUE(projects.name) OVER (foo) AS alias_0__" stmt = Nodes::SelectStatement.new stmt.cores.first.projections << Nodes::SqlLiteral.new(select) - stmt.orders << Nodes::SqlLiteral.new('foo') + stmt.orders << Nodes::SqlLiteral.new("foo") sql = compile(stmt) sql2 = compile(stmt) sql.must_equal sql2 end - it 'splits orders with commas' do + it "splits orders with commas" do # *sigh* select = "DISTINCT foo.id, FIRST_VALUE(projects.name) OVER (foo) AS alias_0__" stmt = Nodes::SelectStatement.new stmt.cores.first.projections << Nodes::SqlLiteral.new(select) - stmt.orders << Nodes::SqlLiteral.new('foo, bar') + stmt.orders << Nodes::SqlLiteral.new("foo, bar") sql = compile(stmt) sql.must_be_like %{ SELECT #{select} ORDER BY alias_0__, alias_1__ } end - it 'splits orders with commas and function calls' do + it "splits orders with commas and function calls" do # *sigh* select = "DISTINCT foo.id, FIRST_VALUE(projects.name) OVER (foo) AS alias_0__" stmt = Nodes::SelectStatement.new stmt.cores.first.projections << Nodes::SqlLiteral.new(select) - stmt.orders << Nodes::SqlLiteral.new('NVL(LOWER(bar, foo), foo) DESC, UPPER(baz)') + stmt.orders << Nodes::SqlLiteral.new("NVL(LOWER(bar, foo), foo) DESC, UPPER(baz)") sql = compile(stmt) sql.must_be_like %{ SELECT #{select} ORDER BY alias_0__ DESC, alias_1__ } end - describe 'Nodes::SelectStatement' do - describe 'limit' do - it 'adds a rownum clause' do + describe "Nodes::SelectStatement" do + describe "limit" do + it "adds a rownum clause" do stmt = Nodes::SelectStatement.new stmt.limit = Nodes::Limit.new(10) sql = compile stmt sql.must_be_like %{ SELECT WHERE ROWNUM <= 10 } end - it 'is idempotent' do + it "is idempotent" do stmt = Nodes::SelectStatement.new - stmt.orders << Nodes::SqlLiteral.new('foo') + stmt.orders << Nodes::SqlLiteral.new("foo") stmt.limit = Nodes::Limit.new(10) sql = compile stmt sql2 = compile stmt sql.must_equal sql2 end - it 'creates a subquery when there is order_by' do + it "creates a subquery when there is order_by" do stmt = Nodes::SelectStatement.new - stmt.orders << Nodes::SqlLiteral.new('foo') + stmt.orders << Nodes::SqlLiteral.new("foo") stmt.limit = Nodes::Limit.new(10) sql = compile stmt sql.must_be_like %{ @@ -89,9 +90,9 @@ module Arel } end - it 'creates a subquery when there is group by' do + it "creates a subquery when there is group by" do stmt = Nodes::SelectStatement.new - stmt.cores.first.groups << Nodes::SqlLiteral.new('foo') + stmt.cores.first.groups << Nodes::SqlLiteral.new("foo") stmt.limit = Nodes::Limit.new(10) sql = compile stmt sql.must_be_like %{ @@ -99,10 +100,10 @@ module Arel } end - it 'creates a subquery when there is DISTINCT' do + it "creates a subquery when there is DISTINCT" do stmt = Nodes::SelectStatement.new stmt.cores.first.set_quantifier = Arel::Nodes::Distinct.new - stmt.cores.first.projections << Nodes::SqlLiteral.new('id') + stmt.cores.first.projections << Nodes::SqlLiteral.new("id") stmt.limit = Arel::Nodes::Limit.new(10) sql = compile stmt sql.must_be_like %{ @@ -110,7 +111,7 @@ module Arel } end - it 'creates a different subquery when there is an offset' do + it "creates a different subquery when there is an offset" do stmt = Nodes::SelectStatement.new stmt.limit = Nodes::Limit.new(10) stmt.offset = Nodes::Offset.new(10) @@ -125,7 +126,7 @@ module Arel } end - it 'creates a subquery when there is limit and offset with BindParams' do + it "creates a subquery when there is limit and offset with BindParams" do stmt = Nodes::SelectStatement.new stmt.limit = Nodes::Limit.new(Nodes::BindParam.new(1)) stmt.offset = Nodes::Offset.new(Nodes::BindParam.new(1)) @@ -140,7 +141,7 @@ module Arel } end - it 'is idempotent with different subquery' do + it "is idempotent with different subquery" do stmt = Nodes::SelectStatement.new stmt.limit = Nodes::Limit.new(10) stmt.offset = Nodes::Offset.new(10) @@ -150,8 +151,8 @@ module Arel end end - describe 'only offset' do - it 'creates a select from subquery with rownum condition' do + describe "only offset" do + it "creates a select from subquery with rownum condition" do stmt = Nodes::SelectStatement.new stmt.offset = Nodes::Offset.new(10) sql = compile stmt @@ -166,7 +167,7 @@ module Arel end end - it 'modified except to be minus' do + it "modified except to be minus" do left = Nodes::SqlLiteral.new("SELECT * FROM users WHERE age > 10") right = Nodes::SqlLiteral.new("SELECT * FROM users WHERE age > 20") sql = compile Nodes::Except.new(left, right) @@ -175,9 +176,9 @@ module Arel } end - describe 'locking' do - it 'defaults to FOR UPDATE when locking' do - node = Nodes::Lock.new(Arel.sql('FOR UPDATE')) + describe "locking" do + it "defaults to FOR UPDATE when locking" do + node = Nodes::Lock.new(Arel.sql("FOR UPDATE")) compile(node).must_be_like "FOR UPDATE" end end diff --git a/activerecord/test/cases/arel/visitors/postgres_test.rb b/activerecord/test/cases/arel/visitors/postgres_test.rb index 6aa786b14f..ba37afecfb 100644 --- a/activerecord/test/cases/arel/visitors/postgres_test.rb +++ b/activerecord/test/cases/arel/visitors/postgres_test.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true -require_relative '../helper' + +require_relative "../helper" module Arel module Visitors @@ -10,19 +11,19 @@ module Arel @attr = @table[:id] end - def compile node + def compile(node) @visitor.accept(node, Collectors::SQLString.new).value end - describe 'locking' do - it 'defaults to FOR UPDATE' do - compile(Nodes::Lock.new(Arel.sql('FOR UPDATE'))).must_be_like %{ + describe "locking" do + it "defaults to FOR UPDATE" do + compile(Nodes::Lock.new(Arel.sql("FOR UPDATE"))).must_be_like %{ FOR UPDATE } end - it 'allows a custom string to be used as a lock' do - node = Nodes::Lock.new(Arel.sql('FOR SHARE')) + it "allows a custom string to be used as a lock" do + node = Nodes::Lock.new(Arel.sql("FOR SHARE")) compile(node).must_be_like %{ FOR SHARE } @@ -32,42 +33,42 @@ module Arel it "should escape LIMIT" do sc = Arel::Nodes::SelectStatement.new sc.limit = Nodes::Limit.new(Nodes.build_quoted("omg")) - sc.cores.first.projections << Arel.sql('DISTINCT ON') + sc.cores.first.projections << Arel.sql("DISTINCT ON") sc.orders << Arel.sql("xyz") - sql = compile(sc) + sql = compile(sc) assert_match(/LIMIT 'omg'/, sql) - assert_equal 1, sql.scan(/LIMIT/).length, 'should have one limit' + assert_equal 1, sql.scan(/LIMIT/).length, "should have one limit" end - it 'should support DISTINCT ON' do + it "should support DISTINCT ON" do core = Arel::Nodes::SelectCore.new - core.set_quantifier = Arel::Nodes::DistinctOn.new(Arel.sql('aaron')) - assert_match 'DISTINCT ON ( aaron )', compile(core) + core.set_quantifier = Arel::Nodes::DistinctOn.new(Arel.sql("aaron")) + assert_match "DISTINCT ON ( aaron )", compile(core) end - it 'should support DISTINCT' do + it "should support DISTINCT" do core = Arel::Nodes::SelectCore.new core.set_quantifier = Arel::Nodes::Distinct.new - assert_equal 'SELECT DISTINCT', compile(core) + assert_equal "SELECT DISTINCT", compile(core) end - it 'encloses LATERAL queries in parens' do - subquery = @table.project(:id).where(@table[:name].matches('foo%')) + it "encloses LATERAL queries in parens" do + subquery = @table.project(:id).where(@table[:name].matches("foo%")) compile(subquery.lateral).must_be_like %{ LATERAL (SELECT id FROM "users" WHERE "users"."name" ILIKE 'foo%') } end - it 'produces LATERAL queries with alias' do - subquery = @table.project(:id).where(@table[:name].matches('foo%')) - compile(subquery.lateral('bar')).must_be_like %{ + it "produces LATERAL queries with alias" do + subquery = @table.project(:id).where(@table[:name].matches("foo%")) + compile(subquery.lateral("bar")).must_be_like %{ LATERAL (SELECT id FROM "users" WHERE "users"."name" ILIKE 'foo%') bar } end describe "Nodes::Matches" do it "should know how to visit" do - node = @table[:name].matches('foo%') + node = @table[:name].matches("foo%") node.must_be_kind_of Nodes::Matches node.case_sensitive.must_equal(false) compile(node).must_be_like %{ @@ -76,7 +77,7 @@ module Arel end it "should know how to visit case sensitive" do - node = @table[:name].matches('foo%', nil, true) + node = @table[:name].matches("foo%", nil, true) node.case_sensitive.must_equal(true) compile(node).must_be_like %{ "users"."name" LIKE 'foo%' @@ -84,14 +85,14 @@ module Arel end it "can handle ESCAPE" do - node = @table[:name].matches('foo!%', '!') + node = @table[:name].matches("foo!%", "!") compile(node).must_be_like %{ "users"."name" ILIKE 'foo!%' ESCAPE '!' } end - it 'can handle subqueries' do - subquery = @table.project(:id).where(@table[:name].matches('foo%')) + it "can handle subqueries" do + subquery = @table.project(:id).where(@table[:name].matches("foo%")) node = @attr.in subquery compile(node).must_be_like %{ "users"."id" IN (SELECT id FROM "users" WHERE "users"."name" ILIKE 'foo%') @@ -101,7 +102,7 @@ module Arel describe "Nodes::DoesNotMatch" do it "should know how to visit" do - node = @table[:name].does_not_match('foo%') + node = @table[:name].does_not_match("foo%") node.must_be_kind_of Nodes::DoesNotMatch node.case_sensitive.must_equal(false) compile(node).must_be_like %{ @@ -110,7 +111,7 @@ module Arel end it "should know how to visit case sensitive" do - node = @table[:name].does_not_match('foo%', nil, true) + node = @table[:name].does_not_match("foo%", nil, true) node.case_sensitive.must_equal(true) compile(node).must_be_like %{ "users"."name" NOT LIKE 'foo%' @@ -118,14 +119,14 @@ module Arel end it "can handle ESCAPE" do - node = @table[:name].does_not_match('foo!%', '!') + node = @table[:name].does_not_match("foo!%", "!") compile(node).must_be_like %{ "users"."name" NOT ILIKE 'foo!%' ESCAPE '!' } end - it 'can handle subqueries' do - subquery = @table.project(:id).where(@table[:name].does_not_match('foo%')) + it "can handle subqueries" do + subquery = @table.project(:id).where(@table[:name].does_not_match("foo%")) node = @attr.in subquery compile(node).must_be_like %{ "users"."id" IN (SELECT id FROM "users" WHERE "users"."name" NOT ILIKE 'foo%') @@ -135,7 +136,7 @@ module Arel describe "Nodes::Regexp" do it "should know how to visit" do - node = @table[:name].matches_regexp('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 %{ @@ -144,7 +145,7 @@ module Arel end it "can handle case insensitive" do - node = @table[:name].matches_regexp('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 %{ @@ -152,8 +153,8 @@ module Arel } end - it 'can handle subqueries' do - subquery = @table.project(:id).where(@table[:name].matches_regexp('foo.*')) + 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" ~ 'foo.*') @@ -163,7 +164,7 @@ module Arel describe "Nodes::NotRegexp" do it "should know how to visit" do - node = @table[:name].does_not_match_regexp('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 %{ @@ -172,15 +173,15 @@ module Arel end it "can handle case insensitive" do - node = @table[:name].does_not_match_regexp('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(@table[:name].does_not_match_regexp('foo.*')) + 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" !~ 'foo.*') diff --git a/activerecord/test/cases/arel/visitors/sqlite_test.rb b/activerecord/test/cases/arel/visitors/sqlite_test.rb index 23f66ee096..6650b6ff3a 100644 --- a/activerecord/test/cases/arel/visitors/sqlite_test.rb +++ b/activerecord/test/cases/arel/visitors/sqlite_test.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true -require_relative '../helper' + +require_relative "../helper" module Arel module Visitors @@ -8,23 +9,23 @@ module Arel @visitor = SQLite.new Table.engine.connection_pool end - it 'defaults limit to -1' do + it "defaults limit to -1" do stmt = Nodes::SelectStatement.new stmt.offset = Nodes::Offset.new(1) sql = @visitor.accept(stmt, Collectors::SQLString.new).value sql.must_be_like "SELECT LIMIT -1 OFFSET 1" end - it 'does not support locking' do - node = Nodes::Lock.new(Arel.sql('FOR UPDATE')) - assert_equal '', @visitor.accept(node, Collectors::SQLString.new).value + it "does not support locking" do + node = Nodes::Lock.new(Arel.sql("FOR UPDATE")) + assert_equal "", @visitor.accept(node, Collectors::SQLString.new).value end - it 'does not support boolean' do + it "does not support boolean" do node = Nodes::True.new() - assert_equal '1', @visitor.accept(node, Collectors::SQLString.new).value + assert_equal "1", @visitor.accept(node, Collectors::SQLString.new).value node = Nodes::False.new() - assert_equal '0', @visitor.accept(node, Collectors::SQLString.new).value + assert_equal "0", @visitor.accept(node, Collectors::SQLString.new).value end end end diff --git a/activerecord/test/cases/arel/visitors/to_sql_test.rb b/activerecord/test/cases/arel/visitors/to_sql_test.rb index 1503bcd578..ce836eded7 100644 --- a/activerecord/test/cases/arel/visitors/to_sql_test.rb +++ b/activerecord/test/cases/arel/visitors/to_sql_test.rb @@ -1,10 +1,11 @@ # frozen_string_literal: true -require_relative '../helper' -require 'bigdecimal' + +require_relative "../helper" +require "bigdecimal" module Arel module Visitors - describe 'the to_sql visitor' do + describe "the to_sql visitor" do before do @conn = FakeRecord::Base.new @visitor = ToSql.new @conn.connection @@ -12,24 +13,24 @@ module Arel @attr = @table[:id] end - def compile node + def compile(node) @visitor.accept(node, Collectors::SQLString.new).value end - it 'works with BindParams' do + it "works with BindParams" do node = Nodes::BindParam.new(1) sql = compile node - sql.must_be_like '?' + sql.must_be_like "?" end - it 'does not quote BindParams used as part of a Values' do + it "does not quote BindParams used as part of a Values" do bp = Nodes::BindParam.new(1) values = Nodes::Values.new([bp]) sql = compile values - sql.must_be_like 'VALUES (?)' + sql.must_be_like "VALUES (?)" end - it 'can define a dispatch method' do + it "can define a dispatch method" do visited = false viz = Class.new(Arel::Visitors::Visitor) { define_method(:hello) do |node, c| @@ -37,117 +38,117 @@ module Arel end def dispatch - { Arel::Table => 'hello' } + { Arel::Table => "hello" } end }.new viz.accept(@table, Collectors::SQLString.new) - assert visited, 'hello method was called' + assert visited, "hello method was called" end - it 'should not quote sql literals' do + it "should not quote sql literals" do node = @table[Arel.star] sql = compile node sql.must_be_like '"users".*' end - it 'should visit named functions' do - function = Nodes::NamedFunction.new('omg', [Arel.star]) - assert_equal 'omg(*)', compile(function) + it "should visit named functions" do + function = Nodes::NamedFunction.new("omg", [Arel.star]) + assert_equal "omg(*)", compile(function) end - it 'should chain predications on named functions' do - function = Nodes::NamedFunction.new('omg', [Arel.star]) + it "should chain predications on named functions" do + function = Nodes::NamedFunction.new("omg", [Arel.star]) sql = compile(function.eq(2)) sql.must_be_like %{ omg(*) = 2 } end - it 'should handle nil with named functions' do - function = Nodes::NamedFunction.new('omg', [Arel.star]) + it "should handle nil with named functions" do + function = Nodes::NamedFunction.new("omg", [Arel.star]) sql = compile(function.eq(nil)) sql.must_be_like %{ omg(*) IS NULL } end - it 'should visit built-in functions' do + it "should visit built-in functions" do function = Nodes::Count.new([Arel.star]) - assert_equal 'COUNT(*)', compile(function) + assert_equal "COUNT(*)", compile(function) function = Nodes::Sum.new([Arel.star]) - assert_equal 'SUM(*)', compile(function) + assert_equal "SUM(*)", compile(function) function = Nodes::Max.new([Arel.star]) - assert_equal 'MAX(*)', compile(function) + assert_equal "MAX(*)", compile(function) function = Nodes::Min.new([Arel.star]) - assert_equal 'MIN(*)', compile(function) + assert_equal "MIN(*)", compile(function) function = Nodes::Avg.new([Arel.star]) - assert_equal 'AVG(*)', compile(function) + assert_equal "AVG(*)", compile(function) end - it 'should visit built-in functions operating on distinct values' do + it "should visit built-in functions operating on distinct values" do function = Nodes::Count.new([Arel.star]) function.distinct = true - assert_equal 'COUNT(DISTINCT *)', compile(function) + assert_equal "COUNT(DISTINCT *)", compile(function) function = Nodes::Sum.new([Arel.star]) function.distinct = true - assert_equal 'SUM(DISTINCT *)', compile(function) + assert_equal "SUM(DISTINCT *)", compile(function) function = Nodes::Max.new([Arel.star]) function.distinct = true - assert_equal 'MAX(DISTINCT *)', compile(function) + assert_equal "MAX(DISTINCT *)", compile(function) function = Nodes::Min.new([Arel.star]) function.distinct = true - assert_equal 'MIN(DISTINCT *)', compile(function) + assert_equal "MIN(DISTINCT *)", compile(function) function = Nodes::Avg.new([Arel.star]) function.distinct = true - assert_equal 'AVG(DISTINCT *)', compile(function) + assert_equal "AVG(DISTINCT *)", compile(function) end - it 'works with lists' do - function = Nodes::NamedFunction.new('omg', [Arel.star, Arel.star]) - assert_equal 'omg(*, *)', compile(function) + it "works with lists" do + function = Nodes::NamedFunction.new("omg", [Arel.star, Arel.star]) + assert_equal "omg(*, *)", compile(function) end - describe 'Nodes::Equality' do + describe "Nodes::Equality" do it "should escape strings" do - test = Table.new(:users)[:name].eq 'Aaron Patterson' + test = Table.new(:users)[:name].eq "Aaron Patterson" compile(test).must_be_like %{ "users"."name" = 'Aaron Patterson' } end - it 'should handle false' do + it "should handle false" do table = Table.new(:users) val = Nodes.build_quoted(false, table[:active]) sql = compile Nodes::Equality.new(val, val) sql.must_be_like %{ 'f' = 'f' } end - it 'should handle nil' do + it "should handle nil" do sql = compile Nodes::Equality.new(@table[:name], nil) sql.must_be_like %{ "users"."name" IS NULL } end end - describe 'Nodes::Grouping' do - it 'wraps nested groupings in brackets only once' do - sql = compile Nodes::Grouping.new(Nodes::Grouping.new(Nodes.build_quoted('foo'))) + describe "Nodes::Grouping" do + it "wraps nested groupings in brackets only once" do + sql = compile Nodes::Grouping.new(Nodes::Grouping.new(Nodes.build_quoted("foo"))) sql.must_equal "('foo')" end end - describe 'Nodes::NotEqual' do - it 'should handle false' do + describe "Nodes::NotEqual" do + it "should handle false" do val = Nodes.build_quoted(false, @table[:active]) sql = compile Nodes::NotEqual.new(@table[:active], val) sql.must_be_like %{ "users"."active" != 'f' } end - it 'should handle nil' do + it "should handle nil" do val = Nodes.build_quoted(nil, @table[:active]) sql = compile Nodes::NotEqual.new(@table[:name], val) sql.must_be_like %{ "users"."name" IS NOT NULL } @@ -225,7 +226,7 @@ module Arel end it "should visit_Hash" do - compile(Nodes.build_quoted({:a => 1})) + compile(Nodes.build_quoted(a: 1)) end it "should visit_Set" do @@ -233,7 +234,7 @@ module Arel end it "should visit_BigDecimal" do - compile Nodes.build_quoted(BigDecimal('2.14')) + compile Nodes.build_quoted(BigDecimal("2.14")) end it "should visit_Date" do @@ -296,21 +297,21 @@ module Arel describe "Nodes::Matches" do it "should know how to visit" do - node = @table[:name].matches('foo%') + node = @table[:name].matches("foo%") compile(node).must_be_like %{ "users"."name" LIKE 'foo%' } end it "can handle ESCAPE" do - node = @table[:name].matches('foo!%', '!') + node = @table[:name].matches("foo!%", "!") compile(node).must_be_like %{ "users"."name" LIKE 'foo!%' ESCAPE '!' } end - it 'can handle subqueries' do - subquery = @table.project(:id).where(@table[:name].matches('foo%')) + it "can handle subqueries" do + subquery = @table.project(:id).where(@table[:name].matches("foo%")) node = @attr.in subquery compile(node).must_be_like %{ "users"."id" IN (SELECT id FROM "users" WHERE "users"."name" LIKE 'foo%') @@ -320,21 +321,21 @@ module Arel describe "Nodes::DoesNotMatch" do it "should know how to visit" do - node = @table[:name].does_not_match('foo%') + node = @table[:name].does_not_match("foo%") compile(node).must_be_like %{ "users"."name" NOT LIKE 'foo%' } end it "can handle ESCAPE" do - node = @table[:name].does_not_match('foo!%', '!') + node = @table[:name].does_not_match("foo!%", "!") compile(node).must_be_like %{ "users"."name" NOT LIKE 'foo!%' ESCAPE '!' } end - it 'can handle subqueries' do - subquery = @table.project(:id).where(@table[:name].does_not_match('foo%')) + it "can handle subqueries" do + subquery = @table.project(:id).where(@table[:name].does_not_match("foo%")) node = @attr.in subquery compile(node).must_be_like %{ "users"."id" IN (SELECT id FROM "users" WHERE "users"."name" NOT LIKE 'foo%') @@ -361,24 +362,24 @@ module Arel it "should return 1=0 when empty right which is always false" do node = @attr.in [] - compile(node).must_equal '1=0' + compile(node).must_equal "1=0" end - it 'can handle two dot ranges' do + it "can handle two dot ranges" do node = @attr.between 1..3 compile(node).must_be_like %{ "users"."id" BETWEEN 1 AND 3 } end - it 'can handle three dot ranges' do + it "can handle three dot ranges" do node = @attr.between 1...3 compile(node).must_be_like %{ "users"."id" >= 1 AND "users"."id" < 3 } end - it 'can handle ranges bounded by infinity' do + it "can handle ranges bounded by infinity" do node = @attr.between 1..Float::INFINITY compile(node).must_be_like %{ "users"."id" >= 1 @@ -395,9 +396,9 @@ module Arel compile(node).must_be_like %{1=1} end - it 'can handle subqueries' do + it "can handle subqueries" do table = Table.new(:users) - subquery = table.project(:id).where(table[:name].eq('Aaron')) + subquery = table.project(:id).where(table[:name].eq("Aaron")) node = @attr.in subquery compile(node).must_be_like %{ "users"."id" IN (SELECT id FROM "users" WHERE "users"."name" = 'Aaron') @@ -459,7 +460,7 @@ module Arel it "should handle arbitrary operators" do node = Arel::Nodes::InfixOperation.new( - '&&', + "&&", Arel::Attributes::String.new(Table.new(:products), :name), Arel::Attributes::String.new(Table.new(:products), :name) ) @@ -474,7 +475,7 @@ module Arel end it "should handle arbitrary operators" do - node = Arel::Nodes::UnaryOperation.new('!', Arel::Attributes::String.new(Table.new(:products), :active)) + node = Arel::Nodes::UnaryOperation.new("!", Arel::Attributes::String.new(Table.new(:products), :active)) compile(node).must_equal %( ! "products"."active") end end @@ -489,24 +490,24 @@ module Arel it "should return 1=1 when empty right which is always true" do node = @attr.not_in [] - compile(node).must_equal '1=1' + compile(node).must_equal "1=1" end - it 'can handle two dot ranges' do + it "can handle two dot ranges" do node = @attr.not_between 1..3 compile(node).must_equal( %{("users"."id" < 1 OR "users"."id" > 3)} ) end - it 'can handle three dot ranges' do + it "can handle three dot ranges" do node = @attr.not_between 1...3 compile(node).must_equal( %{("users"."id" < 1 OR "users"."id" >= 3)} ) end - it 'can handle ranges bounded by infinity' do + it "can handle ranges bounded by infinity" do node = @attr.not_between 1..Float::INFINITY compile(node).must_be_like %{ "users"."id" < 1 @@ -523,9 +524,9 @@ module Arel compile(node).must_be_like %{1=0} end - it 'can handle subqueries' do + it "can handle subqueries" do table = Table.new(:users) - subquery = table.project(:id).where(table[:name].eq('Aaron')) + subquery = table.project(:id).where(table[:name].eq("Aaron")) node = @attr.not_in subquery compile(node).must_be_like %{ "users"."id" NOT IN (SELECT id FROM "users" WHERE "users"."name" = 'Aaron') @@ -533,7 +534,7 @@ module Arel end end - describe 'Constants' do + describe "Constants" do it "should handle true" do test = Table.new(:users).create_true compile(test).must_be_like %{ @@ -549,19 +550,19 @@ module Arel end end - describe 'TableAlias' do + describe "TableAlias" do it "should use the underlying table for checking columns" do - test = Table.new(:users).alias('zomgusers')[:id].eq '3' + test = Table.new(:users).alias("zomgusers")[:id].eq "3" compile(test).must_be_like %{ "zomgusers"."id" = '3' } end end - describe 'distinct on' do - it 'raises not implemented error' do + describe "distinct on" do + it "raises not implemented error" do core = Arel::Nodes::SelectCore.new - core.set_quantifier = Arel::Nodes::DistinctOn.new(Arel.sql('aaron')) + core.set_quantifier = Arel::Nodes::DistinctOn.new(Arel.sql("aaron")) assert_raises(NotImplementedError) do compile(core) @@ -569,9 +570,9 @@ module Arel end end - describe 'Nodes::Regexp' do - it 'raises not implemented error' do - node = Arel::Nodes::Regexp.new(@table[:name], Nodes.build_quoted('foo%')) + describe "Nodes::Regexp" do + it "raises not implemented error" do + node = Arel::Nodes::Regexp.new(@table[:name], Nodes.build_quoted("foo%")) assert_raises(NotImplementedError) do compile(node) @@ -579,9 +580,9 @@ module Arel end end - describe 'Nodes::NotRegexp' do - it 'raises not implemented error' do - node = Arel::Nodes::NotRegexp.new(@table[:name], Nodes.build_quoted('foo%')) + describe "Nodes::NotRegexp" do + it "raises not implemented error" do + node = Arel::Nodes::NotRegexp.new(@table[:name], Nodes.build_quoted("foo%")) assert_raises(NotImplementedError) do compile(node) @@ -589,10 +590,10 @@ module Arel end end - describe 'Nodes::Case' do - it 'supports simple case expressions' do + describe "Nodes::Case" do + it "supports simple case expressions" do node = Arel::Nodes::Case.new(@table[:name]) - .when('foo').then(1) + .when("foo").then(1) .else(0) compile(node).must_be_like %{ @@ -600,7 +601,7 @@ module Arel } end - it 'supports extended case expressions' do + it "supports extended case expressions" do node = Arel::Nodes::Case.new .when(@table[:name].in(%w(foo bar))).then(1) .else(0) @@ -610,19 +611,19 @@ module Arel } end - it 'works without default branch' do + it "works without default branch" do node = Arel::Nodes::Case.new(@table[:name]) - .when('foo').then(1) + .when("foo").then(1) compile(node).must_be_like %{ CASE "users"."name" WHEN 'foo' THEN 1 END } end - it 'allows chaining multiple conditions' do + it "allows chaining multiple conditions" do node = Arel::Nodes::Case.new(@table[:name]) - .when('foo').then(1) - .when('bar').then(2) + .when("foo").then(1) + .when("bar").then(2) .else(0) compile(node).must_be_like %{ @@ -630,7 +631,7 @@ module Arel } end - it 'supports #when with two arguments and no #then' do + it "supports #when with two arguments and no #then" do node = Arel::Nodes::Case.new @table[:name] { foo: 1, bar: 0 }.reduce(node) { |_node, pair| _node.when(*pair) } @@ -640,8 +641,8 @@ module Arel } end - it 'can be chained as a predicate' do - node = @table[:name].when('foo').then('bar').else('baz') + it "can be chained as a predicate" do + node = @table[:name].when("foo").then("bar").else("baz") compile(node).must_be_like %{ CASE "users"."name" WHEN 'foo' THEN 'bar' ELSE 'baz' END |