Last active
December 17, 2015 19:19
-
-
Save delba/5659146 to your computer and use it in GitHub Desktop.
Testing validations with I18n and validators_on
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'test_helper' | |
| class QuestionTest < ActiveSupport::TestCase | |
| include ActionView::Helpers::TranslationHelper | |
| test "title is required" do | |
| question = Question.new.tap(&:valid?) | |
| assert_includes question.errors[:title], | |
| t('errors.messages.blank') | |
| end | |
| test "title is required" do | |
| validators = Question.validators_on(:title) | |
| klass = ActiveRecord::Validations::PresenceValidator | |
| refute_empty validators.grep(klass) | |
| end | |
| delegate :validators_on, to: Question | |
| test "title is required" do | |
| refute_empty validators_on(:title).grep PresenceValidator | |
| end | |
| private | |
| def self.const_missing(const) | |
| return unless const =~ /Validator\z/ | |
| ActiveRecord::Validations.const_get(const) | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment