On one of the many Rails projects I've worked on over the years, I
seem to recall using either a helper or a method on a model to
generate a css id based on the model class and id. It was very useful
particularly in making views more testable in RSpec/Cucumber.
I can't remember if this was part of rails, or from a plugin or
something specific to the project.
I've failed to find anything like this in the rails docs.
On one of the many Rails projects I've worked on over the years, I
seem to recall using either a helper or a method on a model to
generate a css id based on the model class and id. It was very useful
particularly in making views more testable in RSpec/Cucumber.
I can't remember if this was part of rails, or from a plugin or
something specific to the project.
On one of the many Rails projects I’ve worked on over the years, I
seem to recall using either a helper or a method on a model to
generate a css id based on the model class and id. It was very useful
particularly in making views more testable in RSpec/Cucumber.
I can’t remember if this was part of rails, or from a plugin or
something specific to the project.
Are you thinking of dom_id / dom_class ?
Interesting… was not aware of this. Just today was writing a helper method to create a friendly id for an object I am writing to a table row. The challenge with dom_id/class is that when using Cucumber you really do not know (without making a good guess) what the id of a record will be.
I am curious if anyone has done or thought of the following for models, something where one defines what fields would constitute a friendly field id which does not involve the index but fields that would be known in a Cucumber scenario? I seem to be writing helpers for this quite often as it seems like often the best strategy for checking for something on a page is to place the data with an id or as a child of some object with a specific id or class. I am not quite sure how to do this as it seems it would have to extend ActiveModel/ActiveRecord…or maybe be done in a module which can be aware of what constituted the friendly_id of a model:
include FriendlyId
class Borrower < ActiveRecord::Base
friendly_id :last_name, :first_name # so in each model you just define what fields of the model will constitute the friendly id
end
module FriendlyId
def friendly_id
# how do I access the ‘friendly_id’ settings from the model I am mixed in to?
end
end