Compare commits

..

No commits in common. "e6cc0959a40d3a8d7229de1ee9dc2c0d02c562f8" and "c874426f2ec813eab2d92f36f36101bcefcdc4b3" have entirely different histories.

3 changed files with 3 additions and 23 deletions

9
app.rb
View File

@ -18,11 +18,8 @@ class App < Roda
end end
r.get String do | url_code | r.get String do | url_code |
link = links.filter(:code => url_code) link = links.filter(:code => url_code).first[:url]
r.redirect link.first[:url] unless link.first.nil? r.redirect link
@message = "Link #{url_code} doesn't exist"
response.status = 404
view :home
end end
r.post "create" do r.post "create" do
@ -31,7 +28,7 @@ class App < Roda
flash['message'] = "Please enter a valid URL"; flash['message'] = "Please enter a valid URL";
r.redirect '/' r.redirect '/'
end end
if links.filter(:url => url).first.nil? if nil == links.filter(:url => url).first
code = SecureRandom.urlsafe_base64 4 code = SecureRandom.urlsafe_base64 4
links.insert(url: url, code: code) links.insert(url: url, code: code)
@message = "Link created" @message = "Link created"

View File

@ -39,11 +39,3 @@ Feature: Homepage
Given A link already exists with the url "https://google.com" and code "aaaaaa" Given A link already exists with the url "https://google.com" and code "aaaaaa"
When I visit the "/aaaaaa" location When I visit the "/aaaaaa" location
Then I should be redirected to "https://google.com" Then I should be redirected to "https://google.com"
Scenario: Accessing a nonexistent URL code
Given I visit the "/aaaaaa" location
Then I should be on "/aaaaaa" page
And The status code should be 404
And I should see the message "Link aaaaaa doesn't exist"
And I should see a form field "url"
And I should see a "Submit" button

View File

@ -3,7 +3,6 @@ Before('@db-test') do
@links = Sequel.sqlite("db/#{ENV['DB_NAME']}")[:links] @links = Sequel.sqlite("db/#{ENV['DB_NAME']}")[:links]
end end
# GIVEN # GIVEN
Given('I visit the {string} page') do |string| Given('I visit the {string} page') do |string|
@ -18,7 +17,6 @@ Given('A link already exists with the url {string} and code {string}') do |url,
@links.insert(url: url, code: code) @links.insert(url: url, code: code)
end end
# WHEN # WHEN
When('I click the {string} button') do |string| When('I click the {string} button') do |string|
@ -33,7 +31,6 @@ When('I visit the {string} location') do |string|
visit string visit string
end end
# THEN # THEN
Then('I should see text {string}') do |string| Then('I should see text {string}') do |string|
@ -61,12 +58,6 @@ Then('I should be redirected to {string}') do |string|
location = actual.index(string) location = actual.index(string)
location.should equal(0) location.should equal(0)
end end
Then('The status code should be {int}') do |code|
puts page.status_code.should eq(code)
end
# AFTER # AFTER
After('@db-test') do After('@db-test') do