Skip to content

Commit

Permalink
Mongoize dynamic fields.
Browse files Browse the repository at this point in the history
[ fix #2826 ]
  • Loading branch information
durran committed Feb 24, 2013
1 parent 2eddafc commit 0384740
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -13,6 +13,8 @@ For instructions on upgrading to newer versions, visit
middle of a parent update will now properly execute the deletion.
(Arthur Neves)

* \#2826 Dynamic fields are now properly mongoized.

* \#2822 Marshal load of relations now properly reapplies extensions.

## 3.0.22
Expand Down
2 changes: 1 addition & 1 deletion lib/mongoid/attributes.rb
Expand Up @@ -270,7 +270,7 @@ def method_missing(name, *args)
#
# @since 1.0.0
def typed_value_for(key, value)
fields.has_key?(key) ? fields[key].mongoize(value) : value
fields.has_key?(key) ? fields[key].mongoize(value) : value.mongoize
end

module ClassMethods
Expand Down
19 changes: 19 additions & 0 deletions spec/mongoid/attributes_spec.rb
Expand Up @@ -572,6 +572,25 @@
person.respond_to?(:testing).should be_true
end
end

context "when the provided value needs mongoization" do

let(:new_years) do
DateTime.new(2013, 1, 1, 0, 0, 0)
end

before do
person[:new_years] = new_years
end

it "mongoizes the dynamic field" do
person.new_years.should be_a(Time)
end

it "keeps the same value" do
person.new_years.should eq(new_years)
end
end
end

describe "#process" do
Expand Down

0 comments on commit 0384740

Please sign in to comment.