Permalink
Browse files

Added skip_validation?

  • Loading branch information...
1 parent 868d7d1 commit 10e03ce3081054aeedbe2df9e3ce7fc5283b0cb0 @seejohnrun committed Aug 25, 2011
Showing with 13 additions and 4 deletions.
  1. +4 −0 README.md
  2. +8 −3 lib/gotcha.rb
  3. +1 −1 lib/gotcha/controller_helpers.rb
View
@@ -105,6 +105,10 @@ In an initializer:
You have a few ways to determine whether or not a Gotcha was valid. You can use `gotcha_valid?` in views and controllers, or use `validate_gotcha!` (which throws a `Gotcha::ValidationException` if the Gotcha was not valid) in your controllers.
+## Testing
+
+In testing, it's sometimes useful to make validation always return true. For this, you can use: `Gotcha.skip_validation = true`
+
---
## License
View
@@ -22,9 +22,14 @@ def self.random
end
end
- def self.skip_in_test(val = nil)
- @skip_in_test = !!val unless val.nil?
- @skip_in_test || false
+ # Whether or not to skip validation
+ def self.skip_validation?
+ @skip_validation || false
+ end
+
+ # Set whether or not to skip validation
+ def self.skip_validation=(val)
+ @skip_validation = !!val
end
def self.random_type
@@ -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 defined?(Rails) && Rails.env == 'test' && Gotcha.skip_in_test
+ return true if Gotcha.skip_validation?
@_gotcha_validated ||= determine_gotcha_validity(expected)
end

0 comments on commit 10e03ce

Please sign in to comment.