餐厅和位置模型包含HABTM关联。如何为位置控制器编写测试用例
def create
@restaurant = Restaurant.find(params[:restaurant_id])
@location = @restaurant.locations.create(location_params)
if @location.save
flash[:notice] = 'Location added!'
redirect_to admin_locations_path
else
flash[:error] = 'Failed to edit location!'
render :new
end
end
def update
@location = Location.find(params[:id])
if @location.update_attributes(location_params)
flash[:notice] = 'Location updated!'
redirect_to admin_locations_path
else
flash[:error] = 'Failed to edit Location!'
render :edit
end
end
Run Code Online (Sandbox Code Playgroud)