Permalink
Browse files

Handle long urls that already exist

  • Loading branch information...
1 parent 3116798 commit 280d3413cf46bbf7d591d0b84f6a8ddb010a15af @joshuaclayton committed Oct 7, 2009
View
7 app/controllers/peas_controller.rb
@@ -2,6 +2,13 @@ class PeasController < InheritedResources::Base
respond_to :html
actions :create, :show
+ def create
+ if (pea = Pea.find_by_long_url(params[:pea][:long_url]))
+ return redirect_to(pea_path(pea))
+ end
+ create!
+ end
+
def redir
pea = Pea.find_by_key(params[:pea_key])
redirect_to(pea ? pea.long_url : root_path)
View
13 features/generate_shortened_urls.feature
@@ -5,8 +5,15 @@ Feature: Generate shortened URLs
Scenario: Shorten a given URL
When I go to the homepage
- And I fill in "Enter your long URL" with "http://google.com"
+ And I fill in "Enter your long URL" with "http://www.google.com"
And I press "Shorten"
- Then I should see "http://google.com was shortened to:"
- And I should see a short URL for "http://google.com"
+ Then I should see "http://www.google.com was shortened to:"
+ And I should see a short URL for "http://www.google.com"
+ Scenario: Shorten a given URL when the URL exists
+ Given a pea exists for the URL "http://www.google.com"
+ When I go to the homepage
+ And I fill in "Enter your long URL" with "http://www.google.com"
+ And I press "Shorten"
+ Then I should see "http://www.google.com was shortened to:"
+ And I should see a short URL for "http://www.google.com"
View
0 features/homepage_viewing.feature → features/view_homepage.feature
File renamed without changes.

0 comments on commit 280d341

Please sign in to comment.