Skip to content

Commit

Permalink
Return the previous project media for claim description (#1985)
Browse files Browse the repository at this point in the history
Use case: we may need to update the project media information in the Relay store when it's removed from a claim.

Reference: CV2-5000.
  • Loading branch information
caiosba authored Aug 3, 2024
1 parent 455dc84 commit 7956e95
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/graph/types/claim_description_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class ClaimDescriptionType < DefaultObject
field :context, GraphQL::Types::String, null: true, resolver_method: :claim_context
field :user, UserType, null: true
field :project_media, ProjectMediaType, null: true
field :project_media_was, ProjectMediaType, null: true
field :fact_check, FactCheckType, null: true do
argument :report_status, GraphQL::Types::String, required: false, camelize: false
end
Expand Down
4 changes: 4 additions & 0 deletions app/models/claim_description.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ def article_elasticsearch_data(action = 'create_or_update')
self.index_in_elasticsearch(data)
end

def project_media_was
ProjectMedia.find_by_id(self.project_media_id_before_last_save)
end

private

def set_team
Expand Down
1 change: 1 addition & 0 deletions lib/relay.idl
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,7 @@ type ClaimDescription implements Node {
id: ID!
permissions: String
project_media: ProjectMedia
project_media_was: ProjectMedia
updated_at: String
user: User
}
Expand Down
14 changes: 14 additions & 0 deletions public/relay.json
Original file line number Diff line number Diff line change
Expand Up @@ -3696,6 +3696,20 @@
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "project_media_was",
"description": null,
"args": [

],
"type": {
"kind": "OBJECT",
"name": "ProjectMedia",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "updated_at",
"description": null,
Expand Down
8 changes: 8 additions & 0 deletions test/models/claim_description_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -165,4 +165,12 @@ def setup
assert_equal 'paused', fc.reload.report_status
assert_equal 'paused', pm.report_status(true)
end

test "should get information from removed item" do
pm = create_project_media
cd = create_claim_description project_media: pm
cd.project_media = nil
cd.save!
assert_equal pm, cd.project_media_was
end
end

0 comments on commit 7956e95

Please sign in to comment.