【问题标题】:testing cloudinary direct image upload with capybara rspec使用 capybara rspec 测试 cloudinary 直接图像上传
【发布时间】:2014-07-16 07:29:33
【问题描述】:

我正在尝试通过 capybara 测试 cloudinary 直接上传,但 capybara 说它找不到图像上传字段。你如何测试直接上传?

picture_spec.rb

require 'spec_helper'

feature "User Pictures" do
  let(:user) { create(:user) }

  describe "Uploading an image" do 
    describe "for profile photo" do 
      it "raises an error when clicked outside cropping image so image is not cropped" do
        visit new_user_picture_path(user)
        attach_file('#photo upload', "#{Rails.root}/spec/support/images/PRATIQUE_BIG.png")
        click_on "Valider Photo"
        expect(page).to have_content "SVP crop votre image et celle-ci doit mesurer au moins 100 x 100px"
      end
    end
  end

end

新的图片页面

= form_for(@photo, :url => url, role: "form") do |f|          
                .form_line.form-group
                    .upload_button_holder
                        = link_to "Parcourir", "#", class: "btn btn-default upload_button form-control"
                        #photo-upload= f.cl_image_upload :image, class: "form-control" 
                    %span.status
                .form-group
                    .form_control
                        .preview
                = f.hidden_field :crop_x 
                = f.hidden_field :crop_y 
                = f.hidden_field :crop_w 
                = f.hidden_field :crop_h 
                .form-group
                    = f.submit "Valider Photo", class: "btn btn-lg btn-success" 

            = hidden_field_tag :direct, params[:direct] 
        %p= link_to "Retour à Mon Profil", profile_path(current_user.user_code)
 // Configure Cloudinary jQuery plugin 
 = cloudinary_js_config 

Capybara 然后回馈Unable to find file field "photo-upload"

【问题讨论】:

    标签: ruby-on-rails rspec capybara cloudinary


    【解决方案1】:

    cl_image_upload 的字段名称始终为filephoto-update 是周围 div 的 id。您可以通过将html: {id: "my-id"} 传递给cl_image_upload 来为文件输入字段分配一个ID。顺便提一句。类也属于html 哈希参数。

    【讨论】:

      猜你喜欢
      • 2013-08-26
      • 2020-12-20
      • 2016-09-09
      • 2019-02-14
      • 2017-08-30
      • 2013-08-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多