Skip to content

Commit 22936af

Browse files
mxygemseanmarcia
authored andcommitted
Fix current violations and remove todo. (#188)
- Huzzah!!!
1 parent 79ea725 commit 22936af

File tree

7 files changed

+20
-37
lines changed

7 files changed

+20
-37
lines changed

.rubocop.yml

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
inherit_from: .rubocop_todo.yml
2-
31
AllCops:
42
# Use the following Exclude to prevent Rubocop from linting specific
53
# directories or files.
@@ -27,6 +25,9 @@ Metrics/BlockLength:
2725
- spec/**/*
2826
- config/**/*
2927

28+
Metrics/LineLength:
29+
Enabled: False
30+
3031
Metrics/MethodLength:
3132
Max: 12
3233

.rubocop_todo.yml

-13
This file was deleted.

app/controllers/amazon_search_controller.rb

+1-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ class AmazonSearchController < ApplicationController
1010
def show
1111
authorize :amazon_search, :show?
1212
@response = amazon_search_response
13-
if @response.error?
14-
redirect_to new_wishlist_amazon_search_path(params[:wishlist_id]), notice: 'Could not connect to Amazon. Please try again later or contact the website adminitrator.'
15-
end
13+
redirect_to new_wishlist_amazon_search_path(params[:wishlist_id]), notice: 'Could not connect to Amazon. Please try again later or contact the website adminitrator.' if @response.error?
1614
end
1715

1816
def new

lib/amazon_product_api/item_search_endpoint.rb

+6-8
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,12 @@ def get(http: HTTParty)
4444

4545
# Performs the search query and returns the resulting SearchResponse
4646
def response(http: HTTParty, logger: Rails.logger)
47-
begin
48-
response = get(http: http)
49-
logger.debug response
50-
SearchResponse.new(parse_response(response), response.code)
51-
rescue StandardError => e
52-
Rollbar.error(e, "Failed to connect to Amazon. Reqeust: #{http}")
53-
SearchResponse.new({}, 500)
54-
end
47+
response = get(http: http)
48+
logger.debug response
49+
SearchResponse.new(parse_response(response), response.code)
50+
rescue StandardError => e
51+
Rollbar.error(e, "Failed to connect to Amazon. Reqeust: #{http}")
52+
SearchResponse.new({}, 500)
5553
end
5654

5755
private

lib/amazon_product_api/search_response.rb

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ module AmazonProductAPI
99
# this class. By isolating it from the rest of the codebase, we only have one
1010
# file to touch if the API response changes.
1111
class SearchResponse
12-
1312
SUCCESS_CODE_RANGE = (200..299)
1413
FOUND_CODE = 302
1514
NOT_MODIFIED = 304

spec/features/managing_items_and_wishlists_spec.rb

+8-8
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,21 @@
3535
expect(page).to have_text 'Needed: 18'
3636
end
3737

38-
scenario "I get redirected to the search page when Amazon returns an error code.", :external do
38+
scenario 'I get redirected to the search page when Amazon returns an error code.', :external do
3939
visit wishlist_path(wishlist)
40-
click_link "Add to Wishlist"
41-
fill_in "search_field", with: "return an error" # Triggers webmock to return 500
42-
click_button "Search Amazon"
40+
click_link 'Add to Wishlist'
41+
fill_in 'search_field', with: 'return an error' # Triggers webmock to return 500
42+
click_button 'Search Amazon'
4343

4444
expect(page).to have_text 'Could not connect to Amazon'
4545
end
4646

47-
scenario "I get redirected to the search page when the call to Amazon to connect.", :external do
47+
scenario 'I get redirected to the search page when the call to Amazon to connect.', :external do
4848
allow(HTTParty).to receive(:get).and_raise(HTTParty::Error)
4949
visit wishlist_path(wishlist)
50-
click_link "Add to Wishlist"
51-
fill_in "search_field", with: "corgi"
52-
click_button "Search Amazon"
50+
click_link 'Add to Wishlist'
51+
fill_in 'search_field', with: 'corgi'
52+
click_button 'Search Amazon'
5353

5454
expect(page).to have_text 'Could not connect to Amazon'
5555
end

spec/lib/amazon_product_api/search_response_spec.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
end
1616
let(:blank_response) { AmazonProductAPI::SearchResponse.new({}, 200) }
1717
let(:full_response) { AmazonProductAPI::SearchResponse.new(response_hash, 200) }
18-
let(:success_codes) { [ 200, 204, 302, 304 ] }
19-
let(:failure_codes) { [ 400, 500 ] }
18+
let(:success_codes) { [200, 204, 302, 304] }
19+
let(:failure_codes) { [400, 500] }
2020

2121
describe '#num_pages' do
2222
context 'no page number is present' do

0 commit comments

Comments
 (0)