paradeiser 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +1 -1
  3. data/Guardfile +16 -11
  4. data/README.md +1 -1
  5. data/Rakefile +1 -1
  6. data/TODO.md +12 -1
  7. data/bin/par +5 -2
  8. data/lib/paradeiser.rb +22 -2
  9. data/lib/paradeiser/controllers/controller.rb +1 -0
  10. data/lib/paradeiser/controllers/paradeiser_controller.rb +0 -1
  11. data/lib/paradeiser/models/hook.rb +4 -0
  12. data/lib/paradeiser/models/repository.rb +1 -1
  13. data/lib/paradeiser/models/scheduled.rb +4 -0
  14. data/lib/paradeiser/version.rb +1 -1
  15. data/paradeiser.gemspec +1 -6
  16. data/templates/linux/hooks/after-finish-break +2 -0
  17. data/templates/linux/hooks/after-finish-pomodoro +2 -0
  18. data/templates/linux/hooks/after-start-break +2 -0
  19. data/templates/linux/hooks/after-start-pomodoro +2 -0
  20. data/templates/mac/hooks/after-finish-break +2 -0
  21. data/templates/mac/hooks/after-finish-pomodoro +2 -0
  22. data/templates/mac/hooks/after-start-break +2 -0
  23. data/templates/mac/hooks/after-start-pomodoro +2 -0
  24. data/test/helper.rb +14 -36
  25. data/test/integration/test_annotate.rb +15 -13
  26. data/test/integration/test_finish.rb +7 -5
  27. data/test/integration/test_interrupt.rb +7 -5
  28. data/test/integration/test_log.rb +9 -7
  29. data/test/integration/test_no_args.rb +5 -3
  30. data/test/integration/test_start.rb +5 -3
  31. data/test/integration/test_status.rb +8 -6
  32. data/test/integration/test_unknown.rb +5 -3
  33. data/test/lib/controller_test.rb +4 -2
  34. data/test/lib/integration_test.rb +8 -2
  35. data/test/lib/paradeiser_controller_test.rb +7 -1
  36. data/test/lib/token_file_registry.rb +19 -0
  37. data/test/lib/unit_test.rb +47 -0
  38. data/test/lib/view_test.rb +13 -8
  39. data/test/scripts/create-failing-hooks +17 -0
  40. data/test/scripts/fail +5 -0
  41. data/test/unit/test_break.rb +43 -40
  42. data/test/unit/test_break_view.rb +17 -14
  43. data/test/unit/test_breaks_controller.rb +55 -52
  44. data/test/unit/test_interrupt.rb +27 -24
  45. data/test/unit/test_paradeiser_controller_export.rb +103 -100
  46. data/test/unit/test_paradeiser_controller_init.rb +2 -2
  47. data/test/unit/test_paradeiser_controller_report.rb +72 -69
  48. data/test/unit/test_paradeiser_controller_status.rb +78 -75
  49. data/test/unit/test_paradeiser_view_init.rb +5 -3
  50. data/test/unit/test_paradeiser_view_report.rb +116 -114
  51. data/test/unit/test_paradeiser_view_status.rb +14 -11
  52. data/test/unit/test_pomodori_controller.rb +319 -316
  53. data/test/unit/test_pomodori_view.rb +40 -37
  54. data/test/unit/test_pomodoro.rb +116 -113
  55. data/test/unit/test_pomodoro_hooks.rb +172 -170
  56. data/test/unit/test_repository.rb +98 -95
  57. data/test/unit/test_scheduler.rb +39 -30
  58. data/test/unit/test_token_file_registry.rb +40 -0
  59. metadata +59 -49
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dd9b4f1eb7fe225041e03d1824dcfce44b17e680
4
- data.tar.gz: 010a924c64c9ffc32d18a68324afd6a8a79b46fe
3
+ metadata.gz: 456d9290ae49e511ab834fb7230bce40bfb49499
4
+ data.tar.gz: 25244e3c436466d740dfd34f9d9d6472522fefc3
5
5
  SHA512:
