aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCarl Lerche <carllerche@mac.com>2010-04-03 10:40:46 -0700
committerCarl Lerche <carllerche@mac.com>2010-04-03 10:40:46 -0700
commite5454e8d8adcf53829a44702f2328f8ea119a16a (patch)
tree3735541ae1d3f452597de79208b1cf35dd114ef0
parent406fa3d37e8a531bec5646a46a7d109f6ed8c345 (diff)
downloadrails-e5454e8d8adcf53829a44702f2328f8ea119a16a.tar.gz
rails-e5454e8d8adcf53829a44702f2328f8ea119a16a.tar.bz2
rails-e5454e8d8adcf53829a44702f2328f8ea119a16a.zip
Return nil when looking up an attribute by name that does not exist instead of returning a fictitious attribute.
-rw-r--r--lib/arel/algebra/relations/relation.rb9
-rw-r--r--spec/attributes/header_spec.rb11
-rw-r--r--spec/engines/sql/unit/primitives/attribute_spec.rb19
3 files changed, 10 insertions, 29 deletions
diff --git a/lib/arel/algebra/relations/relation.rb b/lib/arel/algebra/relations/relation.rb
index ef2108dcaa..ffd31ae470 100644
--- a/lib/arel/algebra/relations/relation.rb
+++ b/lib/arel/algebra/relations/relation.rb
@@ -84,14 +84,7 @@ module Arel
module AttributeAccessable
def [](index)
- attr = attributes[index]
-
- # Handles a strange ActiveRecord case
- if !attr && (index.is_a?(String) || index.is_a?(Symbol))
- attr = Attribute.new(self, index)
- end
-
- attr
+ attributes[index]
end
def find_attribute_matching_name(name)
diff --git a/spec/attributes/header_spec.rb b/spec/attributes/header_spec.rb
index 5811041734..8fb4007003 100644
--- a/spec/attributes/header_spec.rb
+++ b/spec/attributes/header_spec.rb
@@ -18,8 +18,15 @@ module Arel
end
end
- it "finds attributes by name" do
- @relation.attributes[:name].should == Attributes::String.new(@relation, :name)
+ describe "attribute lookup" do
+ it "finds attributes by name" do
+ @relation.attributes[:name].should == Attributes::String.new(@relation, :name)
+ end
+
+ it "returns nil if no attribute is found" do
+ @relation.attributes[:does_not_exist].should be_nil
+ @relation[:does_not_exist].should be_nil
+ end
end
describe "#union" do
diff --git a/spec/engines/sql/unit/primitives/attribute_spec.rb b/spec/engines/sql/unit/primitives/attribute_spec.rb
index c467d902ad..9f864dd3a1 100644
--- a/spec/engines/sql/unit/primitives/attribute_spec.rb
+++ b/spec/engines/sql/unit/primitives/attribute_spec.rb
@@ -31,25 +31,6 @@ module Arel
end
end
end
-
- describe 'for an inexistent attribute' do
- it "manufactures sql" do
- sql = @relation[:does_not_exist].to_sql
-
- adapter_is :mysql do
- sql.should be_like(%Q{`users`.`does_not_exist`})
- end
-
- adapter_is :oracle do
- sql.should be_like(%Q{"USERS"."DOEST_NOT_EXIST"})
- end
-
- adapter_is_not :mysql, :oracle do
- sql.should be_like(%Q{"users"."does_not_exist"})
- end
- end
- end
-
end
end
end