Sha256: 08026eb32b6b69f238fbc4d21150301bfb0020824b57918168c2937315866b0c

Contents?: true

Size: 1.22 KB

Versions: 2

Compression:

Stored size: 1.22 KB

Contents

$:.push( File.join(File.dirname(File.expand_path(__FILE__)), '../') )
require 'test_helper'

describe :Extention do
  describe "Array#to_hash" do
    describe "when column size is equal data size" do
      before do
        @keys   = %W[id name hp]
        @values = %W[1 hoge 100]
        @h = @values.extend(Flextures::Extensions::Array).to_hash(@keys)
      end

      it "return hash" do
        assert_equal @h, { "id"=>"1", "name"=>"hoge", "hp"=>"100" }
      end
    end

    describe "when column size is bigger than data size" do
      before do
        @keys   = %W[id name hp]
        @values = %W[1 hoge]
        @h = @values.extend(Flextures::Extensions::Array).to_hash(@keys)
      end

      it "return hash, overflow key is filled 'nil'" do
        assert_equal @h, { "id"=>"1", "name"=>"hoge", "hp"=> nil }
      end
    end

    describe "when column size is smaller than data size" do
      before do
        @keys   = %W[id name]
        @values = %W[1 hoge 200]
        @h = @values.extend(Flextures::Extensions::Array).to_hash(@keys)
      end

      it "return hash, overflow value is cut offed" do
        assert_equal @h, { "id"=>"1", "name"=>"hoge" }
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
flextures-4.0.1 test/unit/flextures_extention_modules_test.rb
flextures-4.0.0 test/unit/flextures_extention_modules_test.rb