Skip to content

Jacobperia component unit tests#85

Open
jacobperia wants to merge 6 commits intomainfrom
jacobperia-component_unit_tests
Open

Jacobperia component unit tests#85
jacobperia wants to merge 6 commits intomainfrom
jacobperia-component_unit_tests

Conversation

@jacobperia
Copy link

@jacobperia jacobperia commented Oct 12, 2023

  • Rspec tests for NewUsersComponent and NewActivityComponent
  • Initialize in ApplicationComponent will validate arguments and throw errors for the required components.

@jacobperia jacobperia linked an issue Oct 12, 2023 that may be closed by this pull request
@jacobperia jacobperia force-pushed the jacobperia-component_unit_tests branch from 2c6c793 to 0dfe187 Compare October 12, 2023 20:34
def initialize(events:, time_window: 1.week, color_scheme: "neutral")
raise ArgumentError unless events.is_a?(ActiveRecord::Relation)
raise ArgumentError unless time_window.is_a?(Integer)
validate_arguments(events, time_window)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice way to try things up. I've not really thought about this type of validation before but seems to make sense and definitely better than including it in each file.

Thoughts on leveraging super as an alternative implementation? Not sure it is better ...

In this implementation, I think it would be nice to have named arguments so that the method signature would be:

validate_arguments(events: events, time_window: time_window)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was able to implement both the suggestions. Much cleaner now 🚀

@jacobperia jacobperia requested a review from krsyoung October 13, 2023 19:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Unit Tests for Existing Components

2 participants