Skip to content

Commit abd78ad

Browse files
committed
Added add task + test
1 parent 566e1ea commit abd78ad

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

lib/nirv.rb

+37-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ class Controller < SimpleConsole::Controller
2020
def initialize
2121
super
2222
@my_app_name = 'nirv'
23-
# @version = '0.1'
2423
@nirvana = NirvanaHQ.new $nirvana_config
2524
end
2625

@@ -31,6 +30,43 @@ def default
3130
def method_missing name = "method_missing"
3231
puts "Method #{name} does not exist. Try '#{@my_app_name} help'."
3332
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
3470

3571
#totally lifted from UUID gem.
3672
def version

test/test_console.rb

+6-1
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,14 @@ def test_version
4242
assert out.string.include? " - "
4343
end
4444

45+
# @todo can we store the UUID to use in test_delete?
4546
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
4651

47-
assert false
52+
assert_equal out.string, "Added task: #{task_name}\n"
4853
end
4954

5055
end

0 commit comments

Comments
 (0)