Skip to content

Commit

Permalink
add claim_description to project media being created
Browse files Browse the repository at this point in the history
When setting the params to create project medias we are now
also setting the claim_description_attributes.
To do this I had to add the association and accepts_nested_attributes_for
in project_media.rb
  • Loading branch information
vasconsaurus committed Feb 12, 2024
1 parent 24e4485 commit cbd2f06
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
3 changes: 2 additions & 1 deletion app/models/project_media.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ class ProjectMedia < ApplicationRecord
attr_accessor :quote, :quote_attributions, :file, :media_type, :set_annotation, :set_tasks_responses, :previous_project_id, :cached_permissions, :is_being_created, :related_to_id, :skip_rules, :set_claim_description, :set_fact_check, :set_tags, :set_title, :set_status

belongs_to :media
has_one :claim_description

accepts_nested_attributes_for :media
accepts_nested_attributes_for :media, :claim_description

has_paper_trail on: [:create, :update, :destroy], only: [:source_id], if: proc { |_x| User.current.present? }, versions: { class_name: 'Version' }

Expand Down
31 changes: 30 additions & 1 deletion db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ class PopulatedProjects
def initialize(setup)
@teams = setup.teams
@users = setup.users
# @medias_params = get_medias_params
end

def create_populated_projects
Expand All @@ -186,6 +185,11 @@ def create_populated_projects
{
media_attributes: media_params,
team: teams[:main_team_a],
claim_description_attributes: {
description: create_claim_title(media_params),
context: Faker::Lorem.sentence,
user: users[:main_user_a]
}
}
}
},
Expand All @@ -197,6 +201,11 @@ def create_populated_projects
{
media_attributes: media_params,
team: teams[:invited_team_b1],
claim_description_attributes: {
description: create_claim_title(media_params),
context: Faker::Lorem.sentence,
user: users[:invited_user_b]
}
}
}
},
Expand All @@ -208,6 +217,11 @@ def create_populated_projects
{
media_attributes: media_params,
team: teams[:invited_team_b2],
claim_description_attributes: {
description: create_claim_title(media_params),
context: Faker::Lorem.sentence,
user: users[:invited_user_b]
}
}
}
},
Expand All @@ -219,6 +233,11 @@ def create_populated_projects
{
media_attributes: media_params,
team: teams[:invited_team_c],
claim_description_attributes: {
description: create_claim_title(media_params),
context: Faker::Lorem.sentence,
user: users[:invited_user_c]
}
}
}
}
Expand All @@ -228,6 +247,7 @@ def create_populated_projects
end

private

def get_medias_params
links = [
'https://meedan.com/post/addressing-misinformation-across-countries-a-pioneering-collaboration-between-taiwan-factcheck-center-vera-files',
Expand Down Expand Up @@ -277,6 +297,15 @@ def get_medias_params
*uploadedVideos
]
end

def create_title_from_link(link)
path = URI.parse(link).path
path.remove('/post/').underscore.humanize
end

def create_claim_title(media_params)
media_params[:type] == "Link" ? create_title_from_link(media_params[:url]) : Faker::Company.catch_phrase
end
end

puts "If you want to create a new user: press enter"
Expand Down

0 comments on commit cbd2f06

Please sign in to comment.