Permalink
Browse files

Add POST to application to create links.

  • Loading branch information...
1 parent 97b792c commit d26c700854436919e927718bb966fc340475f012 Gabe Berke-Williams committed Apr 7, 2012
Showing with 22 additions and 3 deletions.
  1. +5 −2 app/application.rb
  2. +17 −1 spec/app/application_spec.rb
View
@@ -1,8 +1,6 @@
require 'bundler/setup'
require 'sinatra/base'
-require_relative '../lib/encoder'
-require_relative '../lib/decoder'
require_relative '../lib/ohm_setup'
require_relative 'models/link'
@@ -13,5 +11,10 @@ class Application < Sinatra::Base
redirect link.url
end
+
+ post '/' do
+ url = params[:url]
+ Link.create(url: url)
+ end
end
end
@@ -2,7 +2,7 @@
describe Shawtie::Application do
context 'GET /:hash' do
- let(:link) { FactoryGirl.build(:link) }
+ let!(:link) { FactoryGirl.create(:link) }
before do
get "/#{link.hash}"
@@ -16,4 +16,20 @@
last_response.location.should == link.url
end
end
+
+ context 'POST /' do
+ let(:url) { 'http://ruby-lang.com' }
+
+ before do
+ post '/', url: url
+ end
+
+ it 'is successful' do
+ last_response.should be_successful
+ end
+
+ it 'creates a link with the given url' do
+ Link.find(url: url).size.should == 1
+ end
+ end
end

0 comments on commit d26c700

Please sign in to comment.