Sha256: bfe9ce51abe00b3df1b75d29003134db5ad35efe2ffd2bf3b22508e88943e0da

Contents?: true

Size: 1008 Bytes

Versions: 23

Compression:

Stored size: 1008 Bytes

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.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

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
rabl-0.7.10 fixtures/sinatra_test/app.rb
rabl-0.7.9 fixtures/sinatra_test/app.rb
rabl-0.7.8 fixtures/sinatra_test/app.rb
rabl-0.7.7 fixtures/sinatra_test/app.rb
rabl-0.7.6 fixtures/sinatra_test/app.rb
rabl-0.7.5 fixtures/sinatra_test/app.rb
rabl-0.7.4 fixtures/sinatra_test/app.rb
rabl-0.7.3 fixtures/sinatra_test/app.rb
rabl-0.7.2 fixtures/sinatra_test/app.rb
rabl-0.7.1 fixtures/sinatra_test/app.rb
rabl-0.7.0 fixtures/sinatra_test/app.rb
rabl-0.6.14 fixtures/sinatra_test/app.rb
rabl-0.6.13 fixtures/sinatra_test/app.rb
rabl-0.6.12 fixtures/sinatra_test/app.rb
rabl-0.6.11 fixtures/sinatra_test/app.rb
rabl-0.6.10 fixtures/sinatra_test/app.rb
rabl-0.6.9 fixtures/sinatra_test/app.rb
rabl-0.6.8 fixtures/sinatra_test/app.rb
rabl-0.6.7 fixtures/sinatra_test/app.rb
rabl-0.6.6 fixtures/sinatra_test/app.rb