specs for validations

git-svn-id: https://dev.finn.de/svn/cockpit/branches/deployment_merge@2090 7926756e-e54e-46e6-9721-ed318f58905e
pull/6827/head
j.wollert 14 years ago
parent bcc97e1bf3
commit 8186cd1217
  1. 58
      spec/models/cost_query/validation_spec.rb
  2. 4
      spec/spec_helper.rb

@ -0,0 +1,58 @@
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
describe CostQuery::Validation do
class SomeBase
include CostQuery::Validation
end
it "should be valid with no validations whatsoever" do
obj = SomeBase.new
obj.validate("foo").should be_true
obj.validations.size.should == 0
end
it "should allow for multiple validations" do
obj = SomeBase.new
obj.register_validations([:integers, :dates])
obj.validations.size.should == 2
end
it "should have errors set when we try to validate something invalid" do
obj = SomeBase.new
obj.register_validation(:integers)
obj.validate("this ain't a number, right?").should be_false
obj.errors.size.should == 1
end
it "should have no errors set when we try to validate something valid" do
obj = SomeBase.new
obj.register_validation(:integers)
obj.validate(1,2,3,4).should be_true
obj.errors.size.should == 0
end
it "should validate integers correctly" do
obj = SomeBase.new
obj.register_validation(:integers)
obj.validate(1,2,3,4).should be_true
obj.errors.size.should == 0
obj.validate("I ain't gonna work on Maggies Farm no more").should be_false
obj.errors.size.should == 1
obj.validate("You've got the touch!", "You've got the power!").should be_false
obj.errors.size.should == 2
obj.validate(1, "This is a good burger").should be_false
obj.errors.size.should == 1
end
it "should validate dates correctly" do
obj = SomeBase.new
obj.register_validation(:dates)
obj.validate("2010-04-15").should be_true
obj.errors.size.should == 0
obj.validate("2010-15-15").should be_false
obj.errors.size.should == 1
obj.validate("2010-04-31").should be_false
obj.errors.size.should == 1
end
end

@ -22,6 +22,10 @@ rescue LoadError => error
raise error
end
def l(*args)
I18n.t(*args)
end
Fixtures.create_fixtures File.join(File.dirname(__FILE__), "fixtures"), ActiveRecord::Base.connection.tables
require File.join(RAILS_ROOT, "test", "object_daddy_helpers.rb")
Dir.glob(File.expand_path("#{__FILE__}/../../../redmine_costs/test/exemplars/*.rb")) { |e| require e }

Loading…
Cancel
Save