forked from bofh/fetsite
increase test coverage for meetings
This commit is contained in:
@@ -1,40 +1,58 @@
|
||||
|
||||
# coding: utf-8
|
||||
# This class represents a single meeting of a group or the whole Fachschaft.
|
||||
#
|
||||
class Meeting < ActiveRecord::Base
|
||||
belongs_to :parent, :polymorphic=>true, touch: true
|
||||
belongs_to :meetingtyp
|
||||
|
||||
attr_accessible :desc, :intern, :name, :parent_id, :parent_type, :calentry,:calentry_attributes, :meetingtyp_id
|
||||
|
||||
|
||||
# Meeting can belong to different kind of parents e.g. topics
|
||||
belongs_to :parent, :polymorphic=>true, touch: true
|
||||
# Each meeting should have a type, for more information see MeetingTyp
|
||||
belongs_to :meetingtyp
|
||||
# Belongs to a news article, that is usually the Announcement of that meeting
|
||||
belongs_to :neuigkeit, touch: true
|
||||
# has one protocol of type Document, which is of typ=10=protocol
|
||||
has_one :protocol, :class_name=>'Document', :conditions=>{:typ=>10}, :as=>:parent
|
||||
# has one agenda of type Document
|
||||
has_one :agenda , :as=>:parent,:conditions=>{:typ=>11}, :class_name=>'Document'
|
||||
# has one calentry which contains the date and time of this meeting
|
||||
has_one :calentry, as: :object, :dependent=> :destroy
|
||||
# has one calendar through the meetingtyp, thus each meeting is put into a calendar
|
||||
has_one :calendar, :through=>:meetingtyp
|
||||
# has one rubrik, thus it is associated to a rubrik
|
||||
has_one :rubrik, :through=>:meetingtyp
|
||||
|
||||
# scope upcomming only contains meetings in the future and 1 hour into the past
|
||||
scope :upcomming, includes(:calentry).where("calentries.start>?",1.hour.ago)
|
||||
default_scope includes(:calentry).order("calentries.start").reverse_order
|
||||
accepts_nested_attributes_for :calentry
|
||||
# validate :agenda, :presence=>true
|
||||
# validate :protocol, :presence=>true
|
||||
|
||||
# Each meeting is required to have a parent otherwise it will not be shown anywhere on the website
|
||||
validate :parent, :presence=>true
|
||||
# Each meeting needs a calendar entry
|
||||
validate :calentry, :presence=>true
|
||||
|
||||
|
||||
# before each validation fix the calendar entry such that it is always
|
||||
before_validation :fix_calentry
|
||||
|
||||
# title is an alias for text
|
||||
def title
|
||||
self.text
|
||||
end
|
||||
|
||||
|
||||
# Text is a text representation of the meeting
|
||||
def text
|
||||
unless self.meetingtyp.try(:name).to_s.empty?
|
||||
t = self.meetingtyp.name.to_s+", "
|
||||
else
|
||||
t=""
|
||||
t = parent.title.to_s + ", " if self.name.empty?
|
||||
end
|
||||
t = self.meetingtyp.try(:name) || self.parent.try(:title) || ""
|
||||
t = t + ", " unless t.empty?
|
||||
t= t+ self.name.to_s
|
||||
# t = t + " " + I18n.l(self.calentry.start) unless self.calentry.nil?
|
||||
t = t +" "+ I18n.t("date.am")+" "+ self.calentry.text unless self.calentry.nil?
|
||||
t
|
||||
end
|
||||
|
||||
# Creante an anouncement with an author
|
||||
# @param user is the author
|
||||
def create_announcement(user)
|
||||
if self.neuigkeit.nil?
|
||||
n = Neuigkeit.new
|
||||
@@ -48,32 +66,40 @@ class Meeting < ActiveRecord::Base
|
||||
self.neuigkeit= n
|
||||
end
|
||||
end
|
||||
|
||||
# Update the title of the announcement to the text of this meeting
|
||||
# @returns [true] if save was successful
|
||||
def update_announcement
|
||||
n=self.neuigkeit
|
||||
n.title=self.text
|
||||
n.save
|
||||
|
||||
end
|
||||
|
||||
# fixing the calendar entry and the calendar
|
||||
# most importantly the calendar of the calentry
|
||||
def fix_calentry
|
||||
self.calentry.object=self unless self.calentry.nil?
|
||||
self.calentry.calendar = self.meetingtyp.rubrik.calendar
|
||||
end
|
||||
|
||||
def public?
|
||||
! (self.intern)
|
||||
end
|
||||
|
||||
# Create a Document that is a protocol for the meeting
|
||||
def create_protocol
|
||||
if self.protocol.nil?
|
||||
if self.protocol.nil? # if no protocol exists
|
||||
d=Document.new
|
||||
d.typ=10
|
||||
d.name="Protokoll"
|
||||
unless self.meetingtyp.protocol.nil?
|
||||
d.text=self.meetingtyp.protocol.text
|
||||
end
|
||||
d.save
|
||||
self.protocol=d
|
||||
end
|
||||
|
||||
# what happens if a protocol already exists?
|
||||
end
|
||||
|
||||
# Create a calender entry for this meeting
|
||||
def create_calentry
|
||||
if self.calentry.nil?
|
||||
ce =Calentry.new
|
||||
@@ -86,9 +112,6 @@ class Meeting < ActiveRecord::Base
|
||||
d=Document.new
|
||||
d.typ=11
|
||||
d.name="Agenda"
|
||||
unless self.meetingtyp.agenda.nil?
|
||||
d.text=self.meetingtyp.agenda.text
|
||||
end
|
||||
d.save
|
||||
self.agenda=d
|
||||
end
|
||||
@@ -112,27 +135,17 @@ class Meeting < ActiveRecord::Base
|
||||
|
||||
def update_time_from_protocol
|
||||
st= /Beginn[\s:]*([^<>]*)/.match(self.protocol.text)[1].to_s
|
||||
st= /Anfang[\s:]*([^<>]*)/.match(self.protocol.text)[1].to_s if st.empty?
|
||||
self.calentry.start=(self.calentry.start.to_date.to_s + " " +st).to_datetime unless st.empty?
|
||||
st= /Ende[\s:]*([^<>]*)/.match(self.protocol.text)[1].to_s
|
||||
self.calentry.ende=(self.calentry.ende.to_date.to_s + " " +st).to_datetime unless st.empty?
|
||||
st= /Anfang[\s:]*([^<>]*)/.match(self.protocol.text)[1].to_s if st.nil? || st.empty?
|
||||
self.calentry.start=(self.calentry.start.to_date.to_s + " " +st).to_datetime unless st.nil? || st.empty?
|
||||
st= /Ende[\s:]*([^<>]*)/.match(self.protocol.text).try(:second).try(:to_s )
|
||||
self.calentry.ende=(self.calentry.ende.to_date.to_s + " " +st).to_datetime unless st.nil? || st.empty?
|
||||
end
|
||||
def agenda_text
|
||||
unless self.agenda.nil?
|
||||
t= self.agenda.text
|
||||
else
|
||||
t= ""
|
||||
end
|
||||
t
|
||||
return self.agenda.try(:text) || ""
|
||||
end
|
||||
def protocol_text
|
||||
unless self.protocol.nil?
|
||||
t= self.protocol.text
|
||||
else
|
||||
t= ""
|
||||
end
|
||||
t
|
||||
end
|
||||
return self.protocol.try(:text) || ""
|
||||
end
|
||||
|
||||
searchable do
|
||||
text :text
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
class Meetingtyp < ActiveRecord::Base
|
||||
attr_accessible :agendaintern, :desc, :name, :protocolintern, :rubrik_id, :picture
|
||||
belongs_to :rubrik
|
||||
validate :rubrik, :presence=>true
|
||||
validates :rubrik, :presence=>true
|
||||
validates :name, :presence=>true
|
||||
has_many :meetings
|
||||
has_one :calendar, through: :rubrik
|
||||
has_one :protocol, :class_name=>'Document', :conditions=>{:typ=>10}, :as=>:parent
|
||||
|
||||
Reference in New Issue
Block a user