Skip to content
This repository was archived by the owner on Dec 3, 2019. It is now read-only.

Conversation

hollomancer
Copy link
Member

Description of changes

Adds a column for military_status, which is currently not present on users. This will allow the information we request regarding a military spouse / active duty in signup flow to save to the DB.

Issue Resolved

Part of fixing #373 (some frontend work needed)

It's been a while for me. Please review.

@hollomancer hollomancer requested a review from hpjaj July 11, 2018 21:44
@hollomancer
Copy link
Member Author

Also fixes #374

Copy link
Collaborator

@hpjaj hpjaj left a comment

Choose a reason for hiding this comment

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

@@ -0,0 +1,5 @@
class AddMilitarystatusToUser < ActiveRecord::Migration[5.0]
def change
add_column :users, :military_status, :string
Copy link
Collaborator

Choose a reason for hiding this comment

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

As this is a string, is the plan to accept any string, or a specific list of strings for consistency? Meaning a specified set of four statuses, for example. I highly recommend the latter.

This way, we can enforce data integrity, hang logic on the responses, do data analysis, filtering and searching, add rules for certain statuses, etc., etc.

If the answer is yes, then we'll need to do a few extra additions in this PR before shipping it.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I agree. Let's do it the right way.

From the frontend, current, veteran, spouse are the values provided.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'd just need to add the check in /app/models/user.rb, is that correct?

Copy link
Collaborator

Choose a reason for hiding this comment

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

@hollomancer - To establish the specific set of validated statuses, you'll want to:

  1. Create a constant for each status here.
  2. Create a constant to represent an array of all of the statuses. You'll need to include one for nil, to account for our current users, and future users, that will not have a status. For example:
CURRENT = 'current'
VETERAN = 'veteran'
SPOUSE = 'spouse'
MILITARY_STATUSES = [CURRENT, VETERAN, SPOUSE, nil]
  1. In models/user.rb, Add an inclusion validation for the new :military_status attribute, for the MILITARY_STATUSES. Here is how to do that.
  2. In admin/user.rb, add the set of selections to ActiveAdmin dashboard form portion. For example:
f.input :military_status, as: :select, collection: User::MILITARY_STATUSES.map { |status| [status, status].compact }.reject(&:empty?), include_blank: true
  1. Add test coverage to user_test.rb testing the new inclusion validation
  2. In apiary.apib, in the military_status definition, change that to something like:
Users military status, either: current, veteran, spouse, or blank

@hpjaj hpjaj mentioned this pull request Jul 14, 2018
@dmarchante
Copy link
Contributor

@hpjaj is this only waiting a review, or are there more changes to be made?

@hollomancer
Copy link
Member Author

@dmarchante, this one's on me to finish validation appropriately.

@hollomancer hollomancer self-assigned this Jul 15, 2018
@@ -1,6 +1,6 @@
require 'test_helper'

class UserTest < ActiveSupport::TestCase
class UserTest < ActiveSupport::TestCase # rubocop:disable Metrics/ClassLength
Copy link
Member Author

Choose a reason for hiding this comment

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

@hpjaj, should we break this up into smaller segments?

Copy link
Collaborator

@hpjaj hpjaj Jul 19, 2018

Choose a reason for hiding this comment

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

No, let's keep all of the user model related test code in this file.

As far as disabling RuboCop, you can:

The latter is slightly preferable. If you run into any issues doing it that way, due to the Metrics/ClassLength setting in .rubocop_todo.yml, then just go with the former. Not a big deal in this case.

f.input :pay_grade
f.input :military_occupational_specialty
f.input :github
f.input :twitter
f.input :linkedin
f.input :employment_status
f.input :education
f.input :military_status
Copy link
Collaborator

Choose a reason for hiding this comment

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

You'll want to delete this input (we'll favor the new collection input on line 109).

@@ -260,4 +260,11 @@ def user_opts
assert_equal data[:zip], userInfo[:zip]
assert_equal '/profile', redirect
end

test 'military status accepts valid states' do
assert create(:user, military_status: 'spouse')
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you pls change these three to pass the three new constants, to support our validation? i.e.

assert create(:user, military_status: User::SPOUSE).valid?

Copy link
Collaborator

@hpjaj hpjaj left a comment

Choose a reason for hiding this comment

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

Nice work @hollomancer !

@hpjaj hpjaj merged commit 22f31f1 into OperationCode:master Jul 21, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants