require 'spec_helper' describe NotEqualsValidator do # Undo validations after each test before { Test.reset_callbacks(:validate) } context "without an :allow_nil key given:" do before { Test.validates :finish, not_equals: { to: :start }} let!(:test) { Test.new } context "if the attributes' values differ" do before do test.start = 2.days.ago.to_date test.finish = 1.day.ago.to_date end it "validation passes" do test.should be_valid test.errors.should be_blank end end context "if the attributes' values are equal" do before { test.start = test.finish = 1.day.ago.to_date } it "validation fails" do test.should_not be_valid test.errors.should_not be_blank end end context "if both the attributes' values aren't set" do before do test.start = nil test.finish = nil end it "validation fails" do test.should_not be_valid test.errors.should_not be_blank end end end context "with an :allow_nil option set to true:" do before { Test.validates :finish, not_equals: { to: :start, allow_nil: true }} let!(:test) { Test.new } context "if both the attributes' values aren't set" do before do test.start = nil test.finish = nil end it "validation passes" do test.should be_valid test.errors.should be_blank end end end end