title: How to test view and controller logic that relies on the created_at property?
body: <p>I'm brand new to Ruby on Rails.</p>
  
  <p>I have an application with a simple controller and view that render an HTML page with a list of Active Record objects from my database in least-recently-created (oldest first) order. </p>
  
  <p>I'm attempt to write a test that verifies this sorting behavior by creating two objects with different <code>created_at</code> values, then verifying that the generated HTML has the oldest item first (using <code>assert_select</code>).</p>
  
  <p>However, when I try to manually alter the <code>created_at</code> value on one of my objects (to ensure that my objects don't have the same <code>created_at</code> value), the other properties of the object appear to be set to a default value.  For example, this code in my test results in an <code>Image</code> object with an <code>url</code> property value of <code>http://www.example.com/image1.png</code>, as expected:</p>
  
  <pre><code>@image1 = Image.create!(url: 'http://www.example.com/image1.png')
  </code></pre>
  
  <p>However, this code results in the <code>url</code> property value in the database unexpectedly changing to <code>MyString</code>:</p>
  
  <pre><code>@image1 = Image.create!(url: 'http://www.example.com/image1.png')
  @image1.created_at = '2017-09-25'
  @image1.save
  </code></pre>
  
  <p>I'm using ruby 2.3.3 and rails 5.1.1.1 (per my Gemfile).</p>
  
  <p>I have two questions at this point:</p>
  
  <ol>
  <li>Why does setting the <code>created_at</code> value on my object have the apparent side effect of changing the value of the <code>url</code> property to <code>MyString</code>? Is changing the <code>created_at</code> date just not allowed?</li>
  <li>What's the proper way to go about arranging data in a test that exercises logic where the <code>created_at</code> dates of objects need to have particular values?</li>
  </ol>