Commit f97296597caf34bb66a3e28a7419665757608795

Authored by Andrew8xx8
1 parent 8db3920c

Issuable consern uses StateMachine now

app/models/concerns/issuable.rb
@@ -17,10 +17,9 @@ module Issuable @@ -17,10 +17,9 @@ module Issuable
17 validates :project, presence: true 17 validates :project, presence: true
18 validates :author, presence: true 18 validates :author, presence: true
19 validates :title, presence: true, length: { within: 0..255 } 19 validates :title, presence: true, length: { within: 0..255 }
20 - validates :closed, inclusion: { in: [true, false] }  
21 20
22 - scope :opened, -> { where(closed: false) }  
23 - scope :closed, -> { where(closed: true) } 21 + scope :opened, -> { with_state(:opened) }
  22 + scope :closed, -> { with_state(:closed) }
24 scope :of_group, ->(group) { where(project_id: group.project_ids) } 23 scope :of_group, ->(group) { where(project_id: group.project_ids) }
25 scope :of_user_team, ->(team) { where(project_id: team.project_ids, assignee_id: team.member_ids) } 24 scope :of_user_team, ->(team) { where(project_id: team.project_ids, assignee_id: team.member_ids) }
26 scope :assigned, ->(u) { where(assignee_id: u.id)} 25 scope :assigned, ->(u) { where(assignee_id: u.id)}
@@ -62,14 +61,6 @@ module Issuable @@ -62,14 +61,6 @@ module Issuable
62 assignee_id_changed? 61 assignee_id_changed?
63 end 62 end
64 63
65 - def is_being_closed?  
66 - closed_changed? && closed  
67 - end  
68 -  
69 - def is_being_reopened?  
70 - closed_changed? && !closed  
71 - end  
72 -  
73 # 64 #
74 # Votes 65 # Votes
75 # 66 #
spec/models/concerns/issuable_spec.rb
@@ -15,7 +15,6 @@ describe Issue, "Issuable" do @@ -15,7 +15,6 @@ describe Issue, "Issuable" do
15 it { should validate_presence_of(:author) } 15 it { should validate_presence_of(:author) }
16 it { should validate_presence_of(:title) } 16 it { should validate_presence_of(:title) }
17 it { should ensure_length_of(:title).is_at_least(0).is_at_most(255) } 17 it { should ensure_length_of(:title).is_at_least(0).is_at_most(255) }
18 - it { should ensure_inclusion_of(:closed).in_array([true, false]) }  
19 end 18 end
20 19
21 describe "Scope" do 20 describe "Scope" do
spec/models/issue_spec.rb
@@ -43,35 +43,4 @@ describe Issue do @@ -43,35 +43,4 @@ describe Issue do
43 subject.is_being_reassigned?.should be_false 43 subject.is_being_reassigned?.should be_false
44 end 44 end
45 end 45 end
46 -  
47 - describe '#is_being_closed?' do  
48 - it 'returns true if the closed attribute has changed and is now true' do  
49 - subject.closed = true  
50 - subject.is_being_closed?.should be_true  
51 - end  
52 - it 'returns false if the closed attribute has changed and is now false' do  
53 - issue = create(:closed_issue)  
54 - issue.closed = false  
55 - issue.is_being_closed?.should be_false  
56 - end  
57 - it 'returns false if the closed attribute has not changed' do  
58 - subject.is_being_closed?.should be_false  
59 - end  
60 - end  
61 -  
62 -  
63 - describe '#is_being_reopened?' do  
64 - it 'returns true if the closed attribute has changed and is now false' do  
65 - issue = create(:closed_issue)  
66 - issue.closed = false  
67 - issue.is_being_reopened?.should be_true  
68 - end  
69 - it 'returns false if the closed attribute has changed and is now true' do  
70 - subject.closed = true  
71 - subject.is_being_reopened?.should be_false  
72 - end  
73 - it 'returns false if the closed attribute has not changed' do  
74 - subject.is_being_reopened?.should be_false  
75 - end  
76 - end  
77 end 46 end
spec/models/merge_request_spec.rb
@@ -62,35 +62,4 @@ describe MergeRequest do @@ -62,35 +62,4 @@ describe MergeRequest do
62 subject.is_being_reassigned?.should be_false 62 subject.is_being_reassigned?.should be_false
63 end 63 end
64 end 64 end
65 -  
66 - describe '#is_being_closed?' do  
67 - it 'returns true if the closed attribute has changed and is now true' do  
68 - subject.closed = true  
69 - subject.is_being_closed?.should be_true  
70 - end  
71 - it 'returns false if the closed attribute has changed and is now false' do  
72 - merge_request = create(:closed_merge_request)  
73 - merge_request.closed = false  
74 - merge_request.is_being_closed?.should be_false  
75 - end  
76 - it 'returns false if the closed attribute has not changed' do  
77 - subject.is_being_closed?.should be_false  
78 - end  
79 - end  
80 -  
81 -  
82 - describe '#is_being_reopened?' do  
83 - it 'returns true if the closed attribute has changed and is now false' do  
84 - merge_request = create(:closed_merge_request)  
85 - merge_request.closed = false  
86 - merge_request.is_being_reopened?.should be_true  
87 - end  
88 - it 'returns false if the closed attribute has changed and is now true' do  
89 - subject.closed = true  
90 - subject.is_being_reopened?.should be_false  
91 - end  
92 - it 'returns false if the closed attribute has not changed' do  
93 - subject.is_being_reopened?.should be_false  
94 - end  
95 - end  
96 end 65 end