Commit 2416e3cb19d6a668fc3274b1ae3382f4119dac1d
1 parent
f6035552
Exists in
master
and in
4 other branches
Add new utility method for an issue to know whether it is being reassigned
Showing
2 changed files
with
25 additions
and
5 deletions
Show diff stats
app/models/issue.rb
... | ... | @@ -27,7 +27,7 @@ class Issue < ActiveRecord::Base |
27 | 27 | validates :title, |
28 | 28 | :presence => true, |
29 | 29 | :length => { :within => 0..255 } |
30 | - | |
30 | + | |
31 | 31 | validates :description, |
32 | 32 | :length => { :within => 0..2000 } |
33 | 33 | |
... | ... | @@ -55,6 +55,15 @@ class Issue < ActiveRecord::Base |
55 | 55 | def new? |
56 | 56 | today? && created_at == updated_at |
57 | 57 | end |
58 | + | |
59 | + # Return the number of +1 comments (upvotes) | |
60 | + def upvotes | |
61 | + notes.select(&:upvote?).size | |
62 | + end | |
63 | + | |
64 | + def is_being_reassigned? | |
65 | + assignee_id_changed? | |
66 | + end | |
58 | 67 | end |
59 | 68 | # == Schema Information |
60 | 69 | # | ... | ... |
spec/models/issue_spec.rb
... | ... | @@ -20,10 +20,21 @@ describe Issue do |
20 | 20 | it { Issue.should respond_to :opened } |
21 | 21 | end |
22 | 22 | |
23 | - it { Factory.create(:issue, | |
24 | - :author => Factory(:user), | |
25 | - :assignee => Factory(:user), | |
26 | - :project => Factory.create(:project)).should be_valid } | |
23 | + subject { Factory.create(:issue, | |
24 | + :author => Factory(:user), | |
25 | + :assignee => Factory(:user), | |
26 | + :project => Factory.create(:project)) } | |
27 | + it { should be_valid } | |
28 | + | |
29 | + describe '#is_being_reassigned?' do | |
30 | + it 'returns true if the issue assignee has changed' do | |
31 | + subject.assignee = Factory(:user) | |
32 | + subject.is_being_reassigned?.should be_true | |
33 | + end | |
34 | + it 'returns false if the issue assignee has not changed' do | |
35 | + subject.is_being_reassigned?.should be_false | |
36 | + end | |
37 | + end | |
27 | 38 | |
28 | 39 | describe "plus 1" do |
29 | 40 | let(:project) { Factory(:project) } | ... | ... |