Merge pull request #638 from bgeuken/small_patches
Few things I stumbled over while waiting for tests to finish:)
This commit is contained in:
commit
01ba76e8c6
2 changed files with 57 additions and 39 deletions
|
|
@ -99,23 +99,9 @@ class Event < ActiveRecord::Base
|
||||||
def as_json(options)
|
def as_json(options)
|
||||||
json = super(options)
|
json = super(options)
|
||||||
|
|
||||||
if room.nil?
|
json[:room_guid] = room.try(:guid)
|
||||||
json[:room_guid] = nil
|
json[:track_color] = track.try(:color) || '#ffffff'
|
||||||
else
|
json[:length] = event_type.try(:length) || 25
|
||||||
json[:room_guid] = room.guid
|
|
||||||
end
|
|
||||||
|
|
||||||
if track.nil?
|
|
||||||
json[:track_color] = '#ffffff'
|
|
||||||
else
|
|
||||||
json[:track_color] = track.color
|
|
||||||
end
|
|
||||||
|
|
||||||
if event_type.nil?
|
|
||||||
json[:length] = 25
|
|
||||||
else
|
|
||||||
json[:length] = event_type.length
|
|
||||||
end
|
|
||||||
|
|
||||||
json
|
json
|
||||||
end
|
end
|
||||||
|
|
@ -155,11 +141,7 @@ class Event < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def abstract_word_count
|
def abstract_word_count
|
||||||
if abstract.nil?
|
abstract.to_s.split.size
|
||||||
0
|
|
||||||
else
|
|
||||||
abstract.split.size
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def week
|
def week
|
||||||
|
|
@ -167,23 +149,16 @@ class Event < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.get_state_color(state)
|
def self.get_state_color(state)
|
||||||
# default azure
|
color = {
|
||||||
result = '#00FFFF'
|
new: '#0000FF', # blue
|
||||||
case state
|
withdrawn: '#FF8000', # orange
|
||||||
when 'new' # blue
|
confirmed: '#00FF00', # green
|
||||||
result = '#0000FF'
|
unconfirmed: '#FFFF00', # yellow
|
||||||
when 'withdrawn' # orange
|
rejected: '#FF0000', # red
|
||||||
result = '#FF8000'
|
canceled: '#848484' # grey
|
||||||
when 'confirmed' # green
|
}[state.to_sym]
|
||||||
result = '#00FF00'
|
|
||||||
when 'unconfirmed' # yellow
|
color || '#00FFFF' # azure
|
||||||
result = '#FFFF00'
|
|
||||||
when 'rejected' # red
|
|
||||||
result = '#FF0000'
|
|
||||||
when 'canceled' # grey
|
|
||||||
result = '#848484'
|
|
||||||
end
|
|
||||||
result
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_state(transition, mail = false, subject = false, send_mail = false, send_mail_param)
|
def update_state(transition, mail = false, subject = false, send_mail = false, send_mail_param)
|
||||||
|
|
|
||||||
43
spec/models/event_spec.rb
Normal file
43
spec/models/event_spec.rb
Normal file
|
|
@ -0,0 +1,43 @@
|
||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe Event do
|
||||||
|
|
||||||
|
describe 'abstract_word_count' do
|
||||||
|
it 'counts words in abstract' do
|
||||||
|
event = build(:event)
|
||||||
|
expect(event.abstract_word_count).to eq(233)
|
||||||
|
event.update_attributes!(abstract: 'abstract.')
|
||||||
|
expect(event.abstract_word_count).to eq(1)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'counts 0 when abstract is empty' do
|
||||||
|
event = build(:event, abstract: nil)
|
||||||
|
expect(event.abstract_word_count).to eq(0)
|
||||||
|
event.abstract = ''
|
||||||
|
expect(event.abstract_word_count).to eq(0)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'as_json' do
|
||||||
|
let(:event) { create(:event) }
|
||||||
|
|
||||||
|
it 'adds the event\'s room_guid, track_color and length' do
|
||||||
|
event.room = create(:room)
|
||||||
|
event.track = create(:track, color: '#efefef')
|
||||||
|
json_hash = event.as_json(nil)
|
||||||
|
|
||||||
|
expect(json_hash[:room_guid]).to eq(event.room.guid)
|
||||||
|
expect(json_hash[:track_color]).to eq('#efefef')
|
||||||
|
expect(json_hash[:length]).to eq(30)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'uses correct default values for room_guid, track_color and length' do
|
||||||
|
event.event_type = nil
|
||||||
|
json_hash = event.as_json(nil)
|
||||||
|
|
||||||
|
expect(json_hash[:room_guid]).to be_nil
|
||||||
|
expect(json_hash[:track_color]).to eq('#ffffff')
|
||||||
|
expect(json_hash[:length]).to eq(25)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
Loading…
Add table
Add a link
Reference in a new issue