Note that there are some explanatory texts on larger screens.

plurals
  1. POInstance variable in view stays empty in Capybara test
    primarykey
    data
    text
    <p>I have a page that's rendering lots of stuff when I really use it, but renders nothing in Capybara. </p> <p>Controller goes like this:</p> <pre><code>class IdeasController &lt; ApplicationController def index @ideas = Idea.all end </code></pre> <p>Relevant bit of the page goes like this:</p> <pre><code>&lt;div class="accordion" id="accordion"&gt; Ideas length is &lt;%= @ideas.length %&gt;. &lt;% @ideas.each do |idea| %&gt; &lt;div class="accordion-group"&gt; &lt;div class="accordion-heading"&gt; &lt;%= link_to(idea.title, '#idea_' + idea.id.to_s, class: "accordion-toggle", data: {toggle: "collapse", parent: "#accordion"} ) %&gt; &lt;/div&gt; &lt;%= div_for(idea, class: "accordion-body collapse") do %&gt; &lt;div class="accordion-inner"&gt; &lt;%= render :partial =&gt; "idea", locals: { :idea =&gt; idea } %&gt; &lt;/div&gt; &lt;% end %&gt; &lt;/div&gt; &lt;% end %&gt; &lt;/div&gt; </code></pre> <p>When viewed in Development, this works beautifully and I get loads of stuff in the view (my db is full of mock data). But when I pop it open mid-test using <code>save_and_open_page</code>, it's completely empty, and says "Ideas length is 0".</p> <p>I did <code>rake db:test:clone</code> and <code>rake db:test:prepare</code>, but nada -- stays empty.</p> <p>Can you help me figure out why? Is there a way to peek into the test db and see if anything's there?</p> <p><strong>Edit:</strong> Inspired by the comments, I realized the trouble must be that the test environment flushes things out every time, so obviously there's nothing. In an (apparently misguided) attempt to resolve this, I did:</p> <pre><code> before do create(:idea) visit root_path click_link "Log In" end </code></pre> <p>Note the <code>create(:idea)</code> line, which was supposed to trigger my Idea factory and stick a mock idea into the db (the factory works fine with other tests).</p> <p>Now the page says:</p> <p>Internal Server Error</p> <p>SQLite3::BusyException: database is locked: INSERT INTO "users" ("created_at", "email", "name", "provider", "uid", "updated_at") VALUES (?, ?, ?, ?, ?, ?)</p> <p>which is beyond weird. <code>Rails s</code> is running in the background.</p> <p>As requested by commenter, full spec follows:</p> <pre><code>require 'spec_helper' describe "Idea page", js: true do subject { page } before do create(:idea) visit root_path click_link "Log In" end context "Single idea" do before do save_and_open_page #click_link('Eligendi sint quod quia alias sed sit vitae repellendus.') end it { should have_selector('a',text:'Claim') } end end </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload