Skip to content
This repository was archived by the owner on Oct 12, 2018. It is now read-only.

Commit 5ac69cb

Browse files
committed
First pass at panopticon app - initially it will just provide our service to tell if a slug is unique
0 parents  commit 5ac69cb

File tree

6 files changed

+195
-0
lines changed

6 files changed

+195
-0
lines changed

.rvmrc

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/usr/bin/env bash
2+
3+
# This is an RVM Project .rvmrc file, used to automatically load the ruby
4+
# development environment upon cd'ing into the directory
5+
6+
# First we specify our desired <ruby>[@<gemset>], the @gemset name is optional.
7+
environment_id="ruby-1.9.2-p180@ag-panopticon"
8+
9+
#
10+
# First we attempt to load the desired environment directly from the environment
11+
# file. This is very fast and efficicent compared to running through the entire
12+
# CLI and selector. If you want feedback on which environment was used then
13+
# insert the word 'use' after --create as this triggers verbose mode.
14+
#
15+
if [[ -d "${rvm_path:-$HOME/.rvm}/environments" \
16+
&& -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]] ; then
17+
\. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
18+
19+
[[ -s ".rvm/hooks/after_use" ]] && . ".rvm/hooks/after_use"
20+
else
21+
# If the environment file has not yet been created, use the RVM CLI to select.
22+
rvm --create use "$environment_id"
23+
fi
24+
25+
#
26+
# If you use an RVM gemset file to install a list of gems (*.gems), you can have
27+
# it be automatically loaded. Uncomment the following and adjust the filename if
28+
# necessary.
29+
#
30+
# filename=".gems"
31+
# if [[ -s "$filename" ]] ; then
32+
# rvm gemset import "$filename" | grep -v already | grep -v listed | grep -v complete | sed '/^$/d'
33+
# fi
34+
35+
#
36+
# If you use bundler and would like to run bundle each time you enter the
37+
# directory, you can uncomment the following code.
38+
#
39+
# # Ensure that Bundler is installed. Install it if it is not.
40+
# if ! command -v bundle >/dev/null; then
41+
# printf "The rubygem 'bundler' is not installed. Installing it now.\n"
42+
# gem install bundler
43+
# fi
44+
#
45+
# # Bundle while reducing excess noise.
46+
# printf "Bundling your gems. This may take a few minutes on a fresh clone.\n"
47+
# bundle | grep -v '^Using ' | grep -v ' is complete' | sed '/^$/d'
48+
#
49+

Gemfile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
source :rubygems
2+
3+
gem 'sinatra'
4+
gem 'datamapper'
5+
gem 'json', '~> 1.4.6'
6+
7+
group :development, :test do
8+
gem 'dm-sqlite-adapter', '~> 1.1.0'
9+
gem 'rack-test', '~> 0.5.0'
10+
end

