Skip to content

Conversation

@rachaelkiteme
Copy link
Collaborator

@rachaelkiteme rachaelkiteme commented May 8, 2018

In your PR did you:

  • Include a description of the changes?
  • Mention the issue the PR addresses?
  • Include screenshots of any changes to the UI?
  • Isolate any changes to gems (meaning that any new, updated, or removed gems and resulting code changes should be in their own PR)?
  • Add and/or update specs for your code?

@rlgreen91
Copy link
Contributor

@rachaelkiteme can you add a spec to make sure that if an agency is created with a random jurisidiction type that's not listed, that it gets flagged as invalid?

@rachaelkiteme
Copy link
Collaborator Author

rachaelkiteme commented May 10, 2018 via email

@rachaelkiteme
Copy link
Collaborator Author

rachaelkiteme commented May 11, 2018 via email

@rlgreen91
Copy link
Contributor

@rachaelkiteme No worries. So what I mean is that I want you to add a test where, if we try to create an agency with some random jurisdiction listed, like carrot, then it will be flagged as invalid and won't save. If you write the test and it fails, meaning that it does save correctly, then you'll need to update the agency model to make sure it doesn't.

If you look at the test ensuring that an agency has a name, that should provide you with a good example. If you do need to update the agency model, then I would check out the enumerated_type gem - they should have a method to get all of the enums of a model without having to hardcode them.

@rlgreen91
Copy link
Contributor

rlgreen91 commented May 20, 2018

Hey, so this looks good, but what I was looking for was kind of the opposite - that if you tried to create an agency with an invalid jurisdiction type, that it would fail. Can you change that? Also, can you add a feature spec that does the same thing? We might as well go ahead and add it now.

Also, I'll check Travis and see what's going on. So it's saying that the agency factory is already registered - I see that you merged master into your branch. Did you run bundle update to get any gem changes? That might be it.

@rlgreen91
Copy link
Contributor

Hey! So, three quick notes: first, I figured out why Travis is complaining - we have two agency factories. You have both a spec/factories/agencies.rb and a spec/factory/agency.rb. They seem identical to me, so just delete one of them, doesn't matter which. Second, having a jurisdiction type isn't required for an agency to be valid - we just need to make sure that if the user enters one it's a valid type. You can keep the tests for it having a valid jurisdiction type, just get rid of the ones that require it to have a jurisdiction type to be a valid object. Third, these are enumerables, so rather than list each jurisdiction type like %w [none, local, state, federal, university] you can just use JurisdictionType.entries.

Anyways, that factory change should get Travis to work. Let me know if it doesn't.

@rachaelkiteme
Copy link
Collaborator Author

rachaelkiteme commented May 28, 2018 via email

@rlgreen91
Copy link
Contributor

You can keep the validation, just set it so that it can be nil - https://stackoverflow.com/questions/5924582/is-there-a-shortcut-for-validating-a-field-only-when-its-present-in-rails-3

@rachaelkiteme
Copy link
Collaborator Author

Hello, once I try assigning jurisdiction_type: 'local' I get error Jurisdiction type is not included in the list then I inspected JurisdictionType.entries the results are as in the screenshot what could be the problem? please help

screenshot from 2018-06-02 18-18-22

@rachaelkiteme
Copy link
Collaborator Author

Had to use %w(none state local federal university private) so that jurisdiction type can be read as listed

@rlgreen91
Copy link
Contributor

Huh, that's weird. Not sure why that wouldn't work, given that's what the gem's author says to do.

Anyways, in app/models/case.rb, allow_nil should be after the inclusion hash - right now it looks like it's inside it.

You can also get rid of the changes you made to the test 'is invalid without a state' and get rid of the test on lines 46-49.

That's pretty much it; I'll merge whenever those changes are made. Thanks for tackling this. Some of this is wrangling with tests in the hopes that it'll be easier later on.

@rlgreen91 rlgreen91 merged commit e4c9099 into master Jun 11, 2018
@rlgreen91 rlgreen91 deleted the change_jurisdiction_enum_to_jurisdiction_type_#1343 branch June 11, 2018 03:11
@rachaelkiteme
Copy link
Collaborator Author

rachaelkiteme commented Jun 11, 2018 via email

@rlgreen91
Copy link
Contributor

Yeah, thanks for sticking with this. Testing is tricky - it really takes some time to grok how testing should go. I think our repo is a bit misleading, because it says we have a really high test coverage, but when you actually look at the tests themselves there's a bunch of stuff we don't account for. Case in point - I'm going to assign you to an issue because I forgot a step in this whole process, and better testing would have caught it.

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.

3 participants