Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/observation multiple evidences #480

Merged
merged 23 commits into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
42e1974
create observation document - observation join table
tsubik Dec 22, 2023
fa336a2
move evidence type to observation document and name it as document_type
tsubik Jan 3, 2024
4f2804f
fix migration
tsubik Jan 5, 2024
7e29cff
add observation_report reference to observation documents
tsubik Jan 5, 2024
70a3f5e
API changes for multiple evidences
tsubik Jan 9, 2024
0ba3e6e
fix observation document uploader
tsubik Jan 9, 2024
fa1d577
remove evidence_type from obs histories as this is no needed
tsubik Jan 11, 2024
66ee048
update migration saving old evidence_type as evidence_type_v0 in pape…
tsubik Jan 11, 2024
1d35c7b
fixing specs
tsubik Jan 11, 2024
f08477c
update model annotations
tsubik Jan 25, 2024
1bbfc41
add observation-report-id to observation document resource to not hav…
tsubik Jan 26, 2024
03151e8
add deleted_at to obs-documents-observations join table, update gener…
tsubik Jan 26, 2024
e6cab37
admin observation report show page: add documents/evidences
tsubik Jan 26, 2024
4d4dc1f
fix not visible documents on index page after moving observation to r…
tsubik Jan 26, 2024
8004ba0
change how admin can add and attach evidences to observations
tsubik Mar 20, 2024
00050a2
tweak observation form, show only relevant evidence inputs based on e…
tsubik Mar 20, 2024
db41407
fix problem with evidences that does not belong to report somehow
tsubik Mar 21, 2024
4a776f6
fix issue with uploader, validate evidence attachment
tsubik Mar 21, 2024
f8f947b
validate name for observation evidence
tsubik Mar 21, 2024
04a9c2d
fixing specs
tsubik Mar 21, 2024
077bc37
remove user from observation documents as it is not even used
tsubik Mar 21, 2024
d822b2f
fix permissions
tsubik Mar 21, 2024
8e24cc9
user reference was removed from observation document
tsubik Mar 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fixing specs
  • Loading branch information
tsubik committed Mar 25, 2024
commit 1d35c7bafe616870349e7f4e5144af8d45fb8a5f
2 changes: 1 addition & 1 deletion app/importers/observations_importer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class ObservationsImporter < FileDataImport::BaseImporter
PERMITTED_ATTRIBUTES = %i[
observation_type publication_date pv is_active location_accuracy
lat lng fmu_id location_information actions_taken
evidence_on_report validation_status is_physical_place user_id
evidence_type evidence_on_report validation_status is_physical_place user_id
observer_ids
].freeze

Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/admin/observations_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
let!(:observation) { create(:gov_observation) }

before do
create(:observation_document, observation: observation)
create(:observation_document, observations: [observation])
end

describe "GET index" do
Expand Down
1 change: 0 additions & 1 deletion spec/factories/observation_documents.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
FactoryBot.define do
factory :observation_document do
user
observation
sequence(:name) { |n| "ObservationDocument#{n}" }
attachment { Rack::Test::UploadedFile.new(File.join(Rails.root, "spec", "support", "files", "image.png")) }
end
Expand Down
4 changes: 2 additions & 2 deletions spec/integration/v1/observation_documents_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module V1
describe "Observation Documents", type: :request do
let(:user) { create(:user) }
let(:observation) { create(:observation) }
let(:observation_report) { create(:observation_report) }

# TODO: add attachment
let(:document_data) {
Expand All @@ -15,7 +15,7 @@ module V1
create: {
success_roles: %i[admin],
failure_roles: %i[user],
valid_params: -> { {name: "Document one", relationships: {user: user.id, observation: observation.id}} }
valid_params: -> { {name: "Document one", relationships: {user: user.id, observation_report: observation_report.id}} }
},
edit: {
success_roles: %i[admin],
Expand Down
9 changes: 5 additions & 4 deletions spec/models/observation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@
subject(:observation) { build(:observation) }

it "Removes old evidences when the evidence is on the report" do
subject.evidence_type = "Uploaded documents"
subject.observation_documents << create(:observation_document)
subject.save!
create(:observation_document, observation: subject)
expect(subject.observation_documents.count).to eql(1)
subject.evidence_type = "Evidence presented in the report"
subject.evidence_on_report = "10"
Expand Down Expand Up @@ -72,7 +73,7 @@
it "is invalid there is evidence on the report but not listed where" do
subject.evidence_type = "Evidence presented in the report"
expect(subject.valid?).to eq(false)
expect(subject.errors[:evidence_on_report]).to include("You must add information on where to find the evidence on the report")
expect(subject.errors[:evidence_on_report]).to include("can't be blank")
end

it "is invalid without observers" do
Expand Down Expand Up @@ -421,15 +422,15 @@
describe "#destroy_documents" do
before do
@observation = create(:observation, country: @country, operator: @operator)
create_list(:observation_document, 3, observation: @observation)
@observation.observation_documents = create_list(:observation_document, 3)
end

it "destroy related observation documents" do
expect(@observation.observation_documents.size).to eql 3

@observation.destroy

expect(ObservationDocument.where(observation_id: @observation.id).size).to eql 0
expect(ObservationDocument.joins(:observations).where(observations: [@observation]).size).to eql 0
end
end
end
Expand Down