Sha256: d893291038601c8178acb917ba76999d8a522686d21792a8a9bf2143702e6528

Contents?: true

Size: 1.64 KB

Versions: 1

Compression:

Stored size: 1.64 KB

Contents

require 'validates_formatting_of/validation_addition'

module ValidatesFormattingOf

  class TestAdding
    extend ValidationAddition
  end

  describe ValidationAddition do
    before do
      TestAdding.add :email, /email/i
    end
    after do
      TestAdding.instance_variable_set("@validations", nil)
    end
    it "should be able to add new validations" do
      TestAdding.add :another, /another/i
      TestAdding.validations.count.should == 2
      TestAdding.validations[:email].should be_instance_of Validation
      TestAdding.validations[:another].should be_instance_of Validation
    end
    it "should be able to smartly determine the method to use" do
      validation = TestAdding.find(:email)
      validation.name.should == :email
      validation.regex.should == /email/i
      validation = TestAdding.find(:non_existent_validation, :using => :email)
      validation.name.should == :email
      validation.regex.should == /email/i
    end
    it "should raise an error if the method does not exist" do
      expect { TestAdding.find(:fake) }.to raise_error MissingValidation
    end
    it "should be able to determine if the method does not exist" do
      TestAdding.exists?(:email).should be_true
      TestAdding.exists?(:non_existent).should be_false
    end
    it "should be able to accept strings for validation names (for namespacing)" do
      TestAdding.add "namespace:phone", /namespace/i
      TestAdding.exists?("namespace:phone").should be_true
    end
    it "should be able to determine if the method is missing" do
      TestAdding.missing?(:non_existent).should be_true
      TestAdding.missing?(:email).should be_false
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
validates_formatting_of-0.7.0 spec/validates_formatting_of/validation_addition_spec.rb