Pregunta

¿Cómo debo especificar esto?

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

Mi especificación actual

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

Resultados de especificaciones

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

   expected 200
        got 422

   (compared using ==)

Ruta

post 'like' => 'flags#like'

No hay solución correcta

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top