-
Notifications
You must be signed in to change notification settings - Fork 22k
Document TestFixtures#fixture #52054
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
# assert_equal "Ruby on Rails", web_sites(:rubyonrails).name | ||
# assert_equal "Ruby on Rails", fixture(:web_sites, :rubyonrails).name | ||
public def fixture(fixture_set_name, *fixture_names); end | ||
silence_warnings { alias_method :fixture, :_active_record_fixture } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without silence_warnings
, this is outputted:
/Users/jko/Developer/rails/rails/activerecord/lib/active_record/test_fixtures.rb:286: warning: method redefined; discarding old fixture
/Users/jko/Developer/rails/rails/activerecord/lib/active_record/test_fixtures.rb:285: warning: previous definition of fixture was here
Is it worth adding a comment specifying what warning we are silencing?
# Generic fixture accessor for fixture names that may conflict. | ||
# | ||
# assert_equal "Ruby on Rails", web_sites(:rubyonrails).name | ||
# assert_equal "Ruby on Rails", fixture(:web_sites, :rubyonrails).name |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm an RDoc noob, definitely let me know if I'm missing something. Perhaps point the source to _active_record_fixture
? Not sure how to do that if so.
# assert_equal "Ruby on Rails", web_sites(:rubyonrails).name | ||
# assert_equal "Ruby on Rails", fixture(:web_sites, :rubyonrails).name | ||
public def fixture(fixture_set_name, *fixture_names); end | ||
silence_warnings { alias_method :fixture, :_active_record_fixture } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI, even though the new documentation says it's a public method, the alias_method
to a private method flips it to be private. Not sure if that's disingenuous or not.
Since we want to document diff --git a/activerecord/lib/active_record/test_fixtures.rb b/activerecord/lib/active_record/test_fixtures.rb
index 00b3f5a846..6dc68087f1 100644
--- a/activerecord/lib/active_record/test_fixtures.rb
+++ b/activerecord/lib/active_record/test_fixtures.rb
@@ -269,14 +269,14 @@ def respond_to_missing?(method, include_private = false)
end
end
- def _active_record_fixture(fixture_set_name, *fixture_names)
+ def fixture(fixture_set_name, *fixture_names) # :doc:
if fs_name = fixture_sets[fixture_set_name.name]
access_fixture(fs_name, *fixture_names)
else
raise StandardError, "No fixture set named '#{fixture_set_name.inspect}'"
end
end
- alias_method :fixture, :_active_record_fixture
+ alias_method :_active_record_fixture, :fixture
def access_fixture(fs_name, *fixture_names) This makes it show up in the doc as a private method for me (and I guess add |
The risk is if the user overrides
I believe the entire point of this pull is to make |
I don't think method redefinition affects aliases, so it shouldn't be a problem.
My understanding was the purpose was to document the method (whether public or private). If we want it to show up as public then personally it makes more sense to me to just make the method public than "lie" about the privacy. |
Agreed. I made this pull more for an intellectual exercise than caring about its intent. I was confused by byroot's comment here: #51213 (comment) |
You are correct. |
Why can't we just do this? 110c65d |
The thing is, assertion methods and test helpers are supposed to be private, but that makes them hard to document. Looking at other assertion methods etc in Rails, they are all public, likely for documentation purposes. So yeah, we should just go with that. |
Fixes rails#52000 Co-Authored-By: Hartley McGuire <skipkayhil@gmail.com>
Document TestFixtures#fixture
Fixes #52000
Checklist
Before submitting the PR make sure the following are checked:
[Fix #issue-number]