title: How do I test with Rspec an initialize method that invokes find_or_initialize_by?
body: <p>How do I write a test to check for the <code>find_or_initialize_by</code> block in this <code>initialize</code> method?</p>
  
  <pre><code>def initialize(document, user)
    @document = document
    @api = @document.api_version
    @template = @document.template
    @user = user
    @brand = @user.brand
    @vars = master_var_hash.extend Hashie::Extensions::DeepFind
  
    template_variables.each do |t|
      @document.template_variables.find_or_initialize_by(name: t.name) do |d|
        d.name           = t.name
        d.tag            = t.tag
        d.box_name       = t.box_name
        d.designator     = t.designator
        d.order_index    = t.order_index
        d.master_id      = t.id
        d.editable       = t.editable
        d.editable_title = t.editable_title
        d.html_box       = t.box.stack.html_box if @api == :v3
        d.text = t.name == 'title' ? default_title : user_value(t)
      end
    end
  end
  </code></pre>
  
  <p>I want to be able to test that the right values have been assigned to the <code>@document</code>'s <code>TemplateVariables</code> from the class' <code>TemplateVariable</code>s. In my coverage report I can't even hit inside the <code>find_or_initialize_by</code> block.</p>
  
  <p>My test for size doesn't really check what I want to test here:</p>
  
  <pre><code>describe 'template_variables' do
    it 'initializes all the new vars per document' do
      expect(document.template_variables.size).to eq subject.master_var_hash.size
    end
  end
  </code></pre>
  
  <p>How can I write a test to check all those values and cover those lines?</p>