-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #132 from leouofa/pillar-topic-population
Added Pillar Topic Population
- Loading branch information
Showing
8 changed files
with
68 additions
and
4 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,22 @@ | ||
class Pillars::CreatePillarTopicsJob < ApplicationJob | ||
queue_as :default | ||
|
||
def perform(*args) | ||
PillarColumn.with_topics.unprocessed.each do |pillar_column| | ||
process_pillar_column(pillar_column:) | ||
end | ||
end | ||
|
||
private | ||
|
||
def process_pillar_column(pillar_column:) | ||
pillar_column.topics.each do |pillar_topic| | ||
create_pillar_topic(pillar_column: ,pillar_topic:) | ||
end | ||
pillar_column.update(processed: true) | ||
end | ||
|
||
def create_pillar_topic(pillar_column:, pillar_topic:) | ||
PillarTopic.create!(pillar_column: pillar_column, title: pillar_topic["title"], summary: pillar_topic["summary"]) | ||
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 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,5 @@ | ||
class AddProcessedToPillarColumn < ActiveRecord::Migration[7.0] | ||
def change | ||
add_column :pillar_columns, :processed, :boolean, default: false | ||
end | ||
end |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe Pillars::CreatePillarTopicsJob, type: :job do | ||
let!(:pillar_column_with_topics) { create(:pillar_column, topics: [{ "title" => "Topic 1", "summary" => "Summary 1" }, { "title" => "Topic 2", "summary" => "Summary 2" }]) } | ||
let!(:pillar_column_without_topics) { create(:pillar_column, topics: nil) } | ||
let!(:processed_pillar_column) { create(:pillar_column, topics: [{ "title" => "Topic 3", "summary" => "Summary 3" }], processed: true) } | ||
|
||
describe '#perform' do | ||
it 'processes unprocessed pillar columns with topics' do | ||
expect { described_class.perform_now }.to change { PillarTopic.count }.by(2) | ||
|
||
pillar_column_with_topics.reload | ||
expect(pillar_column_with_topics.processed).to be_truthy | ||
end | ||
|
||
it 'does not process already processed pillar columns' do | ||
expect { described_class.perform_now }.not_to(change { processed_pillar_column.pillar_topics.count }) | ||
end | ||
|
||
it 'does not process pillar columns without topics' do | ||
expect { described_class.perform_now }.not_to(change { pillar_column_without_topics.pillar_topics.count }) | ||
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