Files
nairobi/app/models/poll/officer_assignment.rb
Javi Martín db97f9d08c Add and apply rubocop rules for empty lines
We were very inconsistent regarding these rules.

Personally I prefer no empty lines around blocks, clases, etc... as
recommended by the Ruby style guide [1], and they're the default values
in rubocop, so those are the settings I'm applying.

The exception is the `private` access modifier, since we were leaving
empty lines around it most of the time. That's the default rubocop rule
as well. Personally I don't have a strong preference about this one.


[1] https://rubystyle.guide/#empty-lines-around-bodies
2019-10-24 17:11:47 +02:00

37 lines
1.2 KiB
Ruby

class Poll
class OfficerAssignment < ApplicationRecord
belongs_to :officer
belongs_to :booth_assignment
has_many :ballot_sheets
has_many :partial_results
has_many :recounts
has_many :voters
validates :officer_id, presence: true
validates :booth_assignment_id, presence: true
validates :date, presence: true
delegate :poll_id, :booth_id, to: :booth_assignment
scope :voting_days, -> { where(final: false) }
scope :final, -> { where(final: true) }
scope :by_officer_and_poll, ->(officer_id, poll_id) do
where("officer_id = ? AND poll_booth_assignments.poll_id = ?", officer_id, poll_id)
end
scope :by_officer, ->(officer) { where(officer_id: officer.id) }
scope :by_poll, ->(poll) { joins(:booth_assignment).where("poll_booth_assignments.poll_id" => poll.id) }
scope :by_booth, ->(booth) { joins(:booth_assignment).where("poll_booth_assignments.booth_id" => booth.id) }
scope :by_date, ->(date) { where(date: date) }
before_create :log_user_data
def log_user_data
self.user_data_log = "#{officer.user_id} - #{officer.user.name_and_email}"
end
def booth
booth_assignment.booth
end
end
end