RSPEC测试控制器上缺少模板错误

时间:2017-07-20 12:01:01

标签: ruby-on-rails ruby rspec

我在测试控制器时遇到以下错误。按照代码...我的模板已创建并正在运行...这是通过ajax请求加载到模态...(:

1) UserManagementController GET #new returns http success
     Failure/Error: render layout: false     
     ActionView::MissingTemplate:
       Missing template user_management/new, application/new with {:locale=>[:pt], :formats=>[:json], :variants=>[], :handlers=>[:raw, :erb, :html, :builder, :ruby, :coffee, :haml, :jbuilder]}. Searched in:
         * "/home/euax/Documentos/RailsProjects/artia-app/app/views"
         * "/home/euax/.rvm/gems/ruby-2.3.3@artia/gems/devise-4.3.0/app/views"
         * "/home/euax/.rvm/gems/ruby-2.3.3@artia/gems/ckeditor-4.2.3/app/views"

按照代码....

Rspec的

it "returns http success" do
   sign_in @administrator_one
   get :new, params: { organization_id: @organization_one.id, "community_id" => "administration" }

   expect(response.status).to eql(200)
end

控制器

    def new
      if administrator? || can_manage_account_permission?(params[:community_id].to_i)
      @accounts = @organization.communities
      @user = OrganizationUser.new(other: true)
      @community_id = params[:community_id].to_i unless params[:community_id] == "administration"

      render layout: false

    else
      response.status = 403
      render json: { message: I18n.t('error_permission') }
    end


  end

1 个答案:

答案 0 :(得分:0)

错误消息实际上非常明确地说明了问题:调用

render layout: false

UserManagementController#new 内隐式期望模板new出现在

app/views/user_management/new.erb

app/views/application/new.erb

阅读Layouts and Rendering in Rails以获得详尽的解释。