テストしている特定のインスタンスに対して、何かの存在を「true」に設定したいと思います。現在存在しないため、その存在 == false です。
ここに私がこれまで持っているコードがあります。誰かが助けてくれることを願っています。
Invitations_Controller:
def join_request
invitation_options = {recipient_id: current_user.id, project_id: @project.id, recipient_email: current_user.email}
if ProjectInvitation.where(invitation_options).present?
flash[:notice] = "You already sent a request to join this project."
redirect_to :back
return
end
Invitations_controller_spec:
describe "Send Join Request" do
before do
@invitation_options = {:recipient_id => @user.id, :project_id => @project.id, :recipient_email => 'address@gmail.com'}
ProjectInvitation.where(@invitation_options).present? == true # This is what I'm stuck on. Pretty sure this doesn't work.
end
context "if you already sent a request" do
it "should tell you that you already sent a request" do
response.should have_text("You already sent a request to join this project.")
end
it "should redirect you to the previous page" do
response.should redirect_to(:back)
end
end
end