Skip to content

Commit

Permalink
Adding nil checks.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Coates committed Aug 1, 2011
1 parent f517d54 commit 328712b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
11 changes: 9 additions & 2 deletions lib/clortho.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,16 @@ module Clortho
module ClassMethods

def searchable(*args)
options = args.extract_options!

args.each do |arg|
key :"#{arg}_keywords", String
key :"#{arg}_keywords_array", Array
key :"#{arg}_keywords", String, default: ""
key :"#{arg}_keywords_array", Array, default: []

class_eval <<-CODE
class << self
end
CODE
end
end

Expand Down
11 changes: 10 additions & 1 deletion test/test_clortho.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def setup
save_posts
end

should 'have a all searchable fields fields' do
should 'have a all searchable fields, both as a string and array' do
@posts.each do |post|
['summary', 'body', 'title'].each do |word|
assert post.respond_to? :"#{word}_keywords"
Expand All @@ -22,6 +22,15 @@ def setup
end
end

should 'have fields that never evaluate to nil unless supplied field is nil' do
@posts.each do |post|
['summary', 'body', 'title'].each do |word|
assert !(post.send :"#{word}_keywords").nil?
assert !(post.send :"#{word}_keywords_array").nil?
end
end
end

private
def save_posts
@posts.each{ |post| post.save }
Expand Down

0 comments on commit 328712b

Please sign in to comment.