diff options
author | Ernie Miller <ernie@metautonomo.us> | 2010-03-30 15:32:39 -0400 |
---|---|---|
committer | Ernie Miller <ernie@metautonomo.us> | 2010-05-07 13:07:21 -0400 |
commit | 0433b054eebd5a53ff6c5f35383a6c0aed0015b2 (patch) | |
tree | ed07230cd0f1e033138f89e103bb2ce4cb6d6f7a /spec/shared/relation_spec.rb | |
parent | 0afcfa27c9f386ca7c190cd1f66db1cdd9971f3b (diff) | |
download | rails-0433b054eebd5a53ff6c5f35383a6c0aed0015b2.tar.gz rails-0433b054eebd5a53ff6c5f35383a6c0aed0015b2.tar.bz2 rails-0433b054eebd5a53ff6c5f35383a6c0aed0015b2.zip |
Tests for notmatches and notin, and fixes for issues found in tests
Diffstat (limited to 'spec/shared/relation_spec.rb')
-rw-r--r-- | spec/shared/relation_spec.rb | 37 |
1 files changed, 30 insertions, 7 deletions
diff --git a/spec/shared/relation_spec.rb b/spec/shared/relation_spec.rb index 1407dddb2a..dabbde2dd5 100644 --- a/spec/shared/relation_spec.rb +++ b/spec/shared/relation_spec.rb @@ -35,7 +35,7 @@ share_examples_for 'A Relation' do @relation.where(@relation[:age].eq(@pivot[@relation[:age]])).should have_rows(expected) end - it "finds rows with a not predicate" do + it "finds rows with a noteq predicate" do expected = @expected.select { |r| r[@relation[:age]] != @pivot[@relation[:age]] } @relation.where(@relation[:age].noteq(@pivot[@relation[:age]])).should have_rows(expected) end @@ -60,17 +60,40 @@ share_examples_for 'A Relation' do @relation.where(@relation[:age].gteq(@pivot[@relation[:age]])).should have_rows(expected) end - it "finds rows with a matches predicate" + it "finds rows with a matches predicate" do + expected = @expected.select { |r| r[@relation[:name]] =~ /#{@pivot[@relation[:name]]}/ } + @relation.where(@relation[:name].matches(/#{@pivot[@relation[:name]]}/)).should have_rows(expected) + end - it "finds rows with a not matches predicate" + it "finds rows with a not matches predicate" do + expected = @expected.select { |r| r[@relation[:name]] !~ /#{@pivot[@relation[:name]]}/ } + @relation.where(@relation[:name].notmatches(/#{@pivot[@relation[:name]]}/)).should have_rows(expected) + end 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) + expected = @expected.select {|r| r[@relation[:age]] >=3 && r[@relation[:age]] <= 20} + @relation.where(@relation[:age].in(3..20)).should have_rows(expected) end - it "finds rows with a not in predicate" + it "finds rows with a not in predicate" do + expected = @expected.select {|r| !(r[@relation[:age]] >=3 && r[@relation[:age]] <= 20)} + @relation.where(@relation[:age].notin(3..20)).should have_rows(expected) + end + + it "finds rows with a not predicate" do + expected = @expected.select {|r| !(r[@relation[:age]] >= 3 && r[@relation[:age]] <= 20)} + @relation.where(@relation[:age].in(3..20).not).should have_rows(expected) + end + + it "finds rows with a grouped predicate of class Any" do + expected = @expected.select {|r| [2,4,8,16].include?(r[@relation[:age]])} + @relation.where(@relation[:age].in_any([2,4], [8, 16])).should have_rows(expected) + end + + it "finds rows with a grouped predicate of class All" do + expected = @expected.select {|r| r[@relation[:name]] =~ /Name/ && r[@relation[:name]] =~ /1/} + @relation.where(@relation[:name].matches_all(/Name/, /1/)).should have_rows(expected) + end end describe "#order" do |