Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Ensure that the url has not already been created.

  • Loading branch information...
commit 50bb43a26ff9f39d8b99f96d792d32830dc483ad 1 parent a79b4c7
@drapergeek authored
View
4 app/controllers/short_urls_controller.rb
@@ -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
View
4 app/models/short_url.rb
@@ -12,6 +12,10 @@ def save
end
end
+ def full_url
+ "http://#{HOSTNAME}/#{name}"
+ end
+
private
def existing_entry_with_same_name?
View
12 spec/features/create_short_url_spec.rb
@@ -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
+
View
7 spec/models/short_url_spec.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.