diff options
author | Nick Kallen <nkallen@nick-kallens-computer-2.local> | 2008-04-12 17:45:36 -0700 |
---|---|---|
committer | Nick Kallen <nkallen@nick-kallens-computer-2.local> | 2008-04-12 17:45:36 -0700 |
commit | 2f9b70b6179d0b66f80d6edd3eca1017aec70659 (patch) | |
tree | 03bbdfe9b30b245ac40fb04b4178ea65bd7fb2ce /lib | |
parent | 97f89cde2af330771d0df80491e718f8b0cb7dd6 (diff) | |
download | rails-2f9b70b6179d0b66f80d6edd3eca1017aec70659.tar.gz rails-2f9b70b6179d0b66f80d6edd3eca1017aec70659.tar.bz2 rails-2f9b70b6179d0b66f80d6edd3eca1017aec70659.zip |
better test coverage of relational operations with blank data
Diffstat (limited to 'lib')
-rw-r--r-- | lib/active_relation/relations.rb | 1 | ||||
-rw-r--r-- | lib/active_relation/relations/relation.rb | 14 | ||||
-rw-r--r-- | lib/active_relation/relations/rename.rb | 26 |
3 files changed, 6 insertions, 35 deletions
diff --git a/lib/active_relation/relations.rb b/lib/active_relation/relations.rb index 240c20736e..9cede2a6d1 100644 --- a/lib/active_relation/relations.rb +++ b/lib/active_relation/relations.rb @@ -10,7 +10,6 @@ require 'active_relation/relations/selection' require 'active_relation/relations/order' require 'active_relation/relations/take' require 'active_relation/relations/skip' -require 'active_relation/relations/rename' require 'active_relation/relations/deletion' require 'active_relation/relations/insertion' require 'active_relation/relations/update' diff --git a/lib/active_relation/relations/relation.rb b/lib/active_relation/relations/relation.rb index f5f2809724..b62a5d9fb9 100644 --- a/lib/active_relation/relations/relation.rb +++ b/lib/active_relation/relations/relation.rb @@ -18,12 +18,14 @@ module ActiveRelation include Enumerable module Operations - def join(other) + def join(other = nil) case other when String Join.new(other, self) when Relation JoinOperation.new("INNER JOIN", self, other) + else + self end end @@ -48,7 +50,7 @@ module ActiveRelation attributes.all?(&:blank?) ? self : Projection.new(self, *attributes) end - def as(aliaz) + def as(aliaz = nil) aliaz.blank?? self : Alias.new(self, aliaz) end @@ -56,18 +58,14 @@ module ActiveRelation attributes.all?(&:blank?) ? self : Order.new(self, *attributes) end - def take(taken) + def take(taken = nil) taken.blank?? self : Take.new(self, taken) end - def skip(skipped) + def skip(skipped = nil) skipped.blank?? self : Skip.new(self, skipped) end - def rename(attribute, aliaz) - Rename.new(self, attribute => aliaz) - end - def aggregate(*expressions) AggregateOperation.new(self, expressions) end diff --git a/lib/active_relation/relations/rename.rb b/lib/active_relation/relations/rename.rb deleted file mode 100644 index 9ab07707a0..0000000000 --- a/lib/active_relation/relations/rename.rb +++ /dev/null @@ -1,26 +0,0 @@ -module ActiveRelation - class Rename < Compound - attr_reader :attribute, :pseudonym - - def initialize(relation, pseudonyms) - @attribute, @pseudonym = pseudonyms.shift - @relation = pseudonyms.empty?? relation : Rename.new(relation, pseudonyms) - end - - def ==(other) - self.class == other.class and - relation == other.relation and - attribute == other.attribute and - pseudonym == other.pseudonym - end - - def attributes - relation.attributes.collect(&method(:christen)) - end - - private - def christen(attribute) - (attribute =~ self.attribute ? attribute.as(pseudonym) : attribute).bind(self) rescue nil - end - end -end
\ No newline at end of file |