Skip to content

Commit

Permalink
Convert Boolean type to Mongoid::Boolean
Browse files Browse the repository at this point in the history
Internally we need to use the Mongoid::Boolean type, and not the Boolean type, so we could convert that internally
  • Loading branch information
arthurnn committed Jan 9, 2014
1 parent fb8fbda commit 53e736c
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/mongoid/fields/standard.rb
Expand Up @@ -165,7 +165,14 @@ def pre_processed?
#
# @since 2.1.0
def type
@type ||= options[:type] || Object
@type ||=
begin
if "Boolean" == options[:type].to_s
Mongoid::Boolean
else
options[:type] || Object
end
end
end

private
Expand Down
31 changes: 31 additions & 0 deletions spec/mongoid/fields/standard_spec.rb
Expand Up @@ -2,6 +2,37 @@

describe Mongoid::Fields::Standard do

describe "Boolean" do

context "when field type is Boolean" do

let(:field) do
described_class.new(
:test,
type: Boolean
)
end

it "returns as Mongoid::Boolean" do
expect(field.type).to eq(Mongoid::Boolean)
end
end

context "when field type is Mongoid::Boolean" do

let(:field) do
described_class.new(
:test,
type: Mongoid::Boolean
)
end

it "returns as Mongoid::Boolean" do
expect(field.type).to eq(Mongoid::Boolean)
end
end
end

describe "#lazy?" do

let(:field) do
Expand Down

0 comments on commit 53e736c

Please sign in to comment.