diff --git a/app/models/cluster.rb b/app/models/cluster.rb index e5ff6cd60..a1f124ad6 100644 --- a/app/models/cluster.rb +++ b/app/models/cluster.rb @@ -50,6 +50,18 @@ def import_medias_to_team(team, claim_title, claim_context, parent_id = nil) parent end + def full_url + "#{CheckConfig.get('checkdesk_client')}/#{self.feed.team.slug}/feed/#{self.feed_id}/#{self.project_media_id}" + end + + def team_names + Team.where(id: self.team_ids.to_a).order('id ASC').map(&:name).uniq + end + + def ratings + self.project_medias.order('team_id ASC').map(&:status_i18n).uniq + end + def self.import_other_medias_to_team(cluster_id, parent_id, max) cluster = Cluster.find_by_id(cluster_id) parent = ProjectMedia.find_by_id(parent_id) diff --git a/app/models/feed.rb b/app/models/feed.rb index 91b2583a4..8a9393262 100755 --- a/app/models/feed.rb +++ b/app/models/feed.rb @@ -173,9 +173,10 @@ def saved_search_was end def get_exported_data(filters) - data = [['Title', 'Description', 'Number of media', 'Number of requests', 'Number of fact-checks']] + data = [['Title', 'Description', 'Date (first)', 'Date (last)', 'Number of media', 'Number of requests', 'Number of fact-checks', 'Cluster URL', 'Workspaces', 'Ratings']] self.filtered_clusters(filters).find_each do |cluster| - data << [cluster.title, cluster.center.description, cluster.media_count, cluster.requests_count, cluster.fact_checks_count] + description = cluster.center.description.blank? ? cluster.center.extracted_text : cluster.center.description + data << [cluster.title, description, cluster.first_item_at, cluster.last_item_at, cluster.media_count, cluster.requests_count, cluster.fact_checks_count, cluster.full_url, cluster.team_names.join("\n"), cluster.ratings.join("\n")] end data end diff --git a/test/models/cluster_test.rb b/test/models/cluster_test.rb index 11fc9988d..073740302 100644 --- a/test/models/cluster_test.rb +++ b/test/models/cluster_test.rb @@ -2,8 +2,12 @@ class ClusterTest < ActiveSupport::TestCase def setup - super + Sidekiq::Testing.fake! Cluster.delete_all + User.current = Team.current = nil + end + + def teardown end test "should create cluster" do @@ -74,4 +78,23 @@ def setup c.project_medias << create_project_media assert_equal 2, c.size end + + test "should return full URL to cluster" do + c = create_cluster + assert_match /^http/, c.full_url + end + + test "should return team names" do + t1 = create_team name: 'Foo' + t2 = create_team name: 'Bar' + c = create_cluster + c.update_column :team_ids, [t1.id, t2.id] + assert_equal ['Foo', 'Bar'], c.team_names + end + + test "should return ratings" do + c = create_cluster + c.project_medias << create_project_media + assert_equal ['Unstarted'], c.ratings + end end