Sha256: 22b2ddaccfcf79fb1235ea7af85ffbf9398f136aa18260db74ef1c16bdfd9ee2

Contents?: true

Size: 1.45 KB

Versions: 16

Compression:

Stored size: 1.45 KB

Contents

require 'test_helper'
require 'netzke/core_ext'

require 'json'

class CoreExtTest < ActiveSupport::TestCase
  test "to_js" do
    assert_equal({"aProperty" => true}, JSON.parse({:a_property => true}.to_js))
    assert_equal({"aProperty" => true}, JSON.parse({:a_property => true, :nil_property => nil}.to_js))
    assert_equal([{"aProperty" => true}, {"anotherProperty" => false}], JSON.parse([{:a_property => true}, {:another_property => false}].to_js))
    assert_equal([{"aProperty" => true}, {"anotherProperty" =>false}], JSON.parse([{:a_property => true, :nil_property => nil}, {:another_property => false}].to_js))
  end
  
  test "recursive delete if nil" do
    assert_equal({:a => 1, :b => {:c => 4, :d => 5}}, {:a => 1, :aa => nil, :b => {:c => 4, :d => 5, :cc => nil}}.recursive_delete_if_nil)

    assert_equal({:a => [{:e => 5}, {:f => 7}], :b => {:c => 4, :d => 5}}, {:a => [{:e => 5, :ee => nil},{:f => 7, :ff => nil}], :aa => nil, :b => {:c => 4, :d => 5, :cc => nil}}.recursive_delete_if_nil)

    assert_equal([
      {:a => [{:e => 5}]}, 
      {}, 
      {:b => {:c => 4, :d => 5}}
    ], [
      {:a => [{:e => 5, :ee => nil}]}, 
      {:aa => nil}, 
      {:b => {:c => 4, :d => 5, :cc => nil}}
    ].recursive_delete_if_nil)
  end
  
  test "convert keys" do
    assert_equal([
      {:aB => 1, :cDD => [{:lookMa => true},{:wowNow => true}]}
    ],[:a_b => 1, :c_d_d => [{:look_ma => true},{:wow_now => true}]].convert_keys{|k| k.camelize(:lower)})
  end
end

Version data entries

16 entries across 16 versions & 2 rubygems

Version Path
skozlov-netzke-core-0.1.0.1 test/core_ext_test.rb
skozlov-netzke-core-0.1.0.2 test/core_ext_test.rb
skozlov-netzke-core-0.1.0 test/core_ext_test.rb
netzke-core-0.1.4 test/core_ext_test.rb
netzke-core-0.2.0 test/core_ext_test.rb
netzke-core-0.2.1 test/core_ext_test.rb
netzke-core-0.2.2 test/core_ext_test.rb
netzke-core-0.2.3 test/core_ext_test.rb
netzke-core-0.1.1.1 test/core_ext_test.rb
netzke-core-0.2.6 test/core_ext_test.rb
netzke-core-0.2.7 test/core_ext_test.rb
netzke-core-0.2.4 test/core_ext_test.rb
netzke-core-0.1.2 test/core_ext_test.rb
netzke-core-0.1.3 test/core_ext_test.rb
netzke-core-0.2.9 test/core_ext_test.rb
netzke-core-0.2.8 test/core_ext_test.rb