aboutsummaryrefslogtreecommitdiffstats
path: root/spec/algebra
diff options
context:
space:
mode:
authorCarl Lerche <carllerche@mac.com>2010-03-12 16:38:36 -0800
committerCarl Lerche <carllerche@mac.com>2010-03-12 16:38:36 -0800
commit3ab6ae0c601d1b4459efd8bb39650fee370aa5b8 (patch)
tree7ec7bb6ab71094cca2b61190728efb2e0c2e1497 /spec/algebra
parent0e6888232a19c8c59416490d3da6079e590fab77 (diff)
downloadrails-3ab6ae0c601d1b4459efd8bb39650fee370aa5b8.tar.gz
rails-3ab6ae0c601d1b4459efd8bb39650fee370aa5b8.tar.bz2
rails-3ab6ae0c601d1b4459efd8bb39650fee370aa5b8.zip
Organize the matchers a bit more
Diffstat (limited to 'spec/algebra')
-rw-r--r--spec/algebra/integration/basic_spec.rb87
1 files changed, 0 insertions, 87 deletions
diff --git a/spec/algebra/integration/basic_spec.rb b/spec/algebra/integration/basic_spec.rb
index e48f94625d..ae9da3a037 100644
--- a/spec/algebra/integration/basic_spec.rb
+++ b/spec/algebra/integration/basic_spec.rb
@@ -1,93 +1,7 @@
require 'spec_helper'
-def have_rows(expected)
- simple_matcher "have rows" do |given, matcher|
- found, got, expected = [], [], expected.map { |r| r.tuple }
- given.each do |row|
- got << row.tuple
- found << expected.find { |r| row.tuple == r }
- end
-
- matcher.failure_message = "Expected to get:\n" \
- "#{expected.map {|r| " #{r.inspect}" }.join("\n")}\n" \
- "instead, got:\n" \
- "#{got.map {|r| " #{r.inspect}" }.join("\n")}"
-
- found.compact.length == expected.length && got.compact.length == expected.length
- end
-end
-
-share_examples_for 'A Relation' do
-
- before :all do
- # The two needed instance variables need to be set in a
- # before :all callback.
- # @relation is the relation being tested here.
- # @expected is an array of the elements that are expected to be in
- # the relation.
- %w[ @relation @expected ].each do |ivar|
- raise "#{ivar} needs to be defined" unless instance_variable_get(ivar)
- end
-
- # There needs to be enough items to be able to run all the tests
- raise "@expected needs to have at least 6 items" unless @expected.length >= 6
- end
-
- describe "#each" do
- it "iterates over the rows in any order" do
- @relation.should have_rows(@expected)
- end
- end
-
- describe "#where" do
- before :all do
- @expected = @expected.sort_by { |r| r[@relation[:age]] }
- @pivot = @expected[@expected.length / 2]
- end
-
- it "finds rows with an equal to predicate" do
- expected = @expected.select { |r| r[@relation[:age]] == @pivot[@relation[:age]] }
- @relation.where(@relation[:age].eq(@pivot[@relation[:age]])).should have_rows(expected)
- end
-
- it "finds rows with a not predicate" do
- expected = @expected.select { |r| r[@relation[:age]] != @pivot[@relation[:age]] }
- @relation.where(@relation[:age].not(@pivot[@relation[:age]])).should have_rows(expected)
- end
-
- it "finds rows with a less than predicate" do
- expected = @expected.select { |r| r[@relation[:age]] < @pivot[@relation[:age]] }
- @relation.where(@relation[:age].lt(@pivot[@relation[:age]])).should have_rows(expected)
- end
-
- it "finds rows with a less than or equal to predicate" do
- expected = @expected.select { |r| r[@relation[:age]] <= @pivot[@relation[:age]] }
- @relation.where(@relation[:age].lteq(@pivot[@relation[:age]])).should have_rows(expected)
- end
-
- it "finds rows with a greater than predicate" do
- expected = @expected.select { |r| r[@relation[:age]] > @pivot[@relation[:age]] }
- @relation.where(@relation[:age].gt(@pivot[@relation[:age]])).should have_rows(expected)
- end
-
- it "finds rows with a greater than or equal to predicate" do
- expected = @expected.select { |r| r[@relation[:age]] >= @pivot[@relation[:age]] }
- @relation.where(@relation[:age].gteq(@pivot[@relation[:age]])).should have_rows(expected)
- end
-
- it "finds rows with a matches predicate"
-
- it "finds rows with an in predicate" do
- pending
- set = @expected[1..(@expected.length/2+1)]
- @relation.all(:id.in => set.map { |r| r.id }).should have_resources(set)
- end
- end
-end
-
module Arel
describe "Relation" do
-
before :all do
@engine = Testing::Engine.new
@relation = Model.build do |r|
@@ -113,6 +27,5 @@ module Arel
@engine.rows.should == [[1, 'Foo', 10]]
end
end
-
end
end \ No newline at end of file