나는 작동 다음 RSpec에 시험이 있습니다FactoryGirl에서 매개 변수를 보내는 방법 (수동으로 매개 변수를 해시로 보내는 것과 반대)?
it "redirects to the created api_key" do
post :create, :api_key => {:api_identifier => "asdfadsf", :verification_code =>
"12345"}
response.should redirect_to(ApiKey.last) #(or any other test function)
end
을하지만 수동으로 api_key
의를 만들 필요가 없습니다 그래서 나는 공장 소녀를 사용합니다.
어떻게하면 위 기능을 복제 할 수 있습니까?
사용 :
it "redirects to the created api_key" do
test = FactoryGirl.build(:api_key)
post :create, :api_key => test
response.should redirect_to(ApiKey.last) #(or any other test function)
end
또는 : 나는 내 컨트롤러에 도착하면
it "redirects to the created api_key" do
post :create, FactoryGirl.build(:api_key)
response.should redirect_to(ApiKey.last) #(or any other test function)
end
나에게 :api_key
값에 대한 null 값을 제공합니다.
def create
@api_key = ApiKey.new(params[:api_key])
@api_key.user = current_user
pp @api_key
respond_to do |format|
if @api_key.save
format.html { redirect_to @api_key, notice: 'Api key was successfully created.' }
format.json { render json: @api_key, status: :created, location: @api_key }
else
format.html { render action: "new" }
format.json { render json: @api_key.errors, status: :unprocessable_entity }
end
end
end
내 하루를 보냈습니다! 많은 감사합니다 !! – Hito