-
Notifications
You must be signed in to change notification settings - Fork 0
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
0 parents
commit ce5de60
Showing
13 changed files
with
243 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
.bundle | ||
/tmp | ||
/log | ||
.DS_Store | ||
.rvmrc | ||
*~ | ||
coverage/ | ||
.idea | ||
selftest |
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
--color |
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
source 'http://rubygems.org' | ||
|
||
gem 'rake' | ||
gem 'sinatra' | ||
gem 'sinatra-contrib' | ||
gem 'rack-contrib', :git => '[email protected]:rack/rack-contrib.git' | ||
gem 'yajl-ruby', :require => "yajl" | ||
gem 'petroglyph' | ||
gem 'unicorn', '~> 4.1.1' | ||
gem 'pebblebed', :git => '[email protected]:benglerpebbles/pebblebed.git' | ||
gem 's3' | ||
|
||
group :development, :test do | ||
gem 'bengler_test_helper', :git => "[email protected]:origo/bengler_test_helper.git" | ||
gem 'rspec', '~> 2.7.0.rc1' | ||
gem 'rack-test' | ||
gem 'simplecov' | ||
gem 'capistrano', '=2.8.0' | ||
gem 'capistrano-ext', '=1.2.1' | ||
# gem 'vcr' | ||
# gem 'webmock' | ||
# gem 'timecop' | ||
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
$:.unshift(File.dirname(__FILE__)) | ||
|
||
require 'bengler_test_helper/tasks' | ||
|
||
task :environment do | ||
require 'config/environment' | ||
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# encoding: utf-8 | ||
require "json" | ||
|
||
Dir.glob("#{File.dirname(__FILE__)}/v1/**/*.rb").each{ |file| require file } | ||
|
||
class TiramisuV1 < Sinatra::Base | ||
set :root, "#{File.dirname(__FILE__)}/v1" | ||
|
||
register Sinatra::Pebblebed | ||
i_am :tiramisu | ||
|
||
post '/a_resource' do | ||
require_god | ||
end | ||
|
||
put '/a_resource/:resource' do |resource| | ||
require_god | ||
end | ||
|
||
get '/a_resource/:resource' do |resource| | ||
require_identity | ||
end | ||
|
||
end |
Empty file.
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
$:.unshift(File.dirname(__FILE__)) | ||
|
||
require 'config/environment' | ||
require 'api/v1' | ||
require 'config/logging' | ||
require 'rack/contrib' | ||
|
||
ENV['RACK_ENV'] ||= 'development' | ||
set :environment, ENV['RACK_ENV'].to_sym | ||
|
||
use Rack::CommonLogger | ||
|
||
map "/api/tiramisu/v1" do | ||
use Rack::PostBodyContentTypeParser | ||
use Rack::MethodOverride | ||
run TiramisuV1 | ||
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
require "bundler" | ||
Bundler.require | ||
|
||
# $memcached = Dalli::Client.new | ||
|
||
Dir.glob('./lib/**/*.rb').each{ |lib| require lib } | ||
|
||
ENV['RACK_ENV'] ||= "development" | ||
environment = ENV['RACK_ENV'] |
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
require 'logger' | ||
|
||
Dir.mkdir('log') unless File.exist?('log') | ||
|
||
logfile = File.new("log/#{Sinatra::Application.environment}.log", 'a+') | ||
|
||
Log = Logger.new(logfile) | ||
Log.level = Sinatra::Application.environment == :production ? Logger::WARN : Logger::DEBUG | ||
Log.datetime_format = "%Y-%m-%d %H:%M:%S.%L" | ||
|
||
unless Sinatra::Application.environment == :test | ||
STDERR.reopen(logfile) | ||
end | ||
|
||
TiramisuV1.use Rack::CommonLogger, logfile |
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# A sample model, just for illustration purposes | ||
# class Resource < ActiveRecord::Base | ||
# 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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
require 'spec_helper' | ||
|
||
describe 'API v1' do | ||
include Rack::Test::Methods | ||
|
||
def app | ||
TiramisuV1 | ||
end | ||
|
||
god_endpoints = [ | ||
{:method => :post, :endpoint => '/a_resource'}, | ||
{:method => :put, :endpoint => '/a_resource/id'}, | ||
] | ||
|
||
user_endpoints = [ | ||
{:method => :get, :endpoint => '/a_resource/id'} | ||
] | ||
|
||
let(:json_output) { JSON.parse(last_response.body) } | ||
|
||
context "with a logged in god" do | ||
before :each do | ||
Pebblebed::Connector.any_instance.stub(:checkpoint).and_return(DeepStruct.wrap(:me => {:id => 1337, :god => true, :realm => 'rock_and_roll'})) | ||
end | ||
|
||
it "does powerful stuff" | ||
|
||
end | ||
|
||
context "with a logged in user" do | ||
before :each do | ||
Pebblebed::Connector.any_instance.stub(:checkpoint).and_return(DeepStruct.wrap(:me => {:id => 1337, :god => false, :realm => 'rock_and_roll'})) | ||
end | ||
|
||
it "accesses all sorts of things" | ||
|
||
describe "has no access to god endpoints" do | ||
god_endpoints.each do |forbidden| | ||
it "fails to #{forbidden[:method]} #{forbidden[:endpoint]}" do | ||
self.send(forbidden[:method], forbidden[:endpoint]) | ||
last_response.status.should eq(403) | ||
end | ||
end | ||
end | ||
end | ||
|
||
describe "with no current user" do | ||
before :each do | ||
Pebblebed::Connector.any_instance.stub(:checkpoint).and_return(DeepStruct.wrap(:me => {})) | ||
end | ||
|
||
it "mostly gets harmless stuff" | ||
|
||
describe "has no access to god endpoints" do | ||
god_endpoints.each do |forbidden| | ||
it "fails to #{forbidden[:method]} #{forbidden[:endpoint]}" do | ||
self.send(forbidden[:method], forbidden[:endpoint]) | ||
last_response.status.should eq(403) | ||
end | ||
end | ||
end | ||
|
||
describe "has no access to user endpoints" do | ||
user_endpoints.each do |forbidden| | ||
it "fails to #{forbidden[:method]} #{forbidden[:endpoint]}" do | ||
self.send(forbidden[:method], forbidden[:endpoint]) | ||
last_response.status.should eq(403) | ||
end | ||
end | ||
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
class Mockcached | ||
def initialize | ||
@store = {} | ||
end | ||
|
||
def set(*args) | ||
@store[args[0]] = args[1] | ||
end | ||
|
||
def get(*args) | ||
@store[args[0]] | ||
end | ||
|
||
def get_multi(*keys) | ||
result = {} | ||
keys.each do |key| | ||
value = get(key) | ||
result[key] = value if value | ||
end | ||
result | ||
end | ||
|
||
def delete(*args) | ||
@store.delete(args[0]) | ||
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
require 'simplecov' | ||
|
||
SimpleCov.add_filter 'spec' | ||
SimpleCov.add_filter 'config' | ||
SimpleCov.start | ||
|
||
$:.unshift(File.dirname(File.dirname(__FILE__))) | ||
|
||
ENV["RACK_ENV"] = "test" | ||
require 'config/environment' | ||
|
||
# require './spec/mockcached' | ||
require 'rack/test' | ||
|
||
require 'api/v1' | ||
require 'config/logging' | ||
|
||
# require 'vcr' | ||
# VCR.config do |c| | ||
# c.cassette_library_dir = 'spec/fixtures/vcr_cassettes' | ||
# c.stub_with :webmock | ||
# end | ||
|
||
set :environment, :test | ||
|
||
# Run all examples in a transaction | ||
RSpec.configure do |c| | ||
c.around(:each) do |example| | ||
clear_cookies if respond_to?(:clear_cookies) | ||
# $memcached = Mockcached.new | ||
ActiveRecord::Base.connection.transaction do | ||
example.run | ||
raise ActiveRecord::Rollback | ||
end | ||
end | ||
end |