-
Type: Task
-
Resolution: Done
-
Affects Version/s: None
-
Component/s: None
require "spec_helper" class Foo include Mongoid::Document field :range, type: Array end describe "Mongoid::Document" do before do [ Foo ].each(&:delete_all) end describe "field" do let(:foo) do Foo.new end it "saves the relationship" do foo.range = [1000.0, 1000.0] foo.save! # works foo.range = nil foo.save! # fails end end end
You get an unhelpful error.
Failure/Error: foo.save!
NoMethodError:
undefined method `-' for nil:NilClass
# ./lib/mongoid/dirty.rb:120:in `block (2 levels) in setters'
# ./lib/mongoid/dirty.rb:114:in `each_pair'
# ./lib/mongoid/dirty.rb:114:in `block in setters'
# ./lib/mongoid/dirty.rb:113:in `tap'
# ./lib/mongoid/dirty.rb:113:in `setters'
Repro on 2.4.0-stable.