Skip to content

Instantly share code, notes, and snippets.

@delba
Created June 30, 2013 18:40
Show Gist options
  • Select an option

  • Save delba/5896337 to your computer and use it in GitHub Desktop.

Select an option

Save delba/5896337 to your computer and use it in GitHub Desktop.
Delegate constant lookup
require 'test_helper'
class ArticleTest < ActiveSupport::TestCase
delegate :validators_on, to: Article
test "validates presence of title" do
refute_emtpy 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