Sha256: 362ee38e1bcbafa6610951b2d360bb56c4e99a102eee13b7a00156ca77015ab5

Contents?: true

Size: 1.5 KB

Versions: 3

Compression:

Stored size: 1.5 KB

Contents

require 'spec_helper'

describe "A class with active validators included" do
  subject { TestRecord }

  validators = ['Email','Url','RespondTo','Phone','Slug','Ip','CreditCard','Date','Password','Twitter'].map(&:underscore)
  validators.each do |validator|
    describe ".validates_#{validator}" do
      it "is defined" do
        subject.should respond_to("validates_#{validator}")
      end

      context "when it doesn't receive a hash with options" do
        it "calls validates #{validator} => true" do
          subject.should_receive('validates').with hash_including(validator => true)
          subject.send("validates_#{validator}")
        end

        it "calls 'validates *attributes, #{validator} => true' when fed with attributes" do
          subject.should_receive('validates').with(:attr1, :attr2, validator => true)
          subject.send("validates_#{validator}", :attr1, :attr2)
        end
      end

      context "when it receives a hash with options" do
        it "calls validates #{validator} => options" do
          subject.should_receive('validates').with hash_including(validator => {:options => :blah})
          subject.send("validates_#{validator}", :options => :blah)
        end

        it "calls 'validates *attributes, #{validator} => options' when fed with attributes" do
          subject.should_receive('validates').with(:attr1, :attr2, validator => {:options => :blah})
          subject.send("validates_#{validator}", :attr1, :attr2, :options => :blah)
        end
      end

    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
activevalidators-1.5.1 spec/activevalidators_spec.rb
activevalidators-1.5.0 spec/activevalidators_spec.rb
activevalidators-1.4.0 spec/activevalidators_spec.rb