aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/models/comment.rb4
-rw-r--r--spec/models/comment_spec.rb14
2 files changed, 18 insertions, 0 deletions
diff --git a/app/models/comment.rb b/app/models/comment.rb
index ab4acfe56..415924fbb 100644
--- a/app/models/comment.rb
+++ b/app/models/comment.rb
@@ -82,6 +82,10 @@ class Comment < ActiveRecord::Base
end
end
+ def first_three_words
+ body.split.first(3).join(' ')
+ end
+
private
def check_body_has_content
diff --git a/spec/models/comment_spec.rb b/spec/models/comment_spec.rb
new file mode 100644
index 000000000..804ce608f
--- /dev/null
+++ b/spec/models/comment_spec.rb
@@ -0,0 +1,14 @@
+require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
+
+describe Comment do
+
+ describe :first_three_words do
+
+ it 'returns the first three words of the comment body' do
+ comment = Comment.new(:body => 'Hello there Alaveteli technical people')
+ comment.first_three_words.should == 'Hello there Alaveteli'
+ end
+
+ end
+
+end