-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Apply feedback from Ana's code review:
- Rename to `Keyword` - Use an `array` field! - validate!
- Loading branch information
Showing
10 changed files
with
44 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
class Journal | ||
class Keyword < ApplicationRecord | ||
location(parent: :journal) | ||
|
||
self.table_name = "journal_keywords" | ||
validates :canonical_keyword, presence: true, uniqueness: {case_sensitive: false, scope: :journal_id} | ||
belongs_to :journal, inverse_of: :keywords | ||
|
||
def self.extract_and_create_from!(body) | ||
body.scan(/#(\w+)/)&.flatten&.each do |keyword| | ||
next if where("'?' = ANY (aliases)", keyword) | ||
.or(where(canonical_keyword: keyword)).exists? | ||
|
||
find_or_create_by!(canonical_keyword: keyword) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
class AddJournalKeywords < ActiveRecord::Migration[7.0] | ||
def change | ||
create_table :journal_keywords, id: :uuid do |t| | ||
t.references :journal, type: :uuid, foreign_key: {to_table: :furnitures} | ||
t.string :canonical_keyword | ||
t.string :aliases, array: true | ||
t.timestamps | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# frozen_string_literal: true | ||
|
||
require "rails_helper" | ||
|
||
RSpec.describe Journal::Keyword, type: :model do | ||
it { is_expected.to validate_presence_of(:canonical_keyword) } | ||
it { is_expected.to validate_uniqueness_of(:canonical_keyword).case_insensitive.scoped_to(:journal_id) } | ||
it { is_expected.to belong_to(:journal).inverse_of(:keywords) } | ||
end |
This file was deleted.
Oops, something went wrong.