How can I test if a method is called in controller? The second test passes but the first one fails and thorws this error:
Failure/Error: expect(@user).to receive(:decreasing_comment_notification_number).with("Post", post.id)
(#<User:0x007fd6f6312db8>).decreasing_comment_notification_number("Post", 1)
expected: 1 time with arguments: ("Post", 1)
received: 0 times
controller
def dropdown_checking_decreasing
current_user.decreasing_comment_notification_number(params[:notifiable_type], params[:notifiable_id])
redirect_to notification_redirection_path(params[:notifiable_type], params[:notifiable_id])
end
test
context "GET dropdown_checking_decreasing" do
let!(:post) { create(:post, user: @user,) }
let!(:notification) { create(:notification, sender: user, recipient: @user, notifiable_type: "Post", notifiable_id: post.id) }
it "invokes decreasing_comment_notification_number on current user" do
expect(@user).to receive(:decreasing_comment_notification_number).with("Post", post.id)
get :dropdown_checking_decreasing, user_id: @user.id, notifiable_type: notification.notifiable_type, notifiable_id: notification.notifiable_id
end
it "redirects to notifiable" do
get :dropdown_checking_decreasing, user_id: @user.id, notifiable_type: notification.notifiable_type, notifiable_id: notification.notifiable_id
expect(response).to redirect_to "/posts#post_#{notification.notifiable_id}"
end
end
Aucun commentaire:
Enregistrer un commentaire