Skip to content

Commit

Permalink
Merge pull request #2666 from manyfold3d/fix-presupported-glitch
Browse files Browse the repository at this point in the history
Fix changing presupported state causing database inconsistency
  • Loading branch information
Floppy committed Sep 10, 2024
2 parents 8cc6d03 + b46b677 commit eed7077
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
6 changes: 6 additions & 0 deletions app/models/model_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class ModelFile < ApplicationRecord
validate :presupported_version_is_presupported
validate :presupported_files_cannot_have_presupported_version

after_update :clear_presupported_relation, if: :presupported_previously_changed?

default_scope { order(:filename) }
scope :unsupported, -> { where(presupported: false) }
scope :presupported, -> { where(presupported: true) }
Expand Down Expand Up @@ -180,4 +182,8 @@ def loader
Mittsu::OBJLoader
end
end

def clear_presupported_relation
unsupported_version&.update presupported_version: nil
end
end
5 changes: 5 additions & 0 deletions spec/models/model_file_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,5 +137,10 @@
expect(presupported).not_to be_valid
expect(presupported.errors[:presupported_version].first).to eq "cannot be set on a presupported file"
end

it "clears presupported version if presupported file is set to unsupported" do
presupported.update!(presupported: false)
expect(unsupported.reload.presupported_version).to be_nil
end
end
end

0 comments on commit eed7077

Please sign in to comment.