带有Capybara-webkit AJAX请求的RecordNotFound

时间:2015-07-20 07:57:50

标签: ruby-on-rails-4 selenium rspec capybara capybara-webkit

我有一个表单来创建新的Address。该表单包含拥有Customer的父模型的ID(在本例中为Address)。提交表单时,AJAX请求转到使用JavaScript响应的AddressesController。问题是,有时会找到父模型,有时不会。

这适用于RSpec:

before do
    click_link add_address
    fill_in country_field, with: country
    fill_in city_field, with: city
    fill_in street_field, with: street
    fill_in postal_code_field, with: postal_code
    click_button submit_address
    expect(page.title).to eq(show_page_title)
end

it { is_expected.to have_content(address_created) }

但是当我将expect(page.title).to eq(show_page_title)从before语句移动到自己的测试时(当然这更好):

it { is_expected.to have_title(show_page_title) }
it { is_expected.to have_content(address_created) }

我收到以下错误:

ActiveRecord::RecordNotFound:
  Couldn't find Customer with 'id'=1

如果我在before语句中以及在收到请求的puts Customer.count中添加AddressesController,我从before语句中的行得到1,而从控制器得到0!这怎么可能?

0 个答案:

没有答案