Note that there are some explanatory texts on larger screens.

plurals
  1. PORspec test on Simple Form Associations
    text
    copied!<p>I am trying to run a request spec on a form (built with Simple Form). The form includes some select boxes that are generated using the association method and therefore database values for the model.</p> <p>When running save_and_open_page it doesn't look like the select the values in the drop downs.</p> <p>I have looked at Mocking and Stubbing but this is new to me and I'm still a little confused on the concept beyond basic usage.</p> <p>Is there any way to generate the collection for the select box so Capybara can pick it up?</p> <p>I'm using Rails 3.1, Simple Form, Capybara and FactoryGirl.</p> <p>My code is...</p> <p><strong>challenge_spec</strong></p> <pre><code>describe "New Challenges" do before(:all) do %w["Under 13", "13 - 16"].each do |item| FactoryGirl.create(:age, :name =&gt; item) end end it "should redirect to resources after submission" do login_valid_user visit new_challenge_path @challenge = Factory.build(:challenge) fill_in "challenge_name", :with =&gt; @challenge.name fill_in "challenge_description", :with =&gt; @challenge.description fill_in "challenge_description", :with =&gt; @challenge.description select "30 mins", :from =&gt; "challenge_timescale" save_and_open_page select 1, :from =&gt; "challenge_age_id" select @challenge.category, :from =&gt; "challenge_category_id" click_button "save_button" end end </code></pre> <p><strong>Controller</strong></p> <pre><code>def new @challenge = Challenge.new respond_to do |format| format.html # new.html.haml format.json { render json: @challenge } end end </code></pre> <p><strong>Form item</strong></p> <pre><code>&lt;%= f.association :age, :prompt =&gt; "Please select..." %&gt; </code></pre> <p><strong>Models</strong></p> <p>Challenge</p> <pre><code>class Challenge &lt; ActiveRecord::Base belongs_to :age end </code></pre> <p>Age</p> <pre><code>class Age &lt; ActiveRecord::Base has_many :challenges end </code></pre>
 

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