• 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_activity_notification.rb
1
# frozen_string_literal: true
2

UNCOV
3
class WorkActivityNotification < ApplicationRecord
×
UNCOV
4
  belongs_to :work_activity
×
UNCOV
5
  belongs_to :user
×
6

UNCOV
7
  after_create do
×
UNCOV
8
    if send_message?
×
UNCOV
9
      mailer = NotificationMailer.with(user:, work_activity:)
×
UNCOV
10
      work = work_activity.work
×
UNCOV
11
      delay = wait_time
×
UNCOV
12
      from_state = check_from_state(work)
×
13

UNCOV
14
      if work.state == "draft" && from_state == :none # draft event
×
UNCOV
15
        new_submission_message = mailer.new_submission_message
×
UNCOV
16
        new_submission_message.deliver_later(wait: delay) unless Rails.env.development?
×
UNCOV
17
      elsif work.state == "draft" && from_state == :awaiting_approval # revert_to_draft event
×
18
        reject_message = mailer.reject_message
×
19
        reject_message.deliver_later(wait: delay) unless Rails.env.development?
×
UNCOV
20
      elsif work.state == "awaiting_approval" && from_state == :draft # complete_submission
×
UNCOV
21
        review_message = mailer.review_message
×
UNCOV
22
        review_message.deliver_later(wait: delay) unless Rails.env.development?
×
UNCOV
23
      else
×
UNCOV
24
        message = mailer.build_message
×
UNCOV
25
        message.deliver_later(wait: delay) unless Rails.env.development?
×
UNCOV
26
      end
×
UNCOV
27
    end
×
UNCOV
28
  end
×
29

UNCOV
30
  private
×
31

UNCOV
32
    def wait_time
×
UNCOV
33
      work = work_activity.work
×
UNCOV
34
      if work.state == "approved"
×
UNCOV
35
        90.minutes
×
UNCOV
36
      else
×
UNCOV
37
        10.seconds
×
UNCOV
38
      end
×
UNCOV
39
    end
×
40

UNCOV
41
    def check_from_state(work) # check the previous state of the work
×
UNCOV
42
      work_states = UserWork.where(work_id: work.id).sort_by(&:created_at).reverse
×
UNCOV
43
      if work_states.count > 1
×
44
        # states[0] is the current state, [1] is the previous state
UNCOV
45
        work_states[1].state.to_sym
×
UNCOV
46
      else
×
UNCOV
47
        :none
×
UNCOV
48
      end
×
UNCOV
49
    end
×
50

UNCOV
51
    def direct_message?
×
UNCOV
52
      @direct_message ||= work_activity.activity_type == WorkActivity::MESSAGE && work_activity.message.include?("@#{user.uid}")
×
UNCOV
53
    end
×
54

UNCOV
55
    def send_message?
×
UNCOV
56
      return true if direct_message? # always send a direct message
×
UNCOV
57
      return false unless user.email_messages_enabled? # do not send message if all emails are disabled
×
UNCOV
58
      work = work_activity.work
×
59

UNCOV
60
      if work.resource.subcommunities.count > 1
×
UNCOV
61
        subcommunities_can_send = work.resource.subcommunities.map { |subcommunity| send_message_for_community?(subcommunity) }
×
UNCOV
62
        subcommunities_can_send.any?
×
UNCOV
63
      else
×
UNCOV
64
        send_message_for_community?(work.resource.subcommunities.first)
×
UNCOV
65
      end
×
UNCOV
66
    end
×
67

UNCOV
68
    def send_message_for_community?(subcommunity)
×
UNCOV
69
      group.messages_enabled_for?(user:, subcommunity:)
×
UNCOV
70
    end
×
71

UNCOV
72
    def group
×
UNCOV
73
      @group ||= work_activity.work.group
×
UNCOV
74
    end
×
UNCOV
75
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