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

pulibrary / pdc_describe / 9091a1ae-29be-458c-984a-339d213919c4

12 Dec 2024 07:41PM UTC coverage: 26.434% (-69.7%) from 96.113%
9091a1ae-29be-458c-984a-339d213919c4

Pull #2000

circleci

jrgriffiniii
Removing integration with ActiveStorage
Pull Request #2000: Bump actionpack from 7.2.1.1 to 7.2.2.1

945 of 3575 relevant lines covered (26.43%)

0.35 hits per line

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

36.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
    end
10

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

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

19
    private
1✔
20

21
      def search_terms_where_clause(search_terms)
1✔
22
        if search_terms.nil?
×
23
          Work.all
×
24
        else
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)
×
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
×
34

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)
38
          user.admin_groups.each do |group|
×
39
            works += search_context.where(group_id: group.id, state:)
×
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|
×
45
          already_included = !works.find { |existing_work| existing_work[:id] == work.id }.nil?
×
46
          works << work unless already_included
×
47
        end
48

49
        works.uniq(&:id).sort_by(&:updated_at).reverse
×
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)
×
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