• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pulibrary / pdc_describe / 4e4e59fc-9df4-4838-9fd4-6c7ea33cdb7c

07 Apr 2025 06:36PM UTC coverage: 1.283% (-94.6%) from 95.862%
4e4e59fc-9df4-4838-9fd4-6c7ea33cdb7c

Pull #1994

circleci

hectorcorrea
Switched to use the autocomplete that we aleady use for ROR. Integrated it with the existing logic for creators
Pull Request #1994: Started adding auto complete to contributors

0 of 46 new or added lines in 2 files covered. (0.0%)

4806 existing lines in 74 files now uncovered.

65 of 5065 relevant lines covered (1.28%)

0.01 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/app/models/work_list.rb
1
# frozen_string_literal: true
2

3
# Encapsulate the logic for finding various lists of works
4
#   Extracted from the work class to stem the ever growing size of the Work Class
UNCOV
5
class WorkList
×
UNCOV
6
  class << self
×
UNCOV
7
    def unfinished_works(user, search_terms = nil)
×
UNCOV
8
      works_by_user_state(user, ["none", "draft", "awaiting_approval"], search_terms)
×
UNCOV
9
    end
×
10

UNCOV
11
    def completed_works(user, search_terms = nil)
×
UNCOV
12
      works_by_user_state(user, "approved", search_terms)
×
UNCOV
13
    end
×
14

UNCOV
15
    def withdrawn_works(user, search_terms = nil)
×
UNCOV
16
      works_by_user_state(user, "withdrawn", search_terms)
×
UNCOV
17
    end
×
18

UNCOV
19
    private
×
20

UNCOV
21
      def search_terms_where_clause(search_terms)
×
UNCOV
22
        if search_terms.nil?
×
UNCOV
23
          Work.all
×
UNCOV
24
        else
×
UNCOV
25
          Work.where("CAST(metadata AS VARCHAR) ILIKE :search_terms", search_terms: "%" + search_terms.strip + "%")
×
UNCOV
26
        end
×
UNCOV
27
      end
×
28

UNCOV
29
      def works_by_user_state(user, state, search_terms)
×
UNCOV
30
        search_context = search_terms_where_clause(search_terms)
×
31

32
        # The user's own works (if any) by state and search terms
UNCOV
33
        works = search_context.where(created_by_user_id: user, state:).to_a
×
34

UNCOV
35
        if user.admin_groups.count > 0
×
36
          # The works that match the given state, in all the groups the user can admin
37
          # (regardless of who created those works)
UNCOV
38
          user.admin_groups.each do |group|
×
UNCOV
39
            works += search_context.where(group_id: group.id, state:)
×
UNCOV
40
          end
×
UNCOV
41
        end
×
42

43
        # Any other works where the user is mentioned
UNCOV
44
        works_mentioned_by_user_state(user, state, search_context).each do |work|
×
UNCOV
45
          already_included = !works.find { |existing_work| existing_work[:id] == work.id }.nil?
×
UNCOV
46
          works << work unless already_included
×
UNCOV
47
        end
×
48

UNCOV
49
        works.uniq(&:id).sort_by(&:updated_at).reverse
×
UNCOV
50
      end
×
51

52
      # Returns an array of work ids where a particular user has been mentioned
53
      # and the work is in a given state.
UNCOV
54
      def works_mentioned_by_user_state(user, state, search_context)
×
UNCOV
55
        search_context.joins(:work_activity)
×
UNCOV
56
                      .joins('INNER JOIN "work_activity_notifications" ON "work_activities"."id" = "work_activity_notifications"."work_activity_id"')
×
UNCOV
57
                      .where(state:)
×
UNCOV
58
                      .where('"work_activity_notifications"."user_id" = ?', user.id)
×
UNCOV
59
      end
×
UNCOV
60
  end
×
UNCOV
61
end
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc