forked from mongodb/mongoid
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow serializable fields to be of type hash. Fixes #1311.
- Loading branch information
Showing
4 changed files
with
47 additions
and
8 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class MyHash < ::Hash | ||
include Mongoid::Fields::Serializable | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
require "spec_helper" | ||
|
||
describe Mongoid::Fields::Serializable do | ||
|
||
context "when included in a hash" do | ||
|
||
let(:hash) do | ||
MyHash.new | ||
end | ||
|
||
context "when setting a value" do | ||
|
||
before do | ||
hash[:key] = "value" | ||
end | ||
|
||
it "allows normal hash access" do | ||
hash[:key].should eq("value") | ||
end | ||
end | ||
|
||
context "when getting a non existant value" do | ||
|
||
it "returns nil" do | ||
hash[:key].should be_nil | ||
end | ||
end | ||
end | ||
end |