<p>Given the code from the <a href="http://railscasts.com/episodes/75" rel="nofollow noreferrer">Complex Form part III</a> how would you go about testing the virtual attribute?</p>
<pre><code>  def new_task_attributes=(task_attributes)
    task_attributes.each do |attributes|
      tasks.build(attributes)
    end
  end
</code></pre>
<p>I am currently trying to test it like this:</p>
<pre><code>  def test_adding_task_to_project
    p = Project.new
    params = {&quot;new_tasks_attributes&quot; =&gt; [{ &quot;name&quot; =&gt; &quot;paint fence&quot;}]}
    p.new_tasks_attributes=(params)
    p.save
    assert p.tasks.length == 1
  end
</code></pre>
<p>But I am getting the following error:</p>
<blockquote>
<p>NoMethodError: undefined method `stringify_keys!' for &quot;new_tasks_attributes&quot;:String</p>
</blockquote>
<p>Any suggestions on improving this test would be greatly appreciated.</p>

It looks as if new_task_attributes= is expecting an array of hashes, but you're passing it a hash. Try this:
```
```
def test_adding_task_to_project
  p = Project.new
  new_tasks_attributes = [{ "name" => "paint fence"}]
  p.new_tasks_attributes = (new_tasks_attributes)
  p.save
  assert p.tasks.length == 1
end
```
```