Skip to content

Commit

Permalink
Merge branch 'feature/unknown-operator' into staging
Browse files Browse the repository at this point in the history
  • Loading branch information
tsubik committed Dec 5, 2023
2 parents e032171 + 1e21df6 commit 86c4ca5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 27 deletions.
4 changes: 2 additions & 2 deletions app/models/observation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class Observation < ApplicationRecord

with_options if: :operator? do
validate :validate_governments_absences
validate :validate_known_operator, if: -> { operator? && (published? || validation_status == "Ready for publication") }
validate :validate_known_operator, if: -> { operator? && (validation_status != "Created") }
end

with_options if: :government? do
Expand Down Expand Up @@ -290,7 +290,7 @@ def validate_governments_absences
end

def validate_known_operator
errors.add(:operator, "Should be present for published observations") if operator.blank? || operator.special_unknown?
errors.add(:operator, "can't be blank or unknown") if operator.blank? || operator.special_unknown?
end

# Validates the statuses transitions.
Expand Down
36 changes: 11 additions & 25 deletions spec/models/observation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,11 @@
describe "#status_changes" do
let(:country) { create(:country) }
let(:status) { "Created" }
let(:operator) { create(:operator, country: country) }
let(:observation) {
build :observation,
country: country,
operator: operator,
validation_status: status
}
subject {
Expand Down Expand Up @@ -168,37 +170,21 @@

describe "for all" do
context "with unknown operator" do
before do
create(:unknown_operator)
observation.save
observation.validation_status = new_status
end

context "when moving to 'Ready for QC'" do
let(:new_status) { "Ready for QC" }

it "should be valid" do
expect(observation.save).to be true
end
end
let(:operator) { create(:unknown_operator) }
before { observation.save }
subject { observation }

context "when publishing" do
let(:new_status) { "Published (no comments)" }

it "should not be valid" do
observation.operator = Operator.find_by(slug: "unknown")
expect(observation.save).to be false
expect(observation.errors[:operator]).to eql ["Should be present for published observations"]
end
context "when creating an observation with status `Created`" do
it { is_expected.to be_valid }
it { is_expected.to be_persisted }
end

context "when ready for publication" do
let(:new_status) { "Ready for publication" }

context "when moving to 'Ready for QC'" do
it "should not be valid" do
observation.validation_status = "Ready for QC"
observation.operator = Operator.find_by(slug: "unknown")
expect(observation.save).to be false
expect(observation.errors[:operator]).to eql ["Should be present for published observations"]
expect(observation.errors[:operator]).to eql ["can't be blank or unknown"]
end
end
end
Expand Down

0 comments on commit 86c4ca5

Please sign in to comment.