Question

Comment dois-je spécifier ceci

class FlagsController
  def like
    flag = current_user.flags.find_or_initialize_by_flaggable_type_and_flaggable_id(params[:like_type], params[:like_id])
    flag.kind = params[:kind]

    if flag.save
      head :ok
    else
      head :unprocessable_entity
    end
  end
end

Ma spécification actuelle

describe FlagsController do
    before (:each) do
      @user = Factory(:user)
      sign_in @user
    end

    describe "flag" do
      it 'with valid params' do
        controller.stub!(:current_user).and_return(@user)
        @user.stub_chain(:flags, :find_or_initialize_by_flaggable_type_and_flaggable_id).
          with('Comment', '1').
          and_return(mock_flag(:save => false)).
          stub!(:kind).
          with('up').
          and_return(mock_flag(:save => true))
        post :like, :like_type => 'Comment', :like_id => '1', :kind => 'up'
        response.response_code.should eq(200)
      end
    end

Résultats des spécifications

Failure/Error: response.response_code.should eq(200)

   expected 200
        got 422

   (compared using ==)

Itinéraire

post 'like' => 'flags#like'

Pas de solution correcte

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top