Sha256: c2812f9abf82d4e639980cf4426de8fd6dc52e0f5669ffdef3001d22017a0be7

Contents?: true

Size: 1.26 KB

Versions: 2

Compression:

Stored size: 1.26 KB

Contents

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
  
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
itrigga-core_ext-0.3.0 spec/hash_spec.rb
itrigga-core_ext-0.2.2 spec/hash_spec.rb