Skip to content

Not all Description config fields should be compared #640

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 23, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion lib/mongo/server/description.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@ class Description
# @since 2.0.0
TAGS = 'tags'.freeze

# Fields to exclude when comparing two descriptions.
#
# @since 2.0.6
EXCLUDE_FOR_COMPARISON = [ 'localTime' ]

# @return [ Address ] address The server's address.
attr_reader :address

Expand Down Expand Up @@ -496,7 +501,9 @@ def replica_set_member?
# @since 2.0.6
def ==(other)
return false if self.class != other.class
config == other.config
!config.keys.empty? && config.keys.all? do |k|
config[k] == other.config[k] || EXCLUDE_FOR_COMPARISON.include?(k)
end
end
alias_method :eql?, :==
end
Expand Down
13 changes: 13 additions & 0 deletions spec/mongo/server/description_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
'maxWriteBatchSize' => 1000,
'maxWireVersion' => 2,
'minWireVersion' => 0,
'localTime' => Time.now,
'ok' => 1
}
end
Expand Down Expand Up @@ -691,6 +692,18 @@

describe '#==' do

let(:description) do
described_class.new(address, replica)
end

let(:other) do
described_class.new(address, replica.merge('localTime' => 1))
end

it 'excludes certain fields' do
expect(description == other).to be(true)
end

context 'when the classes do not match' do

let(:description) do
Expand Down