Skip to content

Commit

Permalink
Attributes should not exist in the db if value was nil
Browse files Browse the repository at this point in the history
  • Loading branch information
durran committed Jan 21, 2010
1 parent d12903e commit a16eedd
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/mongoid/attributes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def process(attrs = {})
if Mongoid.allow_dynamic_fields && !respond_to?("#{key}=")
@attributes[key.to_s] = value
else
send("#{key}=", value)
send("#{key}=", value) if value
end
end
end
Expand Down
22 changes: 22 additions & 0 deletions spec/integration/mongoid/attributes_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
require "spec_helper"

describe Mongoid::Attributes do

context "when persisting nil attributes" do

before do
@person = Person.create(:score => nil, :ssn => "555-66-7777")
end

after do
Person.delete_all
end

it "the field should not exist" do
from_db = Person.find(@person.id)
from_db.attributes.has_key?(:score).should be_false
end

end

end

0 comments on commit a16eedd

Please sign in to comment.