title: How do I pass checkbox collection values in a controller spec with rspec and rails 3
body: <p>With rails 3 and rspec. I have a form in a view like this ..</p>
  
  <pre><code>&lt;%= form_for current_account, { :url =&gt; admins_account_path(current_account), :method =&gt; 'put' } do %&gt;
    &lt;div class="action"&gt;
      &lt;%= submit_tag "Save" %&gt;
    &lt;/div&gt;
    &lt;table&gt;
      &lt;tbody&gt;
  
        &lt;% @accountships.each do |accountship| %&gt;
          &lt;tr&gt;
            &lt;td&gt;&lt;%= check_box_tag "accountship_ids[]", accountship.id, accountship.admin? %&gt;&lt;/td&gt;
            &lt;td&gt;&lt;%= accountship.user.name %&gt;
          &lt;/tr&gt;
        &lt;% end %&gt;
  
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>And in the controller, I handle the PUT with this method in accounts#update_admin. This is all working as expected.</p>
  
  <pre><code>@account.assign_administrators params[:accountship_ids]
  </code></pre>
  
  <p>My question is how do I construct the parameters in rspec to test that controller action. What I have tried so far is not working. Here's my latest try that doesn't work. </p>
  
  <pre><code>before(:each) do
    # code that generates the ids, I know this is working from other tests ..
    .
    .
    .
    @attr = {
      :accountship_ids =&gt; [
        @admin_accountship.id,
        @not_admin_accountship.id,
        @signed_in_user_accountship.id
      ]
    }
  end
  
  it "should assign admin to users in the list" do
  
    # what should I be passing in as @attr?
    put :update_admins, :id =&gt; @account, :accountship_ids =&gt; @attr  
  
    Accountship.find(@admin_accountship.id).admin.should be_true
    Accountship.find(@owner_accountship.id).admin.should be_true
    Accountship.find(@not_admin_accountship.id).admin.should_not be_true
  end
  </code></pre>
  
  <p>All the tests I've been able to write that require values from the form checkbox collection are failing, and it's apparent that the whatever_accountship.admin attribute is not being updated when the rspec test is posting the data.</p>
  
  <p>Thanks in advance!</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>I stumbled onto the solution. The array shouldn't have been wrapped in a hash, and the values in the array literal needed to be converted to strings first, as below.</p>
  
  <pre><code> @attr = [
     @admin_accountship.id.to_s,
     @not_admin_accountship.id.to_s,
     @signed_in_user_accountship.id.to_s
   ]
  </code></pre>
  
  <p>Anyone understand why they need to be strings when other tests I have can accept a full-blown object (no strings required)? </p>
  
  <p>Also, what do I do to my question now that I know the answer?</p>