Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9229331
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:32:41+00:00 2026-06-18T05:32:41+00:00

Given a class that inherits from ActiveRecord::Base, lets call it Task, I have two

  • 0

Given a class that inherits from ActiveRecord::Base, lets call it Task, I have two subclasses that specialize some aspects of a task, Activity and Training, using standard Rails single table inheritance.

I’m confident in that choice after looking at other available since the actual data for the models are the same, it’s just the behavior that differs. A perfect fit for STI.

A task can be created, started, progressed and finished. That is some logic involved in these transitions, especially start(), that calls for the specialization of the base class.

Since I’m doing this TDD and started out with a working Task calls with full test coverage I’m now wondering how to proceed. I have a few senarios that I have thought about:

  1. Duplicate the tests for Task and test both Activity and Training end to end with some small modifications to test their specialization. Pro: it’s quick and easy. Con: it duplicates code and while that might not be a big problem here it will be when the number of specializations grows.

  2. Split tests and keep most of the testing code in a task_spec.rb while moving specialization testing into new specs for the respective subclasses. Pro: keeps the tests DRY. Con: what class do I instantiate in the base test?

That last question is what is nagging at me. Right now I have the base class test set up to randomly create a class from one of the concert subclasses, but is this good form? It almost makes me want to go with approach 1 just to keep the test runs consistent or I’ll have to find a way to base the randomness of my class selection of the random seed for the test suite so that I at least have a repeatable random selection.

I’m guessing this must be a common problem people run in to but I can’t find any good information on the subject. Do you have any resources or thoughts on the matter?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T05:32:42+00:00Added an answer on June 18, 2026 at 5:32 am

    You could use rspec shared examples to test the behavior that is shared among all of them (basically, the inherited behavior, or places where you want to guard against LSP violations).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using Sharp Architecture 1.9 I have a base class that inherits from the Sharp
I have a class that inherits from a dictionary in order to add some
Given an instantiated JavaScript object/class can I make an Ajax call from that class
I have a class that inherits from defaultdict like this: class listdict(defaultdict): def __init__(self):
I have a Balloon class (see this ) that inherits from CCSprite . I
I have a C# class that inherits from DynamicObject and using serialization is creating
I have a base class called Object. PhysicsObject inherits from Object. Ball inherits from
I've got two classes: a template class, and a regular class that inherits from
I have method that returns module path of given class name def findModulePath(path, className):
Given: I have an interface. I have only class that implements that interface. Question:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.