I have a Rails application that deals with sports teams. There's a model, Club
, that contains all the teams and they relate to Match
es, etc. The application is centered around one of these clubs, and relies on the existence of that record. I've got an application helper method that defines the main club, essentially:
def main_club
@main_club ||= Club.find_by(abbrv: 'CLB')
end
And then that gets referred to in controller logic (can do certain things for main_club
that you can't for the others) and in views (displaying certain key info about upcoming matches, etc).
This feels messy to me. Hard code relying on "soft" database records? But I do need the Club to be a record, to allow for all of its relationships.
I've just sort of left it as it is, but it messes up RSpec. Even running Rails.application.load_seed
in config.before(:suite)
, I constantly get specs failing because it can't call .matches
, eg, on nil
.
Is there an established practice for this sort of thing? How should I go about this?
Edit: The seed file includes all current Clubs (including the main one), with the potential for adding more in the administrative interface/controller. It's possible that the RSpec issues are coming from something DatabaseCleaner is doing wrong, but a) I'm not sure what that would be and b) my concerns about hard code relying on "soft" database records remain regardless of RSpec.