Skip to content

Commit

Permalink
Add POST to application to create links.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabe Berke-Williams committed Apr 7, 2012
1 parent 97b792c commit d26c700
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
7 changes: 5 additions & 2 deletions app/application.rb
@@ -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'

Expand All @@ -13,5 +11,10 @@ class Application < Sinatra::Base

redirect link.url
end

post '/' do
url = params[:url]
Link.create(url: url)
end
end
end
18 changes: 17 additions & 1 deletion spec/app/application_spec.rb
Expand Up @@ -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}"
Expand All @@ -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.