diff options
author | Carl Lerche <carllerche@mac.com> | 2010-03-12 12:51:20 -0800 |
---|---|---|
committer | Carl Lerche <carllerche@mac.com> | 2010-03-12 12:52:07 -0800 |
commit | 83c27c0b5e2e341307b7a160d831fb930a9552b4 (patch) | |
tree | fc41004d425cbc9827e82f550959ed40e8c12978 /spec | |
parent | 602722922c8365afcb3e9bed3721d61756322353 (diff) | |
download | rails-83c27c0b5e2e341307b7a160d831fb930a9552b4.tar.gz rails-83c27c0b5e2e341307b7a160d831fb930a9552b4.tar.bz2 rails-83c27c0b5e2e341307b7a160d831fb930a9552b4.zip |
Attributes should be typed
Diffstat (limited to 'spec')
10 files changed, 33 insertions, 26 deletions
diff --git a/spec/arel/algebra/integration/basic_spec.rb b/spec/arel/algebra/integration/basic_spec.rb index 84b8105f66..6ade5c40ac 100644 --- a/spec/arel/algebra/integration/basic_spec.rb +++ b/spec/arel/algebra/integration/basic_spec.rb @@ -29,8 +29,10 @@ class Thing < Arel::Relation attr_reader :engine, :attributes def initialize(engine, attributes) - @engine = engine - @attributes = attributes.map { |a| a.to_attribute(self) } + @engine, @attributes = engine, [] + attributes.each do |name, type| + @attributes << type.new(self, name) + end end def format(attribute, value) @@ -95,26 +97,31 @@ share_examples_for 'A Relation' do end end -describe "Arel::Relation" do - - before :all do - @engine = Arel::Testing::Engine.new - @relation = Thing.new(@engine, [:id, :name, :age]) - end +module Arel + describe "Relation" do - describe "..." do before :all do - @expected = (1..20).map { |i| @relation.insert([i, nil, 2 * i]) } + @engine = Testing::Engine.new + @relation = Thing.new(@engine, + :id => Attributes::Integer, + :name => Attributes::String, + :age => Attributes::Integer) end - it_should_behave_like 'A Relation' - end + describe "..." do + before :all do + @expected = (1..20).map { |i| @relation.insert([i, nil, 2 * i]) } + end - describe "#insert" do - it "inserts the row into the engine" do - @relation.insert([1, 'Foo', 10]) - @engine.rows.should == [[1, 'Foo', 10]] + it_should_behave_like 'A Relation' + end + + describe "#insert" do + it "inserts the row into the engine" do + @relation.insert([1, 'Foo', 10]) + @engine.rows.should == [[1, 'Foo', 10]] + end end - end + end end
\ No newline at end of file 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 0dfcff1ee8..606f3154c7 100644 --- a/spec/arel/engines/memory/integration/joins/cross_engine_spec.rb +++ b/spec/arel/engines/memory/integration/joins/cross_engine_spec.rb @@ -7,7 +7,7 @@ module Arel [1, 'bryan' ], [2, 'emilio' ], [3, 'nick'] - ], [:id, :name]) + ], [[:id, Attributes::Integer], [:name, Attributes::String]]) @photos = Table.new(:photos) @photos.delete @photos.insert(@photos[:id] => 1, @photos[:user_id] => 1, @photos[:camera_id] => 6) diff --git a/spec/arel/engines/memory/unit/relations/array_spec.rb b/spec/arel/engines/memory/unit/relations/array_spec.rb index 9a834148b1..dcec2afa19 100644 --- a/spec/arel/engines/memory/unit/relations/array_spec.rb +++ b/spec/arel/engines/memory/unit/relations/array_spec.rb @@ -7,7 +7,7 @@ module Arel [1, 'duck' ], [2, 'duck' ], [3, 'goose'] - ], [:id, :name]) + ], [[:id, Attributes::Integer], [:name, Attributes::String]]) end describe '#attributes' do diff --git a/spec/arel/engines/memory/unit/relations/insert_spec.rb b/spec/arel/engines/memory/unit/relations/insert_spec.rb index 222e525c7b..987e708e0b 100644 --- a/spec/arel/engines/memory/unit/relations/insert_spec.rb +++ b/spec/arel/engines/memory/unit/relations/insert_spec.rb @@ -7,7 +7,7 @@ module Arel [1, 'duck' ], [2, 'duck' ], [3, 'goose'] - ], [:id, :name]) + ], [[:id, Attributes::Integer], [:name, Attributes::String]]) end describe '#call' do diff --git a/spec/arel/engines/memory/unit/relations/join_spec.rb b/spec/arel/engines/memory/unit/relations/join_spec.rb index 112434ae1d..ed5fe89ef0 100644 --- a/spec/arel/engines/memory/unit/relations/join_spec.rb +++ b/spec/arel/engines/memory/unit/relations/join_spec.rb @@ -7,7 +7,7 @@ module Arel [1, 'duck' ], [2, 'duck' ], [3, 'goose'] - ], [:id, :name]) + ], [[:id, Attributes::Integer], [:name, Attributes::String]]) @relation2 = @relation1.alias end diff --git a/spec/arel/engines/memory/unit/relations/order_spec.rb b/spec/arel/engines/memory/unit/relations/order_spec.rb index 21d77a2a24..9546449bfb 100644 --- a/spec/arel/engines/memory/unit/relations/order_spec.rb +++ b/spec/arel/engines/memory/unit/relations/order_spec.rb @@ -7,7 +7,7 @@ module Arel [1, 'duck' ], [2, 'duck' ], [3, 'goose'] - ], [:id, :name]) + ], [[:id, Attributes::Integer], [:name, Attributes::String]]) end describe '#call' do diff --git a/spec/arel/engines/memory/unit/relations/project_spec.rb b/spec/arel/engines/memory/unit/relations/project_spec.rb index e688b93a39..92ed9fa74b 100644 --- a/spec/arel/engines/memory/unit/relations/project_spec.rb +++ b/spec/arel/engines/memory/unit/relations/project_spec.rb @@ -7,7 +7,7 @@ module Arel [1, 'duck' ], [2, 'duck' ], [3, 'goose'] - ], [:id, :name]) + ], [[:id, Attributes::Integer], [:name, Attributes::String]]) end describe '#call' do diff --git a/spec/arel/engines/memory/unit/relations/skip_spec.rb b/spec/arel/engines/memory/unit/relations/skip_spec.rb index 0c2077db80..089db24cea 100644 --- a/spec/arel/engines/memory/unit/relations/skip_spec.rb +++ b/spec/arel/engines/memory/unit/relations/skip_spec.rb @@ -7,7 +7,7 @@ module Arel [1, 'duck' ], [2, 'duck' ], [3, 'goose'] - ], [:id, :name]) + ], [[:id, Attributes::Integer], [:name, Attributes::String]]) end describe '#call' do diff --git a/spec/arel/engines/memory/unit/relations/take_spec.rb b/spec/arel/engines/memory/unit/relations/take_spec.rb index 4b08a63d22..16b99872c5 100644 --- a/spec/arel/engines/memory/unit/relations/take_spec.rb +++ b/spec/arel/engines/memory/unit/relations/take_spec.rb @@ -7,7 +7,7 @@ module Arel [1, 'duck' ], [2, 'duck' ], [3, 'goose'] - ], [:id, :name]) + ], [[:id, Attributes::Integer], [:name, Attributes::String]]) end describe '#call' do diff --git a/spec/arel/engines/memory/unit/relations/where_spec.rb b/spec/arel/engines/memory/unit/relations/where_spec.rb index 8d0af4b52d..b45c009d83 100644 --- a/spec/arel/engines/memory/unit/relations/where_spec.rb +++ b/spec/arel/engines/memory/unit/relations/where_spec.rb @@ -7,7 +7,7 @@ module Arel [1, 'duck' ], [2, 'duck' ], [3, 'goose'] - ], [:id, :name]) + ], [[:id, Attributes::Integer], [:name, Attributes::String]]) end describe '#call' do |