In my application I have a topic controller and I need to write a test case for creating a new topic. when a new topic is created it will be redirected to the show page of the newly created topic and a notice will be displayed "Topic was created successfully!". I need to write a test case for checking the displayed notice is correct or not using rspec.I have the topic controller:
def create
@topic = Topic.new(topic_params)
if (@topic.save)
redirect_to @topic, :notice => 'Topic was created successfully!'
else
render :action => 'new'
end
end
TopicController spec:
it "should create new Topic and renders show" do
expect {
post :create,params:{ topic:{topicname: "Tech"} }
}.to change(Topic,:count).by(1)
expect(response).to redirect_to(topic_path(id: 1))
/// expect().to include("Topic was created successfully!")
end
Already I have written test cases for redirecting to show page. But I am stuck with the checking the notice that I have mentioned in a comment in my code.