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