From 11870117c6d9231b79e8125218728423e9dff207 Mon Sep 17 00:00:00 2001 From: Jon Leighton Date: Tue, 13 Sep 2011 19:09:01 +0100 Subject: Rename first_or_new to first_or_initialize. For consistency with find_or_initialize_by. Also remove first_or_build alias. --- activerecord/test/cases/base_test.rb | 12 ++---------- activerecord/test/cases/relations_test.rb | 18 ++++++------------ 2 files changed, 8 insertions(+), 22 deletions(-) (limited to 'activerecord/test/cases') diff --git a/activerecord/test/cases/base_test.rb b/activerecord/test/cases/base_test.rb index cb92f79e0e..12c1cfb30e 100644 --- a/activerecord/test/cases/base_test.rb +++ b/activerecord/test/cases/base_test.rb @@ -294,16 +294,8 @@ class BasicsTest < ActiveRecord::TestCase assert_equal parrot, the_same_parrot end - def test_first_or_new - parrot = Bird.first_or_new(:color => 'green', :name => 'parrot') - assert_kind_of Bird, parrot - assert !parrot.persisted? - assert parrot.new_record? - assert parrot.valid? - end - - def test_first_or_build - parrot = Bird.first_or_build(:color => 'green', :name => 'parrot') + def test_first_or_initialize + parrot = Bird.first_or_initialize(:color => 'green', :name => 'parrot') assert_kind_of Bird, parrot assert !parrot.persisted? assert parrot.new_record? diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb index 0f50ac9a2b..95408a5f29 100644 --- a/activerecord/test/cases/relations_test.rb +++ b/activerecord/test/cases/relations_test.rb @@ -956,8 +956,8 @@ class RelationTest < ActiveRecord::TestCase assert_raises(ActiveRecord::RecordInvalid) { Bird.where(:color => 'green').first_or_create!([ {:name => 'parrot'}, {:pirate_id => 1} ]) } end - def test_first_or_new - parrot = Bird.where(:color => 'green').first_or_new(:name => 'parrot') + def test_first_or_initialize + parrot = Bird.where(:color => 'green').first_or_initialize(:name => 'parrot') assert_kind_of Bird, parrot assert !parrot.persisted? assert parrot.valid? @@ -966,8 +966,8 @@ class RelationTest < ActiveRecord::TestCase assert_equal 'green', parrot.color end - def test_first_or_new_with_no_parameters - parrot = Bird.where(:color => 'green').first_or_new + def test_first_or_initialize_with_no_parameters + parrot = Bird.where(:color => 'green').first_or_initialize assert_kind_of Bird, parrot assert !parrot.persisted? assert !parrot.valid? @@ -975,8 +975,8 @@ class RelationTest < ActiveRecord::TestCase assert_equal 'green', parrot.color end - def test_first_or_new_with_block - parrot = Bird.where(:color => 'green').first_or_new { |bird| bird.name = 'parrot' } + def test_first_or_initialize_with_block + parrot = Bird.where(:color => 'green').first_or_initialize { |bird| bird.name = 'parrot' } assert_kind_of Bird, parrot assert !parrot.persisted? assert parrot.valid? @@ -985,12 +985,6 @@ class RelationTest < ActiveRecord::TestCase assert_equal 'parrot', parrot.name end - def test_first_or_build_is_alias_for_first_or_new - birds = Bird.scoped - assert birds.respond_to?(:first_or_build) - assert_equal birds.method(:first_or_new), birds.method(:first_or_build) - end - def test_explicit_create_scope hens = Bird.where(:name => 'hen') assert_equal 'hen', hens.new.name -- cgit v1.2.3