Skip to content
This repository was archived by the owner on Apr 17, 2018. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions spec/unit/validators/block_validator_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
require 'spec_helper'

describe 'DataMapper::Validations::ValidatesWithBlock' do
describe "#validates_with_block" do
let(:klass) {
Class.new do
include DataMapper::Resource
property :id, DataMapper::Property::Serial
property :name, String
validates_with_block(:name, :when => [ :adding ]) do
if ( name == "Special")
[false, "fail"]
else
true
end
end
end
}
subject {klass.new}
context "when validate in a common situation" do
it "should be valid" do
subject.name = "Special"
subject.should be_valid
end
end
context "when validate in a adding" do
it "should be valid" do
subject.name = "Special"
subject.should_not be_valid(:adding)
end
end
end
end