aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorCarl Lerche <carllerche@mac.com>2010-04-02 19:04:23 -0700
committerCarl Lerche <carllerche@mac.com>2010-04-02 19:04:23 -0700
commita46922e4a1089c9880c30b389e1e1d9dfbab02ae (patch)
tree2115e291ff1799d662bbb445b96060f2d029cc0d /spec
parent233ee77f4511255ff2ff7c0b0ebf1cee13e7fc10 (diff)
downloadrails-a46922e4a1089c9880c30b389e1e1d9dfbab02ae.tar.gz
rails-a46922e4a1089c9880c30b389e1e1d9dfbab02ae.tar.bz2
rails-a46922e4a1089c9880c30b389e1e1d9dfbab02ae.zip
Create an Arel::Header class representing a relation's attributes
Diffstat (limited to 'spec')
-rw-r--r--spec/algebra/unit/relations/join_spec.rb3
-rw-r--r--spec/algebra/unit/relations/table_spec.rb2
-rw-r--r--spec/attributes/header_spec.rb35
-rw-r--r--spec/support/matchers/be_like.rb6
-rw-r--r--spec/support/model.rb6
5 files changed, 45 insertions, 7 deletions
diff --git a/spec/algebra/unit/relations/join_spec.rb b/spec/algebra/unit/relations/join_spec.rb
index 9c1422c571..5fa3269052 100644
--- a/spec/algebra/unit/relations/join_spec.rb
+++ b/spec/algebra/unit/relations/join_spec.rb
@@ -18,8 +18,7 @@ module Arel
describe '#attributes' do
it 'combines the attributes of the two relations' do
join = InnerJoin.new(@relation1, @relation2, @predicate)
- join.attributes.should ==
- (@relation1.attributes + @relation2.attributes).collect { |a| a.bind(join) }
+ join.attributes.should == (@relation1.attributes | @relation2.attributes).bind(join)
end
end
end
diff --git a/spec/algebra/unit/relations/table_spec.rb b/spec/algebra/unit/relations/table_spec.rb
index d93446f1b9..d1c7cc46ba 100644
--- a/spec/algebra/unit/relations/table_spec.rb
+++ b/spec/algebra/unit/relations/table_spec.rb
@@ -9,7 +9,7 @@ module Arel
describe '[]' do
describe 'when given a', Symbol do
it "manufactures an attribute if the symbol names an attribute within the relation" do
- check @relation[:id].should == Attribute.new(@relation, :id)
+ check @relation[:id].should == Attributes::Integer.new(@relation, :id)
end
end
diff --git a/spec/attributes/header_spec.rb b/spec/attributes/header_spec.rb
new file mode 100644
index 0000000000..5811041734
--- /dev/null
+++ b/spec/attributes/header_spec.rb
@@ -0,0 +1,35 @@
+require 'spec_helper'
+
+module Arel
+ describe "Header" do
+ before :all do
+ @relation = Model.build do |r|
+ r.attribute :id, Attributes::Integer
+ r.attribute :name, Attributes::String
+ r.attribute :age, Attributes::Integer
+ end
+
+ @other = Model.build do |r|
+ r.attribute :foo, Attributes::String
+ end
+
+ @subset = Model.build do |r|
+ r.attribute :id, Attributes::Integer
+ end
+ end
+
+ it "finds attributes by name" do
+ @relation.attributes[:name].should == Attributes::String.new(@relation, :name)
+ end
+
+ describe "#union" do
+ it "keeps all attributes from disjoint headers" do
+ (@relation.attributes.union @other.attributes).to_ary.should have(4).items
+ end
+
+ it "keeps all attributes from both relations even if they seem like subsets" do
+ (@relation.attributes.union @subset.attributes).to_ary.should have(4).items
+ end
+ end
+ end
+end \ No newline at end of file
diff --git a/spec/support/matchers/be_like.rb b/spec/support/matchers/be_like.rb
index 0608abbbb4..ca49b91274 100644
--- a/spec/support/matchers/be_like.rb
+++ b/spec/support/matchers/be_like.rb
@@ -1,12 +1,12 @@
module Matchers
class BeLike
def initialize(expected)
- @expected = expected
+ @expected = expected.gsub(/\s+/, ' ').strip
end
def matches?(actual)
- @actual = actual
- @expected.gsub(/\s+/, ' ').strip == @actual.gsub(/\s+/, ' ').strip
+ @actual = actual.gsub(/\s+/, ' ').strip
+ @expected == @actual
end
def failure_message
diff --git a/spec/support/model.rb b/spec/support/model.rb
index 10a14d7092..be692e53ec 100644
--- a/spec/support/model.rb
+++ b/spec/support/model.rb
@@ -25,7 +25,7 @@ module Arel
class Model
include Relation
- attr_reader :engine, :attributes
+ attr_reader :engine
def self.build
relation = new
@@ -46,6 +46,10 @@ module Arel
@attributes << type.new(self, name)
end
+ def attributes
+ Header.new(@attributes)
+ end
+
def format(attribute, value)
value
end