Sha256: e330ce26b1bece5568b01bd0547672df30ae3aa1bcad6e67f5a348d058728ac3

Contents?: true

Size: 1.43 KB

Versions: 3

Compression:

Stored size: 1.43 KB

Contents

# -*- encoding : utf-8 -*-
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')

describe Hash do

  describe "Hash.to_conditions" do
    before(:each) do
      @my_hash = { :blart=>'flange', :cheese=>'provolone', :ham=>'mortadella' }
    end
    
    it "should return an array" do
      @my_hash.to_conditions(:blart).class.should == Array
    end
    
    describe "for each key in the hash" do
      describe "when it's in the given allowed_keys" do
        
        it "should appear in the first element" do
          @my_hash.to_conditions( :blart )[0].should =~ /blart/
        end
        
        it "should append the value to the array" do
          @my_hash.to_conditions(:blart).should include('flange')
        end
        
      end
      
      describe "when it's NOT in the given allowed_keys" do
        it "should not appear in the first element" do
          @my_hash.to_conditions( :donkey )[0].should_not =~ /donkey/
        end
      end
    end
    
    context "when column aliases are given" do
      describe "for each given alias" do
        it "should map the param called (key) to a returned column called (alias[key])" do
          @my_hash.to_conditions(:blart, :blart=>'aliased_blart')[0].should =~ /aliased_blart\s*=\s*?/
        end
      end
    end
  end
  
  describe "-" do
    it "should remove the requested keys" do
      ({:a=>'a', :b=>'b', :c=>'c'} - [:a,:b]).should == {:c=>'c'}
    end
  end
  
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
itrigga-core_ext-1.5.1 spec/hash_spec.rb
itrigga-core_ext-1.5.0 spec/hash_spec.rb
itrigga-core_ext-1.3.0 spec/hash_spec.rb