Skip to content

Commit

Permalink
Refactor all_urls_resolve?
Browse files Browse the repository at this point in the history
  • Loading branch information
pezholio committed Jun 6, 2014
1 parent 9390797 commit 992e2cc
Showing 1 changed file with 15 additions and 16 deletions.
31 changes: 15 additions & 16 deletions app/models/response_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -169,24 +169,23 @@ def responses_with_url_type
end

def all_urls_resolve?
errors = []
@errors = []
responses_with_url_type.each do |response|
unless response.string_value.blank?
response_code = Rails.cache.fetch(response.string_value) rescue nil
if response_code.nil?
response_code = HTTParty.get(response.string_value).code rescue nil
end
if response_code != 200
response.error = true
response.save
errors << response
else
response.error = false
response.save
end
end
resolve_url(response)
end
@errors.length == 0
end

def resolve_url(response)
return nil if response.string_value.blank?

response_code = Rails.cache.fetch(response.string_value) rescue nil
if response_code.nil?
response_code = HTTParty.get(response.string_value).code rescue nil
end
errors.length == 0
response.error = (response_code != 200)
response.save
@errors << response if response.error === true
end

def all_mandatory_questions_complete?
Expand Down

0 comments on commit 992e2cc

Please sign in to comment.