diff --git a/app/application.rb b/app/application.rb index cd954bd..2c2f7a3 100644 --- a/app/application.rb +++ b/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' @@ -13,5 +11,10 @@ class Application < Sinatra::Base redirect link.url end + + post '/' do + url = params[:url] + Link.create(url: url) + end end end diff --git a/spec/app/application_spec.rb b/spec/app/application_spec.rb index 3418d14..8badec5 100644 --- a/spec/app/application_spec.rb +++ b/spec/app/application_spec.rb @@ -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