-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprobando
67 lines (58 loc) · 1.84 KB
/
probando
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
probando
class Result < ActiveRecord::Base
belongs_to :subtask
belongs_to :user
attr_accessible :comment, :question_score, :user, :time_begin, :time_end,:time_break,:user_id,:workflow_state
validates :user_id, :presence => true
validates_uniqueness_of :user_id, :scope => [:user_id, :subtask_id]
validates :comment, presence: true, on: :update, if: :workflow_state_finish, if: :subtask_question_coment?
validates :question_score, presence: true, on: :update, if: :workflow_state_finish, if: :subtask_question_select_number?
validates :comment, presence: true, on: :update, if: :workflow_state_finish, if: :subtask_comment_all?
def initialize(current_user)
super(user:current_user, time_begin:Time.now)
end
def time_difference
if self.time_end.nil?
self.time_end = time_break
end
Time.diff(self.time_end,self.time_begin)[:diff]
end
def event_complete
self.time_end = Time.now
end
def event_pause
self.time_break = Time.now
end
def event_start
self.time_begin = Time.now - ( self.time_break - self.time_begin)
end
def workflow_state_finish
workflow_state == "finish"
end
def subtask_question_coment?
self.subtask.type_question == "comment"
end
def subtask_question_select_number?
self.subtask.type_question == "select_number"
end
def subtask_comment_all?
self.subtask.type_question == "all"
end
include Workflow
workflow do
state :begin do
event :event_pause, :transitions_to => :pause
event :event_complete, :transitions_to => :complete
end
state :pause do
event :event_start, :transitions_to => :begin
end
state :complete do
event :event_finish, :transitions_to => :finish
end
state :finish do
event :event_edit, :transitions_to => :complete
event :event_finish, :transitions_to => :finish
end
end
end