6
- metadata.gz: e0ab299f7782dd479bc50981b203a02a8e69725a3b89559ac6683dcdbcadd8197c6bacccf34b9084193d08d46cbb6b704a2013bea2234a23717d350a3378406b
7
- data.tar.gz: 46eb79b934a8210f6ceff2f25855905f06dbcae751a445039e33d49e5ee44b4f57663bff1c9ca29c1001bc6c5dd19ee5b78201e0c71e575207920c9ea4027cfa
6
+ metadata.gz: ea0ab79272226ec07de5c8d89b09e8045af9c76d9ad22b5be10260e656628fe543b504533b6f62967d34706d3ae9caeb5ad5fcb98d8ca0942046b98d19500988
7
+ data.tar.gz: 6da4ed5b67a54b24af4cf3dc78d4c0681c22a2d0fef82e8e42eced3ff2e8434548ae11e84670e4fb86db326abf0b8d9fab42e30caf307cfe022b7ba7276c14c0
data/Gemfile CHANGED
@@ -5,6 +5,6 @@ gemspec
5
5
 
6
6
  group :test do
7
7
  gem 'rake'
8
- gem 'minitest', '~> 5.0.0'
8
+ gem 'minitest'
9
9
  gem 'fakefs', :require => "fakefs/safe"
10
10
  end
data/Guardfile CHANGED
@@ -3,16 +3,21 @@ guard 'bundler' do
3
3
  watch(%r|^.*\.gemspec|)
4
4
  end
5
5
 
6
- guard 'minitest' do
7
- watch(%r|^test/unit/test_(.*)\.rb|){|m| "test/unit/test_#{m[1]}.rb"}
8
- watch(%r|^lib/*\.rb|){'test'}
9
- watch(%r|^lib/.*/*\.rb|){'test'}
10
- watch(%r{^lib/.*/([^/]+)\.rb$}){|m| "test/unit/test_#{m[1]}.rb"}
11
- watch(%r|^test/helper\.rb|){'test'}
12
- watch(%r{^lib/.*/views/(.*)/[^/]+\.erb$}){|m| "test/unit/test_#{m[1]}_view.rb"}
6
+ group 'unit' do
7
+ guard 'minitest' do
8
+ watch(%r|^test/unit/test_(.*)\.rb|){|m| "test/unit/test_#{m[1]}.rb"}
9
+ watch(%r|^lib/*\.rb|){'test/unit'}
10
+ watch(%r|^lib/.*/*\.rb|){'test/unit'}
11
+ watch(%r{^lib/.*/([^/]+)\.rb$}){|m| "test/unit/test_#{m[1]}.rb"}
12
+ watch(%r|^test/helper\.rb|){'test/unit'}
13
+ watch(%r{^lib/.*/views/(.*)/[^/]+\.erb$}){|m| "test/unit/test_#{m[1]}_view.rb"}
14
+ end
15
+ end
13
16
 
14
- # Integration tests
15
- watch(%r{^bin/([^/]+)$}){|m| "test/integration/test_#{m[1]}.rb"}
16
- watch(%r|^test/integration/test_(.*)\.rb|){|m| "test/integration/test_#{m[1]}.rb"}
17
- watch(%r|^test/lib/*\.rb|){'test'}
17
+ group 'integration' do
18
+ guard 'minitest' do
19
+ watch(%r{^bin/([^/]+)$}){"test/integration"}
20
+ watch(%r|^test/integration/test_(.*)\.rb|){|m| "test/integration/test_#{m[1]}.rb"}
21
+ watch(%r|^test/lib/*\.rb|){'test/integration'}
22
+ end
18
23
  end
data/README.md CHANGED
@@ -128,7 +128,7 @@ It will appear in the reports and will count towards efficiency calculations. Th
128
128
 
129
129
  Creates the `$PAR_DIR` directory and the sample hooks in `$PAR_DIR/hooks`. The data store will not be created on `par init`, but when the first write operation happens (e.g. `par pomodoro start`, but not `par report`).
130
130
 
131
- * Initialize an abritrary directory
131
+ * Initialize an arbitrary directory
132
132
 
133
133
  $ par init /tmp
134
134
 
data/Rakefile CHANGED
@@ -5,7 +5,7 @@ require 'paradeiser'
5
5
  require 'tasks/state_machine'
6
6
 
7
7
  Rake::TestTask.new(:test) do |test|
8
- test.libs << 'lib' << 'test' << 'test/helpers'
8
+ test.libs << 'test'
9
9
  test.test_files = FileList['test/**/test_*.rb']
10
10
  end
11
11
 
data/TODO.md CHANGED
@@ -1,14 +1,25 @@
1
1
  # Paradeiser Backlog
2
2
 
3
- * By default, hooks copied by `par init` should not be executable, otherwise the hooks will fail if the optional dependencies (e.g. `notify-send` on Linux) are not present
3
+ * Remove the token files generated in TestPomodoroHooks
4
+
5
+ * BUG: A failing after-start-pomodoro hook seems to prevent `par start` from running, but it actually should not: Only before-hooks are allowed to cancel actions.
4
6
 
5
7
  * Add validations to models. `finished_at` must occur at after created at, etc.
6
8
 
7
9
  * There must be no overlap in pomodori, even if we log one.
8
10
  - Logging one while another one is active must fail unless finished at is before the active one's started at.
11
+ - Could use a range operator with it, e.g. within a pomodoro:
12
+
13
+ class Pomodoro
14
+ def include?(time)
15
+ (started_at..finished_at).cover?(time)
16
+ end
17
+ end
9
18
 
10
19
  * `par log` needs options for when the logged pomodoro was started and / or stopped
11
20
 
21
+ * Refactoring: Replace our custom `pluralize` with the one from actionview
22
+
12
23
  * Improve tests with more doubles
13
24
  - Sandy Metz rules about testing messages:
14
25
  - Incoming: Assert state
data/bin/par CHANGED
@@ -1,10 +1,13 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'commander/import'
3
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
4
+
4
5
  require 'paradeiser'
6
+ require 'commander/import'
7
+
5
8
  include Paradeiser
6
9
 
7
- program :version, Paradeiser::VERSION
10
+ program :version, VERSION
8
11
  program :description, "Paradeiser is a command-line tool for the Pomodoro Technique. It keeps track of the current pomodoro and assists the user in managing active and past pomodori as well as breaks. Status commands and reports are provided to get insights."
9
12
  program :help, 'Author', 'Nicholas E. Rabenau <nerab@gmx.at>'
10
13
 
@@ -2,8 +2,28 @@ require 'pstore'
2
2
  require 'erb'
3
3
  require 'state_machine'
4
4
 
5
- require 'require_all'
6
- require_rel "paradeiser"
5
+ require 'paradeiser/errors'
6
+ require 'paradeiser/executor'
7
+ require 'paradeiser/models/scheduled'
8
+ require 'paradeiser/models/break'
9
+ require 'paradeiser/models/hook'
10
+ require 'paradeiser/models/interrupt'
11
+ require 'paradeiser/models/job'
12
+ require 'paradeiser/models/pomodoro'
13
+ require 'paradeiser/models/repository'
14
+ require 'paradeiser/models/scheduler'
15
+ require 'paradeiser/models/status'
16
+ require 'paradeiser/refinements/numeric'
17
+ require 'paradeiser/refinements/pluralize'
18
+ require 'paradeiser/router'
19
+ require 'paradeiser/version'
20
+ require 'paradeiser/view'
21
+ require 'paradeiser/controllers/controller'
22
+ require 'paradeiser/controllers/breaks_controller'
23
+ require 'paradeiser/controllers/paradeiser_controller'
24
+ require 'paradeiser/controllers/pomodori_controller'
25
+
26
+ require 'paradeiser/initializers/inflections'
7
27
 
8
28
  module Paradeiser
9
29
  def self.par_dir
@@ -6,6 +6,7 @@ module Paradeiser
6
6
  @method = method
7
7
  @exitstatus = 0
8
8
  @has_output = false
9
+ @already_rendered = nil
9
10
  end
10
11
 
11
12
  def call(args, options)
@@ -1,5 +1,4 @@
1
1
  require 'fileutils'
2
- #require 'action_view/helpers/text_helper'
3
2
  require 'active_support/core_ext/enumerable'
4
3
  require 'active_model'
5
4
  require 'active_model/serializers/json'
@@ -13,6 +13,10 @@ module Paradeiser
13
13
  ENV["PAR_#{pom.name.upcase}_STARTED_AT"] = pom.started_at.strftime('%H:%M') if pom.started_at
14
14
 
15
15
  out, err, status = Open3.capture3(hook)
16
+
17
+ ENV.delete("PAR_#{pom.name.upcase}_ID")
18
+ ENV.delete("PAR_#{pom.name.upcase}_STARTED_AT")
19
+
16
20
  raise HookFailedError.new(hook, out, err, status) if 0 != status.exitstatus
17
21
  end
18
22
  end
@@ -62,7 +62,7 @@ module Paradeiser
62
62
  if all.empty?
63
63
  1
64
64
  else
65
- all.max{|a, b| a.id <=> b.id}.id + 1
65
+ all.max{|a, b| a.id <=> b.id}.id.next
66
66
  end
67
67
  end
68
68
 
@@ -4,6 +4,10 @@ module Paradeiser
4
4
  class Scheduled
5
5
  attr_accessor :id, :started_at, :finished_at
6
6
 
7
+ def initialize
8
+ @id = nil
9
+ end
10
+
7
11
  def new?
8
12
  @id.nil?
9
13
  end
@@ -1,3 +1,3 @@
1
1
  module Paradeiser
2
- VERSION = '0.4.0'
2
+ VERSION = '0.5.0'
3
3
  end
@@ -19,19 +19,14 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ["lib"]
20
20
 
21
21
  spec.add_runtime_dependency 'commander'
22
- spec.add_runtime_dependency 'require_all'
23
22
  spec.add_runtime_dependency 'state_machine'
24
23
  spec.add_runtime_dependency 'activesupport'
25
24
  spec.add_runtime_dependency 'actionpack'
26
- # spec.add_runtime_dependency 'actionview'
27
25
  spec.add_runtime_dependency 'activemodel'
28
26
 
29
- # Moved to the Gemfile so that Travis CI can load the test group
30
- # spec.add_development_dependency 'rake'
31
- # spec.add_development_dependency 'minitest'
32
-
33
27
  spec.add_development_dependency 'guard-minitest'
34
28
  spec.add_development_dependency 'guard-bundler'
29
+ spec.add_development_dependency 'terminal-notifier'
35
30
  spec.add_development_dependency 'terminal-notifier-guard'
36
31
  spec.add_development_dependency 'libnotify'
37
32
  spec.add_development_dependency 'rb-inotify'
@@ -7,4 +7,6 @@
7
7
  # $PAR_BREAK_ID - the ID of the break that just ended
8
8
  # $PAR_BREAK_STARTED_AT - the time when the break was started
9
9
  #
10
+ # In order to use this hook, you'll have to chmod +x the hook in ~/paradeiser/hooks/*.
11
+ #
10
12
  notify-send "Pomodoro" "The break $PAR_BREAK_ID (started at $PAR_BREAK_STARTED_AT) is over." -u critical > /dev/null
@@ -7,4 +7,6 @@
7
7
  # $PAR_POMODORO_ID - the ID of the pomodoro that just ended
8
8
  # $PAR_POMODORO_STARTED_AT - the time when the pomodoro was started
9
9
  #
10
+ # In order to use this hook, you'll have to chmod +x the hook in ~/paradeiser/hooks/*.
11
+ #
10
12
  notify-send "Pomodoro" "The pomodoro $PAR_POMODORO_ID (started at $PAR_POMODORO_STARTED_AT) is over." -u critical > /dev/null
@@ -4,4 +4,6 @@
4
4
  # Sample after-start-break hook for Paradeiser (called after a break started). It
5
5
  # displays a simple notification.
6
6
  #
7
+ # In order to use this hook, you'll have to chmod +x the hook in ~/paradeiser/hooks/*.
8
+ #
7
9
  notify-send "Pomodoro" "A new break started." -u critical > /dev/null
@@ -4,4 +4,6 @@
4
4
  # Sample after-start-pomodoro hook for Paradeiser (called after a pomodoro started). It
5
5
  # displays a simple notification.
6
6
  #
7
+ # In order to use this hook, you'll have to chmod +x the hook in ~/paradeiser/hooks/*.
8
+ #
7
9
  notify-send "Pomodoro" "A new pomodoro started." -u critical > /dev/null
@@ -7,4 +7,6 @@
7
7
  # $PAR_BREAK_ID - the ID of the break that just ended
8
8
  # $PAR_BREAK_STARTED_AT - the time when the break was started
9
9
  #
10
+ # In order to use this hook, you'll have to chmod +x the hook in ~/paradeiser/hooks/*.
11
+ #
10
12
  terminal-notifier-success -message "The break $PAR_BREAK_ID (started at $PAR_BREAK_STARTED_AT) is over." > /dev/null
@@ -7,4 +7,6 @@
7
7
  # $PAR_POMODORO_ID - the ID of the pomodoro that just ended
8
8
  # $PAR_POMODORO_STARTED_AT - the time when the pomodoro was started
9
9
  #
10
+ # In order to use this hook, you'll have to chmod +x the hook in ~/paradeiser/hooks/*.
11
+ #
10
12
  terminal-notifier-success -message "The pomodoro $PAR_POMODORO_ID (started at $PAR_POMODORO_STARTED_AT) is over." > /dev/null
@@ -4,4 +4,6 @@
4
4
  # Sample after-start-break hook for Paradeiser (called after a break started). It
5
5
  # displays a simple notification.
6
6
  #
7
+ # In order to use this hook, you'll have to chmod +x the hook in ~/paradeiser/hooks/*.
8
+ #
7
9
  terminal-notifier-success -message "A new break started." > /dev/null
@@ -4,4 +4,6 @@
4
4
  # Sample after-start-pomodoro hook for Paradeiser (called after a pomodoro started). It
5
5
  # displays a simple notification.
6
6
  #
7
+ # In order to use this hook, you'll have to chmod +x the hook in ~/paradeiser/hooks/*.
8
+ #
7
9
  terminal-notifier-success -message "A new pomodoro started." > /dev/null
@@ -1,40 +1,18 @@
1
- require 'minitest/autorun'
2
- require 'paradeiser'
3
- require_rel 'lib'
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
4
2
 
5
3
  require 'lib/at_mock'
6
-
4
+ require 'paradeiser'
7
5
  include Paradeiser
8
6
 
9
- class MiniTest::Test
10
-
11
- protected
12
-
13
- def produce(clazz)
14
- @started = srand
15
-
16
- Time.stub :now, Time.at(@started) do
17
- Scheduler.stub(:add, nil) do
18
- clazz.new
19
- end
20
- end
21
- end
22
-
23
- def interrupt!(type = :internal, pom = @pom)
24
- Scheduler.stub(:clear, nil) do
25
- pom.interrupt!(type)
26
- end
27
- end
28
-
29
- def finish!(thing = @pom || @break)
30
- Scheduler.stub(:clear, nil) do
31
- thing.finish!
32
- end
33
- end
34
-
35
- def cancel!(pom = @pom)
36
- Scheduler.stub(:clear, nil) do
37
- pom.cancel!
38
- end
39
- end
40
- end
7
+ require_relative 'lib/unit_test'
8
+ require_relative 'lib/assertions'
9
+ require_relative 'lib/at_mock'
10
+ require_relative 'lib/controller_test'
11
+ require_relative 'lib/integration_test'
12
+ require_relative 'lib/options_mock'
13
+ require_relative 'lib/paradeiser_controller_test'
14
+ require_relative 'lib/process_status_mock'
15
+ require_relative 'lib/pstore_mock'
16
+ require_relative 'lib/schedulable_mock'
17
+ require_relative 'lib/token_file_registry'
18
+ require_relative 'lib/view_test'
@@ -1,19 +1,21 @@
1
1
  require 'helper'
2
2
 
3
- class TestAnnotateCommand < Paradeiser::IntegrationTest
4
- def test_annotate_no_previous
5
- refute_command('annotate')
6
- end
3
+ module ParadeiserTest
4
+ class TestAnnotateCommand < IntegrationTest
5
+ def test_annotate_no_previous
6
+ refute_command('annotate')
7
+ end
7
8
 
8
- def test_annotate_active
9
- assert_command('start')
10
- assert_command('annotate', 0, name.split('_'))
11
- end
9
+ def test_annotate_active
10
+ assert_command('start')
11
+ assert_command('annotate', 0, name.split('_'))
12
+ end
12
13
 
13
- def test_annotate_second_last_successful
14
- assert_command('start')
15
- assert_command('finish')
16
- assert_command('break')
17
- assert_command('annotate', 0, name.split('_'))
14
+ def test_annotate_second_last_successful
15
+ assert_command('start')
16
+ assert_command('finish')
17
+ assert_command('break')
18
+ assert_command('annotate', 0, name.split('_'))
19
+ end
18
20
  end
19
21
  end
@@ -1,9 +1,11 @@
1
1
  require 'helper'
2
2
 
3
- class TestFinishCommand < Paradeiser::IntegrationTest
4
- def test_finish
5
- refute_command('finish')
6
- assert_command('start')
7
- assert_command('finish')
3
+ module ParadeiserTest
4
+ class TestFinishCommand < IntegrationTest
5
+ def test_finish
6
+ refute_command('finish')
7
+ assert_command('start')
8
+ assert_command('finish')
9
+ end
8
10
  end
9
11
  end
@@ -1,9 +1,11 @@
1
1
  require 'helper'
2
2
 
3
- class TestInterruptCommand < Paradeiser::IntegrationTest
4
- def test_interrupt
5
- refute_command('interrupt')
6
- assert_command('start')
7
- assert_command('interrupt')
3
+ module ParadeiserTest
4
+ class TestInterruptCommand < IntegrationTest
5
+ def test_interrupt
6
+ refute_command('interrupt')
7
+ assert_command('start')
8
+ assert_command('interrupt')
9
+ end
8
10
  end
9
11
  end
@@ -1,12 +1,14 @@
1
1
  require 'helper'
2
2
 
3
- class TestLogCommand < Paradeiser::IntegrationTest
4
- def test_log_inactive
5
- assert_command('log', 0, name.split('_'))
6
- end
3
+ module ParadeiserTest
4
+ class TestLogCommand < IntegrationTest
5
+ def test_log_inactive
6
+ assert_command('log', 0, name.split('_'))
7
+ end
7
8
 
8
- def test_log_active
9
- assert_command('start')
10
- assert_command('log', 0, name.split('_'))
9
+ def test_log_active
10
+ assert_command('start')
11
+ assert_command('log', 0, name.split('_'))
12
+ end
11
13
  end
12
14
  end
@@ -1,7 +1,9 @@
1
1
  require 'helper'
2
2
 
3
- class TestNoArgsCommand < Paradeiser::IntegrationTest
4
- def test_no_args
5
- assert_command('')
3
+ module ParadeiserTest
4
+ class TestNoArgsCommand < IntegrationTest
5
+ def test_no_args
6
+ assert_command('')
7
+ end
6
8
  end
7
9
  end