Skip to content

Commit

Permalink
Added option for #skip_in_test
Browse files Browse the repository at this point in the history
  • Loading branch information
seejohnrun committed Aug 25, 2011
1 parent 2afd8a4 commit 82ee08a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
5 changes: 5 additions & 0 deletions lib/gotcha.rb
Expand Up @@ -22,6 +22,11 @@ def self.random
end
end

def self.skip_in_test(val = nil)
@skip_in_test = !!val unless val.nil?
@skip_in_test || false
end

def self.random_type
@gotcha_types.respond_to?(:sample) ? @gotcha_types.sample : @gotcha_types[rand(@gotcha_types.size)]
end
Expand Down
2 changes: 1 addition & 1 deletion lib/gotcha/controller_helpers.rb
Expand Up @@ -8,7 +8,7 @@ def self.included(base)

# return a true / false as to whether or not *all* of the gotchas on the page validated
def gotcha_valid?(expected = 1)
return true if Rails.env.test?
return true if defined?(Rails) && Rails.env == 'test' && Gotcha.skip_in_test
@_gotcha_validated ||= determine_gotcha_validity(expected)
end

Expand Down
1 change: 0 additions & 1 deletion lib/gotcha/form_helpers.rb
Expand Up @@ -6,7 +6,6 @@ module FormHelpers
def gotcha(options = {})
options[:label_options] ||= {}
options[:text_field_options] ||= {}

if gotcha = Gotcha.random
field = "gotcha_response[#{gotcha.class.name.to_s}-#{Digest::MD5.hexdigest(gotcha.class.down_transform(gotcha.answer))}]"
(label_tag field, gotcha.question, options[:label_options]) + "\n" + (text_field_tag field, nil, options[:text_field_options])
Expand Down

0 comments on commit 82ee08a

Please sign in to comment.