Refactor abstract_word_count method
This commit is contained in:
parent
9f3da955f0
commit
80f8bba951
2 changed files with 21 additions and 5 deletions
|
|
@ -155,11 +155,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
|
||||||
|
|
|
||||||
20
spec/models/event_spec.rb
Normal file
20
spec/models/event_spec.rb
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
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
|
||||||
|
end
|
||||||
Loading…
Add table
Add a link
Reference in a new issue