Sha256: 9a89a282478ba2a2e15b0282a6e455f8acaf9d676ba73db5c96c19a1dbdcc90d

Contents?: true

Size: 1.67 KB

Versions: 8

Compression:

Stored size: 1.67 KB

Contents

require File.expand_path('../../spec_helper', __FILE__)
include RightApi::Helper

describe RightApi::Helper do

  API_MEDIA_TYPES = %w{audit_entry ip_address process server}

  context "#is_singular?" do
    API_MEDIA_TYPES.each do |media_type|
      it "should identify media type #{media_type} as singular" do
        is_singular?(media_type).should == true
      end
    end
  end

  context "#fix_array_of_hashes" do
    it "fixes all the keys that have the value as array of hashes" do
      res = fix_array_of_hashes(
          'a' => '1',
          'b' => [1, 2, 3],
          'c' => {1 => 2, 3 => 4},
          'd' => [
              {5 => 6, 7 => 8},
              {9 => 10, 11 => 12}
          ]
      )

      res.should == {
          'a' => '1',
          'b' => [1, 2, 3],
          'c' => {1 => 2, 3 => 4},
          'd[]' => [
              {5 => 6, 7 => 8},
              {9 => 10, 11 => 12}
          ]
      }

    end

    it "fixes key that have a top-level array of hashes as value" do
      res = fix_array_of_hashes(
          'a' => [
              {1 => 2},
              {3 => 4}
          ]
      )

      res.should == {
          'a[]' => [
              {1 => 2},
              {3 => 4}
          ]
      }
    end

    it "fixes key that have a nested array of hashes as value" do
      res = fix_array_of_hashes(
          'a' => {
              'b' => [
                  {1 => 2},
                  {3 => 4}
              ]
          }
      )

      res.should == {
          'a' => {
              'b' => {
                  '' => [
                      {1 => 2},
                      {3 => 4}
                  ]
              }
          }
      }
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
right_api_client-1.5.19 spec/unit/helper_spec.rb
right_api_client-1.5.18 spec/unit/helper_spec.rb
right_api_client-1.5.17 spec/unit/helper_spec.rb
right_api_client-1.5.16 spec/unit/helper_spec.rb
right_api_client-1.5.15 spec/unit/helper_spec.rb
right_api_client-1.5.14 spec/unit/helper_spec.rb
right_api_client-1.5.13 spec/unit/helper_spec.rb
right_api_client-1.5.12 spec/unit/helper_spec.rb