aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--doc/TODO9
-rw-r--r--spec/arel/engines/memory/unit/relations/array_spec.rb86
-rw-r--r--spec/arel/engines/memory/unit/relations/order_spec.rb27
-rw-r--r--spec/arel/engines/memory/unit/relations/project_spec.rb27
-rw-r--r--spec/arel/engines/memory/unit/relations/skip_spec.rb26
-rw-r--r--spec/arel/engines/memory/unit/relations/take_spec.rb26
-rw-r--r--spec/arel/engines/memory/unit/relations/where_spec.rb39
7 files changed, 149 insertions, 91 deletions
diff --git a/doc/TODO b/doc/TODO
index 7af8db6bdf..2070a26efc 100644
--- a/doc/TODO
+++ b/doc/TODO
@@ -1,13 +1,12 @@
todo:
-- recursive memory operations
- reorganize memory tests
-- deal with table tests in algebra
- implement joins in memory
- result sets should be array relations
+- deal with table tests in algebra
- cross-engine joins
- blocks for joins
-- fix grouping
- implement mnesia adapter
+- fix grouping
- fix AR
- rename externalize to derived.
@@ -15,7 +14,6 @@ todo:
- audit unit coverage of algebra
- data objects
- remove all explicit aliasing
-- and/or w/ predicates
- scoped writes
- refactor adapter pattern
- break out adapters into sep modules
@@ -26,7 +24,6 @@ todo:
done:
- and/or w/ predicates
-- mock out database
. Relation <=> Relation -> InnerJoinOperation
. Relation << Relation -> LeftOuterJoinOperation
. InnerJoinOperation.on(*Predicate) -> InnerJoinRelation
@@ -77,6 +74,7 @@ done:
- test Value, in particular bind.
- test blank checks in relation.rb
- rename active_relation to arel
+- mock out database
- fix complex joining cases:
- active record query adapter
- anonymous table names
@@ -93,6 +91,7 @@ done:
- implement in memory adapter
- clean up block_given stuff
- reorganize sql tests
+- recursive memory operations
icebox:
- #bind in Attribute and Expression should be doing a descend?
diff --git a/spec/arel/engines/memory/unit/relations/array_spec.rb b/spec/arel/engines/memory/unit/relations/array_spec.rb
index 22cddf7156..4fe24c77fa 100644
--- a/spec/arel/engines/memory/unit/relations/array_spec.rb
+++ b/spec/arel/engines/memory/unit/relations/array_spec.rb
@@ -27,92 +27,6 @@ module Arel
Row.new(@relation, [3, 'goose'])
]
end
-
- describe 'where' do
- xit '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
-
- it 'filters the 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
-
- describe 'group' do
- xit 'sorts the relation with the provided ordering' do
- end
- end
-
- describe 'order' 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
-
- describe 'project' do
- it 'projects' 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
-
- describe 'skip' do
- it 'slices' do
- @relation \
- .skip(1) \
- .let do |relation|
- relation.call.should == [
- Row.new(relation, [2, 'duck']),
- Row.new(relation, [3, 'goose']),
- ]
- end
- end
- end
-
- describe 'take' do
- it 'dices' do
- @relation \
- .take(2) \
- .let do |relation|
- relation.call.should == [
- Row.new(relation, [1, 'duck']),
- Row.new(relation, [2, 'duck']),
- ]
- end
- end
- end
-
- describe 'join' do
- end
end
end
end \ No newline at end of file
diff --git a/spec/arel/engines/memory/unit/relations/order_spec.rb b/spec/arel/engines/memory/unit/relations/order_spec.rb
new file mode 100644
index 0000000000..3ecb31068b
--- /dev/null
+++ b/spec/arel/engines/memory/unit/relations/order_spec.rb
@@ -0,0 +1,27 @@
+require File.join(File.dirname(__FILE__), '..', '..', '..', '..', '..', 'spec_helper')
+
+module Arel
+ describe Order do
+ before do
+ @relation = Array.new([
+ [1, 'duck' ],
+ [2, 'duck' ],
+ [3, 'goose']
+ ], [:id, :name])
+ 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 \ No newline at end of file
diff --git a/spec/arel/engines/memory/unit/relations/project_spec.rb b/spec/arel/engines/memory/unit/relations/project_spec.rb
new file mode 100644
index 0000000000..1d1224cfdc
--- /dev/null
+++ b/spec/arel/engines/memory/unit/relations/project_spec.rb
@@ -0,0 +1,27 @@
+require File.join(File.dirname(__FILE__), '..', '..', '..', '..', '..', 'spec_helper')
+
+module Arel
+ describe Project do
+ before do
+ @relation = Array.new([
+ [1, 'duck' ],
+ [2, 'duck' ],
+ [3, 'goose']
+ ], [:id, :name])
+ 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 \ No newline at end of file
diff --git a/spec/arel/engines/memory/unit/relations/skip_spec.rb b/spec/arel/engines/memory/unit/relations/skip_spec.rb
new file mode 100644
index 0000000000..86db45ef61
--- /dev/null
+++ b/spec/arel/engines/memory/unit/relations/skip_spec.rb
@@ -0,0 +1,26 @@
+require File.join(File.dirname(__FILE__), '..', '..', '..', '..', '..', 'spec_helper')
+
+module Arel
+ describe Skip do
+ before do
+ @relation = Array.new([
+ [1, 'duck' ],
+ [2, 'duck' ],
+ [3, 'goose']
+ ], [:id, :name])
+ 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 \ No newline at end of file
diff --git a/spec/arel/engines/memory/unit/relations/take_spec.rb b/spec/arel/engines/memory/unit/relations/take_spec.rb
new file mode 100644
index 0000000000..8b774987e0
--- /dev/null
+++ b/spec/arel/engines/memory/unit/relations/take_spec.rb
@@ -0,0 +1,26 @@
+require File.join(File.dirname(__FILE__), '..', '..', '..', '..', '..', 'spec_helper')
+
+module Arel
+ describe Take do
+ before do
+ @relation = Array.new([
+ [1, 'duck' ],
+ [2, 'duck' ],
+ [3, 'goose']
+ ], [:id, :name])
+ 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 \ No newline at end of file
diff --git a/spec/arel/engines/memory/unit/relations/where_spec.rb b/spec/arel/engines/memory/unit/relations/where_spec.rb
new file mode 100644
index 0000000000..d75ee5dcbe
--- /dev/null
+++ b/spec/arel/engines/memory/unit/relations/where_spec.rb
@@ -0,0 +1,39 @@
+require File.join(File.dirname(__FILE__), '..', '..', '..', '..', '..', 'spec_helper')
+
+module Arel
+ describe Where do
+ before do
+ @relation = Array.new([
+ [1, 'duck' ],
+ [2, 'duck' ],
+ [3, 'goose']
+ ], [:id, :name])
+ 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 \ No newline at end of file