Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

first cut, just catch POST

  • Loading branch information...
commit 7ccc97f98d73df6629a0d1ec7719b7b2e2862040 0 parents
@stevenwilkin authored
4 .gitignore
@@ -0,0 +1,4 @@
+*.swp
+coverage/*
+log/*.log
+.redcar
10 Gemfile
@@ -0,0 +1,10 @@
+source :rubygems
+
+gem 'rake', "~> 0.9.2"
+gem "rack", "~> 1.3.3"
+gem "redis", "~> 2.2.2"
+gem "sinatra"
+
+group :test do
+ gem "rack-test"
+end
25 Gemfile.lock
@@ -0,0 +1,25 @@
+GEM
+ remote: http://rubygems.org/
+ specs:
+ rack (1.3.6)
+ rack-protection (1.2.0)
+ rack
+ rack-test (0.6.1)
+ rack (>= 1.0)
+ rake (0.9.2.2)
+ redis (2.2.2)
+ sinatra (1.3.2)
+ rack (~> 1.3, >= 1.3.6)
+ rack-protection (~> 1.2)
+ tilt (~> 1.3, >= 1.3.3)
+ tilt (1.3.3)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ rack (~> 1.3.3)
+ rack-test
+ rake (~> 0.9.2)
+ redis (~> 2.2.2)
+ sinatra
27 Rakefile
@@ -0,0 +1,27 @@
+$: << File.dirname(__FILE__)
+
+task :default => 'test'
+
+desc "Run all tests"
+task :test do
+ %w{test:unit test:api test:integration}.each do |task|
+ Rake::Task[task].invoke
+ end
+end
+
+namespace :test do
+ desc "Run unit tests"
+ task :unit do
+ Dir["test/unit/**/*_test.rb"].sort.each { |test| load test }
+ end
+
+ desc "Run api tests"
+ task :api do
+ Dir["test/api/**/*_test.rb"].sort.each { |test| load test }
+ end
+
+ desc "Run integration tests"
+ task :integration do
+ Dir["test/integration/**/*_test.rb"].sort.each { |test| load test }
+ end
+end
11 coffee_tracker.rb
@@ -0,0 +1,11 @@
+require 'sinatra'
+
+require_relative 'conf/logger'
+require_relative 'conf/redis'
+
+class CoffeeTracker < Sinatra::Base
+
+ post '/' do
+ end
+
+end
9 conf/logger.rb
@@ -0,0 +1,9 @@
+require 'logger'
+
+if "production".eql?(ENV['RACK_ENV'])
+ $logger = ::Logger.new(STDOUT)
+else
+ $logger = ::Logger.new("#{File.dirname(__FILE__)}/../log/#{ENV['RACK_ENV']}.log")
+end
+
+$logger.level = Logger::DEBUG
28 conf/redis.rb
@@ -0,0 +1,28 @@
+require 'redis'
+
+host = 'localhost'
+port = 6379
+db = 0
+
+case ENV['RACK_ENV']
+ when 'development'
+ $logger.debug("---> development Redis")
+ $redis = Redis.new(:host => host, :port => port, :db => db)
+ when 'test'
+ db = 1
+ $logger.debug("---> test Redis")
+ $redis = Redis.new(:host => host, :port => port, :db => db)
+ when 'production'
+ # RedisToGo on Heroku
+ #
+ if ENV['REDISTOGO_URL']
+ $logger.debug("---> production Redis at " + ENV['REDISTOGO_URL'])
+ uri = URI.parse(ENV['REDISTOGO_URL'])
+ # Timeout is in seconds
+ $redis = Redis.new(:host => uri.host, :port => uri.port, :db => uri.path, :password => uri.password, :user => uri.user, :timeout => 120)
+ else
+ $logger.debug("---> production Redis " + + host + ":" + port.to_s + "/" +db)
+ $redis = Redis.new(:host => host, :port => port, :db => db)
+ end
+end
+
5 config.ru
@@ -0,0 +1,5 @@
+$: << File.dirname(File.expand_path(__FILE__))
+
+require 'coffee_tracker'
+
+run CoffeeTracker
0  log/.gitkeep
No changes.
21 test/test_helpers.rb
@@ -0,0 +1,21 @@
+ENV['RACK_ENV'] ||= 'test'
+
+require 'simplecov'
+require 'test/unit'
+require 'rack/test'
+
+require_relative '../courier'
+
+module TestHelpers
+ include Rack::Test::Methods
+
+ def app
+ # use a module variable so the app is only ever initialised once
+ # NOTE: possible source of nastiness doing this? makes tests run faster...
+ unless defined? @@app
+ config = File.read(File.join(File.dirname(__FILE__), '..', 'config.ru'))
+ @@app = eval("Rack::Builder.new {(#{config})}")
+ end
+ @@app
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.