Gemfile.lock

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
GEM
2+
remote: http://rubygems.org/
3+
specs:
4+
addressable (2.2.6)
5+
bcrypt-ruby (2.1.4)
6+
data_objects (0.10.6)
7+
addressable (~> 2.1)
8+
datamapper (1.1.0)
9+
dm-aggregates (= 1.1.0)
10+
dm-constraints (= 1.1.0)
11+
dm-core (= 1.1.0)
12+
dm-migrations (= 1.1.0)
13+
dm-serializer (= 1.1.0)
14+
dm-timestamps (= 1.1.0)
15+
dm-transactions (= 1.1.0)
16+
dm-types (= 1.1.0)
17+
dm-validations (= 1.1.0)
18+
dm-aggregates (1.1.0)
19+
dm-core (~> 1.1.0)
20+
dm-constraints (1.1.0)
21+
dm-core (~> 1.1.0)
22+
dm-core (1.1.0)
23+
addressable (~> 2.2.4)
24+
dm-do-adapter (1.1.0)
25+
data_objects (~> 0.10.2)
26+
dm-core (~> 1.1.0)
27+
dm-migrations (1.1.0)
28+
dm-core (~> 1.1.0)
29+
dm-serializer (1.1.0)
30+
dm-core (~> 1.1.0)
31+
fastercsv (~> 1.5.4)
32+
json (~> 1.4.6)
33+
dm-sqlite-adapter (1.1.0)
34+
dm-do-adapter (~> 1.1.0)
35+
do_sqlite3 (~> 0.10.2)
36+
dm-timestamps (1.1.0)
37+
dm-core (~> 1.1.0)
38+
dm-transactions (1.1.0)
39+
dm-core (~> 1.1.0)
40+
dm-types (1.1.0)
41+
bcrypt-ruby (~> 2.1.4)
42+
dm-core (~> 1.1.0)
43+
fastercsv (~> 1.5.4)
44+
json (~> 1.4.6)
45+
stringex (~> 1.2.0)
46+
uuidtools (~> 2.1.2)
47+
dm-validations (1.1.0)
48+
dm-core (~> 1.1.0)
49+
do_sqlite3 (0.10.6)
50+
data_objects (= 0.10.6)
51+
fastercsv (1.5.4)
52+
json (1.4.6)
53+
rack (1.3.1)
54+
rack-test (0.5.7)
55+
rack (>= 1.0)
56+
sinatra (1.2.6)
57+
rack (~> 1.1)
58+
tilt (>= 1.2.2, < 2.0)
59+
stringex (1.2.2)
60+
tilt (1.3.2)
61+
uuidtools (2.1.2)
62+
63+
PLATFORMS
64+
ruby
65+
66+
DEPENDENCIES
67+
datamapper
68+
dm-sqlite-adapter (~> 1.1.0)
69+
json (~> 1.4.6)
70+
rack-test (~> 0.5.0)
71+
sinatra

config.ru

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
app_path = File.dirname(__FILE__)
2+
$:.unshift(app_path) unless $:.include?(app_path)
3+
# require 'env'
4+
require 'panopticon'
5+
6+
require "bundler"
7+
8+
Bundler.require(:default, ENV['RACK_ENV'])
9+
run Sinatra::Application

panopticon.rb

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
require 'sinatra'
2+
require 'json'
3+
4+
require 'datamapper'
5+
require 'dm-validations'
6+
DataMapper::setup(:default, 'sqlite3::memory:')
7+
8+
class Resource
9+
include DataMapper::Resource
10+
11+
property :id, Serial
12+
property :active, Boolean, :default => false, :required => true
13+
property :slug, String, :unique => true, :required => true, :length => 4..32
14+
property :owning_app, String, :required => true
15+
property :created_at, DateTime
16+
end
17+
18+
DataMapper.finalize
19+
DataMapper.auto_upgrade!
20+
21+
post '/slugs' do
22+
new_resource = Resource.new(:slug => params[:slug][:name], :owning_app => params[:slug][:owning_app], :active => true)
23+
24+
if new_resource.save
25+
status 201
26+
else
27+
status 406
28+
end
29+
end

test/panopticon_test.rb

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
require File.expand_path('../../panopticon', __FILE__)
2+
require 'test/unit'
3+
require 'rack/test'
4+
5+
ENV['RACK_ENV'] = 'test'
6+
7+
class PanopticonTest < Test::Unit::TestCase
8+
include Rack::Test::Methods
9+
10+
def app
11+
Sinatra::Application
12+
end
13+
14+
def test_it_returns_an_http_201_for_success
15+
params = {:name => 'james', :owning_app => 'guides'}
16+
post '/slugs', :slug => params
17+
assert_equal 201, last_response.status
18+
end
19+
20+
def test_it_returns_an_http_406_for_duplicate_slug
21+
params = {:name => 'james', :owning_app => 'guides'}
22+
post '/slugs', :slug => params
23+
post '/slugs', :slug => params
24+
assert_equal 406, last_response.status
25+
end
26+
27+
end

0 commit comments

Comments
 (0)