Permalink
Browse files

Ensure that the url has not already been created.

  • Loading branch information...
1 parent a79b4c7 commit 50bb43a26ff9f39d8b99f96d792d32830dc483ad @drapergeek committed Dec 16, 2012
@@ -5,9 +5,9 @@ def new
def create
short_url = ShortUrl.new(url: params[:url], name: params[:name])
if short_url.save
- flash[:notice] = "Your url: http://#{HOSTNAME}/#{short_url.name}"
+ flash[:notice] = "Your url: #{short_url.full_url}"
else
- flash[:error] = "That name is already taken"
+ flash[:error] = "#{short_url.name} is already taken"
end
redirect_to new_short_url_path
@@ -12,6 +12,10 @@ def save
end
end
+ def full_url
+ "http://#{HOSTNAME}/#{name}"
+ end
+
private
def existing_entry_with_same_name?
@@ -8,4 +8,16 @@
page.should have_content 'Your url: http://example.com/Search'
end
+
+ scenario 'url name is already taking' do
+ ShortUrl.new(name: "Search",url: "http://bing.com").save
+
+ visit '/'
+ fill_in 'Url', with: 'http://google.com'
+ fill_in 'Name', with: 'Search'
+ click_button 'Create'
+
+ page.should have_content 'Search is already taken'
+ end
end
+
@@ -23,4 +23,11 @@
expect(shorturl.url).to eq("myurl")
end
end
+
+ describe "#full_url" do
+ it "returns the full path to the short url" do
+ shorturl = ShortUrl.new(name: 'mypage', url: 'http://www.url.com')
+ expect(shorturl.full_url).to eq('http://example.com/mypage')
+ end
+ end
end

0 comments on commit 50bb43a

Please sign in to comment.