-
Notifications
You must be signed in to change notification settings - Fork 0
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 domain name support #1
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,14 +62,6 @@ def self.other_attributes(attributes = []) | |
end | ||
end | ||
|
||
def self.other_attributes(attributes = []) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is also declared above, so this copy is redundant and is being removed. 👍 |
||
singleton_class.instance_eval do | ||
define_method(:other_search_fields) do | ||
attributes | ||
end | ||
end | ||
end | ||
|
||
# Add default accessors | ||
SEARCHABLE_FIELD_GROUPS.each do |field_group| | ||
next if respond_to? field_group | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# frozen_string_literal: true | ||
|
||
class DomainName < ActiveRecord::Base | ||
has_many :domain_registrations, dependent: :destroy | ||
has_many :organizations, through: :domain_registrations | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Obviously, this approach would be extensible to other models by making it polymorphic, as we're already doing with the |
||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# frozen_string_literal: true | ||
|
||
class DomainRegistration < ActiveRecord::Base | ||
belongs_to :domain_name | ||
belongs_to :organization | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# frozen_string_literal: true | ||
|
||
class CreateDomainNamesAndDomainRegistrations < ActiveRecord::Migration[6.0] | ||
def change | ||
create_table :domain_names do |t| | ||
t.string :name, null: false | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For the purposes of this exercise, I've decided that all the join models will be searchable based on the |
||
t.timestamps null: false | ||
end | ||
|
||
create_table :domain_registrations do |t| | ||
t.references :domain_name, foreign_key: true | ||
t.references :organization, foreign_key: true | ||
t.timestamps null: false | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1765,7 +1765,7 @@ | |
"description": "Duis mollit Lorem amet anim ea consequat ullamco. Eiusmod tempor incididunt adipisicing in mollit ut officia eu sint sit amet aute.", | ||
"priority": "normal", | ||
"status": "closed", | ||
"submitter_id": 55, | ||
"submitter_id": 555, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As noted in 7ccbc59 - several of these ticket records have what appears to be invalid data. I assume that's intentional, and part of the exercise. I'd initially set these to valid values just to defer a decision on how to handle things. I'm not super enthusiastic about losing our referential integrity, but it feels less-bad for our context here than excluding records. Reviewers, if you're reading this (👋) - definitely interested in hearing opinions on preferred tradeoffs here. |
||
"assignee_id": 17, | ||
"organization_id": 114, | ||
"tags": [ | ||
|
@@ -1927,7 +1927,7 @@ | |
"status": "closed", | ||
"submitter_id": 20, | ||
"assignee_id": 33, | ||
"organization_id": 101, | ||
"organization_id": 555, | ||
"tags": [ | ||
"South Dakota", | ||
"Montana", | ||
|
@@ -4387,7 +4387,7 @@ | |
"priority": "urgent", | ||
"status": "open", | ||
"submitter_id": 13, | ||
"assignee_id": 55, | ||
"assignee_id": 555, | ||
"organization_id": 108, | ||
"tags": [ | ||
"Minnesota", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -96,4 +96,14 @@ def do_setup | |
|
||
assert_includes search.results, tag_org, 'Should find organizations by tag' | ||
end | ||
|
||
test 'finds_by_domains' do | ||
domain_name = 'brawndo.com' | ||
domain_org = create_organization! | ||
domain_org.domain_names << DomainName.where(name: domain_name).first_or_create! | ||
search_params = { domain_names: domain_name } | ||
search = SearchEntities.call(Organization, search_params) | ||
|
||
assert_includes search.results, domain_org, 'Should find organizations by tag' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This error message should say "by domain name", but given that refactoring how we are constructing scopes is part of my next set of changes, I'll roll that update into that commit. |
||
end | ||
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.
This was only ever a placeholder method, and was a less-than-ideal location for it, even then.
The new equivalent is better on both counts, I think.