Skip to content

Commit 4e9524b

Browse files
committed
RUBY-1279 App name in app metadata should be string
1 parent 007ccac commit 4e9524b

File tree

7 files changed

+30
-12
lines changed

7 files changed

+30
-12
lines changed

lib/mongo/cluster/app_metadata.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class AppMetadata
5252
#
5353
# @since 2.4.0
5454
def initialize(cluster)
55-
@app_name = cluster.options[:app_name]
55+
@app_name = cluster.options[:app_name].to_s if cluster.options[:app_name]
5656
@platform = cluster.options[:platform]
5757
@compressors = cluster.options[:compressors] || []
5858
end

spec/mongo/client_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1123,7 +1123,7 @@
11231123
end
11241124

11251125
let(:new_options) do
1126-
{ app_name: 'reports' }
1126+
{ app_name: 'client_test' }
11271127
end
11281128

11291129
let!(:new_client) do

spec/mongo/cluster/app_metadata_spec.rb

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,34 @@
1414

1515
context 'when the cluster has an app name option set' do
1616

17+
let(:client) do
18+
authorized_client.with(app_name: :app_metadata_test)
19+
end
20+
1721
let(:cluster) do
18-
authorized_client.with(app_name: :reports).cluster
22+
client.cluster
23+
end
24+
25+
after do
26+
client.close
1927
end
2028

2129
it 'sets the app name' do
22-
expect(app_metadata.send(:full_client_document)[:application][:name]).to eq(:reports)
30+
expect(app_metadata.send(:full_client_document)[:application][:name]).to eq('app_metadata_test')
2331
end
2432

2533
context 'when the app name exceeds the max length of 128' do
2634

35+
let(:client) do
36+
authorized_client.with(app_name: "\u3042"*43)
37+
end
38+
2739
let(:cluster) do
28-
authorized_client.with(app_name: "\u3042"*43).cluster
40+
client.cluster
41+
end
42+
43+
after do
44+
client.close
2945
end
3046

3147
it 'raises an error' do

spec/mongo/cluster_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -491,11 +491,11 @@
491491
context 'when the client has an app_name set' do
492492

493493
let(:cluster) do
494-
authorized_client.with(app_name: 'reports').cluster
494+
authorized_client.with(app_name: 'cluster_test').cluster
495495
end
496496

497497
it 'constructs an AppMetadata object with the app_name' do
498-
expect(cluster.app_metadata.send(:full_client_document)[:application]).to eq('name' => 'reports')
498+
expect(cluster.app_metadata.send(:full_client_document)[:application]).to eq('name' => 'cluster_test')
499499
end
500500
end
501501

spec/mongo/max_staleness_spec.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@
6767

6868
let(:in_latency_window) do
6969
spec.in_latency_window.collect do |server|
70-
Mongo::Server.new(Mongo::Address.new(server['address']), cluster, monitoring, listeners, options)
70+
s = Mongo::Server.new(Mongo::Address.new(server['address']), cluster, monitoring, listeners, options)
71+
s.monitor.stop!
72+
s
7173
end
7274
end
7375

spec/mongo/uri/srv_protocol_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -896,10 +896,10 @@
896896
end
897897

898898
context 'when an app name option is provided' do
899-
let(:options) { "appname=reports" }
899+
let(:options) { "appname=srv_test" }
900900

901901
it 'sets the app name on the client' do
902-
expect(Mongo::Client.new(string).options[:app_name]).to eq(:reports)
902+
expect(Mongo::Client.new(string).options[:app_name]).to eq(:srv_test)
903903
end
904904
end
905905

spec/mongo/uri_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -962,10 +962,10 @@
962962
end
963963

964964
context 'when an app name option is provided' do
965-
let(:options) { "appname=reports" }
965+
let(:options) { "appname=uri_test" }
966966

967967
it 'sets the app name on the client' do
968-
expect(Mongo::Client.new(string).options[:app_name]).to eq(:reports)
968+
expect(Mongo::Client.new(string).options[:app_name]).to eq(:uri_test)
969969
end
970970
end
971971

0 commit comments

Comments
 (0)