Skip to content

Commit 2fdd254

Browse files
authored
MONGOID-5362 Test return value type of #attributes (#5302)
* MONGOID-5362 Test return value type of #attributes * MONGOID-5362 answer comments * MONGOID-5362 use new flags * MONGOID-5362 update tests
1 parent 0ace00c commit 2fdd254

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

spec/mongoid/document_spec.rb

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,13 +165,40 @@ class << self; attr_accessor :name; end
165165

166166
describe "#attributes" do
167167

168-
let(:person) do
169-
Person.new(title: "Sir")
168+
let!(:person) do
169+
Person.create!(title: "Sir")
170170
end
171171

172172
it "returns the attributes with indifferent access" do
173173
expect(person[:title]).to eq("Sir")
174174
end
175+
176+
context "when instantiating a new document" do
177+
it "returns a Hash" do
178+
expect(person.attributes.class).to eq(Hash)
179+
end
180+
end
181+
182+
context "when retrieving a document from the database" do
183+
184+
let(:from_db) { Person.first }
185+
186+
context "when legacy_attributes is false" do
187+
config_override :legacy_attributes, false
188+
189+
it "returns a Hash" do
190+
expect(from_db.attributes.class).to eq(Hash)
191+
end
192+
end
193+
194+
context "when legacy_attributes is true" do
195+
config_override :legacy_attributes, true
196+
197+
it "returns a BSON::Document" do
198+
expect(from_db.attributes.class).to eq(BSON::Document)
199+
end
200+
end
201+
end
175202
end
176203

177204
describe "#identity" do

0 commit comments

Comments
 (0)