How to complete the rspec put controller test from scaffold

前端 未结 6 1322
Happy的楠姐
Happy的楠姐 2020-12-24 11:58

I\'m using scaffolding to generate rspec controller tests. By default, it creates the test as:

  let(:valid_attributes) {
    skip(\"Add a hash of attributes         


        
6条回答
  •  甜味超标
    2020-12-24 12:56

    Well, I did something that's quite simpler, I'm using Fabricator, but I'm pretty sure it's the same with FactoryGirl:

      let(:new_attributes) ( { "phone" => 87276251 } )
    
      it "updates the requested patient" do
        patient = Fabricate :patient
        put :update, id: patient.to_param, patient: new_attributes
        patient.reload
        # skip("Add assertions for updated state")
        expect(patient.attributes).to include( { "phone" => 87276251 } )
      end
    

    Also, I'm not sure why you are building a new factory, PUT verb is supposed to add new stuff, right?. And what you are testing if what you added in the first place (new_attributes), happens to exist after the put in the same model.

提交回复
热议问题