Created
September 25, 2011 21:55
-
-
Save yfeldblum/1241218 to your computer and use it in GitHub Desktop.
attribute_will_change! in mongoid-2.3 and earlier
This file contains hidden or 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
.....FF....FF | |
Failures: | |
1) Widget without control changes | |
Failure/Error: its(:changes) { should include("ferocious") } | |
expected {} to include "ferocious" | |
Diff: | |
@@ -1,2 +1,2 @@ | |
-ferocious | |
+{} | |
# ./spec/models/widget_spec.rb:36:in `block (3 levels) in <top (required)>' | |
2) Widget without control ferocious_changed? | |
Failure/Error: its(:ferocious_changed?) { should be_true } | |
expected false to be true | |
# ./spec/models/widget_spec.rb:37:in `block (3 levels) in <top (required)>' | |
3) Widget with control changes | |
Failure/Error: its(:changes) { should include("ferocious") } | |
expected {"control"=>[false, true]} to include "ferocious" | |
Diff: | |
@@ -1,2 +1,2 @@ | |
-ferocious | |
+{"control"=>[false, true]} | |
# ./spec/models/widget_spec.rb:52:in `block (3 levels) in <top (required)>' | |
4) Widget with control ferocious_changed? | |
Failure/Error: its(:ferocious_changed?) { should be_true } | |
expected false to be true | |
# ./spec/models/widget_spec.rb:53:in `block (3 levels) in <top (required)>' | |
Finished in 0.03837 seconds | |
13 examples, 4 failures | |
Failed examples: | |
rspec ./spec/models/widget_spec.rb:36 # Widget without control changes | |
rspec ./spec/models/widget_spec.rb:37 # Widget without control ferocious_changed? | |
rspec ./spec/models/widget_spec.rb:52 # Widget with control changes | |
rspec ./spec/models/widget_spec.rb:53 # Widget with control ferocious_changed? |
This file contains hidden or 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
require "spec_helper" | |
class Widget | |
include Mongoid::Document | |
field :ferocious, | |
:type => Boolean, | |
:default => false | |
field :control, | |
:type => Boolean, | |
:default => false | |
end | |
describe Widget do | |
subject { Widget.create! } | |
# When I tell the model that an attribute will change, | |
# I expect the model to obey. Let's see what happens. | |
before { subject.ferocious_will_change! } | |
# Double-Check: | |
its(:changed?) { should be_true } | |
context "without control" do | |
# Double-Check: | |
its(:changed) { should_not include("control") } | |
its(:changes) { should_not include("control") } | |
its(:control_changed?) { should_not be_true } | |
# Passing: | |
its(:changed) { should include("ferocious") } | |
# Failing: | |
its(:changes) { should include("ferocious") } | |
its(:ferocious_changed?) { should be_true } | |
end | |
context "with control" do | |
before { subject.control = true } | |
# Double-Check: | |
its(:changed) { should include("control") } | |
its(:changes) { should include("control") } | |
its(:control_changed?) { should be_true } | |
# Passing: | |
its(:changed) { should include("ferocious") } | |
# Failing: | |
its(:changes) { should include("ferocious") } | |
its(:ferocious_changed?) { should be_true } | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment