diff options
author | Carl Lerche <carllerche@mac.com> | 2010-03-12 14:46:37 -0800 |
---|---|---|
committer | Carl Lerche <carllerche@mac.com> | 2010-03-12 14:46:37 -0800 |
commit | e13420c86afb5c31e90cff800f121bd49255b939 (patch) | |
tree | 7089d188061b2a676143add52227e107a5cf9b45 /spec/engines/memory/unit/relations | |
parent | 0b8b87fb947a746d4e58d11ea73ef20cfb23f576 (diff) | |
download | rails-e13420c86afb5c31e90cff800f121bd49255b939.tar.gz rails-e13420c86afb5c31e90cff800f121bd49255b939.tar.bz2 rails-e13420c86afb5c31e90cff800f121bd49255b939.zip |
We're obviously writing specs for arel. No need for a sub directory.
Diffstat (limited to 'spec/engines/memory/unit/relations')
-rw-r--r-- | spec/engines/memory/unit/relations/array_spec.rb | 32 | ||||
-rw-r--r-- | spec/engines/memory/unit/relations/insert_spec.rb | 28 | ||||
-rw-r--r-- | spec/engines/memory/unit/relations/join_spec.rb | 31 | ||||
-rw-r--r-- | spec/engines/memory/unit/relations/order_spec.rb | 27 | ||||
-rw-r--r-- | spec/engines/memory/unit/relations/project_spec.rb | 27 | ||||
-rw-r--r-- | spec/engines/memory/unit/relations/skip_spec.rb | 26 | ||||
-rw-r--r-- | spec/engines/memory/unit/relations/take_spec.rb | 26 | ||||
-rw-r--r-- | spec/engines/memory/unit/relations/where_spec.rb | 39 |
8 files changed, 236 insertions, 0 deletions
diff --git a/spec/engines/memory/unit/relations/array_spec.rb b/spec/engines/memory/unit/relations/array_spec.rb new file mode 100644 index 0000000000..dcec2afa19 --- /dev/null +++ b/spec/engines/memory/unit/relations/array_spec.rb @@ -0,0 +1,32 @@ +require 'spec_helper' + +module Arel + describe Array do + before do + @relation = Array.new([ + [1, 'duck' ], + [2, 'duck' ], + [3, 'goose'] + ], [[:id, Attributes::Integer], [:name, Attributes::String]]) + end + + describe '#attributes' do + it 'manufactures attributes corresponding to the names given on construction' do + @relation.attributes.should == [ + Attribute.new(@relation, :id), + Attribute.new(@relation, :name) + ] + end + end + + describe '#call' do + it "manufactures an array of hashes of attributes to values" do + @relation.call.should == [ + Row.new(@relation, [1, 'duck']), + Row.new(@relation, [2, 'duck']), + Row.new(@relation, [3, 'goose']) + ] + end + end + end +end diff --git a/spec/engines/memory/unit/relations/insert_spec.rb b/spec/engines/memory/unit/relations/insert_spec.rb new file mode 100644 index 0000000000..987e708e0b --- /dev/null +++ b/spec/engines/memory/unit/relations/insert_spec.rb @@ -0,0 +1,28 @@ +require 'spec_helper' + +module Arel + describe Insert do + before do + @relation = Array.new([ + [1, 'duck' ], + [2, 'duck' ], + [3, 'goose'] + ], [[:id, Attributes::Integer], [:name, Attributes::String]]) + end + + describe '#call' do + it "manufactures an array of hashes of attributes to values" do + @relation \ + .insert(@relation[:id] => 4, @relation[:name] => '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 + end +end diff --git a/spec/engines/memory/unit/relations/join_spec.rb b/spec/engines/memory/unit/relations/join_spec.rb new file mode 100644 index 0000000000..ed5fe89ef0 --- /dev/null +++ b/spec/engines/memory/unit/relations/join_spec.rb @@ -0,0 +1,31 @@ +require 'spec_helper' + +module Arel + describe Join do + before do + @relation1 = Array.new([ + [1, 'duck' ], + [2, 'duck' ], + [3, 'goose'] + ], [[:id, Attributes::Integer], [:name, Attributes::String]]) + @relation2 = @relation1.alias + end + + describe InnerJoin do + describe '#call' do + it 'combines the two tables where the predicate obtains' do + @relation1 \ + .join(@relation2) \ + .on(@relation1[:id].eq(@relation2[:id])) \ + .let do |relation| + relation.call.should == [ + Row.new(relation, [1, 'duck', 1, 'duck' ]), + Row.new(relation, [2, 'duck', 2, 'duck' ]), + Row.new(relation, [3, 'goose', 3, 'goose']) + ] + end + end + end + end + end +end diff --git a/spec/engines/memory/unit/relations/order_spec.rb b/spec/engines/memory/unit/relations/order_spec.rb new file mode 100644 index 0000000000..9546449bfb --- /dev/null +++ b/spec/engines/memory/unit/relations/order_spec.rb @@ -0,0 +1,27 @@ +require 'spec_helper' + +module Arel + describe Order do + before do + @relation = Array.new([ + [1, 'duck' ], + [2, 'duck' ], + [3, 'goose'] + ], [[:id, Attributes::Integer], [:name, Attributes::String]]) + end + + describe '#call' do + it 'sorts the relation with the provided ordering' do + @relation \ + .order(@relation[:id].desc) \ + .let do |relation| + relation.call.should == [ + Row.new(relation, [3, 'goose']), + Row.new(relation, [2, 'duck' ]), + Row.new(relation, [1, 'duck' ]) + ] + end + end + end + end +end diff --git a/spec/engines/memory/unit/relations/project_spec.rb b/spec/engines/memory/unit/relations/project_spec.rb new file mode 100644 index 0000000000..92ed9fa74b --- /dev/null +++ b/spec/engines/memory/unit/relations/project_spec.rb @@ -0,0 +1,27 @@ +require 'spec_helper' + +module Arel + describe Project do + before do + @relation = Array.new([ + [1, 'duck' ], + [2, 'duck' ], + [3, 'goose'] + ], [[:id, Attributes::Integer], [:name, Attributes::String]]) + end + + describe '#call' do + it 'retains only the attributes that are provided' do + @relation \ + .project(@relation[:id]) \ + .let do |relation| + relation.call.should == [ + Row.new(relation, [1]), + Row.new(relation, [2]), + Row.new(relation, [3]) + ] + end + end + end + end +end diff --git a/spec/engines/memory/unit/relations/skip_spec.rb b/spec/engines/memory/unit/relations/skip_spec.rb new file mode 100644 index 0000000000..089db24cea --- /dev/null +++ b/spec/engines/memory/unit/relations/skip_spec.rb @@ -0,0 +1,26 @@ +require 'spec_helper' + +module Arel + describe Skip do + before do + @relation = Array.new([ + [1, 'duck' ], + [2, 'duck' ], + [3, 'goose'] + ], [[:id, Attributes::Integer], [:name, Attributes::String]]) + end + + describe '#call' do + it 'removes the first n rows' do + @relation \ + .skip(1) \ + .let do |relation| + relation.call.should == [ + Row.new(relation, [2, 'duck']), + Row.new(relation, [3, 'goose']), + ] + end + end + end + end +end diff --git a/spec/engines/memory/unit/relations/take_spec.rb b/spec/engines/memory/unit/relations/take_spec.rb new file mode 100644 index 0000000000..16b99872c5 --- /dev/null +++ b/spec/engines/memory/unit/relations/take_spec.rb @@ -0,0 +1,26 @@ +require 'spec_helper' + +module Arel + describe Take do + before do + @relation = Array.new([ + [1, 'duck' ], + [2, 'duck' ], + [3, 'goose'] + ], [[:id, Attributes::Integer], [:name, Attributes::String]]) + end + + describe '#call' do + it 'removes the rows after the first n' do + @relation \ + .take(2) \ + .let do |relation| + relation.call.should == [ + Row.new(relation, [1, 'duck']), + Row.new(relation, [2, 'duck']), + ] + end + end + end + end +end diff --git a/spec/engines/memory/unit/relations/where_spec.rb b/spec/engines/memory/unit/relations/where_spec.rb new file mode 100644 index 0000000000..b45c009d83 --- /dev/null +++ b/spec/engines/memory/unit/relations/where_spec.rb @@ -0,0 +1,39 @@ +require 'spec_helper' + +module Arel + describe Where do + before do + @relation = Array.new([ + [1, 'duck' ], + [2, 'duck' ], + [3, 'goose'] + ], [[:id, Attributes::Integer], [:name, Attributes::String]]) + end + + describe '#call' do + it 'filters the relation with the provided predicate' do + @relation \ + .where(@relation[:id].lt(3)) \ + .let do |relation| + relation.call.should == [ + Row.new(relation, [1, 'duck']), + Row.new(relation, [2, 'duck']), + ] + end + end + + describe 'when filtering a where relation' do + it 'further filters the already-filtered relation with the provided predicate' do + @relation \ + .where(@relation[:id].gt(1)) \ + .where(@relation[:id].lt(3)) \ + .let do |relation| + relation.call.should == [ + Row.new(relation, [2, 'duck']) + ] + end + end + end + end + end +end |