How to write rspec for:
@community = Community.new(params[:community])
@community.url_title = params[:community][:title].parameterize
I searched for it for long but didnt get any positive result.
How to write rspec for:
@community = Community.new(params[:community])
@community.url_title = params[:community][:title].parameterize
I searched for it for long but didnt get any positive result.
You need to provide a bit more detail in order to help here.
Basically what you want to do, I believe, is to test when you call the
method that encloses that code, it sets the @community.url_title with
parameterize
you’ll need to pass the params over to the method and test that at the
end of the method call, @community.url_title has the expected result.
If you provide more context, I could show you an example.
Luis
Thanx luis to take interest in my query.
The above code is in my communities_controller.
Its inside the create action.
I want to pass the title of the called community in the url. Before
passing it to the database i m converting title as an url by using
parameterize method.
I wrote a test case for it as follows:
Community.stub(:new).with({‘these’ => ‘params’}) { mock_community(:save
=> true) }
post :create, :community => {‘these’ => ‘params’}
assigns(:community).should be(mock_community)
But it gives the following failure:
Failure/Error: post :create, :community => {‘these’ => ‘params’}
undefined method `parameterize’ for nil:NilClass
So help me in writing test case for it.
Ishit
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs