-
-
Notifications
You must be signed in to change notification settings - Fork 504
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added archive column to the Families column * Updated the view, controller and test to use the new column * Added auto archive of children on families archive * Finished adding Scope and Default Filtering * Added scope to Families with unit tests * Added default filter to families controller * Updated the CSV output on the families controller * Added `Include Archived?` option on the families view * Added request test to ensure default only returns the non-archived * Added test for `Include Archived?` check on index * Fixed some formatting with for respec * 3351 add family archive Addressing feedback * Extracted archiving the children of a family to a service object that is called in the family controller and took the funciton and callback off of the family model * Updated and added unit test * Updated the migration to remove backfill migration * Addressed rubocop formatting issues * Added ignore for update_all for rubocop since the Child class has no validations * Quick Fix to update the rubocop issue with update_all * Renamed the archive_family_children service object to update_family and updated it to module level function. I also updated the migration table to creat the column and set nill and default all on one line * Missed a whitespace after the UpdateFamily service module * Added archive column to the Families column * Updated the view, controller and test to use the new column * Added auto archive of children on families archive * Finished adding Scope and Default Filtering * Added scope to Families with unit tests * Added default filter to families controller * Updated the CSV output on the families controller * Added `Include Archived?` option on the families view * Added request test to ensure default only returns the non-archived * Added test for `Include Archived?` check on index * Fixed some formatting with for respec * 3351 add family archive Addressing feedback * Extracted archiving the children of a family to a service object that is called in the family controller and took the funciton and callback off of the family model * Updated and added unit test * Updated the migration to remove backfill migration * Addressed rubocop formatting issues * Added ignore for update_all for rubocop since the Child class has no validations * Quick Fix to update the rubocop issue with update_all * Renamed the archive_family_children service object to update_family and updated it to module level function. I also updated the migration table to creat the column and set nill and default all on one line * Missed a whitespace after the UpdateFamily service module * Updated the scope to follow the pattern recommended for checkboxes on filterrific * Fixed some whitespace for rubocop * Fixed a small typo on the migration
- Loading branch information
Showing
12 changed files
with
134 additions
and
13 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
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,21 @@ | ||
# This service object is meant to archive a family and all of | ||
# its children | ||
module Partners | ||
module UpdateFamily | ||
extend ServiceObjectErrorsMixin | ||
# rubocop:disable Rails::SkipsModelValidations | ||
def self.archive(family) | ||
if family.children.exists? | ||
ActiveRecord::Base.transaction do | ||
family.update(archived: true, updated_at: Time.zone.now) | ||
family.children.update_all(archived: true, updated_at: Time.zone.now) | ||
rescue => e | ||
errors.add(:base, e.message) | ||
raise ActiveRecord::Rollback | ||
end | ||
end | ||
self | ||
end | ||
# rubocop:enable Rails::SkipsModelValidations | ||
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
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 @@ | ||
class AddArchiveToFamilies < ActiveRecord::Migration[7.0] | ||
def up | ||
add_column :families, :archived, :boolean, nil: false, default: false | ||
end | ||
|
||
def down | ||
remove_column :families, :archived | ||
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
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,34 @@ | ||
require "rails_helper" | ||
|
||
RSpec.describe Partners::UpdateFamily do | ||
describe "#call" do | ||
subject { described_class.archive(family) } | ||
let(:family) { FactoryBot.create(:partners_family) } | ||
let!(:child1) { FactoryBot.create(:partners_child, family: family) } | ||
let!(:child2) { FactoryBot.create(:partners_child, family: family) } | ||
|
||
context "when family has children" do | ||
it "archives the family and its children" do | ||
expect { | ||
subject | ||
}.to change { family.reload.archived }.from(false).to(true) | ||
.and change { child1.reload.archived }.from(false).to(true) | ||
.and change { child2.reload.archived }.from(false).to(true) | ||
end | ||
end | ||
|
||
context "when an error occurs during archiving" do | ||
it "does not archive the family or its children and adds error to the service" do | ||
allow(family.children).to receive(:update_all).and_raise(StandardError) | ||
|
||
initial_family_archived = family.archived | ||
initial_children_archived = family.children.pluck(:archived) | ||
initial_errors = subject.errors.dup | ||
|
||
expect(family.reload.archived).to eq(initial_family_archived) | ||
expect(family.children.pluck(:archived)).to eq(initial_children_archived) | ||
expect(subject.errors.full_messages).to eq(initial_errors.full_messages) | ||
end | ||
end | ||
end | ||
end |