0

i try to test method create in my controller:

def create
    @fund = Fund.new({started_at: Date.strptime(params[:fund].delete(:started_at), '%m/%d/%Y')}.merge(fund_params))
    if @fund.save
      flash[:alert] = "Fund #{@fund.name} saved!"
      redirect_to funds_path
    else
      flash[:error] = "Fund #{@fund.name} could not be saved"
      render :edit
    end
end

file spec:

it 'Can create a new fund' do
    fund = FactoryGirl.create(:fund)
    post :create
    expect(response).to redirect_to(funds_path)
end

And show this error:

NoMethodError: undefined method `delete' for nil:NilClass

The error is in this line, for the method 'delete':

 @fund = Fund.new({started_at: Date.strptime(params[:fund].delete(:started_at),...

i don't know how solve this problem, Thanks.

1 Answer 1

1

As the error message says, that's because params[:fund] is nil. Try to send the proper parameters to the create action:

post :create, fund: { add_here_needed_params_for_this_action }

Example:

post :create, fund: { started_at: Date.today }
Sign up to request clarification or add additional context in comments.

1 Comment

Yes, it's a great advice, I'll try it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.