小编Mad*_*dda的帖子

如何编写用于在rspec中创建和更新操作的测试用例?

餐厅和位置模型包含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)

ruby-on-rails

5
推荐指数
0
解决办法
68
查看次数

标签 统计

ruby-on-rails ×1