| |   |
| 12 | 12 | end |
| 13 | 13 | |
| 14 | 14 | def erroneous_stuff |
| 15 | | Meta.new do |
| 15 | Meta.new(:name => "ErroneousStuff") do |
| 16 | 16 | on_validation do |doc| |
| 17 | 17 | doc.errors.add(:something, "123") |
| 18 | 18 | doc.errors.add(:other, "456") |
| … | … | |
| 383 | 383 | end |
| 384 | 384 | |
| 385 | 385 | it "should treat accepted value as valid" do |
| 386 | | Meta.new { validates_acceptance_of :eula, :accept => "yep" }.new(:eula => "yep").should be_valid |
| 386 | Meta.new(:name => 'some') { validates_acceptance_of :eula, :accept => "yep" }.new(:eula => "yep").should be_valid |
| 387 | 387 | end |
| 388 | 388 | |
| 389 | 389 | it "should treat not accepted value as invalid" do |
| 390 | | Meta.new { validates_acceptance_of :eula, :accept => "yep" }.new(:eula => "nope").should_not be_valid |
| 390 | Meta.new(:name => 'some') { validates_acceptance_of :eula, :accept => "yep" }.new(:eula => "nope").should_not be_valid |
| 391 | 391 | end |
| 392 | 392 | |
| 393 | 393 | it "should respect allow_nil" do |
| 394 | | Meta.new { validates_acceptance_of :eula, :accept => "yep", :allow_nil => true }.new.should be_valid |
| 395 | | Meta.new { validates_acceptance_of :eula, :accept => "yep", :allow_nil => false }.new.should_not be_valid |
| 394 | Meta.new(:name => 'some') { validates_acceptance_of :eula, :accept => "yep", :allow_nil => true }.new.should be_valid |
| 395 | Meta.new(:name => 'some') { validates_acceptance_of :eula, :accept => "yep", :allow_nil => false }.new.should_not be_valid |
| 396 | 396 | end |
| 397 | 397 | |
| 398 | 398 | it "should set :allow_nil to true by default" do |
| 399 | | Meta.new { validates_acceptance_of :eula, :accept => "yep" }.new.should be_valid |
| 399 | Meta.new(:name => 'some') { validates_acceptance_of :eula, :accept => "yep" }.new.should be_valid |
| 400 | 400 | end |
| 401 | 401 | |
| 402 | 402 | it "should set :accept to \"1\" by default" do |
| 403 | | Meta.new { validates_acceptance_of :eula }.new(:eula => "1").should be_valid |
| 403 | Meta.new(:name => 'some') { validates_acceptance_of :eula }.new(:eula => "1").should be_valid |
| 404 | 404 | end |
| 405 | 405 | |
| 406 | 406 | it "should make a slot virtual" do |
| 407 | | Foo = Meta.new { validates_acceptance_of :eula, :accept => "yep" } |
| 407 | Foo = Meta.new{ validates_acceptance_of :eula, :accept => "yep" } |
| 408 | 408 | f = Foo.create!(:eula => "yep") |
| 409 | 409 | Foo.find(f.uuid).has_slot?("eula").should_not be_true |
| 410 | 410 | end |
| … | … | |
| 417 | 417 | |
| 418 | 418 | describe "options handling" do |
| 419 | 419 | it "should raise ArgumentError when more than one range option is specified" do |
| 420 | | arg_bang { Meta.new { validates_length_of :name, :is => 10, :maximum => 20 } } |
| 421 | | arg_bang { Meta.new { validates_length_of :name, :is => 10, :within => 1..20 } } |
| 420 | arg_bang { Meta.new(:name => 'some') { validates_length_of :name, :is => 10, :maximum => 20 } } |
| 421 | arg_bang { Meta.new(:name => 'some') { validates_length_of :name, :is => 10, :within => 1..20 } } |
| 422 | 422 | end |
| 423 | 423 | |
| 424 | 424 | it "should raise ArgumentError when no range option is specified" do |
| 425 | | arg_bang { Meta.new { validates_length_of :name } } |
| 425 | arg_bang { Meta.new(:name => 'some') { validates_length_of :name } } |
| 426 | 426 | end |
| 427 | 427 | |
| 428 | 428 | it "should raise ArgumentError when not Range given to :in or :within" do |
| 429 | | arg_bang { Meta.new { validates_length_of :name, :in => 10 } } |
| 430 | | arg_bang { Meta.new { validates_length_of :name, :within => "somewhere between one and a million" } } |
| 429 | arg_bang { Meta.new(:name => 'some') { validates_length_of :name, :in => 10 } } |
| 430 | arg_bang { Meta.new(:name => 'some') { validates_length_of :name, :within => "somewhere between one and a million" } } |
| 431 | 431 | end |
| 432 | 432 | |
| 433 | 433 | it "should raise ArgumentError when something other than nonnegative Integer is given to :is, :minimum, :maximum" do |
| 434 | 434 | %w(is minimum maximum).each do |arg| |
| 435 | | arg_bang { Meta.new { validates_length_of :name, arg => "blah" } } |
| 436 | | arg_bang { Meta.new { validates_length_of :name, arg => -1 } } |
| 435 | arg_bang { Meta.new(:name => 'some') { validates_length_of :name, arg => "blah" } } |
| 436 | arg_bang { Meta.new(:name => 'some') { validates_length_of :name, arg => -1 } } |
| 437 | 437 | end |
| 438 | 438 | end |
| 439 | 439 | |
| … | … | |
| 564 | 564 | end |
| 565 | 565 | |
| 566 | 566 | it "should respect :allow_nil" do |
| 567 | | Meta.new { validates_length_of :bar, :is => 10, :allow_nil => false }.new.should_not be_valid |
| 568 | | Meta.new { validates_length_of :bar, :is => 10, :allow_nil => true }.new.should be_valid |
| 567 | Meta.new(:name => 'some') { validates_length_of :bar, :is => 10, :allow_nil => false }.new.should_not be_valid |
| 568 | Meta.new(:name => 'some') { validates_length_of :bar, :is => 10, :allow_nil => true }.new.should be_valid |
| 569 | 569 | end |
| 570 | 570 | |
| 571 | 571 | it "should respect :allow_blank" do |
| … | … | |
| 1027 | 1027 | end |
| 1028 | 1028 | |
| 1029 | 1029 | it "should respect :allow_nil" do |
| 1030 | | Meta.new { validates_numericality_of :number, :allow_nil => true }.new.should be_valid |
| 1030 | Meta.new(:name => 'some') { validates_numericality_of :number, :allow_nil => true }.new.should be_valid |
| 1031 | 1031 | end |
| 1032 | 1032 | |
| 1033 | 1033 | describe "should allow for option combinations" do |
| toggle raw diff |
--- a/spec/lib/strokedb/document/validations_spec.rb
+++ b/spec/lib/strokedb/document/validations_spec.rb
@@ -12,7 +12,7 @@ def validations_setup
end
def erroneous_stuff
- Meta.new do
+ Meta.new(:name => "ErroneousStuff") do
on_validation do |doc|
doc.errors.add(:something, "123")
doc.errors.add(:other, "456")
@@ -383,28 +383,28 @@ describe "validates_acceptance_of" do
end
it "should treat accepted value as valid" do
- Meta.new { validates_acceptance_of :eula, :accept => "yep" }.new(:eula => "yep").should be_valid
+ Meta.new(:name => 'some') { validates_acceptance_of :eula, :accept => "yep" }.new(:eula => "yep").should be_valid
end
it "should treat not accepted value as invalid" do
- Meta.new { validates_acceptance_of :eula, :accept => "yep" }.new(:eula => "nope").should_not be_valid
+ Meta.new(:name => 'some') { validates_acceptance_of :eula, :accept => "yep" }.new(:eula => "nope").should_not be_valid
end
it "should respect allow_nil" do
- Meta.new { validates_acceptance_of :eula, :accept => "yep", :allow_nil => true }.new.should be_valid
- Meta.new { validates_acceptance_of :eula, :accept => "yep", :allow_nil => false }.new.should_not be_valid
+ Meta.new(:name => 'some') { validates_acceptance_of :eula, :accept => "yep", :allow_nil => true }.new.should be_valid
+ Meta.new(:name => 'some') { validates_acceptance_of :eula, :accept => "yep", :allow_nil => false }.new.should_not be_valid
end
it "should set :allow_nil to true by default" do
- Meta.new { validates_acceptance_of :eula, :accept => "yep" }.new.should be_valid
+ Meta.new(:name => 'some') { validates_acceptance_of :eula, :accept => "yep" }.new.should be_valid
end
it "should set :accept to \"1\" by default" do
- Meta.new { validates_acceptance_of :eula }.new(:eula => "1").should be_valid
+ Meta.new(:name => 'some') { validates_acceptance_of :eula }.new(:eula => "1").should be_valid
end
it "should make a slot virtual" do
- Foo = Meta.new { validates_acceptance_of :eula, :accept => "yep" }
+ Foo = Meta.new{ validates_acceptance_of :eula, :accept => "yep" }
f = Foo.create!(:eula => "yep")
Foo.find(f.uuid).has_slot?("eula").should_not be_true
end
@@ -417,23 +417,23 @@ describe "validates_length_of" do
describe "options handling" do
it "should raise ArgumentError when more than one range option is specified" do
- arg_bang { Meta.new { validates_length_of :name, :is => 10, :maximum => 20 } }
- arg_bang { Meta.new { validates_length_of :name, :is => 10, :within => 1..20 } }
+ arg_bang { Meta.new(:name => 'some') { validates_length_of :name, :is => 10, :maximum => 20 } }
+ arg_bang { Meta.new(:name => 'some') { validates_length_of :name, :is => 10, :within => 1..20 } }
end
it "should raise ArgumentError when no range option is specified" do
- arg_bang { Meta.new { validates_length_of :name } }
+ arg_bang { Meta.new(:name => 'some') { validates_length_of :name } }
end
it "should raise ArgumentError when not Range given to :in or :within" do
- arg_bang { Meta.new { validates_length_of :name, :in => 10 } }
- arg_bang { Meta.new { validates_length_of :name, :within => "somewhere between one and a million" } }
+ arg_bang { Meta.new(:name => 'some') { validates_length_of :name, :in => 10 } }
+ arg_bang { Meta.new(:name => 'some') { validates_length_of :name, :within => "somewhere between one and a million" } }
end
it "should raise ArgumentError when something other than nonnegative Integer is given to :is, :minimum, :maximum" do
%w(is minimum maximum).each do |arg|
- arg_bang { Meta.new { validates_length_of :name, arg => "blah" } }
- arg_bang { Meta.new { validates_length_of :name, arg => -1 } }
+ arg_bang { Meta.new(:name => 'some') { validates_length_of :name, arg => "blah" } }
+ arg_bang { Meta.new(:name => 'some') { validates_length_of :name, arg => -1 } }
end
end
@@ -564,8 +564,8 @@ describe "validates_length_of" do
end
it "should respect :allow_nil" do
- Meta.new { validates_length_of :bar, :is => 10, :allow_nil => false }.new.should_not be_valid
- Meta.new { validates_length_of :bar, :is => 10, :allow_nil => true }.new.should be_valid
+ Meta.new(:name => 'some') { validates_length_of :bar, :is => 10, :allow_nil => false }.new.should_not be_valid
+ Meta.new(:name => 'some') { validates_length_of :bar, :is => 10, :allow_nil => true }.new.should be_valid
end
it "should respect :allow_blank" do
@@ -1027,7 +1027,7 @@ describe "validates_numericality_of" do
end
it "should respect :allow_nil" do
- Meta.new { validates_numericality_of :number, :allow_nil => true }.new.should be_valid
+ Meta.new(:name => 'some') { validates_numericality_of :number, :allow_nil => true }.new.should be_valid
end
describe "should allow for option combinations" do |