Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 144731062b | |||
| 72f3e03edd | |||
| b08693e866 |
@@ -34,6 +34,20 @@ class App < Roda
|
|||||||
flash['message'] = "Please enter a valid URL";
|
flash['message'] = "Please enter a valid URL";
|
||||||
r.redirect '/'
|
r.redirect '/'
|
||||||
end
|
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?
|
if links.filter(:url => url).first.nil?
|
||||||
code = SecureRandom.urlsafe_base64 4
|
code = SecureRandom.urlsafe_base64 4
|
||||||
links.insert(url: url, code: code)
|
links.insert(url: url, code: code)
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ Then('I should be redirected to {string}') do |string|
|
|||||||
end
|
end
|
||||||
|
|
||||||
Then('The status code should be {int}') do |code|
|
Then('The status code should be {int}') do |code|
|
||||||
puts page.status_code.should eq(code)
|
page.status_code.should eq(code)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -26,3 +26,27 @@ Feature: Submit
|
|||||||
And I click the "Submit" button
|
And I click the "Submit" button
|
||||||
Then I should be on "/create" page
|
Then I should be on "/create" page
|
||||||
And I should see the message "Link exists"
|
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"
|
||||||
|
|||||||
Reference in New Issue
Block a user