From b522778a61670825948e2fbd4a3353583c1c7223 Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Mon, 18 May 2009 19:59:47 -0300 Subject: Require active_support/core_ext since ActiveRecord don't require it any more --- lib/arel.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/arel.rb b/lib/arel.rb index 00bfa1e292..0240e23959 100644 --- a/lib/arel.rb +++ b/lib/arel.rb @@ -1,7 +1,8 @@ $LOAD_PATH.unshift(File.dirname(__FILE__)) require 'rubygems' -require 'activesupport' +require 'active_support' +require 'active_support/core_ext' require 'activerecord' require 'active_record/connection_adapters/abstract/quoting' -- cgit v1.2.3 From 4b8526dddd6a906a1879ec786401070b3545d7f4 Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Mon, 18 May 2009 20:00:38 -0300 Subject: Don't quote columns when they are not an attribute --- lib/arel/relations/writes/update.rb | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/arel/relations/writes/update.rb b/lib/arel/relations/writes/update.rb index 2e90de3a52..52ca6ecf05 100644 --- a/lib/arel/relations/writes/update.rb +++ b/lib/arel/relations/writes/update.rb @@ -10,9 +10,7 @@ module Arel def to_sql(formatter = nil) [ "UPDATE #{table_sql} SET", - assignments.collect do |attribute, value| - "#{engine.quote_column_name(attribute.name)} = #{attribute.format(value)}" - end.join(",\n"), + map_assignments, ("WHERE #{wheres.map(&:to_sql).join('\n\tAND ')}" unless wheres.blank? ), ("LIMIT #{taken}" unless taken.blank? ) ].join("\n") @@ -21,5 +19,12 @@ module Arel def call(connection = engine) connection.update(to_sql) end + + def map_assignments + assignments.collect do |attribute, value| + attribute.respond_to?(:name) ? + "#{engine.quote_column_name(attribute.name)} = #{attribute.format(value)}" : attribute + end.join(",\n") + end end end -- cgit v1.2.3 From ae1e0ac5e98a7e5a2894d0a431f8c34af6575cae Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Tue, 26 May 2009 12:12:19 -0300 Subject: Removed lib to avoid any conflict in merge --- lib/arel.rb | 16 --- lib/arel/.DS_Store | Bin 6148 -> 0 bytes lib/arel/arel.rb | 3 - lib/arel/engine.rb | 18 --- lib/arel/extensions.rb | 6 - lib/arel/extensions/array.rb | 13 -- lib/arel/extensions/class.rb | 37 ------ lib/arel/extensions/hash.rb | 7 - lib/arel/extensions/nil_class.rb | 5 - lib/arel/extensions/object.rb | 23 ---- lib/arel/extensions/range.rb | 9 -- lib/arel/predicates.rb | 81 ------------ lib/arel/primitives.rb | 4 - lib/arel/primitives/attribute.rb | 145 -------------------- lib/arel/primitives/expression.rb | 35 ----- lib/arel/primitives/value.rb | 32 ----- lib/arel/relations.rb | 8 -- lib/arel/relations/operations.rb | 8 -- lib/arel/relations/operations/alias.rb | 8 -- lib/arel/relations/operations/group.rb | 15 --- lib/arel/relations/operations/join.rb | 57 -------- lib/arel/relations/operations/order.rb | 16 --- lib/arel/relations/operations/project.rb | 19 --- lib/arel/relations/operations/skip.rb | 10 -- lib/arel/relations/operations/take.rb | 10 -- lib/arel/relations/operations/where.rb | 16 --- lib/arel/relations/relation.rb | 169 ------------------------ lib/arel/relations/table.rb | 36 ----- lib/arel/relations/utilities.rb | 5 - lib/arel/relations/utilities/compound.rb | 18 --- lib/arel/relations/utilities/externalization.rb | 34 ----- lib/arel/relations/utilities/nil.rb | 10 -- lib/arel/relations/utilities/recursion.rb | 13 -- lib/arel/relations/writes.rb | 3 - lib/arel/relations/writes/delete.rb | 19 --- lib/arel/relations/writes/insert.rb | 23 ---- lib/arel/relations/writes/update.rb | 30 ----- lib/arel/session.rb | 47 ------- lib/arel/sql.rb | 2 - lib/arel/sql/christener.rb | 13 -- lib/arel/sql/formatters.rb | 121 ----------------- 41 files changed, 1144 deletions(-) delete mode 100644 lib/arel.rb delete mode 100644 lib/arel/.DS_Store delete mode 100644 lib/arel/arel.rb delete mode 100644 lib/arel/engine.rb delete mode 100644 lib/arel/extensions.rb delete mode 100644 lib/arel/extensions/array.rb delete mode 100644 lib/arel/extensions/class.rb delete mode 100644 lib/arel/extensions/hash.rb delete mode 100644 lib/arel/extensions/nil_class.rb delete mode 100644 lib/arel/extensions/object.rb delete mode 100644 lib/arel/extensions/range.rb delete mode 100644 lib/arel/predicates.rb delete mode 100644 lib/arel/primitives.rb delete mode 100644 lib/arel/primitives/attribute.rb delete mode 100644 lib/arel/primitives/expression.rb delete mode 100644 lib/arel/primitives/value.rb delete mode 100644 lib/arel/relations.rb delete mode 100644 lib/arel/relations/operations.rb delete mode 100644 lib/arel/relations/operations/alias.rb delete mode 100644 lib/arel/relations/operations/group.rb delete mode 100644 lib/arel/relations/operations/join.rb delete mode 100644 lib/arel/relations/operations/order.rb delete mode 100644 lib/arel/relations/operations/project.rb delete mode 100644 lib/arel/relations/operations/skip.rb delete mode 100644 lib/arel/relations/operations/take.rb delete mode 100644 lib/arel/relations/operations/where.rb delete mode 100644 lib/arel/relations/relation.rb delete mode 100644 lib/arel/relations/table.rb delete mode 100644 lib/arel/relations/utilities.rb delete mode 100644 lib/arel/relations/utilities/compound.rb delete mode 100644 lib/arel/relations/utilities/externalization.rb delete mode 100644 lib/arel/relations/utilities/nil.rb delete mode 100644 lib/arel/relations/utilities/recursion.rb delete mode 100644 lib/arel/relations/writes.rb delete mode 100644 lib/arel/relations/writes/delete.rb delete mode 100644 lib/arel/relations/writes/insert.rb delete mode 100644 lib/arel/relations/writes/update.rb delete mode 100644 lib/arel/session.rb delete mode 100644 lib/arel/sql.rb delete mode 100644 lib/arel/sql/christener.rb delete mode 100644 lib/arel/sql/formatters.rb diff --git a/lib/arel.rb b/lib/arel.rb deleted file mode 100644 index 0240e23959..0000000000 --- a/lib/arel.rb +++ /dev/null @@ -1,16 +0,0 @@ -$LOAD_PATH.unshift(File.dirname(__FILE__)) - -require 'rubygems' -require 'active_support' -require 'active_support/core_ext' -require 'activerecord' -require 'active_record/connection_adapters/abstract/quoting' - -require 'arel/arel' -require 'arel/extensions' -require 'arel/sql' -require 'arel/predicates' -require 'arel/relations' -require 'arel/engine' -require 'arel/session' -require 'arel/primitives' diff --git a/lib/arel/.DS_Store b/lib/arel/.DS_Store deleted file mode 100644 index 9918127870..0000000000 Binary files a/lib/arel/.DS_Store and /dev/null differ diff --git a/lib/arel/arel.rb b/lib/arel/arel.rb deleted file mode 100644 index 7780d45e25..0000000000 --- a/lib/arel/arel.rb +++ /dev/null @@ -1,3 +0,0 @@ -def Arel(name, engine = (Arel::Table.engine || ActiveRecord::Base.connection)) - Arel::Table.new(name, engine) -end diff --git a/lib/arel/engine.rb b/lib/arel/engine.rb deleted file mode 100644 index 5a5ef06878..0000000000 --- a/lib/arel/engine.rb +++ /dev/null @@ -1,18 +0,0 @@ -module Arel - # this file is currently just a hack to adapt between activerecord::base which holds the connection specification - # and active relation. ultimately, this file should be in effect what the connection specification is in active record; - # that is: a spec of the database (url, password, etc.), a quoting adapter layer, and a connection pool. - class Engine - def initialize(ar = nil) - @ar = ar - end - - def connection - @ar.connection - end - - def method_missing(method, *args, &block) - @ar.connection.send(method, *args, &block) - end - end -end diff --git a/lib/arel/extensions.rb b/lib/arel/extensions.rb deleted file mode 100644 index 160cf36e5b..0000000000 --- a/lib/arel/extensions.rb +++ /dev/null @@ -1,6 +0,0 @@ -require 'arel/extensions/object' -require 'arel/extensions/class' -require 'arel/extensions/array' -require 'arel/extensions/hash' -require 'arel/extensions/range' -require 'arel/extensions/nil_class' \ No newline at end of file diff --git a/lib/arel/extensions/array.rb b/lib/arel/extensions/array.rb deleted file mode 100644 index 793c06aad8..0000000000 --- a/lib/arel/extensions/array.rb +++ /dev/null @@ -1,13 +0,0 @@ -class Array - def to_hash - Hash[*flatten] - end - - def to_sql(formatter = nil) - "(" + collect { |e| e.to_sql(formatter) }.join(', ') + ")" - end - - def inclusion_predicate_sql - "IN" - end -end \ No newline at end of file diff --git a/lib/arel/extensions/class.rb b/lib/arel/extensions/class.rb deleted file mode 100644 index f37898e7d7..0000000000 --- a/lib/arel/extensions/class.rb +++ /dev/null @@ -1,37 +0,0 @@ -class Class - def attributes(*attrs) - @attributes = attrs - attr_reader *attrs - end - - def deriving(*methods) - methods.each { |m| derive m } - end - - def derive(method_name) - methods = { - :initialize => " - def #{method_name}(#{@attributes.join(',')}) - #{@attributes.collect { |a| "@#{a} = #{a}" }.join("\n")} - end - ", - :== => " - def ==(other) - #{name} === other && - #{@attributes.collect { |a| "@#{a} == other.#{a}" }.join(" &&\n")} - end - " - } - class_eval methods[method_name], __FILE__, __LINE__ - end - - def hash_on(delegatee) - define_method :eql? do |other| - self == other - end - - define_method :hash do - @hash ||= delegatee.hash - end - end -end \ No newline at end of file diff --git a/lib/arel/extensions/hash.rb b/lib/arel/extensions/hash.rb deleted file mode 100644 index 7472b5aa73..0000000000 --- a/lib/arel/extensions/hash.rb +++ /dev/null @@ -1,7 +0,0 @@ -class Hash - def bind(relation) - inject({}) do |bound, (key, value)| - bound.merge(key.bind(relation) => value.bind(relation)) - end - end -end \ No newline at end of file diff --git a/lib/arel/extensions/nil_class.rb b/lib/arel/extensions/nil_class.rb deleted file mode 100644 index 729c4cada7..0000000000 --- a/lib/arel/extensions/nil_class.rb +++ /dev/null @@ -1,5 +0,0 @@ -class NilClass - def equality_predicate_sql - 'IS' - end -end \ No newline at end of file diff --git a/lib/arel/extensions/object.rb b/lib/arel/extensions/object.rb deleted file mode 100644 index 14e2f82ce5..0000000000 --- a/lib/arel/extensions/object.rb +++ /dev/null @@ -1,23 +0,0 @@ -class Object - def bind(relation) - Arel::Value.new(self, relation) - end - - def find_correlate_in(relation) - bind(relation) - end - - def to_sql(formatter) - formatter.scalar self - end - - def equality_predicate_sql - '=' - end - - def metaclass - class << self - self - end - end -end diff --git a/lib/arel/extensions/range.rb b/lib/arel/extensions/range.rb deleted file mode 100644 index d7329efe34..0000000000 --- a/lib/arel/extensions/range.rb +++ /dev/null @@ -1,9 +0,0 @@ -class Range - def to_sql(formatter = nil) - formatter.range self.begin, self.end - end - - def inclusion_predicate_sql - "BETWEEN" - end -end \ No newline at end of file diff --git a/lib/arel/predicates.rb b/lib/arel/predicates.rb deleted file mode 100644 index b639022b4e..0000000000 --- a/lib/arel/predicates.rb +++ /dev/null @@ -1,81 +0,0 @@ -module Arel - class Predicate - def or(other_predicate) - Or.new(self, other_predicate) - end - - def and(other_predicate) - And.new(self, other_predicate) - end - end - - class Binary < Predicate - attributes :operand1, :operand2 - deriving :initialize - - def ==(other) - self.class === other and - @operand1 == other.operand1 and - @operand2 == other.operand2 - end - - def bind(relation) - self.class.new(operand1.find_correlate_in(relation), operand2.find_correlate_in(relation)) - end - - def to_sql(formatter = nil) - "#{operand1.to_sql} #{predicate_sql} #{operand1.format(operand2)}" - end - alias_method :to_s, :to_sql - end - - class CompoundPredicate < Binary - def to_sql(formatter = nil) - "(#{operand1.to_sql(formatter)} #{predicate_sql} #{operand2.to_sql(formatter)})" - end - end - - class Or < CompoundPredicate - def predicate_sql; "OR" end - end - - class And < CompoundPredicate - def predicate_sql; "AND" end - end - - class Equality < Binary - def ==(other) - Equality === other and - ((operand1 == other.operand1 and operand2 == other.operand2) or - (operand1 == other.operand2 and operand2 == other.operand1)) - end - - def predicate_sql - operand2.equality_predicate_sql - end - end - - class GreaterThanOrEqualTo < Binary - def predicate_sql; '>=' end - end - - class GreaterThan < Binary - def predicate_sql; '>' end - end - - class LessThanOrEqualTo < Binary - def predicate_sql; '<=' end - end - - class LessThan < Binary - def predicate_sql; '<' end - end - - class Match < Binary - def predicate_sql; 'LIKE' end - end - - class In < Binary - def predicate_sql; operand2.inclusion_predicate_sql end - end -end diff --git a/lib/arel/primitives.rb b/lib/arel/primitives.rb deleted file mode 100644 index d84713d3d5..0000000000 --- a/lib/arel/primitives.rb +++ /dev/null @@ -1,4 +0,0 @@ -require 'arel/primitives/attribute' -require 'arel/primitives/value' -require 'arel/primitives/expression' - diff --git a/lib/arel/primitives/attribute.rb b/lib/arel/primitives/attribute.rb deleted file mode 100644 index 6cb558d8ce..0000000000 --- a/lib/arel/primitives/attribute.rb +++ /dev/null @@ -1,145 +0,0 @@ -require 'set' - -module Arel - class Attribute - attributes :relation, :name, :alias, :ancestor - deriving :== - delegate :engine, :christener, :to => :relation - - def initialize(relation, name, options = {}) - @relation, @name, @alias, @ancestor = relation, name, options[:alias], options[:ancestor] - end - - def named?(hypothetical_name) - (@alias || name).to_s == hypothetical_name.to_s - end - - def aggregation? - false - end - - def column - original_relation.column_for(self) - end - - def format(object) - object.to_sql(Sql::Attribute.new(self)) - end - - def to_sql(formatter = Sql::WhereCondition.new(relation)) - formatter.attribute self - end - - module Transformations - def self.included(klass) - klass.send :alias_method, :eql?, :== - end - - def hash - @hash ||= history.size + name.hash + relation.hash - end - - def as(aliaz = nil) - Attribute.new(relation, name, :alias => aliaz, :ancestor => self) - end - - def bind(new_relation) - relation == new_relation ? self : Attribute.new(new_relation, name, :alias => @alias, :ancestor => self) - end - - def to_attribute - self - end - end - include Transformations - - module Congruence - def history - @history ||= [self] + (ancestor ? ancestor.history : []) - end - - def join? - relation.join? - end - - def root - history.last - end - - def original_relation - @original_relation ||= original_attribute.relation - end - - def original_attribute - @original_attribute ||= history.detect { |a| !a.join? } - end - - def find_correlate_in(relation) - relation[self] || self - end - - def descends_from?(other) - history.include?(other) - end - - def /(other) - other ? (history & other.history).size : 0 - end - end - include Congruence - - module Predications - def eq(other) - Equality.new(self, other) - end - - def lt(other) - LessThan.new(self, other) - end - - def lteq(other) - LessThanOrEqualTo.new(self, other) - end - - def gt(other) - GreaterThan.new(self, other) - end - - def gteq(other) - GreaterThanOrEqualTo.new(self, other) - end - - def matches(regexp) - Match.new(self, regexp) - end - - def in(array) - In.new(self, array) - end - end - include Predications - - module Expressions - def count(distinct = false) - distinct ? Expression.new(self, "DISTINCT").count : Expression.new(self, "COUNT") - end - - def sum - Expression.new(self, "SUM") - end - - def maximum - Expression.new(self, "MAX") - end - - def minimum - Expression.new(self, "MIN") - end - - def average - Expression.new(self, "AVG") - end - end - include Expressions - end -end diff --git a/lib/arel/primitives/expression.rb b/lib/arel/primitives/expression.rb deleted file mode 100644 index 836f014745..0000000000 --- a/lib/arel/primitives/expression.rb +++ /dev/null @@ -1,35 +0,0 @@ -module Arel - class Expression < Attribute - attributes :attribute, :function_sql, :alias, :ancestor - deriving :== - delegate :relation, :to => :attribute - alias_method :name, :alias - - def initialize(attribute, function_sql, aliaz = nil, ancestor = nil) - @attribute, @function_sql, @alias, @ancestor = attribute, function_sql, aliaz, ancestor - end - - def to_sql(formatter = Sql::SelectClause.new(relation)) - formatter.expression self - end - - def aggregation? - true - end - - module Transformations - def as(aliaz) - Expression.new(attribute, function_sql, aliaz, self) - end - - def bind(new_relation) - new_relation == relation ? self : Expression.new(attribute.bind(new_relation), function_sql, @alias, self) - end - - def to_attribute - Attribute.new(relation, @alias, :ancestor => self) - end - end - include Transformations - end -end diff --git a/lib/arel/primitives/value.rb b/lib/arel/primitives/value.rb deleted file mode 100644 index 9c6e518a95..0000000000 --- a/lib/arel/primitives/value.rb +++ /dev/null @@ -1,32 +0,0 @@ -module Arel - class Value - attributes :value, :relation - deriving :initialize, :== - delegate :inclusion_predicate_sql, :equality_predicate_sql, :to => :value - - - def to_sql(formatter = Sql::WhereCondition.new(relation)) - if value =~ /^\(.*\)$/ - value - else - formatter.value value - end - end - - def format(object) - object.to_sql(Sql::Value.new(relation)) - end - - def bind(relation) - Value.new(value, relation) - end - - def aggregation? - false - end - - def to_attribute - value - end - end -end diff --git a/lib/arel/relations.rb b/lib/arel/relations.rb deleted file mode 100644 index 3394fac7cb..0000000000 --- a/lib/arel/relations.rb +++ /dev/null @@ -1,8 +0,0 @@ -require 'arel/relations/relation' - -require 'arel/relations/utilities' - -require 'arel/relations/table' - -require 'arel/relations/writes' -require 'arel/relations/operations' \ No newline at end of file diff --git a/lib/arel/relations/operations.rb b/lib/arel/relations/operations.rb deleted file mode 100644 index c598c7fcc9..0000000000 --- a/lib/arel/relations/operations.rb +++ /dev/null @@ -1,8 +0,0 @@ -require 'arel/relations/operations/alias' -require 'arel/relations/operations/group' -require 'arel/relations/operations/join' -require 'arel/relations/operations/order' -require 'arel/relations/operations/project' -require 'arel/relations/operations/where' -require 'arel/relations/operations/skip' -require 'arel/relations/operations/take' \ No newline at end of file diff --git a/lib/arel/relations/operations/alias.rb b/lib/arel/relations/operations/alias.rb deleted file mode 100644 index 8ed33fc597..0000000000 --- a/lib/arel/relations/operations/alias.rb +++ /dev/null @@ -1,8 +0,0 @@ -module Arel - class Alias < Compound - include Recursion::BaseCase - attributes :relation - deriving :initialize - alias_method :==, :equal? - end -end \ No newline at end of file diff --git a/lib/arel/relations/operations/group.rb b/lib/arel/relations/operations/group.rb deleted file mode 100644 index 04fd9fea62..0000000000 --- a/lib/arel/relations/operations/group.rb +++ /dev/null @@ -1,15 +0,0 @@ -module Arel - class Group < Compound - attributes :relation, :groupings - deriving :== - - def initialize(relation, *groupings, &block) - @relation = relation - @groupings = (groupings + (block_given?? [yield(relatoin)] : [])).collect { |g| g.bind(relation) } - end - - def externalizable? - true - end - end -end \ No newline at end of file diff --git a/lib/arel/relations/operations/join.rb b/lib/arel/relations/operations/join.rb deleted file mode 100644 index 8fe89358d8..0000000000 --- a/lib/arel/relations/operations/join.rb +++ /dev/null @@ -1,57 +0,0 @@ -module Arel - class Join < Relation - attributes :join_sql, :relation1, :relation2, :predicates - deriving :== - delegate :engine, :name, :to => :relation1 - hash_on :relation1 - - def initialize(join_sql, relation1, relation2 = Nil.instance, *predicates) - @join_sql, @relation1, @relation2, @predicates = join_sql, relation1, relation2, predicates - end - - def table_sql(formatter = Sql::TableReference.new(self)) - relation1.externalize.table_sql(formatter) - end - - def joins(environment, formatter = Sql::TableReference.new(environment)) - @joins ||= begin - this_join = [ - join_sql, - relation2.externalize.table_sql(formatter), - ("ON" unless predicates.blank?), - (ons + relation2.externalize.wheres).collect { |p| p.bind(environment).to_sql(Sql::WhereClause.new(environment)) }.join(' AND ') - ].compact.join(" ") - [relation1.joins(environment), this_join, relation2.joins(environment)].compact.join(" ") - end - end - - def attributes - @attributes ||= (relation1.externalize.attributes + - relation2.externalize.attributes).collect { |a| a.bind(self) } - end - - def wheres - # TESTME bind to self? - relation1.externalize.wheres - end - - def ons - @ons ||= @predicates.collect { |p| p.bind(self) } - end - - # TESTME - def externalizable? - relation1.externalizable? or relation2.externalizable? - end - - def join? - true - end - end - - class Relation - def join? - false - end - end -end diff --git a/lib/arel/relations/operations/order.rb b/lib/arel/relations/operations/order.rb deleted file mode 100644 index 05af3fde4d..0000000000 --- a/lib/arel/relations/operations/order.rb +++ /dev/null @@ -1,16 +0,0 @@ -module Arel - class Order < Compound - attributes :relation, :orderings - deriving :== - - def initialize(relation, *orderings, &block) - @relation = relation - @orderings = (orderings + (block_given?? [yield(relation)] : [])).collect { |o| o.bind(relation) } - end - - # TESTME - def orders - (orderings + relation.orders).collect { |o| o.bind(self) } - end - end -end \ No newline at end of file diff --git a/lib/arel/relations/operations/project.rb b/lib/arel/relations/operations/project.rb deleted file mode 100644 index 5507ea3163..0000000000 --- a/lib/arel/relations/operations/project.rb +++ /dev/null @@ -1,19 +0,0 @@ -module Arel - class Project < Compound - attributes :relation, :projections - deriving :== - - def initialize(relation, *projections, &block) - @relation = relation - @projections = (projections + (block_given?? [yield(relation)] : [])).collect { |p| p.bind(relation) } - end - - def attributes - @attributes ||= projections.collect { |p| p.bind(self) } - end - - def externalizable? - attributes.any?(&:aggregation?) or relation.externalizable? - end - end -end diff --git a/lib/arel/relations/operations/skip.rb b/lib/arel/relations/operations/skip.rb deleted file mode 100644 index 930e4c94ea..0000000000 --- a/lib/arel/relations/operations/skip.rb +++ /dev/null @@ -1,10 +0,0 @@ -module Arel - class Skip < Compound - attributes :relation, :skipped - deriving :initialize, :== - - def externalizable? - true - end - end -end \ No newline at end of file diff --git a/lib/arel/relations/operations/take.rb b/lib/arel/relations/operations/take.rb deleted file mode 100644 index 2fd3fdf635..0000000000 --- a/lib/arel/relations/operations/take.rb +++ /dev/null @@ -1,10 +0,0 @@ -module Arel - class Take < Compound - attributes :relation, :taken - deriving :initialize, :== - - def externalizable? - true - end - end -end \ No newline at end of file diff --git a/lib/arel/relations/operations/where.rb b/lib/arel/relations/operations/where.rb deleted file mode 100644 index 608aaeb4b7..0000000000 --- a/lib/arel/relations/operations/where.rb +++ /dev/null @@ -1,16 +0,0 @@ -module Arel - class Where < Compound - attributes :relation, :predicate - deriving :== - - def initialize(relation, *predicates, &block) - predicate = block_given?? yield(relation) : predicates.shift - @relation = predicates.empty?? relation : Where.new(relation, *predicates) - @predicate = predicate.bind(@relation) - end - - def wheres - @wheres ||= (relation.wheres + [predicate]).collect { |p| p.bind(self) } - end - end -end diff --git a/lib/arel/relations/relation.rb b/lib/arel/relations/relation.rb deleted file mode 100644 index 5d2c336a15..0000000000 --- a/lib/arel/relations/relation.rb +++ /dev/null @@ -1,169 +0,0 @@ -module Arel - class Relation - attr_reader :count - - def session - Session.new - end - - def count - @count = "COUNT(*) AS count_all" - end - - def to_sql(formatter = Sql::SelectStatement.new(self)) - formatter.select select_sql, self - end - alias_method :to_s, :to_sql - - def select_sql - [ - "SELECT #{@count} #{attributes.collect { |a| a.to_sql(Sql::SelectClause.new(self)) }.join(', ') unless @count}", - "FROM #{table_sql(Sql::TableReference.new(self))}", - (joins(self) unless joins(self).blank? ), - ("WHERE #{wheres .collect { |w| w.to_sql(Sql::WhereClause.new(self)) }.join("\n\tAND ")}" unless wheres.blank? ), - ("GROUP BY #{groupings.collect { |g| g.to_sql(Sql::GroupClause.new(self)) }.join(', ')}" unless groupings.blank? ), - ("ORDER BY #{orders .collect { |o| o.to_sql(Sql::OrderClause.new(self)) }.join(', ')}" unless orders.blank? ), - ("LIMIT #{taken}" unless taken.blank? ), - ("OFFSET #{skipped}" unless skipped.blank? ) - ].compact.join("\n") - end - - def inclusion_predicate_sql - "IN" - end - - def call(connection = engine) - results = connection.execute(to_sql) - rows = [] - results.each do |row| - rows << attributes.zip(row).to_hash - end - rows - end - - def bind(relation) - self - end - - def root - self - end - - def christener - @christener ||= Sql::Christener.new - end - - module Enumerable - include ::Enumerable - - def each(&block) - session.read(self).each(&block) - end - - def first - session.read(self).first - end - end - include Enumerable - - module Operable - def join(other_relation = nil, join_type = "INNER JOIN") - case other_relation - when String - Join.new(other_relation, self) - when Relation - JoinOperation.new(join_type, self, other_relation) - else - self - end - end - - def outer_join(other_relation = nil) - join(other_relation, "LEFT OUTER JOIN") - end - - [:where, :project, :order, :take, :skip, :group].each do |operation_name| - operation = <<-OPERATION - def #{operation_name}(*arguments, &block) - arguments.all?(&:blank?) && !block_given?? self : #{operation_name.to_s.classify}.new(self, *arguments, &block) - end - OPERATION - class_eval operation, __FILE__, __LINE__ - end - - def alias - Alias.new(self) - end - - module Writable - def insert(record) - session.create Insert.new(self, record); self - end - - def update(assignments) - session.update Update.new(self, assignments) - end - - def delete - session.delete Deletion.new(self) - end - end - include Writable - - JoinOperation = Struct.new(:join_sql, :relation1, :relation2) do - def on(*predicates) - Join.new(join_sql, relation1, relation2, *predicates) - end - end - end - include Operable - - module AttributeAccessable - def [](index) - case index - when Symbol, String - find_attribute_matching_name(index) - when Attribute, Expression - find_attribute_matching_attribute(index) - when Array - index.collect { |i| self[i] } - end - end - - def find_attribute_matching_name(name) - attributes.detect { |a| a.named?(name) } - end - - def find_attribute_matching_attribute(attribute) - matching_attributes(attribute).max do |a1, a2| - (a1.original_attribute / attribute) <=> (a2.original_attribute / attribute) - end - end - - private - def matching_attributes(attribute) - (@matching_attributes ||= attributes.inject({}) do |hash, a| - (hash[a.root] ||= []) << a - hash - end)[attribute.root] || [] - end - - def has_attribute?(attribute) - !matching_attributes(attribute).empty? - end - end - include AttributeAccessable - - module DefaultOperations - def attributes; [] end - def wheres; [] end - def orders; [] end - def inserts; [] end - def groupings; [] end - def joins(formatter = nil); nil end - def taken; nil end - def skipped; nil end - end - include DefaultOperations - end -end diff --git a/lib/arel/relations/table.rb b/lib/arel/relations/table.rb deleted file mode 100644 index 0433abbbb2..0000000000 --- a/lib/arel/relations/table.rb +++ /dev/null @@ -1,36 +0,0 @@ -module Arel - class Table < Relation - include Recursion::BaseCase - - cattr_accessor :engine - attr_reader :name, :engine - hash_on :name - - def initialize(name, engine = Table.engine) - @name, @engine = name.to_s, engine - end - - def attributes - @attributes ||= columns.collect do |column| - Attribute.new(self, column.name.to_sym) - end - end - - def column_for(attribute) - has_attribute?(attribute) and columns.detect { |c| c.name == attribute.name.to_s } - end - - def columns - @columns ||= engine.columns(name, "#{name} Columns") - end - - def reset - @attributes = @columns = nil - end - - def ==(other) - Table === other and - name == other.name - end - end -end diff --git a/lib/arel/relations/utilities.rb b/lib/arel/relations/utilities.rb deleted file mode 100644 index 454d455359..0000000000 --- a/lib/arel/relations/utilities.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'arel/relations/utilities/compound' -require 'arel/relations/utilities/recursion' -require 'arel/relations/utilities/nil' -require 'arel/relations/utilities/externalization' -require 'arel/relations/utilities/recursion' \ No newline at end of file diff --git a/lib/arel/relations/utilities/compound.rb b/lib/arel/relations/utilities/compound.rb deleted file mode 100644 index b1e8054d4d..0000000000 --- a/lib/arel/relations/utilities/compound.rb +++ /dev/null @@ -1,18 +0,0 @@ -module Arel - class Compound < Relation - attr_reader :relation - hash_on :relation - delegate :joins, :join?, :inserts, :taken, :skipped, :name, :externalizable?, - :column_for, :engine, :table, :table_sql, - :to => :relation - - [:attributes, :wheres, :groupings, :orders].each do |operation_name| - operation = <<-OPERATION - def #{operation_name} - @#{operation_name} ||= relation.#{operation_name}.collect { |o| o.bind(self) } - end - OPERATION - class_eval operation, __FILE__, __LINE__ - end - end -end diff --git a/lib/arel/relations/utilities/externalization.rb b/lib/arel/relations/utilities/externalization.rb deleted file mode 100644 index 3b9b2296dc..0000000000 --- a/lib/arel/relations/utilities/externalization.rb +++ /dev/null @@ -1,34 +0,0 @@ -module Arel - class Externalization < Compound - attributes :relation - deriving :initialize, :== - include Recursion::BaseCase - - def wheres - [] - end - - def table_sql(formatter = Sql::TableReference.new(relation)) - formatter.select relation.select_sql, self - end - - def attributes - @attributes ||= relation.attributes.collect(&:to_attribute).collect { |a| a.bind(self) } - end - - # REMOVEME - def name - relation.name + '_external' - end - end - - class Relation - def externalize - @externalized ||= externalizable?? Externalization.new(self) : self - end - - def externalizable? - false - end - end -end diff --git a/lib/arel/relations/utilities/nil.rb b/lib/arel/relations/utilities/nil.rb deleted file mode 100644 index 56cf395d2c..0000000000 --- a/lib/arel/relations/utilities/nil.rb +++ /dev/null @@ -1,10 +0,0 @@ -require 'singleton' - -module Arel - class Nil < Relation - include Singleton - - def table_sql(formatter = nil); '' end - def name; '' end - end -end diff --git a/lib/arel/relations/utilities/recursion.rb b/lib/arel/relations/utilities/recursion.rb deleted file mode 100644 index 848b059507..0000000000 --- a/lib/arel/relations/utilities/recursion.rb +++ /dev/null @@ -1,13 +0,0 @@ -module Arel - module Recursion - module BaseCase - def table - self - end - - def table_sql(formatter = Sql::TableReference.new(self)) - formatter.table self - end - end - end -end \ No newline at end of file diff --git a/lib/arel/relations/writes.rb b/lib/arel/relations/writes.rb deleted file mode 100644 index 1495d9c857..0000000000 --- a/lib/arel/relations/writes.rb +++ /dev/null @@ -1,3 +0,0 @@ -require 'arel/relations/writes/delete' -require 'arel/relations/writes/update' -require 'arel/relations/writes/insert' \ No newline at end of file diff --git a/lib/arel/relations/writes/delete.rb b/lib/arel/relations/writes/delete.rb deleted file mode 100644 index b1ff3bef27..0000000000 --- a/lib/arel/relations/writes/delete.rb +++ /dev/null @@ -1,19 +0,0 @@ -module Arel - class Deletion < Compound - attributes :relation - deriving :initialize, :== - - def to_sql(formatter = nil) - [ - "DELETE", - "FROM #{table_sql}", - ("WHERE #{wheres.collect(&:to_sql).join('\n\tAND ')}" unless wheres.blank? ), - ("LIMIT #{taken}" unless taken.blank? ), - ].compact.join("\n") - end - - def call(connection = engine) - connection.delete(to_sql) - end - end -end diff --git a/lib/arel/relations/writes/insert.rb b/lib/arel/relations/writes/insert.rb deleted file mode 100644 index d579ad06d0..0000000000 --- a/lib/arel/relations/writes/insert.rb +++ /dev/null @@ -1,23 +0,0 @@ -module Arel - class Insert < Compound - attributes :relation, :record - deriving :== - - def initialize(relation, record) - @relation, @record = relation, record.bind(relation) - end - - def to_sql(formatter = nil) - [ - "INSERT", - "INTO #{table_sql}", - "(#{record.keys.map { |key| engine.quote_column_name(key.name) }.join(', ')})", - "VALUES (#{record.map { |key, value| key.format(value) }.join(', ')})" - ].join("\n") - end - - def call(connection = engine) - connection.insert(to_sql) - end - end -end diff --git a/lib/arel/relations/writes/update.rb b/lib/arel/relations/writes/update.rb deleted file mode 100644 index 52ca6ecf05..0000000000 --- a/lib/arel/relations/writes/update.rb +++ /dev/null @@ -1,30 +0,0 @@ -module Arel - class Update < Compound - attributes :relation, :assignments - deriving :== - - def initialize(relation, assignments) - @relation, @assignments = relation, assignments - end - - def to_sql(formatter = nil) - [ - "UPDATE #{table_sql} SET", - map_assignments, - ("WHERE #{wheres.map(&:to_sql).join('\n\tAND ')}" unless wheres.blank? ), - ("LIMIT #{taken}" unless taken.blank? ) - ].join("\n") - end - - def call(connection = engine) - connection.update(to_sql) - end - - def map_assignments - assignments.collect do |attribute, value| - attribute.respond_to?(:name) ? - "#{engine.quote_column_name(attribute.name)} = #{attribute.format(value)}" : attribute - end.join(",\n") - end - end -end diff --git a/lib/arel/session.rb b/lib/arel/session.rb deleted file mode 100644 index d9a6e4b5e4..0000000000 --- a/lib/arel/session.rb +++ /dev/null @@ -1,47 +0,0 @@ -require 'singleton' - -module Arel - class Session - class << self - attr_accessor :instance - alias_method :manufacture, :new - - def start - if @started - yield - else - begin - @started = true - @instance = manufacture - metaclass.send :alias_method, :new, :instance - yield - ensure - metaclass.send :alias_method, :new, :manufacture - @started = false - end - end - end - end - - module CRUD - def create(insert) - insert.call(insert.engine) - end - - def read(select) - (@read ||= Hash.new do |hash, select| - hash[select] = select.call(select.engine) - end)[select] - end - - def update(update) - update.call(update.engine) - end - - def delete(delete) - delete.call(delete.engine) - end - end - include CRUD - end -end diff --git a/lib/arel/sql.rb b/lib/arel/sql.rb deleted file mode 100644 index 7e7dd0a80f..0000000000 --- a/lib/arel/sql.rb +++ /dev/null @@ -1,2 +0,0 @@ -require 'arel/sql/formatters' -require 'arel/sql/christener' \ No newline at end of file diff --git a/lib/arel/sql/christener.rb b/lib/arel/sql/christener.rb deleted file mode 100644 index 5883a75f41..0000000000 --- a/lib/arel/sql/christener.rb +++ /dev/null @@ -1,13 +0,0 @@ -module Arel - module Sql - class Christener - def name_for(relation) - @used_names ||= Hash.new(0) - (@relation_names ||= Hash.new do |hash, relation| - @used_names[name = relation.name] += 1 - hash[relation] = name + (@used_names[name] > 1 ? "_#{@used_names[name]}" : '') - end)[relation.table] - end - end - end -end \ No newline at end of file diff --git a/lib/arel/sql/formatters.rb b/lib/arel/sql/formatters.rb deleted file mode 100644 index f82ddf631f..0000000000 --- a/lib/arel/sql/formatters.rb +++ /dev/null @@ -1,121 +0,0 @@ -module Arel - module Sql - class Formatter - attr_reader :environment - delegate :christener, :engine, :to => :environment - delegate :name_for, :to => :christener - delegate :quote_table_name, :quote_column_name, :quote, :to => :engine - - def initialize(environment) - @environment = environment - end - end - - class SelectClause < Formatter - def attribute(attribute) - # FIXME this should check that the column exists - if attribute.name.to_s =~ /^\w*$/ - "#{quote_table_name(name_for(attribute.original_relation))}.#{quote_column_name(attribute.name)}" + (attribute.alias ? " AS #{quote(attribute.alias.to_s)}" : "") - else - attribute.name.to_s + (attribute.alias ? " AS #{quote(attribute.alias.to_s)}" : "") - end - end - - def expression(expression) - if expression.function_sql == "DISTINCT" - "#{expression.function_sql} #{expression.attribute.to_sql(self)}" + (expression.alias ? " AS #{quote_column_name(expression.alias)}" : '') - else - "#{expression.function_sql}(#{expression.attribute.to_sql(self)})" + (expression.alias ? " AS #{quote_column_name(expression.alias)}" : " AS #{expression.function_sql.to_s.downcase}_id") - end - end - - def select(select_sql, table) - "(#{select_sql}) AS #{quote_table_name(name_for(table))}" - end - - def value(value) - value - end - end - - class PassThrough < Formatter - def value(value) - value - end - end - - class WhereClause < PassThrough - end - - class OrderClause < PassThrough - def attribute(attribute) - "#{quote_table_name(name_for(attribute.original_relation))}.#{quote_column_name(attribute.name)}" - end - end - - class GroupClause < PassThrough - def attribute(attribute) - "#{quote_table_name(name_for(attribute.original_relation))}.#{quote_column_name(attribute.name)}" - end - end - - class WhereCondition < Formatter - def attribute(attribute) - "#{quote_table_name(name_for(attribute.original_relation))}.#{quote_column_name(attribute.name)}" - end - - def expression(expression) - "#{expression.function_sql}(#{expression.attribute.to_sql(self)})" - end - - def value(value) - value.to_sql(self) - end - - def scalar(value, column = nil) - quote(value, column) - end - - def select(select_sql, table) - "(#{select_sql})" - end - end - - class SelectStatement < Formatter - def select(select_sql, table) - select_sql - end - end - - class TableReference < Formatter - def select(select_sql, table) - "(#{select_sql}) AS #{quote_table_name(name_for(table))}" - end - - def table(table) - if table.name =~ /^(\w|-)*$/ - quote_table_name(table.name) + (table.name != name_for(table) ? " AS " + quote_table_name(name_for(table)) : '') - else - table.name + (table.name != name_for(table) ? " AS " + (name_for(table)) : '') - end - end - end - - class Attribute < WhereCondition - def scalar(scalar) - quote(scalar, environment.column) - end - - def array(array) - "(" + array.collect { |e| e.to_sql(self) }.join(', ') + ")" - end - - def range(left, right) - "#{left} AND #{right}" - end - end - - class Value < WhereCondition - end - end -end -- cgit v1.2.3 From 054b0103a8a833e643c954fb31b9a5d88e29968e Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Thu, 28 May 2009 18:08:48 -0300 Subject: This should be performed by the engine, if it does not exists, then create SQLLiteral not Attribute. --- lib/arel/engines/sql/formatters.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/arel/engines/sql/formatters.rb b/lib/arel/engines/sql/formatters.rb index ae80feb18e..22935ebff1 100644 --- a/lib/arel/engines/sql/formatters.rb +++ b/lib/arel/engines/sql/formatters.rb @@ -13,7 +13,6 @@ module Arel class SelectClause < Formatter def attribute(attribute) - # FIXME this should check that the column exists "#{quote_table_name(name_for(attribute.original_relation))}.#{quote_column_name(attribute.name)}" + (attribute.alias ? " AS #{quote(attribute.alias.to_s)}" : "") end -- cgit v1.2.3 From dc09a633c37ca0b214e4d1dd1572cdb9070fc38d Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Thu, 28 May 2009 18:24:40 -0300 Subject: Don't quote the table if it isn't a table name. By doing this Arel supports using custom SQL FROM like: edges USE INDEX(unique_edge_index) --- lib/arel/engines/sql/formatters.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/arel/engines/sql/formatters.rb b/lib/arel/engines/sql/formatters.rb index 22935ebff1..626803a887 100644 --- a/lib/arel/engines/sql/formatters.rb +++ b/lib/arel/engines/sql/formatters.rb @@ -91,8 +91,12 @@ module Arel end def table(table) - quote_table_name(table.name) + - (table.name != name_for(table) ? " AS " + quote_table_name(name_for(table)) : '') + if table.name =~ /\s/ + table.name + else + quote_table_name(table.name) + + (table.name != name_for(table) ? " AS " + quote_table_name(name_for(table)) : '') + end end end -- cgit v1.2.3 From c55226bac0cfac67081b01860baa61f3acbb2ca9 Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Thu, 28 May 2009 18:41:20 -0300 Subject: Allow expressions on literal SQL fragments --- lib/arel/engines/sql/primitives.rb | 4 +++- spec/arel/engines/sql/unit/primitives/literal_spec.rb | 12 ++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/arel/engines/sql/primitives.rb b/lib/arel/engines/sql/primitives.rb index bb3bed78e6..a08ca11c12 100644 --- a/lib/arel/engines/sql/primitives.rb +++ b/lib/arel/engines/sql/primitives.rb @@ -3,10 +3,12 @@ module Arel def relation nil end - + def to_sql(formatter = nil) self end + + include Attribute::Expressions end class Attribute diff --git a/spec/arel/engines/sql/unit/primitives/literal_spec.rb b/spec/arel/engines/sql/unit/primitives/literal_spec.rb index c7ff1cf879..ed8bea339b 100644 --- a/spec/arel/engines/sql/unit/primitives/literal_spec.rb +++ b/spec/arel/engines/sql/unit/primitives/literal_spec.rb @@ -18,6 +18,18 @@ module Arel sql.should be_like(%Q{SELECT COUNT(*) AS count_id FROM "users"}) end end + + it "manufactures expressions on literal SQL fragment" do + sql = @relation.project(SqlLiteral.new("2 * credit_limit").sum).to_sql + + adapter_is :mysql do + sql.should be_like(%Q{SELECT SUM(2 * credit_limit) AS sum_id FROM `users`}) + end + + adapter_is_not :mysql do + sql.should be_like(%Q{SELECT SUM(2 * credit_limit) AS sum_id FROM "users"}) + end + end end end end -- cgit v1.2.3 From 324f265c1de98212f59f42c287d441b85b2350b7 Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Tue, 2 Jun 2009 12:33:33 -0300 Subject: Return delete result instead Arel object --- lib/arel/session.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/arel/session.rb b/lib/arel/session.rb index 921ad0a7ac..abef5c543b 100644 --- a/lib/arel/session.rb +++ b/lib/arel/session.rb @@ -35,12 +35,10 @@ module Arel def update(update) update.call - update end def delete(delete) delete.call - delete end end include CRUD -- cgit v1.2.3 From 3e6ad6e5838d20c946d7a286cb34be12aae177ff Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Wed, 10 Jun 2009 19:53:51 -0300 Subject: Allow strings as update assignments --- lib/arel/engines/sql/relations/writes.rb | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/arel/engines/sql/relations/writes.rb b/lib/arel/engines/sql/relations/writes.rb index f1a9bfd2ac..f7073654e9 100644 --- a/lib/arel/engines/sql/relations/writes.rb +++ b/lib/arel/engines/sql/relations/writes.rb @@ -31,9 +31,13 @@ module Arel protected def assignment_sql - assignments.collect do |attribute, value| - "#{engine.quote_column_name(attribute.name)} = #{attribute.format(value)}" - end.join(",\n") + if assignments.respond_to?(:collect) + assignments.collect do |attribute, value| + "#{engine.quote_column_name(attribute.name)} = #{attribute.format(value)}" + end.join(",\n") + else + assignments.value + end end end end -- cgit v1.2.3 From ae0c58fed1cd3aca1edd75a249fa99bc9571a8a3 Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Tue, 23 Jun 2009 17:18:37 -0300 Subject: Build valid SQL query for SQLite3 and PostgreSQL when updating records with limited conditions --- lib/arel/engines/sql/relations/writes.rb | 20 ++++++++++++++++++-- spec/arel/engines/sql/unit/relations/update_spec.rb | 18 ++++++++++++------ 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/lib/arel/engines/sql/relations/writes.rb b/lib/arel/engines/sql/relations/writes.rb index f7073654e9..471fceabd8 100644 --- a/lib/arel/engines/sql/relations/writes.rb +++ b/lib/arel/engines/sql/relations/writes.rb @@ -24,8 +24,7 @@ module Arel build_query \ "UPDATE #{table_sql} SET", assignment_sql, - ("WHERE #{wheres.collect(&:to_sql).join('\n\tAND ')}" unless wheres.blank? ), - ("LIMIT #{taken}" unless taken.blank? ) + build_update_conditions_sql end protected @@ -39,5 +38,22 @@ module Arel assignments.value end end + + def build_update_conditions_sql + conditions = "" + conditions << " WHERE #{wheres.collect(&:to_sql).join('\n\tAND ')}" unless wheres.blank? + conditions << " ORDER BY #{order_clauses.join(', ')}" unless orders.blank? + + unless taken.blank? + conditions << " LIMIT #{taken}" + + if engine.adapter_name != "MySQL" + quote_primary_key = engine.quote_column_name(table.name.classify.constantize.primary_key) + conditions = "WHERE #{quote_primary_key} IN (SELECT #{quote_primary_key} FROM #{engine.connection.quote_table_name table.name} #{conditions})" + end + end + + conditions + end end end diff --git a/spec/arel/engines/sql/unit/relations/update_spec.rb b/spec/arel/engines/sql/unit/relations/update_spec.rb index 4d728eb241..4b1d824ce5 100644 --- a/spec/arel/engines/sql/unit/relations/update_spec.rb +++ b/spec/arel/engines/sql/unit/relations/update_spec.rb @@ -1,5 +1,11 @@ require File.join(File.dirname(__FILE__), '..', '..', '..', '..', '..', 'spec_helper') +class User + def self.primary_key + "id" + end +end + module Arel describe Update do before do @@ -45,17 +51,17 @@ module Arel adapter_is :sqlite3 do sql.should be_like(%Q{ - UPDATE "users" - SET "name" = 'nick' - LIMIT 1 + UPDATE "users" SET + "name" = 'nick' + WHERE "id" IN (SELECT "id" FROM "users" LIMIT 1) }) end adapter_is :postgresql do sql.should be_like(%Q{ - UPDATE "users" - SET "name" = E'nick' - LIMIT 1 + UPDATE "users" SET + "name" = E'nick' + WHERE "id" IN (SELECT "id" FROM "users" LIMIT 1) }) end end -- cgit v1.2.3 From a9486193c8c6250d56bfb0258be50025f7f62f5e Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Tue, 23 Jun 2009 17:37:10 -0300 Subject: Build valid SQL query when using PostreSQL with given order and DISTINCT ON clause. TODO: refactoring to clean up components. --- lib/arel/engines/sql/relations/relation.rb | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/lib/arel/engines/sql/relations/relation.rb b/lib/arel/engines/sql/relations/relation.rb index 4cfb83a601..ed7f19ddbd 100644 --- a/lib/arel/engines/sql/relations/relation.rb +++ b/lib/arel/engines/sql/relations/relation.rb @@ -5,6 +5,26 @@ module Arel end def select_sql + if engine.adapter_name == "PostgreSQL" && !orders.blank? && using_distinct_on? + # PostgreSQL does not allow arbitrary ordering when using DISTINCT ON, so we work around this + # by wrapping the +sql+ string as a sub-select and ordering in that query. + order = order_clauses.join(', ').split(',').map { |s| s.strip }.reject(&:blank?) + order = order.zip((0...order.size).to_a).map { |s,i| "id_list.alias_#{i} #{'DESC' if s =~ /\bdesc$/i}" }.join(', ') + + query = build_query \ + "SELECT #{select_clauses.to_s}", + "FROM #{table_sql(Sql::TableReference.new(self))}", + (joins(self) unless joins(self).blank? ), + ("WHERE #{where_clauses.join("\n\tAND ")}" unless wheres.blank? ), + ("GROUP BY #{group_clauses.join(', ')}" unless groupings.blank? ) + + build_query \ + "SELECT * FROM (#{query}) AS id_list", + "ORDER BY #{order}", + ("LIMIT #{taken}" unless taken.blank? ), + ("OFFSET #{skipped}" unless skipped.blank? ) + + else build_query \ "SELECT #{select_clauses.join(', ')}", "FROM #{table_sql(Sql::TableReference.new(self))}", @@ -14,6 +34,7 @@ module Arel ("ORDER BY #{order_clauses.join(', ')}" unless orders.blank? ), ("LIMIT #{taken}" unless taken.blank? ), ("OFFSET #{skipped}" unless skipped.blank? ) + end end def inclusion_predicate_sql @@ -46,5 +67,8 @@ module Arel orders.collect { |o| o.to_sql(Sql::OrderClause.new(self)) } end + def using_distinct_on? + select_clauses.any? { |x| x =~ /DISTINCT ON/ } + end end end -- cgit v1.2.3 From 97811698ab0e68b33fbf3067c3764e385dd75d53 Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Tue, 23 Jun 2009 19:45:14 -0300 Subject: If the class or method isn't defined use "id" as primary_key. --- lib/arel/engines/sql/relations/writes.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/arel/engines/sql/relations/writes.rb b/lib/arel/engines/sql/relations/writes.rb index 471fceabd8..b90d380c64 100644 --- a/lib/arel/engines/sql/relations/writes.rb +++ b/lib/arel/engines/sql/relations/writes.rb @@ -48,7 +48,12 @@ module Arel conditions << " LIMIT #{taken}" if engine.adapter_name != "MySQL" - quote_primary_key = engine.quote_column_name(table.name.classify.constantize.primary_key) + begin + quote_primary_key = engine.quote_column_name(table.name.classify.constantize.primary_key) + rescue NameError + quote_primary_key = engine.quote_column_name("id") + end + conditions = "WHERE #{quote_primary_key} IN (SELECT #{quote_primary_key} FROM #{engine.connection.quote_table_name table.name} #{conditions})" end end -- cgit v1.2.3 From 808b9e90a38c6c19e109da8eb5f2a264fd780d9a Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Wed, 1 Jul 2009 20:29:33 -0300 Subject: Allow SQL strings to insert query. Insert should better return engine's result. --- lib/arel/engines/sql/relations/writes.rb | 11 ++++++++--- lib/arel/session.rb | 1 - .../engines/memory/integration/joins/cross_engine_spec.rb | 5 ++--- spec/arel/engines/memory/unit/relations/insert_spec.rb | 14 +++++++------- 4 files changed, 17 insertions(+), 14 deletions(-) diff --git a/lib/arel/engines/sql/relations/writes.rb b/lib/arel/engines/sql/relations/writes.rb index b90d380c64..d648a54d91 100644 --- a/lib/arel/engines/sql/relations/writes.rb +++ b/lib/arel/engines/sql/relations/writes.rb @@ -11,11 +11,17 @@ module Arel class Insert < Compound def to_sql(formatter = nil) + insertion_attributes_values_sql = if record.is_a?(Value) + record.value + else + build_query "(#{record.keys.collect { |key| engine.quote_column_name(key.name) }.join(', ')})", + "VALUES (#{record.collect { |key, value| key.format(value) }.join(', ')})" + end + build_query \ "INSERT", "INTO #{table_sql}", - "(#{record.keys.collect { |key| engine.quote_column_name(key.name) }.join(', ')})", - "VALUES (#{record.collect { |key, value| key.format(value) }.join(', ')})" + insertion_attributes_values_sql end end @@ -28,7 +34,6 @@ module Arel end protected - def assignment_sql if assignments.respond_to?(:collect) assignments.collect do |attribute, value| diff --git a/lib/arel/session.rb b/lib/arel/session.rb index abef5c543b..cf04e8a93a 100644 --- a/lib/arel/session.rb +++ b/lib/arel/session.rb @@ -24,7 +24,6 @@ module Arel module CRUD def create(insert) insert.call - insert end def read(select) diff --git a/spec/arel/engines/memory/integration/joins/cross_engine_spec.rb b/spec/arel/engines/memory/integration/joins/cross_engine_spec.rb index bffecc9182..07228bb0f7 100644 --- a/spec/arel/engines/memory/integration/joins/cross_engine_spec.rb +++ b/spec/arel/engines/memory/integration/joins/cross_engine_spec.rb @@ -10,9 +10,8 @@ module Arel ], [:id, :name]) @photos = Table.new(:photos) @photos.delete - @photos \ - .insert(@photos[:id] => 1, @photos[:user_id] => 1, @photos[:camera_id] => 6) \ - .insert(@photos[:id] => 2, @photos[:user_id] => 2, @photos[:camera_id] => 42) + @photos.insert(@photos[:id] => 1, @photos[:user_id] => 1, @photos[:camera_id] => 6) + @photos.insert(@photos[:id] => 2, @photos[:user_id] => 2, @photos[:camera_id] => 42) end describe 'when the in memory relation is on the left' do diff --git a/spec/arel/engines/memory/unit/relations/insert_spec.rb b/spec/arel/engines/memory/unit/relations/insert_spec.rb index 59e43328a3..873737e3b5 100644 --- a/spec/arel/engines/memory/unit/relations/insert_spec.rb +++ b/spec/arel/engines/memory/unit/relations/insert_spec.rb @@ -14,13 +14,13 @@ module Arel it "manufactures an array of hashes of attributes to values" do @relation \ .insert(@relation[:id] => 4, @relation[:name] => 'guinea fowl') \ - .let do |relation| - relation.call.should == [ - Row.new(relation, [1, 'duck']), - Row.new(relation, [2, 'duck']), - Row.new(relation, [3, 'goose']), - Row.new(relation, [4, 'guinea fowl']) - ] + do |relation| + relation.should == [ + Row.new(relation, [1, 'duck']), + Row.new(relation, [2, 'duck']), + Row.new(relation, [3, 'goose']), + Row.new(relation, [4, 'guinea fowl']) + ] end end end -- cgit v1.2.3 From 5dcbca25cef8e8f5809913977cfeb4366c8b44d0 Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Fri, 14 Aug 2009 10:49:15 -0300 Subject: Allow joining a StringJoin with another join relation. --- lib/arel/engines/sql/relations/operations/join.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/arel/engines/sql/relations/operations/join.rb b/lib/arel/engines/sql/relations/operations/join.rb index 7c5e13510a..a3aaaa163b 100644 --- a/lib/arel/engines/sql/relations/operations/join.rb +++ b/lib/arel/engines/sql/relations/operations/join.rb @@ -26,8 +26,8 @@ module Arel end class StringJoin < Join - def joins(_, __ = nil) - relation2 + def joins(environment, formatter = Sql::TableReference.new(environment)) + [relation1.joins(environment), relation2].compact.join(" ") end end end -- cgit v1.2.3 From 3d747a56b76ae97645dd265cc75e73e5f7827193 Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Fri, 14 Aug 2009 10:49:50 -0300 Subject: Accept Arel::Value in hash values and treat them properly. --- lib/arel/algebra/relations/relation.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/arel/algebra/relations/relation.rb b/lib/arel/algebra/relations/relation.rb index 9fdac26528..5403e40fae 100644 --- a/lib/arel/algebra/relations/relation.rb +++ b/lib/arel/algebra/relations/relation.rb @@ -110,7 +110,7 @@ module Arel private def matching_attributes(attribute) (@matching_attributes ||= attributes.inject({}) do |hash, a| - (hash[a.root] ||= []) << a + (hash[a.is_a?(Value) ? a.value : a.root] ||= []) << a hash end)[attribute.root] || [] end -- cgit v1.2.3 From 755a7ced2f98b0bb246089c80cdfa04cd918fa89 Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Sun, 23 Aug 2009 17:24:59 -0300 Subject: REAME updated: remove whitespaces, fix invalid join in query output. --- README.markdown | 52 ++++++++++++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/README.markdown b/README.markdown index 4d95234423..20d6e62b44 100644 --- a/README.markdown +++ b/README.markdown @@ -15,20 +15,20 @@ The long term goal, following both LINQ and DataMapper, is to have Arel adapt to Generating a query with ARel is simple. For example, in order to produce SELECT * FROM users - + you construct a table relation and convert it to sql: users = Table(:users) users.to_sql - + In fact, you will probably never call `#to_sql`. Rather, you'll work with data from the table directly. You can iterate through all rows in the `users` table like this: users.each { |user| ... } - + In other words, Arel relations implement Ruby's Enumerable interface. Let's have a look at a concrete example: users.first # => { users[:id] => 1, users[:name] => 'bob' } - + As you can see, Arel converts the rows from the database into a hash, the values of which are sublimated to the appropriate Ruby primitive (integers, strings, and so forth). ### More Sophisticated Queries Relations ### @@ -43,7 +43,7 @@ First is the 'restriction' operator, `where`: What would, in SQL, be part of the `SELECT` clause is called in Arel a `projection`: users.project(users[:id]) # => SELECT users.id FROM users - + Joins resemble SQL strongly: users.join(photos).on(users[:id].eq(photos[:user_id])) @@ -53,7 +53,7 @@ What are called `LIMIT` and `OFFSET` in SQL are called `take` and `skip` in Arel users.take(5) # => SELECT * FROM users LIMIT 5 users.skip(4) # => SELECT * FROM users OFFSET 4 - + `GROUP BY` is called `group`: users.group(users[:name]) # => SELECT * FROM users GROUP BY name @@ -68,7 +68,7 @@ The best property of the Relational Algebra is its "composability", or closure u All operators are chainable in this way, and they are chainable any number of times, in any order. users.where(users[:name].eq('bob')).where(users[:age].lt(25)) - + Of course, many of the operators take multiple arguments, so the last example can be written more tersely: users.where(users[:name].eq('bob'), users[:age].lt(25)) @@ -76,7 +76,7 @@ Of course, many of the operators take multiple arguments, so the last example ca The `OR` operator is not yet supported. It will work like this: users.where(users[:name].eq('bob').or(users[:age].lt(25))) - + The `AND` operator will behave similarly. Finally, most operations take a block form. For example: @@ -96,7 +96,7 @@ The examples above are fairly simple and other libraries match or come close to Where Arel really shines in its ability to handle complex joins and aggregations. As a first example, let's consider an "adjacency list", a tree represented in a table. Suppose we have a table `comments`, representing a threaded discussion: comments = Table(:comments) - + And this table has the following attributes: comments.attributes # => [comments[:id], comments[:body], comments[:parent_id]] @@ -107,23 +107,23 @@ The `parent_id` column is a foreign key from the `comments` table to itself. Now comments_with_replies = \ comments.join(replies).on(replies[:parent_id].eq(comments[:id])) # => SELECT * FROM comments INNER JOIN comments AS comments_2 WHERE comments_2.parent_id = comments.id - + The call to `#alias` is actually optional: Arel will always produce a unique name for every table joined in the relation, and it will always do so deterministically to exploit query caching. Explicit aliasing is more common, however. When you want to extract specific slices of data, aliased tables are a necessity. For example to get just certain columns from the row, treat a row like a hash: comments_with_replies.first[replies[:body]] - + This will return the first comment's reply's body. If you don't need to extract the data later (for example, you're simply doing a join to find comments that have replies, you don't care what the content of the replies are), the block form may be preferable: comments.join(comments) { |comments, replies| replies[:parent_id].eq(comments[:id]) } # => SELECT * FROM comments INNER JOIN comments AS comments_2 WHERE comments_2.parent_id = comments.id - + Note that you do NOT want to do something like: comments.join(comments, comments[:parent_id].eq(comments[:id])) # => SELECT * FROM comments INNER JOIN comments AS comments_2 WHERE comments.parent_id = comments.id - + This does NOT have the same meaning as the previous query, since the comments[:parent_id] reference is effectively ambiguous. #### Complex Aggregations #### @@ -135,24 +135,24 @@ The easiest way to introduce this is in SQL. Your task is to get all users and t SELECT count(*) FROM photos GROUP BY user_id - + Now, we'd like to join this with the user table. Naively, you might try to do this: SELECT users.*, count(photos.id) FROM users LEFT OUTER JOIN photos - ON users.id = photos.id + ON users.id = photos.user_id GROUP BY photos.user_id - + Of course, this has a slightly different meaning than our intended query. This is actually a fairly advanced topic in SQL so let's see why this doesn't work *step by step*. Suppose we have these records in our `users` table: mysql> select * from users; +------+--------+ | id | name | +------+--------+ - | 1 | hai | - | 2 | bai | - | 3 | dumpty | + | 1 | hai | + | 2 | bai | + | 3 | dumpty | +------+--------+ And these in the photos table: @@ -161,19 +161,19 @@ And these in the photos table: +------+---------+-----------+ | id | user_id | camera_id | +------+---------+-----------+ - | 1 | 1 | 1 | - | 2 | 1 | 1 | - | 3 | 1 | 1 | + | 1 | 1 | 1 | + | 2 | 1 | 1 | + | 3 | 1 | 1 | +------+---------+-----------+ - + If we perform the above, incorrect query, we get the following: mysql> select users.*, count(photos.id) from users left outer join photos on users.id = photos.user_id limit 3 group by user_id; +------+------+------------------+ | id | name | count(photos.id) | +------+------+------------------+ - | 2 | bai | 0 | - | 1 | hai | 3 | + | 2 | bai | 0 | + | 1 | hai | 3 | +------+------+------------------+ As you can see, we're completely missing data for user with id 3. `dumpty` has no photos, neither does `bai`. But strangely `bai` appeared and `dumpty` didn't! The reason is that the `GROUP BY` clause is aggregating on both tables, not just the `photos` table. All users without photos have a `photos.id` of `null` (thanks to the left outer join). These are rolled up together and an arbitrary user wins. In this case, `bai` not `dumpty`. @@ -181,4 +181,4 @@ As you can see, we're completely missing data for user with id 3. `dumpty` has n SELECT users.*, photos_aggregation.cnt FROM users LEFT OUTER JOIN (SELECT user_id, count(*) as cnt FROM photos GROUP BY user_id) AS photos_aggregation - ON photos_aggregation.user_id = users.id \ No newline at end of file + ON photos_aggregation.user_id = users.id -- cgit v1.2.3 From 32af162414f2e092afa004b74a0be64fa53e7834 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Mon, 14 Sep 2009 02:50:12 -0700 Subject: Require active_support and active_record by name in LOAD_PATH instead of gem name (deprecated) --- lib/arel.rb | 4 ++-- spec/connections/mysql_connection.rb | 3 ++- spec/connections/postgresql_connection.rb | 3 ++- spec/connections/sqlite3_connection.rb | 5 +++-- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/arel.rb b/lib/arel.rb index 54a31b6ed0..b67186a308 100644 --- a/lib/arel.rb +++ b/lib/arel.rb @@ -1,11 +1,11 @@ $LOAD_PATH.unshift(File.dirname(__FILE__)) require 'rubygems' -require 'activesupport' +require 'active_support' require 'active_support/dependencies' require 'active_support/core_ext/class/attribute_accessors' require 'active_support/core_ext/module/delegation' -require 'activerecord' +require 'active_record' require 'active_record/connection_adapters/abstract/quoting' require 'arel/algebra' diff --git a/spec/connections/mysql_connection.rb b/spec/connections/mysql_connection.rb index a58ddc35ef..dbece8646f 100644 --- a/spec/connections/mysql_connection.rb +++ b/spec/connections/mysql_connection.rb @@ -1,5 +1,6 @@ -require "activerecord" puts "Using native MySQL" +require "active_record" +require 'logger' ActiveRecord::Base.logger = Logger.new("debug.log") diff --git a/spec/connections/postgresql_connection.rb b/spec/connections/postgresql_connection.rb index e376d33ec6..0fb6dfe065 100644 --- a/spec/connections/postgresql_connection.rb +++ b/spec/connections/postgresql_connection.rb @@ -1,5 +1,6 @@ -require "activerecord" puts "Using native PostgreSQL" +require "active_record" +require 'logger' ActiveRecord::Base.logger = Logger.new("debug.log") diff --git a/spec/connections/sqlite3_connection.rb b/spec/connections/sqlite3_connection.rb index 9e9503e0ca..e8eeee17d0 100644 --- a/spec/connections/sqlite3_connection.rb +++ b/spec/connections/sqlite3_connection.rb @@ -1,6 +1,6 @@ -require "rubygems" -require "activerecord" puts "Using native SQLite3" +require "active_record" +require 'logger' ActiveRecord::Base.logger = Logger.new("debug.log") @@ -16,6 +16,7 @@ ActiveRecord::Base.configurations = { unless File.exist?(db_file) puts "SQLite3 database not found at #{db_file}. Rebuilding it." + require 'fileutils' FileUtils.mkdir_p(File.dirname(db_file)) sqlite_command = %Q{sqlite3 "#{db_file}" "create table a (a integer); drop table a;"} puts "Executing '#{sqlite_command}'" -- cgit v1.2.3 From a727cef713c75875941f56fc1e3779216c93d539 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Mon, 14 Sep 2009 03:12:54 -0700 Subject: Remove explicit rubygems require. Use Active Support provided by Active Record. Add self to load path after requiring Active Record. --- lib/arel.rb | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/lib/arel.rb b/lib/arel.rb index b67186a308..c5fa5ba903 100644 --- a/lib/arel.rb +++ b/lib/arel.rb @@ -1,13 +1,7 @@ -$LOAD_PATH.unshift(File.dirname(__FILE__)) - -require 'rubygems' -require 'active_support' -require 'active_support/dependencies' -require 'active_support/core_ext/class/attribute_accessors' -require 'active_support/core_ext/module/delegation' require 'active_record' require 'active_record/connection_adapters/abstract/quoting' +$LOAD_PATH.unshift(File.dirname(__FILE__)) require 'arel/algebra' require 'arel/engines' require 'arel/session' -- cgit v1.2.3 From bad67f8a4a480a41adb9541ddc11d1dce08990f4 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Mon, 14 Sep 2009 03:14:53 -0700 Subject: Submodule rails master rather than rely on gems --- .gitmodules | 3 +++ Rakefile | 1 + vendor/rails | 1 + 3 files changed, 5 insertions(+) create mode 100644 .gitmodules create mode 160000 vendor/rails diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000000..5f43dd3ae5 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "vendor/rails"] + path = vendor/rails + url = git://github.com/rails/rails.git diff --git a/Rakefile b/Rakefile index 17a6f8d35d..cc5249c2c5 100644 --- a/Rakefile +++ b/Rakefile @@ -20,6 +20,7 @@ namespace :spec do for adapter in %w[mysql sqlite3 postgresql] desc "Run specs with the #{adapter} database adapter" Spec::Rake::SpecTask.new(adapter) do |t| + t.libs << "#{File.dirname(__FILE__)}/vendor/rails/activerecord/lib" t.spec_files = ["spec/connections/#{adapter}_connection.rb"] + ["spec/schemas/#{adapter}_schema.rb"] + diff --git a/vendor/rails b/vendor/rails new file mode 160000 index 0000000000..181cd109d9 --- /dev/null +++ b/vendor/rails @@ -0,0 +1 @@ +Subproject commit 181cd109d9812d371e2d554a4846f0b2b25b1690 -- cgit v1.2.3 From 7a7ee72ec1cb5a0b31d0ed9cd5c58a018876b65d Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Mon, 14 Sep 2009 03:21:24 -0700 Subject: Use load path rather than relative path for spec_helper requires. Also fixes specs on Ruby 1.9 since . is no longer in the load path. --- Rakefile | 1 + spec/arel/algebra/unit/predicates/binary_spec.rb | 2 +- spec/arel/algebra/unit/predicates/equality_spec.rb | 2 +- spec/arel/algebra/unit/predicates/in_spec.rb | 2 +- spec/arel/algebra/unit/primitives/attribute_spec.rb | 2 +- spec/arel/algebra/unit/primitives/expression_spec.rb | 2 +- spec/arel/algebra/unit/primitives/value_spec.rb | 2 +- spec/arel/algebra/unit/relations/alias_spec.rb | 2 +- spec/arel/algebra/unit/relations/delete_spec.rb | 2 +- spec/arel/algebra/unit/relations/group_spec.rb | 2 +- spec/arel/algebra/unit/relations/insert_spec.rb | 2 +- spec/arel/algebra/unit/relations/join_spec.rb | 2 +- spec/arel/algebra/unit/relations/order_spec.rb | 2 +- spec/arel/algebra/unit/relations/project_spec.rb | 2 +- spec/arel/algebra/unit/relations/relation_spec.rb | 2 +- spec/arel/algebra/unit/relations/skip_spec.rb | 2 +- spec/arel/algebra/unit/relations/table_spec.rb | 2 +- spec/arel/algebra/unit/relations/take_spec.rb | 2 +- spec/arel/algebra/unit/relations/update_spec.rb | 2 +- spec/arel/algebra/unit/relations/where_spec.rb | 2 +- spec/arel/algebra/unit/session/session_spec.rb | 2 +- spec/arel/engines/memory/integration/joins/cross_engine_spec.rb | 2 +- spec/arel/engines/memory/unit/relations/array_spec.rb | 2 +- spec/arel/engines/memory/unit/relations/insert_spec.rb | 2 +- spec/arel/engines/memory/unit/relations/join_spec.rb | 2 +- spec/arel/engines/memory/unit/relations/order_spec.rb | 2 +- spec/arel/engines/memory/unit/relations/project_spec.rb | 2 +- spec/arel/engines/memory/unit/relations/skip_spec.rb | 2 +- spec/arel/engines/memory/unit/relations/take_spec.rb | 2 +- spec/arel/engines/memory/unit/relations/where_spec.rb | 2 +- spec/arel/engines/sql/integration/joins/with_adjacency_spec.rb | 2 +- spec/arel/engines/sql/integration/joins/with_aggregations_spec.rb | 2 +- spec/arel/engines/sql/integration/joins/with_compounds_spec.rb | 2 +- spec/arel/engines/sql/unit/engine_spec.rb | 2 +- spec/arel/engines/sql/unit/predicates/binary_spec.rb | 2 +- spec/arel/engines/sql/unit/predicates/equality_spec.rb | 2 +- spec/arel/engines/sql/unit/predicates/in_spec.rb | 2 +- spec/arel/engines/sql/unit/predicates/predicates_spec.rb | 2 +- spec/arel/engines/sql/unit/primitives/attribute_spec.rb | 2 +- spec/arel/engines/sql/unit/primitives/expression_spec.rb | 2 +- spec/arel/engines/sql/unit/primitives/literal_spec.rb | 2 +- spec/arel/engines/sql/unit/primitives/value_spec.rb | 2 +- spec/arel/engines/sql/unit/relations/alias_spec.rb | 2 +- spec/arel/engines/sql/unit/relations/delete_spec.rb | 2 +- spec/arel/engines/sql/unit/relations/group_spec.rb | 2 +- spec/arel/engines/sql/unit/relations/insert_spec.rb | 2 +- spec/arel/engines/sql/unit/relations/join_spec.rb | 2 +- spec/arel/engines/sql/unit/relations/order_spec.rb | 2 +- spec/arel/engines/sql/unit/relations/project_spec.rb | 2 +- spec/arel/engines/sql/unit/relations/skip_spec.rb | 2 +- spec/arel/engines/sql/unit/relations/table_spec.rb | 2 +- spec/arel/engines/sql/unit/relations/take_spec.rb | 2 +- spec/arel/engines/sql/unit/relations/update_spec.rb | 2 +- spec/arel/engines/sql/unit/relations/where_spec.rb | 2 +- 54 files changed, 54 insertions(+), 53 deletions(-) diff --git a/Rakefile b/Rakefile index cc5249c2c5..47474e4b7b 100644 --- a/Rakefile +++ b/Rakefile @@ -21,6 +21,7 @@ namespace :spec do desc "Run specs with the #{adapter} database adapter" Spec::Rake::SpecTask.new(adapter) do |t| t.libs << "#{File.dirname(__FILE__)}/vendor/rails/activerecord/lib" + t.libs << "#{File.dirname(__FILE__)}/spec" t.spec_files = ["spec/connections/#{adapter}_connection.rb"] + ["spec/schemas/#{adapter}_schema.rb"] + diff --git a/spec/arel/algebra/unit/predicates/binary_spec.rb b/spec/arel/algebra/unit/predicates/binary_spec.rb index 14fd7ab21b..97ef098e0e 100644 --- a/spec/arel/algebra/unit/predicates/binary_spec.rb +++ b/spec/arel/algebra/unit/predicates/binary_spec.rb @@ -1,4 +1,4 @@ -require File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'spec_helper') +require 'spec_helper' module Arel describe Binary do diff --git a/spec/arel/algebra/unit/predicates/equality_spec.rb b/spec/arel/algebra/unit/predicates/equality_spec.rb index af91f8b51b..c917520158 100644 --- a/spec/arel/algebra/unit/predicates/equality_spec.rb +++ b/spec/arel/algebra/unit/predicates/equality_spec.rb @@ -1,4 +1,4 @@ -require File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'spec_helper') +require 'spec_helper' module Arel describe Equality do diff --git a/spec/arel/algebra/unit/predicates/in_spec.rb b/spec/arel/algebra/unit/predicates/in_spec.rb index a8a15ce4e3..54a6d6c7da 100644 --- a/spec/arel/algebra/unit/predicates/in_spec.rb +++ b/spec/arel/algebra/unit/predicates/in_spec.rb @@ -1,4 +1,4 @@ -require File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'spec_helper') +require 'spec_helper' module Arel describe In do diff --git a/spec/arel/algebra/unit/primitives/attribute_spec.rb b/spec/arel/algebra/unit/primitives/attribute_spec.rb index 2ca63ba48e..cd484007e1 100644 --- a/spec/arel/algebra/unit/primitives/attribute_spec.rb +++ b/spec/arel/algebra/unit/primitives/attribute_spec.rb @@ -1,4 +1,4 @@ -require File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'spec_helper') +require 'spec_helper' module Arel describe Attribute do diff --git a/spec/arel/algebra/unit/primitives/expression_spec.rb b/spec/arel/algebra/unit/primitives/expression_spec.rb index 768bb492a7..ac932ed139 100644 --- a/spec/arel/algebra/unit/primitives/expression_spec.rb +++ b/spec/arel/algebra/unit/primitives/expression_spec.rb @@ -1,4 +1,4 @@ -require File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'spec_helper') +require 'spec_helper' module Arel describe Expression do diff --git a/spec/arel/algebra/unit/primitives/value_spec.rb b/spec/arel/algebra/unit/primitives/value_spec.rb index 45208e6c5d..8fed752d66 100644 --- a/spec/arel/algebra/unit/primitives/value_spec.rb +++ b/spec/arel/algebra/unit/primitives/value_spec.rb @@ -1,4 +1,4 @@ -require File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'spec_helper') +require 'spec_helper' module Arel describe Value do diff --git a/spec/arel/algebra/unit/relations/alias_spec.rb b/spec/arel/algebra/unit/relations/alias_spec.rb index a5d716a638..2aa4d52d99 100644 --- a/spec/arel/algebra/unit/relations/alias_spec.rb +++ b/spec/arel/algebra/unit/relations/alias_spec.rb @@ -1,4 +1,4 @@ -require File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'spec_helper') +require 'spec_helper' module Arel describe Alias do diff --git a/spec/arel/algebra/unit/relations/delete_spec.rb b/spec/arel/algebra/unit/relations/delete_spec.rb index 7578e12a3e..c244be8631 100644 --- a/spec/arel/algebra/unit/relations/delete_spec.rb +++ b/spec/arel/algebra/unit/relations/delete_spec.rb @@ -1,4 +1,4 @@ -require File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'spec_helper') +require 'spec_helper' module Arel describe Deletion do diff --git a/spec/arel/algebra/unit/relations/group_spec.rb b/spec/arel/algebra/unit/relations/group_spec.rb index 58f9252356..48fc818682 100644 --- a/spec/arel/algebra/unit/relations/group_spec.rb +++ b/spec/arel/algebra/unit/relations/group_spec.rb @@ -1,4 +1,4 @@ -require File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'spec_helper') +require 'spec_helper' module Arel describe Group do diff --git a/spec/arel/algebra/unit/relations/insert_spec.rb b/spec/arel/algebra/unit/relations/insert_spec.rb index feb1a5eae4..3141fa2fc4 100644 --- a/spec/arel/algebra/unit/relations/insert_spec.rb +++ b/spec/arel/algebra/unit/relations/insert_spec.rb @@ -1,4 +1,4 @@ -require File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'spec_helper') +require 'spec_helper' module Arel describe Insert do diff --git a/spec/arel/algebra/unit/relations/join_spec.rb b/spec/arel/algebra/unit/relations/join_spec.rb index f5a8bd32aa..9c1422c571 100644 --- a/spec/arel/algebra/unit/relations/join_spec.rb +++ b/spec/arel/algebra/unit/relations/join_spec.rb @@ -1,4 +1,4 @@ -require File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'spec_helper') +require 'spec_helper' module Arel describe Join do diff --git a/spec/arel/algebra/unit/relations/order_spec.rb b/spec/arel/algebra/unit/relations/order_spec.rb index 8b3c932fb9..4190901024 100644 --- a/spec/arel/algebra/unit/relations/order_spec.rb +++ b/spec/arel/algebra/unit/relations/order_spec.rb @@ -1,4 +1,4 @@ -require File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'spec_helper') +require 'spec_helper' module Arel describe Order do diff --git a/spec/arel/algebra/unit/relations/project_spec.rb b/spec/arel/algebra/unit/relations/project_spec.rb index 9f4358ea54..8886e65a2e 100644 --- a/spec/arel/algebra/unit/relations/project_spec.rb +++ b/spec/arel/algebra/unit/relations/project_spec.rb @@ -1,4 +1,4 @@ -require File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'spec_helper') +require 'spec_helper' module Arel describe Project do diff --git a/spec/arel/algebra/unit/relations/relation_spec.rb b/spec/arel/algebra/unit/relations/relation_spec.rb index adf82847ac..0a08deffb8 100644 --- a/spec/arel/algebra/unit/relations/relation_spec.rb +++ b/spec/arel/algebra/unit/relations/relation_spec.rb @@ -1,4 +1,4 @@ -require File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'spec_helper') +require 'spec_helper' module Arel describe Relation do diff --git a/spec/arel/algebra/unit/relations/skip_spec.rb b/spec/arel/algebra/unit/relations/skip_spec.rb index a41913436e..e7dea6c1cf 100644 --- a/spec/arel/algebra/unit/relations/skip_spec.rb +++ b/spec/arel/algebra/unit/relations/skip_spec.rb @@ -1,4 +1,4 @@ -require File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'spec_helper') +require 'spec_helper' module Arel describe Skip do diff --git a/spec/arel/algebra/unit/relations/table_spec.rb b/spec/arel/algebra/unit/relations/table_spec.rb index dfe457043c..e4c4e58b75 100644 --- a/spec/arel/algebra/unit/relations/table_spec.rb +++ b/spec/arel/algebra/unit/relations/table_spec.rb @@ -1,4 +1,4 @@ -require File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'spec_helper') +require 'spec_helper' module Arel describe Table do diff --git a/spec/arel/algebra/unit/relations/take_spec.rb b/spec/arel/algebra/unit/relations/take_spec.rb index 2bc17db5a1..3ad8d269f1 100644 --- a/spec/arel/algebra/unit/relations/take_spec.rb +++ b/spec/arel/algebra/unit/relations/take_spec.rb @@ -1,4 +1,4 @@ -require File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'spec_helper') +require 'spec_helper' module Arel describe Take do diff --git a/spec/arel/algebra/unit/relations/update_spec.rb b/spec/arel/algebra/unit/relations/update_spec.rb index e9642ffc99..9ed20a446b 100644 --- a/spec/arel/algebra/unit/relations/update_spec.rb +++ b/spec/arel/algebra/unit/relations/update_spec.rb @@ -1,4 +1,4 @@ -require File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'spec_helper') +require 'spec_helper' module Arel describe Update do diff --git a/spec/arel/algebra/unit/relations/where_spec.rb b/spec/arel/algebra/unit/relations/where_spec.rb index 6c3074a3a5..96b95b5823 100644 --- a/spec/arel/algebra/unit/relations/where_spec.rb +++ b/spec/arel/algebra/unit/relations/where_spec.rb @@ -1,4 +1,4 @@ -require File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'spec_helper') +require 'spec_helper' module Arel describe Where do diff --git a/spec/arel/algebra/unit/session/session_spec.rb b/spec/arel/algebra/unit/session/session_spec.rb index ca0a43f278..03aab6a03f 100644 --- a/spec/arel/algebra/unit/session/session_spec.rb +++ b/spec/arel/algebra/unit/session/session_spec.rb @@ -1,4 +1,4 @@ -require File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'spec_helper') +require 'spec_helper' module Arel describe Session do diff --git a/spec/arel/engines/memory/integration/joins/cross_engine_spec.rb b/spec/arel/engines/memory/integration/joins/cross_engine_spec.rb index 07228bb0f7..db754d9cec 100644 --- a/spec/arel/engines/memory/integration/joins/cross_engine_spec.rb +++ b/spec/arel/engines/memory/integration/joins/cross_engine_spec.rb @@ -1,4 +1,4 @@ -require File.join(File.dirname(__FILE__), '..', '..', '..', '..', '..', 'spec_helper') +require 'spec_helper' module Arel describe Join do diff --git a/spec/arel/engines/memory/unit/relations/array_spec.rb b/spec/arel/engines/memory/unit/relations/array_spec.rb index dd9da41569..9a834148b1 100644 --- a/spec/arel/engines/memory/unit/relations/array_spec.rb +++ b/spec/arel/engines/memory/unit/relations/array_spec.rb @@ -1,4 +1,4 @@ -require File.join(File.dirname(__FILE__), '..', '..', '..', '..', '..', 'spec_helper') +require 'spec_helper' module Arel describe Array do diff --git a/spec/arel/engines/memory/unit/relations/insert_spec.rb b/spec/arel/engines/memory/unit/relations/insert_spec.rb index 873737e3b5..222e525c7b 100644 --- a/spec/arel/engines/memory/unit/relations/insert_spec.rb +++ b/spec/arel/engines/memory/unit/relations/insert_spec.rb @@ -1,4 +1,4 @@ -require File.join(File.dirname(__FILE__), '..', '..', '..', '..', '..', 'spec_helper') +require 'spec_helper' module Arel describe Insert do diff --git a/spec/arel/engines/memory/unit/relations/join_spec.rb b/spec/arel/engines/memory/unit/relations/join_spec.rb index 110fdb03b7..112434ae1d 100644 --- a/spec/arel/engines/memory/unit/relations/join_spec.rb +++ b/spec/arel/engines/memory/unit/relations/join_spec.rb @@ -1,4 +1,4 @@ -require File.join(File.dirname(__FILE__), '..', '..', '..', '..', '..', 'spec_helper') +require 'spec_helper' module Arel describe Join do diff --git a/spec/arel/engines/memory/unit/relations/order_spec.rb b/spec/arel/engines/memory/unit/relations/order_spec.rb index 1e9690bbbf..21d77a2a24 100644 --- a/spec/arel/engines/memory/unit/relations/order_spec.rb +++ b/spec/arel/engines/memory/unit/relations/order_spec.rb @@ -1,4 +1,4 @@ -require File.join(File.dirname(__FILE__), '..', '..', '..', '..', '..', 'spec_helper') +require 'spec_helper' module Arel describe Order do diff --git a/spec/arel/engines/memory/unit/relations/project_spec.rb b/spec/arel/engines/memory/unit/relations/project_spec.rb index 1690910026..e688b93a39 100644 --- a/spec/arel/engines/memory/unit/relations/project_spec.rb +++ b/spec/arel/engines/memory/unit/relations/project_spec.rb @@ -1,4 +1,4 @@ -require File.join(File.dirname(__FILE__), '..', '..', '..', '..', '..', 'spec_helper') +require 'spec_helper' module Arel describe Project do diff --git a/spec/arel/engines/memory/unit/relations/skip_spec.rb b/spec/arel/engines/memory/unit/relations/skip_spec.rb index 3411c5493b..0c2077db80 100644 --- a/spec/arel/engines/memory/unit/relations/skip_spec.rb +++ b/spec/arel/engines/memory/unit/relations/skip_spec.rb @@ -1,4 +1,4 @@ -require File.join(File.dirname(__FILE__), '..', '..', '..', '..', '..', 'spec_helper') +require 'spec_helper' module Arel describe Skip do diff --git a/spec/arel/engines/memory/unit/relations/take_spec.rb b/spec/arel/engines/memory/unit/relations/take_spec.rb index 5e7c4fb462..4b08a63d22 100644 --- a/spec/arel/engines/memory/unit/relations/take_spec.rb +++ b/spec/arel/engines/memory/unit/relations/take_spec.rb @@ -1,4 +1,4 @@ -require File.join(File.dirname(__FILE__), '..', '..', '..', '..', '..', 'spec_helper') +require 'spec_helper' module Arel describe Take do diff --git a/spec/arel/engines/memory/unit/relations/where_spec.rb b/spec/arel/engines/memory/unit/relations/where_spec.rb index 1d2c2eb39c..8d0af4b52d 100644 --- a/spec/arel/engines/memory/unit/relations/where_spec.rb +++ b/spec/arel/engines/memory/unit/relations/where_spec.rb @@ -1,4 +1,4 @@ -require File.join(File.dirname(__FILE__), '..', '..', '..', '..', '..', 'spec_helper') +require 'spec_helper' module Arel describe Where do diff --git a/spec/arel/engines/sql/integration/joins/with_adjacency_spec.rb b/spec/arel/engines/sql/integration/joins/with_adjacency_spec.rb index 50b0908441..37afb1a8f2 100644 --- a/spec/arel/engines/sql/integration/joins/with_adjacency_spec.rb +++ b/spec/arel/engines/sql/integration/joins/with_adjacency_spec.rb @@ -1,4 +1,4 @@ -require File.join(File.dirname(__FILE__), '..', '..', '..', '..', '..', 'spec_helper') +require 'spec_helper' module Arel describe Join do diff --git a/spec/arel/engines/sql/integration/joins/with_aggregations_spec.rb b/spec/arel/engines/sql/integration/joins/with_aggregations_spec.rb index 709ae9f8d1..5ed530508a 100644 --- a/spec/arel/engines/sql/integration/joins/with_aggregations_spec.rb +++ b/spec/arel/engines/sql/integration/joins/with_aggregations_spec.rb @@ -1,4 +1,4 @@ -require File.join(File.dirname(__FILE__), '..', '..', '..', '..', '..', 'spec_helper') +require 'spec_helper' module Arel describe Join do diff --git a/spec/arel/engines/sql/integration/joins/with_compounds_spec.rb b/spec/arel/engines/sql/integration/joins/with_compounds_spec.rb index 4bceef4975..5909716542 100644 --- a/spec/arel/engines/sql/integration/joins/with_compounds_spec.rb +++ b/spec/arel/engines/sql/integration/joins/with_compounds_spec.rb @@ -1,4 +1,4 @@ -require File.join(File.dirname(__FILE__), '..', '..', '..', '..', '..', 'spec_helper') +require 'spec_helper' module Arel describe Join do diff --git a/spec/arel/engines/sql/unit/engine_spec.rb b/spec/arel/engines/sql/unit/engine_spec.rb index c607abcfa1..f782f56938 100644 --- a/spec/arel/engines/sql/unit/engine_spec.rb +++ b/spec/arel/engines/sql/unit/engine_spec.rb @@ -1,4 +1,4 @@ -require File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'spec_helper') +require 'spec_helper' module Arel describe Sql::Engine do diff --git a/spec/arel/engines/sql/unit/predicates/binary_spec.rb b/spec/arel/engines/sql/unit/predicates/binary_spec.rb index b1400e2588..ccf9d4ef73 100644 --- a/spec/arel/engines/sql/unit/predicates/binary_spec.rb +++ b/spec/arel/engines/sql/unit/predicates/binary_spec.rb @@ -1,4 +1,4 @@ -require File.join(File.dirname(__FILE__), '..', '..', '..', '..', '..', 'spec_helper') +require 'spec_helper' module Arel describe Binary do diff --git a/spec/arel/engines/sql/unit/predicates/equality_spec.rb b/spec/arel/engines/sql/unit/predicates/equality_spec.rb index 688a6a20be..3588604062 100644 --- a/spec/arel/engines/sql/unit/predicates/equality_spec.rb +++ b/spec/arel/engines/sql/unit/predicates/equality_spec.rb @@ -1,4 +1,4 @@ -require File.join(File.dirname(__FILE__), '..', '..', '..', '..', '..', 'spec_helper') +require 'spec_helper' module Arel describe Equality do diff --git a/spec/arel/engines/sql/unit/predicates/in_spec.rb b/spec/arel/engines/sql/unit/predicates/in_spec.rb index d3e75cfb84..4a3eff79ec 100644 --- a/spec/arel/engines/sql/unit/predicates/in_spec.rb +++ b/spec/arel/engines/sql/unit/predicates/in_spec.rb @@ -1,4 +1,4 @@ -require File.join(File.dirname(__FILE__), '..', '..', '..', '..', '..', 'spec_helper') +require 'spec_helper' module Arel describe In do diff --git a/spec/arel/engines/sql/unit/predicates/predicates_spec.rb b/spec/arel/engines/sql/unit/predicates/predicates_spec.rb index d55e178e43..fe0010a8cb 100644 --- a/spec/arel/engines/sql/unit/predicates/predicates_spec.rb +++ b/spec/arel/engines/sql/unit/predicates/predicates_spec.rb @@ -1,4 +1,4 @@ -require File.join(File.dirname(__FILE__), '..', '..', '..', '..', '..', 'spec_helper') +require 'spec_helper' module Arel describe Predicate do diff --git a/spec/arel/engines/sql/unit/primitives/attribute_spec.rb b/spec/arel/engines/sql/unit/primitives/attribute_spec.rb index 6cb72f3c19..d24b6a9d13 100644 --- a/spec/arel/engines/sql/unit/primitives/attribute_spec.rb +++ b/spec/arel/engines/sql/unit/primitives/attribute_spec.rb @@ -1,4 +1,4 @@ -require File.join(File.dirname(__FILE__), '..', '..', '..', '..', '..', 'spec_helper') +require 'spec_helper' module Arel describe Attribute do diff --git a/spec/arel/engines/sql/unit/primitives/expression_spec.rb b/spec/arel/engines/sql/unit/primitives/expression_spec.rb index ee7f2c1461..d4df4f8d5a 100644 --- a/spec/arel/engines/sql/unit/primitives/expression_spec.rb +++ b/spec/arel/engines/sql/unit/primitives/expression_spec.rb @@ -1,4 +1,4 @@ -require File.join(File.dirname(__FILE__), '..', '..', '..', '..', '..', 'spec_helper') +require 'spec_helper' module Arel describe Expression do diff --git a/spec/arel/engines/sql/unit/primitives/literal_spec.rb b/spec/arel/engines/sql/unit/primitives/literal_spec.rb index ed8bea339b..cf66a60be9 100644 --- a/spec/arel/engines/sql/unit/primitives/literal_spec.rb +++ b/spec/arel/engines/sql/unit/primitives/literal_spec.rb @@ -1,4 +1,4 @@ -require File.join(File.dirname(__FILE__), '..', '..', '..', '..', '..', 'spec_helper') +require 'spec_helper' module Arel describe SqlLiteral do diff --git a/spec/arel/engines/sql/unit/primitives/value_spec.rb b/spec/arel/engines/sql/unit/primitives/value_spec.rb index ff3533f6ef..c8f03fc270 100644 --- a/spec/arel/engines/sql/unit/primitives/value_spec.rb +++ b/spec/arel/engines/sql/unit/primitives/value_spec.rb @@ -1,4 +1,4 @@ -require File.join(File.dirname(__FILE__), '..', '..', '..', '..', '..', 'spec_helper') +require 'spec_helper' module Arel describe Value do diff --git a/spec/arel/engines/sql/unit/relations/alias_spec.rb b/spec/arel/engines/sql/unit/relations/alias_spec.rb index b67a0bbc89..55d5a9b671 100644 --- a/spec/arel/engines/sql/unit/relations/alias_spec.rb +++ b/spec/arel/engines/sql/unit/relations/alias_spec.rb @@ -1,4 +1,4 @@ -require File.join(File.dirname(__FILE__), '..', '..', '..', '..', '..', 'spec_helper') +require 'spec_helper' module Arel describe Alias do diff --git a/spec/arel/engines/sql/unit/relations/delete_spec.rb b/spec/arel/engines/sql/unit/relations/delete_spec.rb index 7a5e2b0088..0b1e2329b6 100644 --- a/spec/arel/engines/sql/unit/relations/delete_spec.rb +++ b/spec/arel/engines/sql/unit/relations/delete_spec.rb @@ -1,4 +1,4 @@ -require File.join(File.dirname(__FILE__), '..', '..', '..', '..', '..', 'spec_helper') +require 'spec_helper' module Arel describe Deletion do diff --git a/spec/arel/engines/sql/unit/relations/group_spec.rb b/spec/arel/engines/sql/unit/relations/group_spec.rb index 5e0c675c8b..703dc35be5 100644 --- a/spec/arel/engines/sql/unit/relations/group_spec.rb +++ b/spec/arel/engines/sql/unit/relations/group_spec.rb @@ -1,4 +1,4 @@ -require File.join(File.dirname(__FILE__), '..', '..', '..', '..', '..', 'spec_helper') +require 'spec_helper' module Arel describe Group do diff --git a/spec/arel/engines/sql/unit/relations/insert_spec.rb b/spec/arel/engines/sql/unit/relations/insert_spec.rb index 29a5e0bf42..1884e32a3d 100644 --- a/spec/arel/engines/sql/unit/relations/insert_spec.rb +++ b/spec/arel/engines/sql/unit/relations/insert_spec.rb @@ -1,4 +1,4 @@ -require File.join(File.dirname(__FILE__), '..', '..', '..', '..', '..', 'spec_helper') +require 'spec_helper' module Arel describe Insert do diff --git a/spec/arel/engines/sql/unit/relations/join_spec.rb b/spec/arel/engines/sql/unit/relations/join_spec.rb index f904b61870..2820763a66 100644 --- a/spec/arel/engines/sql/unit/relations/join_spec.rb +++ b/spec/arel/engines/sql/unit/relations/join_spec.rb @@ -1,4 +1,4 @@ -require File.join(File.dirname(__FILE__), '..', '..', '..', '..', '..', 'spec_helper') +require 'spec_helper' module Arel describe Join do diff --git a/spec/arel/engines/sql/unit/relations/order_spec.rb b/spec/arel/engines/sql/unit/relations/order_spec.rb index ce97a4dd5e..575e617021 100644 --- a/spec/arel/engines/sql/unit/relations/order_spec.rb +++ b/spec/arel/engines/sql/unit/relations/order_spec.rb @@ -1,4 +1,4 @@ -require File.join(File.dirname(__FILE__), '..', '..', '..', '..', '..', 'spec_helper') +require 'spec_helper' module Arel describe Order do diff --git a/spec/arel/engines/sql/unit/relations/project_spec.rb b/spec/arel/engines/sql/unit/relations/project_spec.rb index 5e29124cfa..70f2dff70a 100644 --- a/spec/arel/engines/sql/unit/relations/project_spec.rb +++ b/spec/arel/engines/sql/unit/relations/project_spec.rb @@ -1,4 +1,4 @@ -require File.join(File.dirname(__FILE__), '..', '..', '..', '..', '..', 'spec_helper') +require 'spec_helper' module Arel describe Project do diff --git a/spec/arel/engines/sql/unit/relations/skip_spec.rb b/spec/arel/engines/sql/unit/relations/skip_spec.rb index c14bd1ce95..2d606359ee 100644 --- a/spec/arel/engines/sql/unit/relations/skip_spec.rb +++ b/spec/arel/engines/sql/unit/relations/skip_spec.rb @@ -1,4 +1,4 @@ -require File.join(File.dirname(__FILE__), '..', '..', '..', '..', '..', 'spec_helper') +require 'spec_helper' module Arel describe Skip do diff --git a/spec/arel/engines/sql/unit/relations/table_spec.rb b/spec/arel/engines/sql/unit/relations/table_spec.rb index 9797b38822..26b9364929 100644 --- a/spec/arel/engines/sql/unit/relations/table_spec.rb +++ b/spec/arel/engines/sql/unit/relations/table_spec.rb @@ -1,4 +1,4 @@ -require File.join(File.dirname(__FILE__), '..', '..', '..', '..', '..', 'spec_helper') +require 'spec_helper' module Arel describe Table do diff --git a/spec/arel/engines/sql/unit/relations/take_spec.rb b/spec/arel/engines/sql/unit/relations/take_spec.rb index 8f1240fc17..2a8aea3d9d 100644 --- a/spec/arel/engines/sql/unit/relations/take_spec.rb +++ b/spec/arel/engines/sql/unit/relations/take_spec.rb @@ -1,4 +1,4 @@ -require File.join(File.dirname(__FILE__), '..', '..', '..', '..', '..', 'spec_helper') +require 'spec_helper' module Arel describe Take do diff --git a/spec/arel/engines/sql/unit/relations/update_spec.rb b/spec/arel/engines/sql/unit/relations/update_spec.rb index 4b1d824ce5..fd444e27a8 100644 --- a/spec/arel/engines/sql/unit/relations/update_spec.rb +++ b/spec/arel/engines/sql/unit/relations/update_spec.rb @@ -1,4 +1,4 @@ -require File.join(File.dirname(__FILE__), '..', '..', '..', '..', '..', 'spec_helper') +require 'spec_helper' class User def self.primary_key diff --git a/spec/arel/engines/sql/unit/relations/where_spec.rb b/spec/arel/engines/sql/unit/relations/where_spec.rb index 4f0cce1e01..8f9a8db4c7 100644 --- a/spec/arel/engines/sql/unit/relations/where_spec.rb +++ b/spec/arel/engines/sql/unit/relations/where_spec.rb @@ -1,4 +1,4 @@ -require File.join(File.dirname(__FILE__), '..', '..', '..', '..', '..', 'spec_helper') +require 'spec_helper' module Arel describe Where do -- cgit v1.2.3 From 8852db7087a8f4f98e5fd26fa33bac14a5400979 Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Mon, 14 Sep 2009 17:36:41 -0300 Subject: Cherry pick AS extensions. --- lib/arel.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/arel.rb b/lib/arel.rb index c5fa5ba903..c4069aa78e 100644 --- a/lib/arel.rb +++ b/lib/arel.rb @@ -1,3 +1,7 @@ +require 'active_support/inflector' +require 'active_support/core_ext/module/delegation' +require 'active_support/core_ext/class/attribute_accessors' + require 'active_record' require 'active_record/connection_adapters/abstract/quoting' -- cgit v1.2.3