我正在尝试使用 ajax 测试调用控制器操作的链接。本质上,当用户点击“关注”时,他将与公司相关联,并且将使用 JS 执行渲染部分。问题是当我在开发中尝试它时它可以正常工作,但它在测试中没有响应。我一直在尝试很多方法,看起来调用永远不会到达控制器。
在这里你可以看到测试:
#spec/integration/following_spec.rb
it "should add the company to the ones followed by the user", :js => true do
find("#current_company").click_link "Follow"
sleep 2
@user.companies_followed.include?(@company).should be_true
end
风景:
#app/views/companies/_follow_button.html.slim
= link_to change_follow_state_company_path(@company), :method => :put, :remote => true, :id => "follow", :class => "btn_block light" do
' Follow
以及测试配置:
#spec/integration_helper.rb
require 'spec_helper'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'capybara/rspec'
require 'capybara/rails'
Dir[Rails.root.join("spec/integration/support/**/*.rb")].each {|f| require f}
RSpec.configure do |config|
config.use_transactional_fixtures = true
config.before do
clear_email_queue
end
end
Rails.cache.clear