File tree Expand file tree Collapse file tree 2 files changed +32
-1
lines changed
Expand file tree Collapse file tree 2 files changed +32
-1
lines changed Original file line number Diff line number Diff line change @@ -90,7 +90,10 @@ def build_default_options_headers
9090 {
9191 'Content-Type' => 'application/json' ,
9292 'Authorization' => ( "Bearer #{ @api_key } " unless @api_key . nil? ) ,
93- 'User-Agent' => MeiliSearch . qualified_version
93+ 'User-Agent' => [
94+ @options . fetch ( :client_agents , [ ] ) ,
95+ MeiliSearch . qualified_version
96+ ] . flatten . join ( ';' )
9497 } . compact
9598 end
9699
Original file line number Diff line number Diff line change 126126 index . fetch_info
127127 end
128128
129+ it 'supports client_agents' do
130+ custom_agent = 'Meilisearch Rails (v0.0.1)'
131+ options = { timeout : 2 , max_retries : 1 , client_agents : [ custom_agent ] }
132+ expected_headers = {
133+ 'Authorization' => "Bearer #{ MASTER_KEY } " ,
134+ 'User-Agent' => "#{ custom_agent } ;#{ MeiliSearch . qualified_version } "
135+ }
136+
137+ new_client = MeiliSearch ::Client . new ( URL , MASTER_KEY , options )
138+ new_client . create_index! ( 'options' )
139+ index = new_client . fetch_index ( 'options' )
140+ expect ( index . options ) . to eq ( options . merge ( { convert_body? : true } ) )
141+
142+ expect ( MeiliSearch ::Index ) . to receive ( :get ) . with (
143+ "#{ URL } /indexes/options" ,
144+ {
145+ headers : expected_headers ,
146+ body : 'null' ,
147+ query : { } ,
148+ max_retries : 1 ,
149+ timeout : 2
150+ }
151+ ) . and_return ( double ( success? : true ,
152+ parsed_response : { 'createdAt' => '2021-10-16T14:57:35Z' ,
153+ 'updatedAt' => '2021-10-16T14:57:35Z' } ) )
154+ index . fetch_info
155+ end
156+
129157 it 'deletes index' do
130158 client . create_index! ( 'uid' )
131159
You can’t perform that action at this time.
0 commit comments