Compare commits
3 Commits
ae2360a480
...
144731062b
| Author | SHA1 | Date |
|---|---|---|
|
|
144731062b | |
|
|
72f3e03edd | |
|
|
b08693e866 |
14
app.rb
14
app.rb
|
|
@ -34,6 +34,20 @@ class App < Roda
|
|||
flash['message'] = "Please enter a valid URL";
|
||||
r.redirect '/'
|
||||
end
|
||||
|
||||
begin
|
||||
OpenURI.open_uri(url)
|
||||
rescue URI::BadURIError
|
||||
flash['message'] = "Invalid URL"
|
||||
r.redirect '/'
|
||||
rescue OpenURI::HTTPError
|
||||
flash['message'] = "URL not found"
|
||||
r.redirect '/'
|
||||
rescue SocketError => e
|
||||
flash['message'] = "URL does not resolve"
|
||||
r.redirect '/'
|
||||
end
|
||||
|
||||
if links.filter(:url => url).first.nil?
|
||||
code = SecureRandom.urlsafe_base64 4
|
||||
links.insert(url: url, code: code)
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ Then('I should be redirected to {string}') do |string|
|
|||
end
|
||||
|
||||
Then('The status code should be {int}') do |code|
|
||||
puts page.status_code.should eq(code)
|
||||
page.status_code.should eq(code)
|
||||
end
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -26,3 +26,27 @@ Feature: Submit
|
|||
And I click the "Submit" button
|
||||
Then I should be on "/create" page
|
||||
And I should see the message "Link exists"
|
||||
|
||||
@db-test
|
||||
Scenario: Submitting the form with a URL that is 404
|
||||
Given I visit the "/" page
|
||||
When I type "http://google.com/example" in the "url" field
|
||||
And I click the "Submit" button
|
||||
Then I should be on "/" page
|
||||
And I should see the message "URL not found"
|
||||
|
||||
@db-test
|
||||
Scenario: Submitting the form with a URL that does not resolve
|
||||
Given I visit the "/" page
|
||||
When I type "http://bad.tld" in the "url" field
|
||||
And I click the "Submit" button
|
||||
Then I should be on "/" page
|
||||
And I should see the message "URL does not resolve"
|
||||
|
||||
@db-test
|
||||
Scenario: Submitting the form with an invalid URL
|
||||
Given I visit the "/" page
|
||||
When I type "not-an-url" in the "url" field
|
||||
And I click the "Submit" button
|
||||
Then I should be on "/" page
|
||||
And I should see the message "Invalid URL"
|
||||
|
|
|
|||
Loading…
Reference in New Issue