Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
adding diff => != for single fields
  • Loading branch information
andersonleite committed Oct 5, 2010
1 parent c159c6a commit 76b659e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 4 additions & 0 deletions lib/relata/dsl/field_search.rb
Expand Up @@ -10,6 +10,10 @@ def ==(value)
@rel.where("#{@field} == ?", value)
end

def !=(value)
@rel.where("#{@field} <> ?", value)
end

def >=(value)
@rel.where("#{@field} >= ?", value)
end
Expand Down
8 changes: 7 additions & 1 deletion test/dsl_test.rb
Expand Up @@ -128,12 +128,18 @@ class DSLTest < ActiveSupport::TestCase
end

test "supports == with simple field" do
@caelum.update_attributes(:comments => [Comment.create, Comment.create])
posts = Post.where { body == "CaelumObjects training and inovation" }
assert_equal @caelum, posts[0]
assert_equal 1, posts.size
end

test "supports != with simple field" do
posts = Post.where { body != "diff" }
assert_equal @caelum, posts[0]
assert_equal @guilherme, posts[1]
assert_equal 2, posts.size
end

test "accepts two conditions one after the other" do
@caelum.update_attributes :published_at => 1.year.ago
@guilherme.update_attributes :published_at => 1.year.ago
Expand Down

0 comments on commit 76b659e

Please sign in to comment.