Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into 3-1-stable
Conflicts: test/basic_test.rb
- Loading branch information
Showing
4 changed files
with
52 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 |