Skip to content

Commit

Permalink
Failing tests for predicate matches and blank when false
Browse files Browse the repository at this point in the history
Specifying matches false for boolean attribute should generate sql
to find records with attribute = false for given db adapter

Specifying blank is false for a given attribute should generate
sql to find records with attribute not null or not blank for given
db adapter
  • Loading branch information
jeffreyiacono committed Jul 15, 2011
1 parent bcc54d7 commit 4eb7952
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
2 changes: 1 addition & 1 deletion spec/blueprints/people.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Person.blueprint do
name
salary
end
end
24 changes: 24 additions & 0 deletions spec/ransack/predicate_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,29 @@ module Ransack
@s.result.to_sql.should match /"people"."name" IS NOT NULL/
end
end

describe 'matches' do
it "generates a value LIKE 't' when true" do
@s.is_cool_matches = true
@s.result.to_sql.should match /"people"."is_cool" LIKE 't'/
end

it "generates a value LIKE 'f' when false" do
@s.is_cool_matches = false
@s.result.to_sql.should match /"people"."is_cool" LIKE 'f'/
end
end

describe 'blank' do
it "generates a value IS NULL OR ='' when true" do
@s.name_blank = true
@s.result.to_sql.should match /"people"."name" IS NULL OR "people"."name" = ''/
end

it "generates a value IS NOT NULL OR !='' when false" do
@s.name_blank = false
@s.result.to_sql.should match /"people"."name" IS NOT NULL OR "people"."name" != ''/
end
end
end
end
3 changes: 2 additions & 1 deletion spec/support/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def self.create
t.integer :parent_id
t.string :name
t.integer :salary
t.boolean :is_cool
t.timestamps
end

Expand Down Expand Up @@ -107,4 +108,4 @@ def self.create
Comment.make(:body => 'First post!', :article => Article.make(:title => 'Hello, world!'))

end
end
end

0 comments on commit 4eb7952

Please sign in to comment.