From 2416e3cb19d6a668fc3274b1ae3382f4119dac1d Mon Sep 17 00:00:00 2001 From: Robb Kidd Date: Sun, 20 May 2012 14:15:13 -0400 Subject: [PATCH] Add new utility method for an issue to know whether it is being reassigned --- app/models/issue.rb | 11 ++++++++++- spec/models/issue_spec.rb | 19 +++++++++++++++---- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/app/models/issue.rb b/app/models/issue.rb index 3ed47ef1..f1cb2e22 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -27,7 +27,7 @@ class Issue < ActiveRecord::Base validates :title, :presence => true, :length => { :within => 0..255 } - + validates :description, :length => { :within => 0..2000 } @@ -55,6 +55,15 @@ class Issue < ActiveRecord::Base def new? today? && created_at == updated_at end + + # Return the number of +1 comments (upvotes) + def upvotes + notes.select(&:upvote?).size + end + + def is_being_reassigned? + assignee_id_changed? + end end # == Schema Information # diff --git a/spec/models/issue_spec.rb b/spec/models/issue_spec.rb index 791e9cde..68c05f2e 100644 --- a/spec/models/issue_spec.rb +++ b/spec/models/issue_spec.rb @@ -20,10 +20,21 @@ describe Issue do it { Issue.should respond_to :opened } end - it { Factory.create(:issue, - :author => Factory(:user), - :assignee => Factory(:user), - :project => Factory.create(:project)).should be_valid } + subject { Factory.create(:issue, + :author => Factory(:user), + :assignee => Factory(:user), + :project => Factory.create(:project)) } + it { should be_valid } + + describe '#is_being_reassigned?' do + it 'returns true if the issue assignee has changed' do + subject.assignee = Factory(:user) + subject.is_being_reassigned?.should be_true + end + it 'returns false if the issue assignee has not changed' do + subject.is_being_reassigned?.should be_false + end + end describe "plus 1" do let(:project) { Factory(:project) }