Compare commits

..

No commits in common. "5bce31baf283a051d1213c30601355494939d8d5" and "f8499a79c2c8cd6b5e495886dc436010945bd55a" have entirely different histories.

3 changed files with 7 additions and 18 deletions

11
app.rb
View File

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

View File

@ -42,8 +42,5 @@ Feature: Homepage
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
Then I should be on "/" page
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]
end
# GIVEN
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)
end
# WHEN
When('I click the {string} button') do |string|
@ -33,7 +31,6 @@ When('I visit the {string} location') do |string|
visit string
end
# THEN
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.should equal(0)
end
Then('The status code should be {int}') do |code|
puts page.status_code.should eq(code)
end
# AFTER
After('@db-test') do