Skip to content

Commit

Permalink
RUBY-1148 Check CRUD operation options for collation String key
Browse files Browse the repository at this point in the history
  • Loading branch information
estolfo committed Sep 28, 2016
1 parent b6ab98e commit 4499305
Show file tree
Hide file tree
Showing 4 changed files with 227 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lib/mongo/collection/view.rb
Expand Up @@ -178,7 +178,9 @@ def new(options)
end

def validate_collation!(server, opts)
raise Error::UnsupportedCollation.new if opts[:collation] && !server.features.collation_enabled?
if (opts[:collation] || opts[Operation::COLLATION]) && !server.features.collation_enabled?
raise Error::UnsupportedCollation.new
end
end

def view; self; end
Expand Down
4 changes: 3 additions & 1 deletion lib/mongo/collection/view/aggregation.rb
Expand Up @@ -120,7 +120,9 @@ def send_initial_query(server)
end

def validate_collation!(server)
raise Error::UnsupportedCollation.new if @options[:collation] && !server.features.collation_enabled?
if (@options[:collation] || @options[Operation::COLLATION]) && !server.features.collation_enabled?
raise Error::UnsupportedCollation.new
end
end
end
end
Expand Down
13 changes: 13 additions & 0 deletions spec/mongo/collection/view_spec.rb
Expand Up @@ -187,6 +187,19 @@
result
}.to raise_exception(Mongo::Error::UnsupportedCollation)
end

context 'when a String key is used' do

let(:options) do
{ 'collation' => { locale: 'en_US', strength: 2 } }
end

it 'raises an exception' do
expect {
result
}.to raise_exception(Mongo::Error::UnsupportedCollation)
end
end
end
end

Expand Down
208 changes: 208 additions & 0 deletions spec/mongo/collection_spec.rb
Expand Up @@ -1193,6 +1193,19 @@ def generate
result
}.to raise_exception(Mongo::Error::UnsupportedCollation)
end

context 'when a String key is used' do

let(:options) do
{ 'collation' => { locale: 'en_US', strength: 2 } }
end

it 'raises an exception' do
expect {
result
}.to raise_exception(Mongo::Error::UnsupportedCollation)
end
end
end
end
end
Expand Down Expand Up @@ -1250,6 +1263,19 @@ def generate
result
}.to raise_exception(Mongo::Error::UnsupportedCollation)
end

context 'when a String key is used' do

let(:options) do
{ 'collation' => { locale: 'en_US', strength: 2 } }
end

it 'raises an exception' do
expect {
result
}.to raise_exception(Mongo::Error::UnsupportedCollation)
end
end
end
end
end
Expand Down Expand Up @@ -1312,6 +1338,19 @@ def generate
result
}.to raise_exception(Mongo::Error::UnsupportedCollation)
end

context 'when a String key is used' do

let(:options) do
{ 'collation' => { locale: 'en_US', strength: 2 } }
end

it 'raises an exception' do
expect {
result
}.to raise_exception(Mongo::Error::UnsupportedCollation)
end
end
end
end

Expand Down Expand Up @@ -1425,6 +1464,19 @@ def generate
result
}.to raise_exception(Mongo::Error::UnsupportedCollation)
end

context 'when a String key is used' do

let(:options) do
{ 'collation' => { locale: 'en_US', strength: 2 } }
end

it 'raises an exception' do
expect {
result
}.to raise_exception(Mongo::Error::UnsupportedCollation)
end
end
end
end

Expand All @@ -1435,6 +1487,19 @@ def generate
result
}.to raise_exception(Mongo::Error::UnsupportedCollation)
end

context 'when a String key is used' do

let(:options) do
{ 'collation' => { locale: 'en_US', strength: 2 } }
end

it 'raises an exception' do
expect {
result
}.to raise_exception(Mongo::Error::UnsupportedCollation)
end
end
end
end

Expand Down Expand Up @@ -1537,6 +1602,19 @@ def generate
result
}.to raise_exception(Mongo::Error::UnsupportedCollation)
end

context 'when a String key is used' do

let(:options) do
{ 'collation' => { locale: 'en_US', strength: 2 } }
end

it 'raises an exception' do
expect {
result
}.to raise_exception(Mongo::Error::UnsupportedCollation)
end
end
end
end

