forked from mongodb/mongoid
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Validation context should default to proper context instead of none:
- When no context provided to Document#valid? use the following
defaults: :create if new, :update if persisted.
- Slight refactoring of the include annoyance in the validations module.
- Mongoid now includes ActiveModel::Validations::Callbacks
- Initialize callback runs only :after.
- Fixes #556.
- Loading branch information
Showing
4 changed files
with
92 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
require "spec_helper" | ||
|
||
describe Mongoid::Validations do | ||
|
||
let(:account) do | ||
Account.new(:name => "Testing a really long name.") | ||
end | ||
|
||
describe "#valid?" do | ||
|
||
context "when provided a context" do | ||
|
||
it "uses the provided context" do | ||
account.should be_valid(:update) | ||
end | ||
end | ||
|
||
context "when not provided a context" do | ||
|
||
context "when the document is new" do | ||
|
||
it "defaults the context to :create" do | ||
account.should_not be_valid | ||
end | ||
end | ||
|
||
context "when the document is persisted" do | ||
|
||
before do | ||
account.name = "Testing" | ||
account.save | ||
account.name = "Testing a really long name." | ||
end | ||
|
||
it "defaults the context to :update" do | ||
account.should be_valid | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters