tempo-cli 0.1.6 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile.lock +3 -3
- data/README.md +9 -3
- data/bin/tempo +20 -2
- data/features/arrange.feature +1 -1
- data/features/directory.feature +108 -0
- data/features/project.feature +2 -2
- data/features/report.feature +3 -2
- data/features/start.feature +0 -1
- data/features/step_definitions/tempo_steps.rb +99 -20
- data/features/update.feature +7 -1
- data/lib/file_record/directory.rb +19 -3
- data/lib/file_record/file_utility.rb +122 -0
- data/lib/file_record/record.rb +36 -83
- data/lib/tempo/controllers/arrange_controller.rb +5 -5
- data/lib/tempo/controllers/base.rb +8 -8
- data/lib/tempo/controllers/checkout_controller.rb +4 -4
- data/lib/tempo/controllers/end_controller.rb +4 -5
- data/lib/tempo/controllers/projects_controller.rb +13 -10
- data/lib/tempo/controllers/records_controller.rb +8 -5
- data/lib/tempo/controllers/report_controller.rb +4 -4
- data/lib/tempo/controllers/start_controller.rb +4 -3
- data/lib/tempo/controllers/update_controller.rb +22 -8
- data/lib/tempo/exceptions.rb +2 -2
- data/lib/tempo/models/base.rb +26 -18
- data/lib/tempo/models/composite.rb +5 -3
- data/lib/tempo/models/log.rb +61 -38
- data/lib/tempo/models/project.rb +9 -6
- data/lib/tempo/models/time_record.rb +14 -14
- data/lib/tempo/version.rb +1 -1
- data/lib/tempo/views/arrange_view.rb +4 -4
- data/lib/tempo/views/base.rb +10 -23
- data/lib/tempo/views/formatters/base.rb +2 -2
- data/lib/tempo/views/formatters/screen.rb +7 -7
- data/lib/tempo/views/projects_view.rb +8 -8
- data/lib/tempo/views/report_view.rb +5 -5
- data/lib/tempo/views/reporter.rb +4 -4
- data/lib/tempo/views/time_record_view.rb +5 -5
- data/lib/tempo/views/view_records/base.rb +8 -8
- data/lib/tempo/views/view_records/composite.rb +4 -4
- data/lib/tempo/views/view_records/log.rb +3 -3
- data/lib/tempo/views/view_records/project.rb +3 -3
- data/lib/tempo/views/view_records/time_record.rb +5 -5
- data/lib/tempo.rb +3 -0
- data/lib/time_utilities.rb +4 -4
- data/tempo-cli.gemspec +8 -7
- data/test/lib/file_record/directory_test.rb +14 -1
- data/test/lib/file_record/record_test.rb +40 -75
- data/test/lib/tempo/models/base_test.rb +2 -2
- data/test/lib/tempo/models/composite_test.rb +9 -9
- data/test/lib/tempo/models/log_test.rb +31 -16
- data/test/lib/tempo/models/time_record_test.rb +29 -19
- data/test/support/factories.rb +5 -0
- data/test/support/helpers.rb +7 -7
- metadata +40 -53
@@ -13,7 +13,7 @@ module Tempo
|
|
13
13
|
|
14
14
|
class Screen < Tempo::Views::Formatters::Base
|
15
15
|
|
16
|
-
def message_block
|
16
|
+
def message_block(record)
|
17
17
|
record.format do |m|
|
18
18
|
case m.category
|
19
19
|
when :error
|
@@ -25,18 +25,18 @@ module Tempo
|
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
-
def duration_block
|
28
|
+
def duration_block(record)
|
29
29
|
record.format do |d|
|
30
30
|
puts "#{ d.hours.to_s }:#{ d.minutes.to_s.rjust(2, '0') }"
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
34
|
# spacer for project titles, active project marked with *
|
35
|
-
def active_indicator(
|
35
|
+
def active_indicator(project)
|
36
36
|
indicator = project.current ? "* " : " "
|
37
37
|
end
|
38
38
|
|
39
|
-
def tag_partial
|
39
|
+
def tag_partial(tags, title_length)
|
40
40
|
max_length = ViewRecords::Project.max_title_length
|
41
41
|
max_length += ViewRecords::Project.max_depth * 2 if @options[:depth]
|
42
42
|
max_length += 6 if @options[:id]
|
@@ -50,11 +50,11 @@ module Tempo
|
|
50
50
|
view[0..-3] + "]"
|
51
51
|
end
|
52
52
|
|
53
|
-
def id_partial
|
53
|
+
def id_partial(id)
|
54
54
|
@options[:id] ? "[#{id}] ".rjust(6, ' ') : ""
|
55
55
|
end
|
56
56
|
|
57
|
-
def project_block
|
57
|
+
def project_block(record)
|
58
58
|
|
59
59
|
record.format do |r|
|
60
60
|
@options[:active] = @options.fetch( :active, false )
|
@@ -71,7 +71,7 @@ module Tempo
|
|
71
71
|
end
|
72
72
|
end
|
73
73
|
|
74
|
-
def timerecord_block
|
74
|
+
def timerecord_block(record)
|
75
75
|
record.format do |r|
|
76
76
|
id = id_partial r.id
|
77
77
|
running = r.running ? "*" : " "
|
@@ -6,7 +6,7 @@ module Tempo
|
|
6
6
|
ViewRecords::Project.new project, depth: depth
|
7
7
|
end
|
8
8
|
|
9
|
-
def projects_list_view
|
9
|
+
def projects_list_view(projects=Tempo::Model::Project.index, parent=:root, depth=0)
|
10
10
|
return no_items( "projects" ) if projects.empty?
|
11
11
|
|
12
12
|
Tempo::Model::Project.sort_by_title projects do |projects|
|
@@ -26,7 +26,7 @@ module Tempo
|
|
26
26
|
end
|
27
27
|
|
28
28
|
# list of sorted projects, no hierarchy
|
29
|
-
def projects_flat_list_view
|
29
|
+
def projects_flat_list_view(projects=Tempo::Model::Project.index)
|
30
30
|
|
31
31
|
Tempo::Model::Project.sort_by_title projects do |projects|
|
32
32
|
projects.each do |p|
|
@@ -35,32 +35,32 @@ module Tempo
|
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
-
def project_added
|
38
|
+
def project_added(project)
|
39
39
|
ViewRecords::Message.new "added project:"
|
40
40
|
project_view project
|
41
41
|
end
|
42
42
|
|
43
|
-
def project_deleted
|
43
|
+
def project_deleted(project)
|
44
44
|
ViewRecords::Message.new "deleted project:"
|
45
45
|
project_view project
|
46
46
|
end
|
47
47
|
|
48
|
-
def project_checkout
|
48
|
+
def project_checkout(project)
|
49
49
|
ViewRecords::Message.new "switched to project:"
|
50
50
|
project_view project
|
51
51
|
end
|
52
52
|
|
53
|
-
def project_already_current
|
53
|
+
def project_already_current(project)
|
54
54
|
ViewRecords::Message.new "already on project:"
|
55
55
|
project_view project
|
56
56
|
end
|
57
57
|
|
58
|
-
def project_tags
|
58
|
+
def project_tags(project)
|
59
59
|
ViewRecords::Message.new "altered project tags:"
|
60
60
|
project_view project
|
61
61
|
end
|
62
62
|
|
63
|
-
def ambiguous_project(
|
63
|
+
def ambiguous_project(matches, command)
|
64
64
|
|
65
65
|
ViewRecords::Message.new "The following projects matched your search:"
|
66
66
|
|
@@ -2,13 +2,13 @@ module Tempo
|
|
2
2
|
module Views
|
3
3
|
class << self
|
4
4
|
|
5
|
-
def report_records_view
|
5
|
+
def report_records_view(options={})
|
6
6
|
|
7
|
-
projects = options.fetch(
|
8
|
-
return no_items(
|
7
|
+
projects = options.fetch(:projects, Tempo::Model::Project.index)
|
8
|
+
return no_items("projects") if projects.empty?
|
9
9
|
|
10
10
|
time_records = options.fetch( :time_records, Tempo::Model::TimeRecord.days_index )
|
11
|
-
return no_items(
|
11
|
+
return no_items("time records") if time_records.empty?
|
12
12
|
|
13
13
|
time_records.each do |d_id, days_record|
|
14
14
|
|
@@ -23,4 +23,4 @@ module Tempo
|
|
23
23
|
end
|
24
24
|
end
|
25
25
|
end
|
26
|
-
end
|
26
|
+
end
|
data/lib/tempo/views/reporter.rb
CHANGED
@@ -27,7 +27,7 @@ module Tempo
|
|
27
27
|
class << self
|
28
28
|
attr_accessor :view_records
|
29
29
|
|
30
|
-
def add_format
|
30
|
+
def add_format(*formats)
|
31
31
|
@@formats ||= []
|
32
32
|
formats.each {|format| @@formats << format}
|
33
33
|
end
|
@@ -40,12 +40,12 @@ module Tempo
|
|
40
40
|
@@options ||= {}
|
41
41
|
end
|
42
42
|
|
43
|
-
def add_options
|
43
|
+
def add_options(options)
|
44
44
|
@@options ||= {}
|
45
45
|
@@options.merge! options
|
46
46
|
end
|
47
47
|
|
48
|
-
def add_view_record
|
48
|
+
def add_view_record(record)
|
49
49
|
@@view_records ||= []
|
50
50
|
|
51
51
|
if /Views::ViewRecords/.match record.class.name
|
@@ -67,4 +67,4 @@ module Tempo
|
|
67
67
|
end
|
68
68
|
end
|
69
69
|
end
|
70
|
-
end
|
70
|
+
end
|
@@ -2,26 +2,26 @@ module Tempo
|
|
2
2
|
module Views
|
3
3
|
class << self
|
4
4
|
|
5
|
-
def time_record_view
|
5
|
+
def time_record_view(time_record)
|
6
6
|
ViewRecords::TimeRecord.new time_record
|
7
7
|
end
|
8
8
|
|
9
|
-
def start_time_record_view
|
9
|
+
def start_time_record_view(time_record)
|
10
10
|
ViewRecords::Message.new "time record started:"
|
11
11
|
time_record_view time_record
|
12
12
|
end
|
13
13
|
|
14
|
-
def end_time_record_view
|
14
|
+
def end_time_record_view(time_record)
|
15
15
|
ViewRecords::Message.new "time record ended:"
|
16
16
|
time_record_view time_record
|
17
17
|
end
|
18
18
|
|
19
|
-
def update_time_record_view
|
19
|
+
def update_time_record_view(time_record)
|
20
20
|
ViewRecords::Message.new "time record updated:"
|
21
21
|
time_record_view time_record
|
22
22
|
end
|
23
23
|
|
24
|
-
def delete_time_record_view
|
24
|
+
def delete_time_record_view(time_record)
|
25
25
|
ViewRecords::Message.new "time record deleted:"
|
26
26
|
time_record_view time_record
|
27
27
|
end
|
@@ -30,14 +30,14 @@ module Tempo
|
|
30
30
|
class Message
|
31
31
|
attr_accessor :type, :message, :category
|
32
32
|
|
33
|
-
def initialize
|
33
|
+
def initialize(message, options={})
|
34
34
|
@message = message
|
35
35
|
@category = options.fetch( :category, :info )
|
36
36
|
@type = "message"
|
37
37
|
Reporter.add_view_record self
|
38
38
|
end
|
39
39
|
|
40
|
-
def format
|
40
|
+
def format(&block)
|
41
41
|
block ||= lambda {|m| "#{m.message}"}
|
42
42
|
block.call self
|
43
43
|
end
|
@@ -63,18 +63,18 @@ module Tempo
|
|
63
63
|
@total = seconds
|
64
64
|
end
|
65
65
|
|
66
|
-
def format
|
66
|
+
def format(&block)
|
67
67
|
block ||= lambda do |d|
|
68
68
|
"#{ d.hours.to_s }:#{ d.minutes.to_s.rjust(2, '0') }"
|
69
69
|
end
|
70
70
|
block.call self
|
71
71
|
end
|
72
72
|
|
73
|
-
def add
|
73
|
+
def add(seconds)
|
74
74
|
@total += seconds
|
75
75
|
end
|
76
76
|
|
77
|
-
def subtract
|
77
|
+
def subtract(seconds)
|
78
78
|
@total -= seconds
|
79
79
|
end
|
80
80
|
|
@@ -96,7 +96,7 @@ module Tempo
|
|
96
96
|
class Model
|
97
97
|
attr_accessor :id, :type
|
98
98
|
|
99
|
-
def initialize
|
99
|
+
def initialize(model, options={})
|
100
100
|
@id = model.id
|
101
101
|
|
102
102
|
# example: Tempo::Model::Something => "something"
|
@@ -104,11 +104,11 @@ module Tempo
|
|
104
104
|
Reporter.add_view_record self
|
105
105
|
end
|
106
106
|
|
107
|
-
def format
|
107
|
+
def format(&block)
|
108
108
|
block ||= lambda {|model| "#{ model.type.capitalize} #{model.id}"}
|
109
109
|
block.call self
|
110
110
|
end
|
111
111
|
end
|
112
112
|
end
|
113
113
|
end
|
114
|
-
end
|
114
|
+
end
|
@@ -18,23 +18,23 @@ module Tempo
|
|
18
18
|
attr_accessor :depth
|
19
19
|
|
20
20
|
class << self
|
21
|
-
def max_depth
|
21
|
+
def max_depth(depth=0)
|
22
22
|
@max_depth ||= 0
|
23
23
|
@max_depth = @max_depth > depth ? @max_depth : depth
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
-
def initialize
|
27
|
+
def initialize(model, options={})
|
28
28
|
super model, options
|
29
29
|
@depth = options.fetch(:depth, 0)
|
30
30
|
self.class.max_depth @depth
|
31
31
|
end
|
32
32
|
|
33
|
-
def format
|
33
|
+
def format(&block)
|
34
34
|
block ||= lambda {|model| "#{" " * model.depth}#{ model.type.capitalize} #{model.id}"}
|
35
35
|
block.call self
|
36
36
|
end
|
37
37
|
end
|
38
38
|
end
|
39
39
|
end
|
40
|
-
end
|
40
|
+
end
|
@@ -12,17 +12,17 @@ module Tempo
|
|
12
12
|
class Log < ViewRecords::Model
|
13
13
|
attr_accessor :start_time, :d_id
|
14
14
|
|
15
|
-
def initialize
|
15
|
+
def initialize(model, options={})
|
16
16
|
super model, options
|
17
17
|
@start_time = model.start_time
|
18
18
|
@d_id = model.d_id
|
19
19
|
end
|
20
20
|
|
21
|
-
def format
|
21
|
+
def format(&block)
|
22
22
|
block ||= lambda {|model| "#{ model.type.capitalize} #{model.d_id}-#{model.id} #{model.start_time.strftime('%H:%M')}"}
|
23
23
|
block.call self
|
24
24
|
end
|
25
25
|
end
|
26
26
|
end
|
27
27
|
end
|
28
|
-
end
|
28
|
+
end
|
@@ -12,13 +12,13 @@ module Tempo
|
|
12
12
|
attr_accessor :title, :tags, :current, :duration
|
13
13
|
|
14
14
|
class << self
|
15
|
-
def max_title_length
|
15
|
+
def max_title_length(len=0)
|
16
16
|
@max_title_length ||= 0
|
17
17
|
@max_title_length = @max_title_length > len ? @max_title_length : len
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
|
-
def initialize
|
21
|
+
def initialize(model, options={})
|
22
22
|
super model, options
|
23
23
|
@title = model.title
|
24
24
|
@tags = model.tags
|
@@ -29,4 +29,4 @@ module Tempo
|
|
29
29
|
end
|
30
30
|
end
|
31
31
|
end
|
32
|
-
end
|
32
|
+
end
|
@@ -11,18 +11,18 @@ module Tempo
|
|
11
11
|
attr_accessor :description, :duration, :end_time, :project, :running
|
12
12
|
|
13
13
|
class << self
|
14
|
-
def max_description_length
|
14
|
+
def max_description_length(len=0)
|
15
15
|
@max_description_length ||= 0
|
16
16
|
@max_description_length = @max_description_length > len ? @max_description_length : len
|
17
17
|
end
|
18
18
|
|
19
|
-
def max_project_length
|
19
|
+
def max_project_length(len=0)
|
20
20
|
@max_project_length ||= 0
|
21
21
|
@max_project_length = @max_project_length > len ? @max_project_length : len
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
-
def initialize
|
25
|
+
def initialize(model, options={})
|
26
26
|
super model, options
|
27
27
|
@description = model.description
|
28
28
|
@description ||= ""
|
@@ -34,7 +34,7 @@ module Tempo
|
|
34
34
|
self.class.max_project_length @project.length
|
35
35
|
end
|
36
36
|
|
37
|
-
def format
|
37
|
+
def format(&block)
|
38
38
|
block ||= lambda do |m|
|
39
39
|
running = m.running ? "*" : " "
|
40
40
|
description = @description ? "#{m.project}: #{m.description}" : "#{m.project}"
|
@@ -45,4 +45,4 @@ module Tempo
|
|
45
45
|
end
|
46
46
|
end
|
47
47
|
end
|
48
|
-
end
|
48
|
+
end
|
data/lib/tempo.rb
CHANGED
@@ -15,6 +15,8 @@ require 'tempo/controllers/base.rb'
|
|
15
15
|
Dir[File.dirname(__FILE__) + '/tempo/controllers/*.rb'].each {|file| require file }
|
16
16
|
|
17
17
|
require 'tempo/views/view_records/base.rb'
|
18
|
+
require 'tempo/views/view_records/composite.rb'
|
19
|
+
require 'tempo/views/view_records/log.rb'
|
18
20
|
Dir[File.dirname(__FILE__) + '/tempo/views/view_records/*.rb'].each {|file| require file }
|
19
21
|
|
20
22
|
require 'tempo/views/reporter.rb'
|
@@ -25,4 +27,5 @@ require 'tempo/views/base.rb'
|
|
25
27
|
Dir[File.dirname(__FILE__) + '/tempo/views/*.rb'].each {|file| require file }
|
26
28
|
|
27
29
|
require 'file_record/directory.rb'
|
30
|
+
require 'file_record/file_utility.rb'
|
28
31
|
require 'file_record/record.rb'
|
data/lib/time_utilities.rb
CHANGED
@@ -5,9 +5,9 @@ require 'chronic'
|
|
5
5
|
class Time
|
6
6
|
|
7
7
|
class << self
|
8
|
-
def parse
|
8
|
+
def parse(time)
|
9
9
|
# Chronic will usually return nil when unable to parse time
|
10
|
-
# it throws an error, on 't' and a few other
|
10
|
+
# it throws an error, on 't' and a few other strings, so we
|
11
11
|
# capture these here an assure that nil is returned
|
12
12
|
begin
|
13
13
|
chron = Chronic.parse time
|
@@ -19,12 +19,12 @@ class Time
|
|
19
19
|
end
|
20
20
|
|
21
21
|
#default to whole minutes
|
22
|
-
def round
|
22
|
+
def round(options={})
|
23
23
|
seconds = 60
|
24
24
|
Time.at((self.to_f / seconds).round * seconds)
|
25
25
|
end
|
26
26
|
|
27
|
-
def add_days
|
27
|
+
def add_days(days)
|
28
28
|
t = self + days * 86400 # 24 * 60 * 60
|
29
29
|
end
|
30
30
|
end
|
data/tempo-cli.gemspec
CHANGED
@@ -5,6 +5,7 @@ spec = Gem::Specification.new do |s|
|
|
5
5
|
s.version = Tempo::VERSION
|
6
6
|
s.author = 'Jonathan Gabel'
|
7
7
|
s.email = 'hello@jonathangabel.com'
|
8
|
+
s.license = 'MIT'
|
8
9
|
s.homepage = 'https://github.com/josankapo/tempo-cli'
|
9
10
|
s.platform = Gem::Platform::RUBY
|
10
11
|
s.summary = 'A command line time tracker for recording by day and by project'
|
@@ -14,11 +15,11 @@ spec = Gem::Specification.new do |s|
|
|
14
15
|
s.has_rdoc = true
|
15
16
|
s.bindir = 'bin'
|
16
17
|
s.executables << 'tempo'
|
17
|
-
s.add_development_dependency('rake')
|
18
|
-
s.add_development_dependency('rdoc')
|
19
|
-
s.add_development_dependency('aruba')
|
20
|
-
s.add_development_dependency('turn', '~> 0.9
|
21
|
-
s.add_development_dependency('pry','~> 0.9
|
22
|
-
s.add_runtime_dependency('gli','2.
|
23
|
-
s.add_runtime_dependency "chronic", "~> 0.10
|
18
|
+
s.add_development_dependency('rake', '~> 10.3')
|
19
|
+
s.add_development_dependency('rdoc', '~> 4.1')
|
20
|
+
s.add_development_dependency('aruba', '~> 0.5')
|
21
|
+
s.add_development_dependency('turn', '~> 0.9')
|
22
|
+
s.add_development_dependency('pry','~> 0.9')
|
23
|
+
s.add_runtime_dependency('gli', '~> 2.10')
|
24
|
+
s.add_runtime_dependency "chronic", "~> 0.10"
|
24
25
|
end
|
@@ -4,11 +4,13 @@ describe FileRecord do
|
|
4
4
|
|
5
5
|
before do
|
6
6
|
@dir = File.join(Dir.home,"tempo")
|
7
|
+
@alt_dir = File.join(Dir.home, "testdir", "tempo")
|
7
8
|
FileUtils.rm_r @dir if File.exists?(@dir)
|
8
9
|
end
|
9
10
|
|
10
11
|
after do
|
11
12
|
FileUtils.rm_r @dir if File.exists?(@dir)
|
13
|
+
FileUtils.rm_r @alt_dir if File.exists?(@alt_dir)
|
12
14
|
end
|
13
15
|
|
14
16
|
|
@@ -25,6 +27,17 @@ describe FileRecord do
|
|
25
27
|
File.exists?( project_file ).must_equal true
|
26
28
|
File.exists?( readme ).must_equal true
|
27
29
|
end
|
30
|
+
|
31
|
+
it "should take an optional directory parameter" do
|
32
|
+
project_file = File.join(@alt_dir, "tempo_projects.yaml")
|
33
|
+
readme = File.join(@alt_dir, "README.txt")
|
34
|
+
dir = File.join(Dir.home, "testdir")
|
35
|
+
|
36
|
+
FileRecord::Directory.create_new directory: dir
|
37
|
+
File.exists?( @alt_dir ).must_equal true
|
38
|
+
File.exists?( project_file ).must_equal true
|
39
|
+
File.exists?( readme ).must_equal true
|
40
|
+
end
|
28
41
|
end
|
29
42
|
end
|
30
|
-
end
|
43
|
+
end
|
@@ -12,81 +12,6 @@ describe FileRecord do
|
|
12
12
|
|
13
13
|
describe "Record" do
|
14
14
|
|
15
|
-
before do
|
16
|
-
@file = File.join( @dir, "filerecord_create.txt")
|
17
|
-
end
|
18
|
-
|
19
|
-
after do
|
20
|
-
File.delete(@file) if File.exists?(@file)
|
21
|
-
end
|
22
|
-
|
23
|
-
describe "create" do
|
24
|
-
|
25
|
-
it "should create a new record" do
|
26
|
-
FileRecord::Record.create( @file, "" )
|
27
|
-
File.exists?( @file ).must_equal true
|
28
|
-
end
|
29
|
-
|
30
|
-
it "should raise and error if the file exists" do
|
31
|
-
FileRecord::Record.create( @file, "" )
|
32
|
-
proc { FileRecord::Record.create( @file, "" ) }.must_raise ArgumentError
|
33
|
-
end
|
34
|
-
|
35
|
-
it "should overwrite a file with option :force" do
|
36
|
-
File.open( @file,'w' ) do |f|
|
37
|
-
f.puts "Now this file already exists"
|
38
|
-
end
|
39
|
-
FileRecord::Record.create( @file, "overwrite file", force: true )
|
40
|
-
contents = eval_file_as_array( @file )
|
41
|
-
contents.must_equal ["overwrite file"]
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
describe "recording a string" do
|
46
|
-
it "should be able to record a string" do
|
47
|
-
FileRecord::Record.create( @file, "a simple string" )
|
48
|
-
contents = eval_file_as_array( @file )
|
49
|
-
contents.must_equal ["a simple string"]
|
50
|
-
end
|
51
|
-
|
52
|
-
it "should be able to record a string as yaml" do
|
53
|
-
FileRecord::Record.create( @file, "a simple string", format: 'yaml' )
|
54
|
-
contents = eval_file_as_array( @file )
|
55
|
-
contents.must_equal ["--- a simple string", "..."]
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
describe "recording and array" do
|
60
|
-
|
61
|
-
it "should be able to record a shallow array as string" do
|
62
|
-
FileRecord::Record.create( @file, ["a","simple","array"], format: "string" )
|
63
|
-
contents = eval_file_as_array( @file )
|
64
|
-
contents.must_equal ["a","simple","array"]
|
65
|
-
end
|
66
|
-
|
67
|
-
it "should default to recording a shallow array as yaml" do
|
68
|
-
FileRecord::Record.create( @file, ["a","simple","array"] )
|
69
|
-
contents = eval_file_as_array( @file )
|
70
|
-
contents.must_equal ["---", "- a", "- simple", "- array"]
|
71
|
-
end
|
72
|
-
|
73
|
-
it "should record a nested array as yaml" do
|
74
|
-
FileRecord::Record.create( @file, ["a",["nested",["array"]]])
|
75
|
-
contents = eval_file_as_array( @file )
|
76
|
-
contents.must_equal ["---", "- a", "- - nested", " - - array"]
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
describe "recording a hash" do
|
81
|
-
|
82
|
-
it "should default to and record a hash as yaml" do
|
83
|
-
hash = {a: 1, b: true, c: Hash.new, d: "object", with: ['an', 'array']}
|
84
|
-
FileRecord::Record.create( @file, hash )
|
85
|
-
contents = eval_file_as_array( @file )
|
86
|
-
contents.must_equal ["---", ":a: 1", ":b: true", ":c: {}", ":d: object", ":with:", "- an", "- array"]
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
15
|
describe "recording a Tempo Model" do
|
91
16
|
|
92
17
|
it "should create a record of all instances" do
|
@@ -102,5 +27,45 @@ describe FileRecord do
|
|
102
27
|
"---", ":id: 5", ":genious: Panthera", ":species: p. zdanskyi"]
|
103
28
|
end
|
104
29
|
end
|
30
|
+
|
31
|
+
describe "redording a Tempo Log" do
|
32
|
+
|
33
|
+
it "should create daily records containing each instance" do
|
34
|
+
test_file_1 = File.join(ENV['HOME'],'tempo','tempo_message_logs', '20140101.yaml')
|
35
|
+
File.delete( test_file ) if File.exists?( test_file_1 )
|
36
|
+
test_file_2 = File.join(ENV['HOME'],'tempo','tempo_message_logs', '20140102.yaml')
|
37
|
+
File.delete( test_file ) if File.exists?( test_file_2 )
|
38
|
+
|
39
|
+
log_factory
|
40
|
+
FileRecord::Record.save_log(Tempo::Model::MessageLog)
|
41
|
+
contents = eval_file_as_array( test_file_1 )
|
42
|
+
contents.must_equal [ "---",
|
43
|
+
":start_time: 2014-01-01 07:00:00.000000000 -05:00",
|
44
|
+
":id: 1",
|
45
|
+
":message: day 1 pet the sheep",
|
46
|
+
"---",
|
47
|
+
":start_time: 2014-01-01 07:30:00.000000000 -05:00",
|
48
|
+
":id: 2",
|
49
|
+
":message: day 1 drinking coffee, check on the mushrooms",
|
50
|
+
"---",
|
51
|
+
":start_time: 2014-01-01 12:30:00.000000000 -05:00",
|
52
|
+
":id: 3",
|
53
|
+
":message: day 1 water the bonsai"]
|
54
|
+
|
55
|
+
contents = eval_file_as_array( test_file_2 )
|
56
|
+
contents.must_equal [ "---",
|
57
|
+
":start_time: 2014-01-02 07:15:00.000000000 -05:00",
|
58
|
+
":id: 1",
|
59
|
+
":message: day 2 pet the sheep",
|
60
|
+
"---",
|
61
|
+
":start_time: 2014-01-02 07:45:00.000000000 -05:00",
|
62
|
+
":id: 2",
|
63
|
+
":message: day 2 drinking coffee, check on the mushrooms",
|
64
|
+
"---",
|
65
|
+
":start_time: 2014-01-02 12:00:00.000000000 -05:00",
|
66
|
+
":id: 3",
|
67
|
+
":message: day 2 water the bonsai"]
|
68
|
+
end
|
69
|
+
end
|
105
70
|
end
|
106
71
|
end
|
@@ -10,7 +10,7 @@ describe Tempo do
|
|
10
10
|
|
11
11
|
describe "Model::Base" do
|
12
12
|
|
13
|
-
it "
|
13
|
+
it "is inheritable from" do
|
14
14
|
Tempo::Model::Animal.superclass.must_equal Tempo::Model::Base
|
15
15
|
end
|
16
16
|
|
@@ -30,7 +30,7 @@ describe Tempo do
|
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
|
-
it "
|
33
|
+
it "knows which file name to save to" do
|
34
34
|
frog_factory
|
35
35
|
Tempo::Model::Animal.file.must_equal "tempo_animals.yaml"
|
36
36
|
end
|
@@ -42,15 +42,15 @@ describe Tempo do
|
|
42
42
|
end
|
43
43
|
|
44
44
|
it "should revive a tree structure from a file" do
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
45
|
+
tree_factory
|
46
|
+
test_file = File.join(ENV['HOME'],'tempo','tempo_trees.yaml')
|
47
|
+
File.delete(test_file) if File.exists?( test_file )
|
48
|
+
contents = Tempo::Model::Tree.save_to_file
|
49
|
+
Tempo::Model::Tree.clear_all
|
50
|
+
Tempo::Model::Tree.read_from_file
|
51
|
+
branch1 = Tempo::Model::Tree.find_by_id 3
|
52
|
+
branch1.parent.must_equal 1
|
53
|
+
branch1.children.must_equal [7,8]
|
54
54
|
end
|
55
55
|
|
56
56
|
it "should have a << child method" do
|