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

pulibrary / pdc_describe / cace366a-ffad-45f1-9b60-678e607fa527

14 May 2024 02:21PM UTC coverage: 60.862% (-35.0%) from 95.908%
cace366a-ffad-45f1-9b60-678e607fa527

push

circleci

jrgriffiniii
wip

1 of 3 new or added lines in 2 files covered. (33.33%)

1194 existing lines in 57 files now uncovered.

2076 of 3411 relevant lines covered (60.86%)

22.71 hits per line

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

96.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
5
class WorkList
1✔
6
  class << self
1✔
7
    def unfinished_works(user, search_terms = nil)
1✔
8
      works_by_user_state(user, ["none", "draft", "awaiting_approval"], search_terms)
9✔
9
    end
10

11
    def completed_works(user, search_terms = nil)
1✔
12
      works_by_user_state(user, "approved", search_terms)
9✔
13
    end
14

15
    def withdrawn_works(user, search_terms = nil)
1✔
16
      works_by_user_state(user, "withdrawn", search_terms)
9✔
17
    end
18

19
    private
1✔
20

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

29
      def works_by_user_state(user, state, search_terms)
1✔
30
        search_context = search_terms_where_clause(search_terms)
27✔
31

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

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

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

49
        works.uniq(&:id).sort_by(&:updated_at).reverse
27✔
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.
54
      def works_mentioned_by_user_state(user, state, search_context)
1✔
55
        search_context.joins(:work_activity)
27✔
56
                      .joins('INNER JOIN "work_activity_notifications" ON "work_activities"."id" = "work_activity_notifications"."work_activity_id"')
57
                      .where(state:)
58
                      .where('"work_activity_notifications"."user_id" = ?', user.id)
59
      end
60
  end
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