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
Conversation
app/services/import_helpers.rb
Outdated
puts "Couldn't find Location with ISO: #{country_iso}" | ||
end | ||
|
||
def try_to_parse_date(date, expected_date_formats) |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this 👍
app/models/document_type.rb
Outdated
# | ||
|
||
class DocumentType < Tag | ||
DOCUMENT_TYPES = [ |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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".
There was a problem hiding this comment.
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.
app/services/import_helpers.rb
Outdated
@@ -0,0 +1,17 @@ | |||
module ImportHelpers |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea
app/services/import_helpers.rb
Outdated
puts "Couldn't find Location with ISO: #{country_iso}" | ||
end | ||
|
||
def try_to_parse_date(date, expected_date_formats) |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
@tsubik more updates:
|
There was a problem hiding this 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.
app/models/document_type.rb
Outdated
# | ||
|
||
class DocumentType < Tag | ||
DOCUMENT_TYPES = [ |
There was a problem hiding this comment.
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.
app/services/import_helpers.rb
Outdated
@@ -0,0 +1,17 @@ | |||
module ImportHelpers |
There was a problem hiding this comment.
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")]
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok.
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great! Thanks 👍
date_passed
anddocument_types
(as tags) toLegislations
.you can re-import records via
bundle exec rake import:legislation