Compare commits
No commits in common. "144731062ba0332ef8908d27939b41b82497cac3" and "ae2360a48074df6501ae2312c83d1fe67c87f6ea" have entirely different histories.
144731062b
...
ae2360a480
14
app.rb
14
app.rb
|
|
@ -34,20 +34,6 @@ 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|
|
||||||
page.status_code.should eq(code)
|
puts page.status_code.should eq(code)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,27 +26,3 @@ 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"
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue