Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 5fb05f82f0
Fetching contributors…

Cannot retrieve contributors at this time

file 36 lines (27 sloc) 0.789 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
require 'test_helper'

class ReloadTest < ActiveRecord::TestCase
  def test_reload_existing_record
    assert_queries(2) do
      # Query 1
      users = User.all

      lifo = users.detect {|u| u.name == 'Lifo'}

      # Query 2 - Reload Lifo
      assert_equal 'Lifo', lifo.reload.name
    end
  end

  def test_reload_newly_created_record
    noob = User.create(:name => 'Noob')

    assert_queries(1) { assert_equal 'Noob', noob.reload.name }
  end

  def test_belongs_reload
    assert_queries(3) do
      # Query 1
      posts = Post.all
      hello_post = posts.detect {|p| p.title == 'Hello' }

      # Query 2 - Load all the users
      assert_equal 'Bob', hello_post.user.name

      # Query 3- Reload Bob
      assert_equal 'Bob', hello_post.user.reload.name
    end
  end

end
Something went wrong with that request. Please try again.