spec/mongo/collection/view/readable_spec.rb in mongo-2.3.1 vs spec/mongo/collection/view/readable_spec.rb in mongo-2.4.0.rc0
- old
+ new
@@ -403,10 +403,45 @@
end
it 'sets the max_time_ms option on the command', if: write_command_enabled? do
expect(view.count(max_time_ms: 100)).to eq(10)
end
+
+ context 'when a collation is specified' do
+
+ let(:selector) do
+ { name: 'BANG' }
+ end
+
+ let(:result) do
+ view.count(count_options)
+ end
+
+ before do
+ authorized_collection.insert_one(name: 'bang')
+ end
+
+ let(:count_options) do
+ { collation: { locale: 'en_US', strength: 2 } }
+ end
+
+ context 'when the server selected supports collations', if: collation_enabled? do
+
+ it 'applies the collation to the count' do
+ expect(result).to eq(1)
+ end
+ end
+
+ context 'when the server selected does not support collations', unless: collation_enabled? do
+
+ it 'raises an exception' do
+ expect {
+ result
+ }.to raise_exception(Mongo::Error::UnsupportedCollation)
+ end
+ end
+ end
end
describe '#distinct' do
context 'when incorporating read concern' do
@@ -644,9 +679,57 @@
context 'when the field does not exist' do
it 'returns an empty array' do
expect(view.distinct(:nofieldexists)).to be_empty
+ end
+ end
+
+ context 'when a collation is specified' do
+
+ let(:result) do
+ view.distinct(:name, distinct_options)
+ end
+
+ before do
+ authorized_collection.insert_one(name: 'bang')
+ authorized_collection.insert_one(name: 'BANG')
+ end
+
+ let(:distinct_options) do
+ { collation: { locale: 'en_US', strength: 2 } }
+ end
+
+ context 'when the server selected supports collations', if: collation_enabled? do
+
+ it 'applies the collation to the distinct' do
+ expect(result).to eq(['bang'])
+ end
+ end
+
+ context 'when the server selected does not support collations', unless: collation_enabled? do
+
+ it 'raises an exception' do
+ expect {
+ result
+ }.to raise_exception(Mongo::Error::UnsupportedCollation)
+ end
+ end
+ end
+
+ context 'when a collation is not specified' do
+
+ let(:result) do
+ view.distinct(:name)
+ end
+
+ before do
+ authorized_collection.insert_one(name: 'bang')
+ authorized_collection.insert_one(name: 'BANG')
+ end
+
+ it 'does not apply the collation to the distinct' do
+ expect(result).to eq(['bang', 'BANG'])
end
end
end
describe '#hint' do