How should I test Rails Enums? -
suppose have model called creditcard. due technical restrictions, it's best if card networks represented enum. code looks this:
class creditcard < activerecord::base enum network: [:visa, :mastercard, :amex] end
what should tested when using enums if anything?
if use array, need make sure order keeped:
class creditcard < activerecord::base enum network: [:visa, :mastercard, :amex] end describe creditcard, '#status' let(:network) { [:visa, :mastercard, :amex] } 'has right index' network.each_with_index |item, index| expect(described_class.statuses[item]).to eq index end end end
if use hash order not matter, value of each key, will. so, it's to make sure same number each key.