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

Add uniqueness check for rule types #64

Merged
merged 3 commits into from
May 27, 2016

Conversation

RyanHedges
Copy link
Contributor

This adds uniqueness for rule type ids and their class names.

I did this because we do not want the rule types to be stored with the same
name within a rule type registry. This would make it difficult to find the
correct rule type if it was given the same name.
I did this because we don't want users to use different ids to reference the
same class name. This might cause us to not identify the correct type id when
looking them up by class name. This ensures that, along with type id, they are
unique.
end
end
end

describe 'get registered rule type class' do
it 'returns the associated rule type class' do
Togls.rule_types do
register(:test_rule_one, Togls::Rules::Boolean)
register(:test_rule_one, String)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since Togls::Rules::Boolean is defined when included I couldn't use it. I switched it to Class but the previous test still had it defined. To get the test to pass I had to pick other class names since I couldn't get them to clear out of the rule type registry.

I tried setting the rule type repository and registry to nil but it introduced a bunch of other problems. I'm still playing with it.

Edit: you can see in the following tests i used Integer, Hash, and Array to get it to pass.

Copy link
Owner

Choose a reason for hiding this comment

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

can you get any more specific with the other problems the nil reset introduced?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Dug into why setting the rule type registry/repository to nil is causing a bunch of failures...

Looks like because we are using the included hook in the manager to register the 'boolean' and 'group' rule types, they are getting cleared out when the repository/registry is being set to nil. Since the included hook is only being triggered one time when we require 'togls' in spec_helper.rb, those rule types are not being registered again. As a result a bunch of tests fail because it tries to call .new on nil after trying to look up the 'boolean' rule type.

Why you made the change:

I did this because everything else was already setup to lazy load and this part
wasn't which broken our conventions around testing and expected behavior.
@drewdeponte drewdeponte self-assigned this May 27, 2016
@drewdeponte drewdeponte merged commit d92d344 into master May 27, 2016
@drewdeponte drewdeponte deleted the add_uniquness_check_for_rule_types branch May 27, 2016 20:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants