diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2012-06-22 07:51:11 -0700 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2012-06-22 07:51:11 -0700 |
commit | fb8cf55868d555b7f06215db5976c8aaf083d30b (patch) | |
tree | 0e7ac61acba88d4a0b6f137343a98eb465353ce8 /activerecord/test/cases | |
parent | 9298d60af08767d427d28f1b0dbf76b2d54418b4 (diff) | |
parent | f984b8152fb497919b30c9c96e471e0736f3a6d2 (diff) | |
download | rails-fb8cf55868d555b7f06215db5976c8aaf083d30b.tar.gz rails-fb8cf55868d555b7f06215db5976c8aaf083d30b.tar.bz2 rails-fb8cf55868d555b7f06215db5976c8aaf083d30b.zip |
Merge pull request #6800 from mschneider/dynamic_finders_for_aliased_attributes
Dynamic finders for aliased attributes
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r-- | activerecord/test/cases/deprecated_dynamic_methods_test.rb | 3 | ||||
-rw-r--r-- | activerecord/test/cases/finder_respond_to_test.rb | 5 | ||||
-rw-r--r-- | activerecord/test/cases/finder_test.rb | 5 |
3 files changed, 12 insertions, 1 deletions
diff --git a/activerecord/test/cases/deprecated_dynamic_methods_test.rb b/activerecord/test/cases/deprecated_dynamic_methods_test.rb index 7c108b983e..09ca61aa1b 100644 --- a/activerecord/test/cases/deprecated_dynamic_methods_test.rb +++ b/activerecord/test/cases/deprecated_dynamic_methods_test.rb @@ -524,7 +524,8 @@ class DynamicScopeMatchTest < ActiveRecord::TestCase end def test_scoped_by - match = ActiveRecord::DynamicMatchers::Method.match(nil, "scoped_by_age_and_sex_and_location") + model = stub(attribute_aliases: {}) + match = ActiveRecord::DynamicMatchers::Method.match(model, "scoped_by_age_and_sex_and_location") assert_not_nil match assert_equal %w(age sex location), match.attribute_names end diff --git a/activerecord/test/cases/finder_respond_to_test.rb b/activerecord/test/cases/finder_respond_to_test.rb index eedbaac3bd..9440cd429a 100644 --- a/activerecord/test/cases/finder_respond_to_test.rb +++ b/activerecord/test/cases/finder_respond_to_test.rb @@ -36,6 +36,11 @@ class FinderRespondToTest < ActiveRecord::TestCase assert_respond_to Topic, :find_by_title_and_author_name end + def test_should_respond_to_find_all_by_an_aliased_attribute + ensure_topic_method_is_not_cached(:find_by_heading) + assert_respond_to Topic, :find_by_heading + end + def test_should_respond_to_find_or_initialize_from_one_attribute ensure_topic_method_is_not_cached(:find_or_initialize_by_title) assert_respond_to Topic, :find_or_initialize_by_title diff --git a/activerecord/test/cases/finder_test.rb b/activerecord/test/cases/finder_test.rb index df21585961..e62d984ebd 100644 --- a/activerecord/test/cases/finder_test.rb +++ b/activerecord/test/cases/finder_test.rb @@ -535,6 +535,11 @@ class FinderTest < ActiveRecord::TestCase assert_raise(ActiveRecord::RecordNotFound) { Topic.find_by_title!("The First Topic!") } end + def test_find_by_one_attribute_that_is_an_alias + assert_equal topics(:first), Topic.find_by_heading("The First Topic") + assert_nil Topic.find_by_heading("The First Topic!") + end + def test_find_by_one_attribute_with_conditions assert_equal accounts(:rails_core_account), Account.where('firm_id = ?', 6).find_by_credit_limit(50) end |