Expand All @@ -1547,6 +1625,19 @@ def generate
result
}.to raise_exception(Mongo::Error::UnsupportedCollation)
end

context 'when a String key is used' do

let(:options) do
{ 'collation' => { locale: 'en_US', strength: 2 } }
end

it 'raises an exception' do
expect {
result
}.to raise_exception(Mongo::Error::UnsupportedCollation)
end
end
end
end

Expand Down Expand Up @@ -1893,6 +1984,19 @@ def generate
result
}.to raise_exception(Mongo::Error::UnsupportedCollation)
end

context 'when a String key is used' do

let(:options) do
{ 'collation' => { locale: 'en_US', strength: 2 } }
end

it 'raises an exception' do
expect {
result
}.to raise_exception(Mongo::Error::UnsupportedCollation)
end
end
end
end

Expand All @@ -1903,6 +2007,19 @@ def generate
result
}.to raise_exception(Mongo::Error::UnsupportedCollation)
end

context 'when a String key is used' do

let(:options) do
{ 'collation' => { locale: 'en_US', strength: 2 } }
end

it 'raises an exception' do
expect {
result
}.to raise_exception(Mongo::Error::UnsupportedCollation)
end
end
end
end

Expand Down Expand Up @@ -2127,6 +2244,19 @@ def generate
result
}.to raise_exception(Mongo::Error::UnsupportedCollation)
end

context 'when a String key is used' do

let(:options) do
{ 'collation' => { locale: 'en_US', strength: 2 } }
end

it 'raises an exception' do
expect {
result
}.to raise_exception(Mongo::Error::UnsupportedCollation)
end
end
end
end

Expand All @@ -2137,6 +2267,19 @@ def generate
result
}.to raise_exception(Mongo::Error::UnsupportedCollation)
end

context 'when a String key is used' do

let(:options) do
{ 'collation' => { locale: 'en_US', strength: 2 } }
end

it 'raises an exception' do
expect {
result
}.to raise_exception(Mongo::Error::UnsupportedCollation)
end
end
end
end

Expand Down Expand Up @@ -2360,6 +2503,19 @@ def generate
result
}.to raise_exception(Mongo::Error::UnsupportedCollation)
end

context 'when a String key is used' do

let(:options) do
{ 'collation' => { locale: 'en_US', strength: 2 } }
end

it 'raises an exception' do
expect {
result
}.to raise_exception(Mongo::Error::UnsupportedCollation)
end
end
end
end

Expand All @@ -2370,6 +2526,19 @@ def generate
result
}.to raise_exception(Mongo::Error::UnsupportedCollation)
end

context 'when a String key is used' do

let(:options) do
{ 'collation' => { locale: 'en_US', strength: 2 } }
end

it 'raises an exception' do
expect {
result
}.to raise_exception(Mongo::Error::UnsupportedCollation)
end
end
end
end

Expand Down Expand Up @@ -2546,6 +2715,19 @@ def generate
result
}.to raise_exception(Mongo::Error::UnsupportedCollation)
end

context 'when a String key is used' do

let(:options) do
{ 'collation' => { locale: 'en_US', strength: 2 } }
end

it 'raises an exception' do
expect {
result
}.to raise_exception(Mongo::Error::UnsupportedCollation)
end
end
end
end

Expand Down Expand Up @@ -2842,6 +3024,19 @@ def generate
result
}.to raise_exception(Mongo::Error::UnsupportedCollation)
end

context 'when a String key is used' do

let(:options) do
{ 'collation' => { locale: 'en_US', strength: 2 } }
end

it 'raises an exception' do
expect {
result
}.to raise_exception(Mongo::Error::UnsupportedCollation)
end
end
end
end

Expand Down Expand Up @@ -3112,6 +3307,19 @@ def generate
result
}.to raise_exception(Mongo::Error::UnsupportedCollation)
end

context 'when a String key is used' do

let(:options) do
{ 'collation' => { locale: 'en_US', strength: 2 } }
end

it 'raises an exception' do
expect {
result
}.to raise_exception(Mongo::Error::UnsupportedCollation)
end
end
end
end

Expand Down

0 comments on commit 4499305

Please sign in to comment.