对于我正在测试的特定实例,我想将某些东西的存在设置为“真”。它当前不存在,因此它的存在 == false。
这是我到目前为止的代码。希望有人可以提供帮助。
在邀请控制器中:
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
在邀请控制器规范中:
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