Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

First pass at panopticon app - initially it will just provide our ser…

…vice to tell if a slug is unique
  • Loading branch information...
jystewart committed Jul 25, 2011
0 parents commit 5ac69cbf048acd381c369465ca905f580dcdb85d
Showing with 195 additions and 0 deletions.
  1. +49 −0 .rvmrc
  2. +10 −0 Gemfile
  3. +71 −0 Gemfile.lock
  4. +9 −0 config.ru
  5. +29 −0 panopticon.rb
  6. +27 −0 test/panopticon_test.rb
49 .rvmrc
@@ -0,0 +1,49 @@
#!/usr/bin/env bash

# This is an RVM Project .rvmrc file, used to automatically load the ruby
# development environment upon cd'ing into the directory

# First we specify our desired <ruby>[@<gemset>], the @gemset name is optional.
environment_id="ruby-1.9.2-p180@ag-panopticon"

#
# First we attempt to load the desired environment directly from the environment
# file. This is very fast and efficicent compared to running through the entire
# CLI and selector. If you want feedback on which environment was used then
# insert the word 'use' after --create as this triggers verbose mode.
#
if [[ -d "${rvm_path:-$HOME/.rvm}/environments" \
&& -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]] ; then
\. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"

[[ -s ".rvm/hooks/after_use" ]] && . ".rvm/hooks/after_use"
else
# If the environment file has not yet been created, use the RVM CLI to select.
rvm --create use "$environment_id"
fi

#
# If you use an RVM gemset file to install a list of gems (*.gems), you can have
# it be automatically loaded. Uncomment the following and adjust the filename if
# necessary.
#
# filename=".gems"
# if [[ -s "$filename" ]] ; then
# rvm gemset import "$filename" | grep -v already | grep -v listed | grep -v complete | sed '/^$/d'
# fi

#
# If you use bundler and would like to run bundle each time you enter the
# directory, you can uncomment the following code.
#
# # Ensure that Bundler is installed. Install it if it is not.
# if ! command -v bundle >/dev/null; then
# printf "The rubygem 'bundler' is not installed. Installing it now.\n"
# gem install bundler
# fi
#
# # Bundle while reducing excess noise.
# printf "Bundling your gems. This may take a few minutes on a fresh clone.\n"
# bundle | grep -v '^Using ' | grep -v ' is complete' | sed '/^$/d'
#

10 Gemfile
@@ -0,0 +1,10 @@
source :rubygems

gem 'sinatra'
gem 'datamapper'
gem 'json', '~> 1.4.6'

group :development, :test do
gem 'dm-sqlite-adapter', '~> 1.1.0'
gem 'rack-test', '~> 0.5.0'
end
@@ -0,0 +1,71 @@
GEM
remote: http://rubygems.org/
specs:
addressable (2.2.6)
bcrypt-ruby (2.1.4)
data_objects (0.10.6)
addressable (~> 2.1)
datamapper (1.1.0)
dm-aggregates (= 1.1.0)
dm-constraints (= 1.1.0)
dm-core (= 1.1.0)
dm-migrations (= 1.1.0)
dm-serializer (= 1.1.0)
dm-timestamps (= 1.1.0)
dm-transactions (= 1.1.0)
dm-types (= 1.1.0)
dm-validations (= 1.1.0)
dm-aggregates (1.1.0)
dm-core (~> 1.1.0)
dm-constraints (1.1.0)
dm-core (~> 1.1.0)
dm-core (1.1.0)
addressable (~> 2.2.4)
dm-do-adapter (1.1.0)
data_objects (~> 0.10.2)
dm-core (~> 1.1.0)
dm-migrations (1.1.0)
dm-core (~> 1.1.0)
dm-serializer (1.1.0)
dm-core (~> 1.1.0)
fastercsv (~> 1.5.4)
json (~> 1.4.6)
dm-sqlite-adapter (1.1.0)
dm-do-adapter (~> 1.1.0)
do_sqlite3 (~> 0.10.2)
dm-timestamps (1.1.0)
dm-core (~> 1.1.0)
dm-transactions (1.1.0)
dm-core (~> 1.1.0)
dm-types (1.1.0)
bcrypt-ruby (~> 2.1.4)
dm-core (~> 1.1.0)
fastercsv (~> 1.5.4)
json (~> 1.4.6)
stringex (~> 1.2.0)
uuidtools (~> 2.1.2)
dm-validations (1.1.0)
dm-core (~> 1.1.0)
do_sqlite3 (0.10.6)
data_objects (= 0.10.6)
fastercsv (1.5.4)
json (1.4.6)
rack (1.3.1)
rack-test (0.5.7)
rack (>= 1.0)
sinatra (1.2.6)
rack (~> 1.1)
tilt (>= 1.2.2, < 2.0)
stringex (1.2.2)
tilt (1.3.2)
uuidtools (2.1.2)

PLATFORMS
ruby

DEPENDENCIES
datamapper
dm-sqlite-adapter (~> 1.1.0)
json (~> 1.4.6)
rack-test (~> 0.5.0)
sinatra
@@ -0,0 +1,9 @@
app_path = File.dirname(__FILE__)
$:.unshift(app_path) unless $:.include?(app_path)
# require 'env'
require 'panopticon'

require "bundler"

Bundler.require(:default, ENV['RACK_ENV'])
run Sinatra::Application
@@ -0,0 +1,29 @@
require 'sinatra'
require 'json'

require 'datamapper'
require 'dm-validations'
DataMapper::setup(:default, 'sqlite3::memory:')

class Resource
include DataMapper::Resource

property :id, Serial
property :active, Boolean, :default => false, :required => true
property :slug, String, :unique => true, :required => true, :length => 4..32
property :owning_app, String, :required => true
property :created_at, DateTime
end

DataMapper.finalize
DataMapper.auto_upgrade!

post '/slugs' do
new_resource = Resource.new(:slug => params[:slug][:name], :owning_app => params[:slug][:owning_app], :active => true)

if new_resource.save
status 201
else
status 406
end
end
@@ -0,0 +1,27 @@
require File.expand_path('../../panopticon', __FILE__)
require 'test/unit'
require 'rack/test'

ENV['RACK_ENV'] = 'test'

class PanopticonTest < Test::Unit::TestCase
include Rack::Test::Methods

def app
Sinatra::Application
end

def test_it_returns_an_http_201_for_success
params = {:name => 'james', :owning_app => 'guides'}
post '/slugs', :slug => params
assert_equal 201, last_response.status
end

def test_it_returns_an_http_406_for_duplicate_slug
params = {:name => 'james', :owning_app => 'guides'}
post '/slugs', :slug => params
post '/slugs', :slug => params
assert_equal 406, last_response.status
end

end

0 comments on commit 5ac69cb

Please sign in to comment.
You can’t perform that action at this time.