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

(feature) added date_passed & document_types to Legislations #10

Merged
merged 9 commits into from Jul 29, 2019

Conversation

kowal
Copy link
Contributor

@kowal kowal commented Jul 26, 2019

  • Added date_passed and document_types (as tags) to Legislations.
  • extracted some import helpers

you can re-import records via bundle exec rake import:legislation

Zrzut ekranu 2019-07-28 o 21 39 59

@kowal kowal requested a review from tsubik July 26, 2019 12:46
@kowal kowal marked this pull request as ready for review July 26, 2019 12:46
puts "Couldn't find Location with ISO: #{country_iso}"
end

def try_to_parse_date(date, expected_date_formats)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

maybe rename it to find_date_with_format?

Copy link
Collaborator

Choose a reason for hiding this comment

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

You can change it, for me both are good.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will leave it as it is.

Copy link
Collaborator

@tsubik tsubik left a comment

Choose a reason for hiding this comment

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

I will test this PR in a couple hours. Leaving a few comments for now.

@@ -1,3 +1,25 @@
# To tag your model with let's say 'keywords', you need to
Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks for this 👍

#

class DocumentType < Tag
DOCUMENT_TYPES = [
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmm, not sure if we want to restrict that list

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also, that list is funny now, I wouldn't pay too much attention to what is in the data currently. See there is document type All, they should clean this up, what they wanted to just tag Law with different types. Maybe we will have to extract some of those tags to be something else in the future (for example if application logic will depend on it, I suspect "Out of date" would be the first candidate)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah I agree, this list will definitely change. For now I can remove the validation, but eventually, I think we will need some constraint on "document type". I guess this is a more precise term than, let's say "category".

Copy link
Collaborator

Choose a reason for hiding this comment

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

Not sure, I think right now those are like categories, and definitely, that list needs cleanup from their side. I would just remove validation for now.

@@ -0,0 +1,17 @@
module ImportHelpers
Copy link
Collaborator

Choose a reason for hiding this comment

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

Good idea

puts "Couldn't find Location with ISO: #{country_iso}"
end

def try_to_parse_date(date, expected_date_formats)
Copy link
Collaborator

Choose a reason for hiding this comment

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

You can change it, for me both are good.

let!(:legislation) { create(:legislation) }
let(:valid_attributes) {
attributes_for(:legislation).merge(
Copy link
Contributor Author

@kowal kowal Jul 28, 2019

Choose a reason for hiding this comment

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

@tsubik I couldn't find a way to include location by default in what's returned by attributes_for :/ then I found your approach from other models and used it here as well.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, attributes_for are not working with associations, probably they have a good reason for that.

@kowal
Copy link
Contributor Author

kowal commented Jul 28, 2019

@tsubik more updates:

  • date_passed: added filter + default sort order + fix parsing some dates in importer
  • better CSV output
  • added more specs

@kowal kowal changed the title Feature/legislations model update (feature) added date_passed & document_types to Legislations Jul 28, 2019
Copy link
Collaborator

@tsubik tsubik left a comment

Choose a reason for hiding this comment

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

Looks great 👍

Just I'm not sure about that Document_types. They were using it as a category and had full control over the values.

#

class DocumentType < Tag
DOCUMENT_TYPES = [
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not sure, I think right now those are like categories, and definitely, that list needs cleanup from their side. I would just remove validation for now.

@@ -0,0 +1,17 @@
module ImportHelpers
Copy link
Collaborator

Choose a reason for hiding this comment

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

We can move it to app/services/concerns. I'm not sure if that would require to add new concern directory to autoload_paths in config/application.rb, like config.autoload_paths += Dir[Rails.root.join("app", "services", "concerns")]

Copy link
Contributor Author

@kowal kowal Jul 29, 2019

Choose a reason for hiding this comment

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

I think concerns are meant to encapsulate a piece of domain logic, here we have 2 simple helper methods related to different things.

Maybe I add 2 different modules, which could be used like this (I also renamed methods)

def normalize_date
  Import::DateUtils.safe_parse(date)
end

def attributes
  { location: Import::LocationUtils.find_by_iso(..) }
end

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also, I'd move all import classes to services/import as well, so we'll end up with Import::Companies.new.call and so on.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ok.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done, please re-review

let!(:legislation) { create(:legislation) }
let(:valid_attributes) {
attributes_for(:legislation).merge(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, attributes_for are not working with associations, probably they have a good reason for that.

Copy link
Collaborator

@tsubik tsubik left a comment

Choose a reason for hiding this comment

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

Great! Thanks 👍

@tsubik tsubik merged commit 54efc6b into develop Jul 29, 2019
@kowal kowal deleted the feature/legislations-model-update branch July 30, 2019 07:58
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.

None yet

2 participants