Skip to content

Commit a11f6ff

Browse files
Respond to code review feedback
* Use more idiomatic .present? method in tacos_enabled? helper * Update the default TACOS_SOURCE value to be specific to this codebase, rather than a generic "unset" * Rename the Tacos model method .call to .analyze
1 parent 720ff31 commit a11f6ff

File tree

4 files changed

+9
-9
lines changed

4 files changed

+9
-9
lines changed

app/controllers/tacos_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ class TacosController < ApplicationController
44
def analyze
55
return unless ApplicationHelper.tacos_enabled?
66

7-
Tacos.call(params[:q])
7+
Tacos.analyze(params[:q])
88
end
99
end

app/helpers/application_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module ApplicationHelper
22
def tacos_enabled?
3-
ENV.fetch('TACOS_URL', '').length > 0
3+
ENV.fetch('TACOS_URL', '').present?
44
end
55
module_function :tacos_enabled?
66

app/models/tacos.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ class Tacos
22
# The tacos_client argument here is unused in production - it is provided for
33
# our test suite so that we can mock various error conditions to ensure that
44
# error handling happens as we intend.
5-
def self.call(term, tacos_client = nil)
5+
def self.analyze(term, tacos_client = nil)
66
tacos_http = setup(tacos_client)
77
query = '{ "query": "{ logSearchEvent(searchTerm: \"' + clean_term(term) + '\", sourceSystem: \"' + tacos_source + '\" ) { phrase source detectors { suggestedResources { title url } } } }" }'
88
begin
@@ -30,7 +30,7 @@ def self.origins
3030
end
3131

3232
# We define the HTTP connection this way so that it can be overridden during
33-
# testing, to make sure that the .call method can handle specific error
33+
# testing, to make sure that the .analyze method can handle specific error
3434
# conditions.
3535
def self.setup(tacos_client)
3636
tacos_client || HTTP.persistent(tacos_url)
@@ -40,7 +40,7 @@ def self.setup(tacos_client)
4040
end
4141

4242
def self.tacos_source
43-
ENV.fetch('TACOS_SOURCE', 'unset')
43+
ENV.fetch('TACOS_SOURCE', 'timdexui_unset')
4444
end
4545

4646
def self.tacos_url

test/models/tacos_test.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class TacosTest < ActiveSupport::TestCase
2525
VCR.use_cassette('tacos popcorn') do
2626
searchterm = 'popcorn'
2727

28-
result = Tacos.call(searchterm)
28+
result = Tacos.analyze(searchterm)
2929

3030
assert_instance_of Hash, result
3131
assert_equal searchterm, result['data']['logSearchEvent']['phrase']
@@ -35,7 +35,7 @@ class TacosTest < ActiveSupport::TestCase
3535
test 'TACOS model will use ENV to populate the sourceSystem value' do
3636
VCR.use_cassette('tacos fake system') do
3737
ClimateControl.modify(TACOS_SOURCE: 'faked') do
38-
result = Tacos.call('popcorn')
38+
result = Tacos.analyze('popcorn')
3939

4040
assert_equal 'faked', result['data']['logSearchEvent']['source']
4141
end
@@ -45,7 +45,7 @@ class TacosTest < ActiveSupport::TestCase
4545
test 'TACOS model catches connection errors' do
4646
tacos_client = TacosConnectionError.new
4747

48-
result = Tacos.call('popcorn', tacos_client)
48+
result = Tacos.analyze('popcorn', tacos_client)
4949

5050
assert_instance_of Hash, result
5151
assert_equal 'A connection error has occurred', result['error']
@@ -54,7 +54,7 @@ class TacosTest < ActiveSupport::TestCase
5454
test 'TACOS model catches parsing errors' do
5555
tacos_client = TacosParsingError.new
5656

57-
result = Tacos.call('popcorn', tacos_client)
57+
result = Tacos.analyze('popcorn', tacos_client)
5858

5959
assert_instance_of Hash, result
6060
assert_equal 'A parsing error has occurred', result['error']

0 commit comments

Comments
 (0)