File tree 2 files changed +43
-2
lines changed
2 files changed +43
-2
lines changed Original file line number Diff line number Diff line change @@ -20,7 +20,6 @@ class Controller < SimpleConsole::Controller
20
20
def initialize
21
21
super
22
22
@my_app_name = 'nirv'
23
- # @version = '0.1'
24
23
@nirvana = NirvanaHQ . new $nirvana_config
25
24
end
26
25
@@ -31,6 +30,43 @@ def default
31
30
def method_missing name = "method_missing"
32
31
puts "Method #{ name } does not exist. Try '#{ @my_app_name } help'."
33
32
end
33
+
34
+ def add
35
+ # allow basic add action - nirv add "task name" without having
36
+ # to speicify the name explicitly
37
+ params [ :name ] = params [ :name ] || params [ :id ]
38
+
39
+ if params [ :name ]
40
+
41
+ #prepare payload
42
+ now = Time . now . to_i
43
+
44
+ #set some sane defaults.
45
+ task = {
46
+ "method" => "task.save" ,
47
+ "id" => UUID . generate ,
48
+ "type" => 0 ,
49
+ "_type" => now ,
50
+ "state" => 0 ,
51
+ "_state" => now ,
52
+ }
53
+
54
+ #@commentplz: anyone know better way to do this? still new to rb
55
+ [ :name , :tags , :note ] . each do | tag |
56
+ begin
57
+ task [ tag ] = params [ tag ]
58
+ task [ "_#{ tag } " ] = now
59
+ end if params [ tag ]
60
+ end
61
+
62
+ #obviously, need to rethink this, and how we handle errors
63
+ result = @nirvana . add task
64
+ @message = "Added task: #{ params [ :name ] } "
65
+
66
+ else
67
+ @message = "Missing name of task, which is the bare minimum. Try '#{ @my_app_name } help'."
68
+ end
69
+ end
34
70
35
71
#totally lifted from UUID gem.
36
72
def version
Original file line number Diff line number Diff line change @@ -42,9 +42,14 @@ def test_version
42
42
assert out . string . include? " - "
43
43
end
44
44
45
+ # @todo can we store the UUID to use in test_delete?
45
46
def test_add
47
+ task_name = "Test Task Add"
48
+ out = capture_stdout do
49
+ SimpleConsole ::Application . run ( [ :add , task_name ] , Controller , View )
50
+ end
46
51
47
- assert false
52
+ assert_equal out . string , "Added task: #{ task_name } \n "
48
53
end
49
54
50
55
end
You can’t perform that action at this time.
0 commit comments