Skip to content

Commit

Permalink
Fix bson class for mongoid-4
Browse files Browse the repository at this point in the history
  • Loading branch information
Jagdeep Singh committed Jun 24, 2016
1 parent 211ff84 commit 12c7d74
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions spec/unit/trackable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,8 @@ def my_changes
my_embed_many_models: my_embed_many_models)
end

let(:bson_class) { defined?(BSON::ObjectId) ? BSON::ObjectId : Moped::BSON::ObjectId }

describe '#modified_attributes_for_create' do
subject { my_trackable_model.send(:modified_attributes_for_create) }

Expand All @@ -334,14 +336,14 @@ def my_changes

it 'should include tracked embeds_one objects attributes' do
expect(subject['my_embed_one_model'][0]).to be_nil
expect(subject['my_embed_one_model'][1]['_id']).to be_a Moped::BSON::ObjectId
expect(subject['my_embed_one_model'][1]['_id']).to be_a bson_class
expect(subject['my_embed_one_model'][1]['baz']).to eq 'Baz'
end

it 'should include tracked embeds_many objects attributes' do
expect(subject['my_embed_many_models'][0]).to be_nil
expect(subject['my_embed_many_models'][1].size).to eq 1
expect(subject['my_embed_many_models'][1][0]['_id']).to be_a Moped::BSON::ObjectId
expect(subject['my_embed_many_models'][1][0]['_id']).to be_a bson_class
expect(subject['my_embed_many_models'][1][0]['bla']).to eq 'Bla'
end

Expand All @@ -358,7 +360,7 @@ def my_changes
subject { my_trackable_model.send(:modified_attributes_for_destroy) }

it 'should track reserved fields' do
expect(subject['_id'][0]).to be_a Moped::BSON::ObjectId
expect(subject['_id'][0]).to be_a bson_class
expect(subject['_id'][1]).to be_nil
end

Expand All @@ -368,14 +370,14 @@ def my_changes
end

it 'should include tracked embeds_one objects attributes' do
expect(subject['my_embed_one_model'][0]['_id']).to be_a Moped::BSON::ObjectId
expect(subject['my_embed_one_model'][0]['_id']).to be_a bson_class
expect(subject['my_embed_one_model'][0]['baz']).to eq 'Baz'
expect(subject['my_embed_one_model'][1]).to be_nil
end

it 'should include tracked embeds_many objects attributes' do
expect(subject['my_embed_many_models'][0].size).to eq 1
expect(subject['my_embed_many_models'][0][0]['_id']).to be_a Moped::BSON::ObjectId
expect(subject['my_embed_many_models'][0][0]['_id']).to be_a bson_class
expect(subject['my_embed_many_models'][0][0]['bla']).to eq 'Bla'
expect(subject['my_embed_many_models'][1]).to be_nil
end
Expand Down

0 comments on commit 12c7d74

Please sign in to comment.