Sha256: 18c15363fe4c946f6a03ef58316d11bb58a8ac5d748134ee231fba0bbf14599f

Contents?: true

Size: 1.14 KB

Versions: 48

Compression:

Stored size: 1.14 KB

Contents

require 'test_helper'
require 'json'

class JbuilderTemplateExtensionsTest < ActiveSupport::TestCase

  class TestClass

    attr_reader :errors

    def initialize
      @errors = {
          :base => [ 'something bad happened' ],
          :name => 'is too long',
          :code => [ 'is not uppercase', 'is too long' ]
      }
    end
  end

  def setup
    @json = JbuilderTemplate.new(self)
    @item = TestClass.new
  end

  test 'has extension methods' do
    assert @json.respond_to?(:api_errors!)
  end

  test 'builds expected values' do
    @json.api_errors! 'test_class', @item.errors
    val = JSON.parse(@json.target!)

    assert val.is_a?(::Hash)

    assert val['error'].is_a?(::String)
    assert_equal 'Test class ' + @item.errors[:base].first, val['error']

    assert val['fieldErrors'].is_a?(::Array)
    assert_equal 2, val['fieldErrors'].count
    e = val['fieldErrors'].find{|v| v['name'] == 'test_class.name'}
    assert e
    assert_equal 'Name is too long', e['status']
    e = val['fieldErrors'].find{|v| v['name'] == 'test_class.code'}
    assert e
    assert_equal "Code is not uppercase<br>\nCode is too long", e['status']
  end

end

Version data entries

48 entries across 48 versions & 1 rubygems

Version Path
incline-0.3.14 test/extensions/jbuilder_template_extensions_test.rb
incline-0.3.13 test/extensions/jbuilder_template_extensions_test.rb
incline-0.3.12 test/extensions/jbuilder_template_extensions_test.rb
incline-0.3.11 test/extensions/jbuilder_template_extensions_test.rb
incline-0.3.10 test/extensions/jbuilder_template_extensions_test.rb
incline-0.3.9 test/extensions/jbuilder_template_extensions_test.rb
incline-0.3.8 test/extensions/jbuilder_template_extensions_test.rb
incline-0.3.7 test/extensions/jbuilder_template_extensions_test.rb
incline-0.3.6 test/extensions/jbuilder_template_extensions_test.rb
incline-0.3.5 test/extensions/jbuilder_template_extensions_test.rb
incline-0.3.4 test/extensions/jbuilder_template_extensions_test.rb
incline-0.3.3 test/extensions/jbuilder_template_extensions_test.rb
incline-0.3.2 test/extensions/jbuilder_template_extensions_test.rb
incline-0.3.1 test/extensions/jbuilder_template_extensions_test.rb
incline-0.3.0 test/extensions/jbuilder_template_extensions_test.rb
incline-0.2.36 test/extensions/jbuilder_template_extensions_test.rb
incline-0.2.35 test/extensions/jbuilder_template_extensions_test.rb
incline-0.2.34 test/extensions/jbuilder_template_extensions_test.rb
incline-0.2.28 test/extensions/jbuilder_template_extensions_test.rb
incline-0.2.27 test/extensions/jbuilder_template_extensions_test.rb