Sha256: 740c9f3d54514e486efeb0e97381ec352ebc0426e269677e9030cbbcba7621f3

Contents?: true

Size: 1.94 KB

Versions: 65

Compression:

Stored size: 1.94 KB

Contents

require File.expand_path('../helper', __FILE__)

begin
require 'rabl'
require 'ostruct'
require 'json'
require 'active_support/core_ext/hash/conversions'

class RablTest < Minitest::Test
  def rabl_app(&block)
    mock_app {
      set :views, File.dirname(__FILE__) + '/views'
      get '/', &block
    }
    get '/'
  end

  it 'renders inline rabl strings' do
    rabl_app do
      @foo = OpenStruct.new(:baz => 'w00t')
      rabl %q{
        object @foo
        attributes :baz
      }
    end
    assert ok?
    assert_equal '{"openstruct":{"baz":"w00t"}}', body
  end
  it 'renders .rabl files in views path' do
    rabl_app do
      @foo = OpenStruct.new(:bar => 'baz')
      rabl :hello
    end
    assert ok?
    assert_equal '{"openstruct":{"bar":"baz"}}', body
  end

  it "renders with file layouts" do
    rabl_app {
      @foo = OpenStruct.new(:bar => 'baz')
      rabl :hello, :layout => :layout2
    }
    assert ok?
    assert_equal '{"qux":{"openstruct":{"bar":"baz"}}}', body
  end

  it "raises error if template not found" do
    mock_app {
      get('/') { rabl :no_such_template }
    }
    assert_raises(Errno::ENOENT) { get('/') }
  end

  it "passes rabl options to the rabl engine" do
    mock_app do
      get('/') do
        @foo = OpenStruct.new(:bar => 'baz')
        rabl %q{
          object @foo
          attributes :bar
        }, :format => 'xml'
      end
    end
    get '/'
    assert ok?
    assert_body '<?xml version="1.0" encoding="UTF-8"?><openstruct><bar>baz</bar></openstruct>'
  end

  it "passes default rabl options to the rabl engine" do
    mock_app do
      set :rabl, :format => 'xml'
      get('/') do
        @foo = OpenStruct.new(:bar => 'baz')
        rabl %q{
          object @foo
          attributes :bar
        }
      end
    end
    get '/'
    assert ok?
    assert_body '<?xml version="1.0" encoding="UTF-8"?><openstruct><bar>baz</bar></openstruct>'
  end

end

rescue LoadError
  warn "#{$!.to_s}: skipping rabl tests"
end

Version data entries

65 entries across 62 versions & 18 rubygems

Version Path
logstash-output-scalyr-0.2.1.beta vendor/bundle/jruby/2.5.0/gems/sinatra-1.4.8/test/rabl_test.rb
logstash-output-scalyr-0.2.0 vendor/bundle/jruby/2.5.0/gems/sinatra-1.4.8/test/rabl_test.rb
logstash-output-scalyr-0.2.0.beta vendor/bundle/jruby/2.5.0/gems/sinatra-1.4.8/test/rabl_test.rb
logstash-output-scalyr-0.1.26.beta vendor/bundle/jruby/2.5.0/gems/sinatra-1.4.8/test/rabl_test.rb
logstash-output-scalyr-0.1.25.beta vendor/bundle/jruby/2.5.0/gems/sinatra-1.4.8/test/rabl_test.rb
logstash-output-scalyr-0.1.24.beta vendor/bundle/jruby/2.5.0/gems/sinatra-1.4.8/test/rabl_test.rb
logstash-output-scalyr-0.1.23.beta vendor/bundle/jruby/2.5.0/gems/sinatra-1.4.8/test/rabl_test.rb
logstash-output-scalyr-0.1.22.beta vendor/bundle/jruby/2.5.0/gems/sinatra-1.4.8/test/rabl_test.rb
logstash-output-scalyr-0.1.21.beta vendor/bundle/jruby/2.5.0/gems/sinatra-1.4.8/test/rabl_test.rb
logstash-output-scalyr-0.1.20.beta vendor/bundle/jruby/2.5.0/gems/sinatra-1.4.8/test/rabl_test.rb
logstash-output-scalyr-0.1.19.beta vendor/bundle/jruby/2.5.0/gems/sinatra-1.4.8/test/rabl_test.rb
logstash-output-scalyr-0.1.18.beta vendor/bundle/jruby/2.5.0/gems/sinatra-1.4.8/test/rabl_test.rb
logstash-output-scalyr-0.1.17.beta vendor/bundle/jruby/2.5.0/gems/sinatra-1.4.8/test/rabl_test.rb
logstash-output-scalyr-0.1.16.beta vendor/bundle/jruby/2.5.0/gems/sinatra-1.4.8/test/rabl_test.rb
logstash-output-scalyr-0.1.15.beta vendor/bundle/jruby/2.5.0/gems/sinatra-1.4.8/test/rabl_test.rb
logstash-output-scalyr-0.1.14.beta vendor/bundle/jruby/2.5.0/gems/sinatra-1.4.8/test/rabl_test.rb
logstash-output-scalyr-0.1.13 vendor/bundle/jruby/2.5.0/gems/sinatra-1.4.8/test/rabl_test.rb
logstash-output-scalyr-0.1.12 vendor/bundle/jruby/2.5.0/gems/sinatra-1.4.8/test/rabl_test.rb
logstash-output-scalyr-0.1.11.beta vendor/bundle/jruby/2.5.0/gems/sinatra-1.4.8/test/rabl_test.rb
logstash-output-scalyr-0.1.10.beta vendor/bundle/jruby/2.5.0/gems/sinatra-1.4.8/test/rabl_test.rb