jeudi 21 janvier 2016

How To Write Rspec for Class methods in rails?

I have a model named CrTransaction. It contain a self method

def self.set_exclusion_attributes(ach_payment_ids) 
CrTransaction.where(:id => ach_payment_ids).update_all(:updated_at => Time.now, :cr_status => 'EXCLUDED' , :is_cr_excluded => 1)
end

i would like to write a test for that method so that i can test the value of the field cr_status and is_cr_excluded is updated. i have created one. but it shows me error.

@cr_transaction_obj10 = FactoryGirl.create(:ach_5, cr_status: nil, is_cr_excluded: false)
it 'method--set_exclusion_attributes--' do
        CrTransaction.set_exclusion_attributes(@cr_transaction_obj10.id)
        expect(cr_transaction_obj10.cr_status).to eq ('EXCLUDED')
        expect(cr_transaction_obj10.is_cr_excluded).to eq true
    end

Aucun commentaire:

Enregistrer un commentaire