Skip to content
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

Jacobperia component unit tests #85

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

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
@@ -2,8 +2,7 @@

class Matey::ActiveUsersComponent < Matey::ApplicationComponent
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 🚀

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