Commit b82ca590365216b05c18109494b33b13b5a54563
1 parent
489586f1
Exists in
master
and in
1 other branch
fix spec on problem with mongoid 2.2.x
Showing
2 changed files
with
13 additions
and
0 deletions
Show diff stats
app/models/problem.rb
| @@ -2,6 +2,14 @@ | @@ -2,6 +2,14 @@ | ||
| 2 | # reported as various Errs, but the user has grouped the | 2 | # reported as various Errs, but the user has grouped the |
| 3 | # Errs together as belonging to the same problem. | 3 | # Errs together as belonging to the same problem. |
| 4 | 4 | ||
| 5 | +## Add methode nan? in Time because needed by #max(:created_at) | ||
| 6 | +# | ||
| 7 | +# Fix on Mongoid > 2.3.x with commit : | ||
| 8 | +# https://github.com/mongoid/mongoid/commit/5481556e24480f0a1783f85d6b5b343b0cef7192 | ||
| 9 | +class Time | ||
| 10 | + def nan?; false ;end | ||
| 11 | +end | ||
| 12 | + | ||
| 5 | class Problem | 13 | class Problem |
| 6 | include Mongoid::Document | 14 | include Mongoid::Document |
| 7 | include Mongoid::Timestamps | 15 | include Mongoid::Timestamps |
spec/models/problem_spec.rb
| @@ -91,6 +91,11 @@ describe Problem do | @@ -91,6 +91,11 @@ describe Problem do | ||
| 91 | problem = Fabricate(:problem) | 91 | problem = Fabricate(:problem) |
| 92 | problem.should_not be_resolved | 92 | problem.should_not be_resolved |
| 93 | problem.stub!(:valid?).and_return(false) | 93 | problem.stub!(:valid?).and_return(false) |
| 94 | + ## update_attributes not test #valid? but #errors.any? | ||
| 95 | + # https://github.com/mongoid/mongoid/blob/master/lib/mongoid/persistence.rb#L137 | ||
| 96 | + er = ActiveModel::Errors.new(problem) | ||
| 97 | + er.add_on_blank(:resolved) | ||
| 98 | + problem.stub!(:errors).and_return(er) | ||
| 94 | problem.should_not be_valid | 99 | problem.should_not be_valid |
| 95 | lambda { | 100 | lambda { |
| 96 | problem.resolve! | 101 | problem.resolve! |