Sha256: dd3057fe226c8bb6597c04c9b78a34e4c30349848c9b4e1d19edac27e49d7d5b

Contents?: true

Size: 1.34 KB

Versions: 6

Compression:

Stored size: 1.34 KB

Contents

require_relative "spec_helper"

module Nyara
  describe 'mini_support' do
    it "Array#sum" do
      assert_equal 0, [].sum
      assert_equal 3, [1, 2].sum
    end

    # just test existence, no need to repeat activesupport tests
    it "Object#blank?" do
      assert [].respond_to? :blank?
    end

    # just test existence, no need to repeat activesupport tests
    it "Object#to_query" do
      assert ''.respond_to? :to_query
    end

    it "to_json works with inheritance" do
      h = HeaderHash.new
      h[:Accept] = 'en'
      assert_equal('{"Accept":"en"}', h.to_json)
    end

    # just a class with .json_create(attrs)
    class MyClass
      def self.json_create attrs
        1
      end
    end
    it "json load security" do
      assert_equal({"json_class" => "MyClass", "length" => 1}, JSON.load('{"json_class":"MyClass","length":1}'))
    end

    it "json dump security" do
      h = {"a" => '</script>', "b" => true}
      assert_not_include(h.to_json, '</script>')
      assert_equal h, JSON.parse(h.to_json)
    end

    if RUBY_VERSION <= '2.0.0'
      it "String#b" do
        assert_equal 'ASCII-8BIT', "你".b.encoding.to_s
      end

      it "String#scrub" do
        # from rdoc examples
        assert_equal "abc\u3042\uFFFD", "abc\u3042\x81".scrub
        assert_equal "abc\u3042*", "abc\u3042\x81".scrub("*")
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
nyara-0.1.pre.2 spec/mini_support_spec.rb
nyara-0.1.pre.1 spec/mini_support_spec.rb
nyara-0.1.pre.0 spec/mini_support_spec.rb
nyara-0.0.1.pre.9 spec/mini_support_spec.rb
nyara-0.0.1.pre.8 spec/mini_support_spec.rb
nyara-0.0.1.pre.6 spec/mini_support_spec.rb