ruby on rails - FactoryGirl: omit attributes without creating an additional factory -


sometimes attributes_for strategy returns unnecessary attributes, in other words, if need couple of attributes, rather return of them:

factorygirl.define   factory :user     name { ffaker::name.name }     nickname { ffaker::name.suffix }     email { ffaker::internet.email }      factory :special_user       provider 'email'       confirmed_at time.now.strftime('%f %t')     end      trait :confirmation       current_password 'secret098'       password 'secret567'     end      trait :valid       password_confirmation 'secret567'     end      trait :invalid       password_confirmation 'secret568'     end   end      end 

there need use factories traits, ever possible return current_password, password , password_confirmation only? attributes_for() doesn't work traits. or maybe there way that?

attributes_for return hash of attributes, select ones want out of hash.

eg.

factorygirl.attributes_for(:user, :confirmation)   .slice(:current_password, :password_confirmation) 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -