Skip to content

Commit

Permalink
update test and update create_claim_media to look for original_claim
Browse files Browse the repository at this point in the history
  • Loading branch information
vasconsaurus committed Jan 24, 2025
1 parent 18d07c9 commit bbb9235
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
2 changes: 1 addition & 1 deletion app/models/concerns/project_media_creators.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def download_file(url, ext)
end

def create_claim_media(text)
Claim.create!(quote: text, original_claim: text)
Claim.find_by(original_claim: text) || Claim.create!(quote: text, original_claim: text)
end

def create_link_media(url)
Expand Down
12 changes: 5 additions & 7 deletions test/models/project_media_7_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -243,14 +243,12 @@ def setup
end
end

# For whatever reason this last test is actually creating 4 Medias: 2 Claims and 2 Links
# I don't think it should create the Link Medias
test "should check if the original_claim exists and return that instance when trying to create media" do
t = create_team
create_project team: t
text = 'This is a claim.'

assert_difference 'Media.count', 1 do
2.times { create_project_media(team: t, set_original_claim: 'This is a claim.') }
end
claim = Claim.create!(quote: text, original_claim: text)
pm = create_project_media(set_original_claim: text)

assert_equal claim.id, pm.media.id
end
end

0 comments on commit bbb9235

Please sign in to comment.