Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Gabe Berke-Williams
committed
Apr 7, 2012
1 parent
f0248a6
commit 0637262
Showing
12 changed files
with
119 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,17 @@ | |||
require 'bundler/setup' | |||
require 'sinatra/base' | |||
|
|||
require_relative '../lib/encoder' | |||
require_relative '../lib/decoder' | |||
require_relative '../lib/ohm_setup' | |||
require_relative 'models/link' | |||
|
|||
module Shawtie | |||
class Application < Sinatra::Base | |||
get '/:hash' do |hash| | |||
link = Link.find(hash: hash).first | |||
|
|||
redirect link.url | |||
end | |||
end | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,11 @@ | |||
class Link < Ohm::Model | |||
attribute :url | |||
attribute :hash | |||
|
|||
index :hash | |||
|
|||
def validate | |||
assert_present :url | |||
assert_present :hash | |||
end | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,3 @@ | |||
require 'ohm' | |||
|
|||
# Ohm.connect |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,19 @@ | |||
require 'spec_helper' | |||
|
|||
describe Shawtie::Application do | |||
context 'GET /:hash' do | |||
let(:link) { FactoryGirl.build(:link) } | |||
|
|||
before do | |||
get "/#{link.hash}" | |||
end | |||
|
|||
it 'is a redirect' do | |||
last_response.should be_redirect | |||
end | |||
|
|||
it 'redirects to the URL' do | |||
last_response.location.should == link.url | |||
end | |||
end | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,10 @@ | |||
FactoryGirl.define do | |||
factory :link do | |||
ignore do | |||
url 'http://example.com' | |||
sequence(:hash) { |n| "hash#{n}" } | |||
end | |||
|
|||
initialize_with { Link.create(url: url, hash: hash) } | |||
end | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,15 @@ | |||
require 'spec_helper' | |||
|
|||
describe Link do | |||
context 'validations' do | |||
it 'requires url to be present' do | |||
link = Link.create(url: nil) | |||
link.errors.assoc(:url)[1].should == :not_present | |||
end | |||
|
|||
it 'requires hash to be present' do | |||
link = Link.create(hash: nil) | |||
link.errors.assoc(:hash)[1].should == :not_present | |||
end | |||
end | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,5 +1,10 @@ | |||
$LOAD_PATH << File.expand_path('../lib', __FILE__) | $LOAD_PATH << File.dirname(__FILE__) | ||
|
|
||
require 'bundler/setup' | |||
require 'rspec' | require 'rspec' | ||
require 'encoder' | require 'rack/test' | ||
require 'decoder' | require 'factory_girl' | ||
|
|||
require_relative '../app/application' | |||
|
|||
Dir['spec/support/**/*.rb'].each { |f| require File.expand_path(f) } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1 @@ | |||
FactoryGirl.find_definitions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,7 @@ | |||
RSpec.configure do |config| | |||
config.include Rack::Test::Methods | |||
|
|||
def app | |||
Shawtie::Application | |||
end | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,5 @@ | |||
RSpec.configure do |config| | |||
config.before do | |||
Ohm.redis.flushdb | |||
end | |||
end |