Sha256: cc325b91884897853a3a00a637ac250f905a02134ff256693dbaaf1cf189040d

Contents?: true

Size: 1.19 KB

Versions: 19

Compression:

Stored size: 1.19 KB

Contents

require 'rubygems'
require 'sinatra'
require 'rabl'
require 'active_support/core_ext'
require 'active_support/inflector'
require 'active_record'
require 'builder'

ActiveRecord::Base.establish_connection(
  :adapter => 'sqlite3',
  :database =>  ':memory:'
)

Dir[File.dirname(__FILE__) + "/models/*.rb"].each do |file|
  require File.expand_path(file)
end

# Register RABL
Rabl.configure do |config|
  config.perform_caching = true
end
Rabl.register!

class SinatraTest < Sinatra::Application
  set :root, File.expand_path(File.dirname(__FILE__))
  set :views, Proc.new { File.join(root, "views") }

  get "/posts" do
    @posts = Post.order("id ASC")
    render :rabl, :"posts/index", :format => "json"
  end

  get "/posts/:id" do
    @post = Post.find(params[:id])
    render :rabl, :"posts/show", :format => "json"
  end

  get "/users" do
    @users = User.order("username ASC")
    render :rabl, :"users/index.json", :format => "json"
  end

  get "/users/:id" do
    @user = User.find(params[:id])
    render :rabl, :"users/show.json", :format => "json"
  end
end

# Patch times to return as iso8601
class Time
  alias_method :old_to_s, :to_s
  def to_s(format=nil)
    format ? old_to_s(format) : iso8601
  end
end

Version data entries

19 entries across 19 versions & 2 rubygems

Version Path
rabl-0.14.3 fixtures/sinatra_test/app.rb
rabl-0.14.2 fixtures/sinatra_test/app.rb
rabl-0.14.1 fixtures/sinatra_test/app.rb
rabl-0.14.0 fixtures/sinatra_test/app.rb
rabl-0.13.1 fixtures/sinatra_test/app.rb
rabl-0.13.0 fixtures/sinatra_test/app.rb
rabl-0.12.0 fixtures/sinatra_test/app.rb
rabl-0.11.8 fixtures/sinatra_test/app.rb
rabl-0.11.7 fixtures/sinatra_test/app.rb
solidus_backend-1.0.0.pre3 vendor/bundle/gems/rabl-0.11.6/fixtures/sinatra_test/app.rb
solidus_backend-1.0.0.pre2 vendor/bundle/gems/rabl-0.11.6/fixtures/sinatra_test/app.rb
solidus_backend-1.0.0.pre vendor/bundle/gems/rabl-0.11.6/fixtures/sinatra_test/app.rb
rabl-0.11.6 fixtures/sinatra_test/app.rb
rabl-0.11.5 fixtures/sinatra_test/app.rb
rabl-0.11.4 fixtures/sinatra_test/app.rb
rabl-0.11.3 fixtures/sinatra_test/app.rb
rabl-0.11.2 fixtures/sinatra_test/app.rb
rabl-0.11.1 fixtures/sinatra_test/app.rb
rabl-0.11.0 fixtures/sinatra_test/app.rb