正如标题所示,我只是想用 RSpec 测试我的 API 控制器中的创建操作。控制器看起来像:
module Api
module V1
class BathroomController < ApplicationController
skip_before_action :verify_authenticity_token, only: [:create]`
def create
bathroom = Bathroom.new(bathroom_params)
bathroom.user = current_user
if bathroom.save
render json: { status: 'SUCCESS', message: 'Saved new bathroom', bathrooms: bathroom }, status: :ok
end
end
private
def bathroom_params
params.require(:bathroom).permit(:establishment, :address, :city, :state, :zip, :gender, :key_needed, :toilet_quantity)
end
end
end
end
Run Code Online (Sandbox Code Playgroud)
现在这正是它应该做的,这很棒。然而,测试......不是那么多。这是我对测试部分的了解:
describe "POST #create" do
let!(:bath) {{
establishment: "Fake Place",
address: "123 Main St",
city: "Cityton",
state: "NY",
zip: "11111",
gender: "Unisex", …Run Code Online (Sandbox Code Playgroud)