Browse files

Add Turnip tests and views. App has basic functionality.

  • Loading branch information...
1 parent d26c700 commit a0e69ca8aab5ae63fb43fe524f4e06772b4a7618 @gabebw committed Apr 7, 2012
View
1 .rspec
@@ -0,0 +1 @@
+-r turnip
View
2 Gemfile
@@ -10,4 +10,6 @@ group :test do
gem 'rack-test'
gem 'rspec', '~> 2.9.0'
gem 'factory_girl', '~> 3.1.0'
+ gem 'turnip', '~> 0.3.0'
+ gem 'capybara', '~> 1.1.2'
end
View
28 Gemfile.lock
@@ -4,13 +4,28 @@ GEM
activesupport (3.2.3)
i18n (~> 0.6)
multi_json (~> 1.0)
+ capybara (1.1.2)
+ mime-types (>= 1.16)
+ nokogiri (>= 1.3.3)
+ rack (>= 1.0.0)
+ rack-test (>= 0.5.4)
+ selenium-webdriver (~> 2.0)
+ xpath (~> 0.1.4)
+ childprocess (0.3.1)
+ ffi (~> 1.0.6)
diff-lcs (1.1.3)
factory_girl (3.1.0)
activesupport (>= 3.0.0)
+ ffi (1.0.11)
+ gherkin (2.9.3)
+ json (>= 1.4.6)
i18n (0.6.0)
+ json (1.6.6)
+ mime-types (1.18)
multi_json (1.2.0)
nest (1.1.1)
redis
+ nokogiri (1.5.2)
ohm (1.0.0.rc1)
nest (~> 1.0)
scrivener (~> 0.0.3)
@@ -31,17 +46,29 @@ GEM
rspec-expectations (2.9.1)
diff-lcs (~> 1.1.3)
rspec-mocks (2.9.0)
+ rubyzip (0.9.6.1)
scrivener (0.0.3)
+ selenium-webdriver (2.20.0)
+ childprocess (>= 0.2.5)
+ ffi (~> 1.0)
+ multi_json (~> 1.0)
+ rubyzip
sinatra (1.3.2)
rack (~> 1.3, >= 1.3.6)
rack-protection (~> 1.2)
tilt (~> 1.3, >= 1.3.3)
tilt (1.3.3)
+ turnip (0.3.0)
+ gherkin (>= 2.5)
+ rspec (~> 2.0)
+ xpath (0.1.4)
+ nokogiri (~> 1.3)
PLATFORMS
ruby
DEPENDENCIES
+ capybara (~> 1.1.2)
factory_girl (~> 3.1.0)
ohm (~> 1.0.0.rc1)
ohm-contrib (~> 1.0.0.rc2)
@@ -50,3 +77,4 @@ DEPENDENCIES
redis (~> 2.2.2)
rspec (~> 2.9.0)
sinatra (~> 1.3.2)
+ turnip (~> 0.3.0)
View
8 app/application.rb
@@ -6,6 +6,10 @@
module Shawtie
class Application < Sinatra::Base
+ get '/' do
+ erb :index
+ end
+
get '/:hash' do |hash|
link = Link.find(hash: hash).first
@@ -14,7 +18,9 @@ class Application < Sinatra::Base
post '/' do
url = params[:url]
- Link.create(url: url)
+ link = Link.create(url: url)
+ shortened_url = URI.join("http://#{request.host_with_port}", link.hash)
+ erb :show, locals: { url: shortened_url }
end
end
end
View
6 app/views/index.erb
@@ -0,0 +1,6 @@
+<form action='/' method='post'>
+ <label for='url'>URL
+ <input type="text" name="url" />
+ </label>
+ <input type="submit" value="Submit" />
+</form>
View
6 app/views/layout.erb
@@ -0,0 +1,6 @@
+<!DOCTYPE html>
+<html>
+ <body>
+ <%= yield %>
+ </body>
+</html>
View
3 app/views/show.erb
@@ -0,0 +1,3 @@
+<p>
+ Shortened URL: <%= url %>
+</p>
View
5 spec/acceptance/create_link.feature
@@ -0,0 +1,5 @@
+Feature: Create a link
+
+ Scenario: Create a link
+ When I create a link
+ Then I should see the shortened URL
View
1 spec/spec_helper.rb
@@ -4,6 +4,7 @@
require 'rspec'
require 'rack/test'
require 'factory_girl'
+require 'turnip/capybara'
require_relative '../app/application'
View
10 spec/step_definitions/link_steps.rb
@@ -0,0 +1,10 @@
+step 'I create a link' do
+ visit '/'
+ fill_in 'URL', with: 'http://example.com'
+ click_button 'Submit'
+end
+
+step 'I should see the shortened URL' do
+ latest_link = Link.all.first(order: 'DESC')
+ page.should have_content "#{page.current_host}/#{latest_link.hash}"
+end
View
3 spec/support/rack.rb
@@ -1,5 +1,8 @@
RSpec.configure do |config|
config.include Rack::Test::Methods
+ config.before(:each, type: :request) do
+ Capybara.app = app
+ end
def app
Shawtie::Application

0 comments on commit a0e69ca

Please sign in to comment.