2017-01-10 12 views
-2

ですが、私はRSpecの内のユーザーを更新しようとしている:更新が機能していない、ステータスは200

require "rails_helper" 

RSpec.describe UsersController, type: :controller do 
    describe "PUT #update" do 
    it 'should update a user' do 
     attr1 = { .............. } 
     u1 = User.create!(attr1) 
     put :update, { id: u1.to_param, user: attr1.merge({name: "name2", email: "[email protected]"}) }, format: :json 
     u1.reload 

     expect(response.status).to eq(200) 
     expect(u1.name).to eq("name2") 

ステータスは200ですが、体内で返される属性は」上がりません更新されました。

+0

あなたのログが何を言うのですか? 'log/test.log' – Anthony

+1

コントローラが200を返すと、あなたに何も言われません。あなたは何もせず200を返すコントローラを持つことができます。テスト中の実際のコードを含めてください。 – max

+0

@max、どのようなコードですか? – Jodooomi

答えて

1

私はあなたの属性はattrの上にあるか知っているが、これを試してみません:

describe "PUT #update" do 
     let(:option) { assigns(:option) } 

     before(:each) do 
     attr1 = { .............. } 
     u1 = create(:user, attr1....) 
     put :update, params: { 
      user: attributes_for(:user, name: "name2", email: "[email protected]"), 
      id: u1.id 
     } 
     end 

     it "should be success" do 
     expect(response.status).to eq(200) 
     end 

     it "should update attributes" do 
     expect(u1.name).to "name2" 
     end 
    end 
関連する問題