diff options
| author | Zack Hobson | 2013-12-22 02:01:37 -0800 | 
|---|---|---|
| committer | Zack Hobson | 2013-12-22 02:01:37 -0800 | 
| commit | 24bb1cc3fea3e75aedcc64cdc30bb73089a7c157 (patch) | |
| tree | 9a57f2baf979605e349d0856f62fe91d63da2ea4 | |
| parent | de34961a1a1795bd12b3cabd47ca06e01c73c27a (diff) | |
| download | hcl-24bb1cc3fea3e75aedcc64cdc30bb73089a7c157.tar.bz2 | |
coverage game!
| -rw-r--r-- | lib/hcl/app.rb | 9 | ||||
| -rw-r--r-- | test/day_entry_test.rb | 18 | ||||
| -rw-r--r-- | test/task_test.rb | 34 | 
3 files changed, 51 insertions, 10 deletions
| diff --git a/lib/hcl/app.rb b/lib/hcl/app.rb index 18d293c..1bceab8 100644 --- a/lib/hcl/app.rb +++ b/lib/hcl/app.rb @@ -12,8 +12,6 @@ module HCl      HCL_DIR = ENV['HCL_DIR'] || "#{ENV['HOME']}/.hcl"      SETTINGS_FILE = "#{HCL_DIR}/settings.yml"      CONFIG_FILE = "#{HCL_DIR}/config.yml" -    OLD_SETTINGS_FILE = "#{ENV['HOME']}/.hcl_settings" -    OLD_CONFIG_FILE = "#{ENV['HOME']}/.hcl_config"      def initialize        FileUtils.mkdir_p(HCL_DIR) @@ -143,10 +141,6 @@ EOM            load_password config          end          TimesheetResource.configure config -      elsif File.exists? OLD_CONFIG_FILE -        config = YAML::load File.read(OLD_CONFIG_FILE) -        TimesheetResource.configure config -        write_config config        else          request_config        end @@ -177,9 +171,6 @@ EOM      def read_settings        if File.exists? SETTINGS_FILE          @settings = YAML.load(File.read(SETTINGS_FILE)) -      elsif File.exists? OLD_SETTINGS_FILE -        @settings = YAML.load(File.read(OLD_SETTINGS_FILE)) -        write_settings        else          @settings = {}        end diff --git a/test/day_entry_test.rb b/test/day_entry_test.rb index 5b390c3..581b22b 100644 --- a/test/day_entry_test.rb +++ b/test/day_entry_test.rb @@ -1,6 +1,24 @@  require 'test_helper'  class DayEntryTest < HCl::TestCase +  def test_cancel_success +    entry = HCl::DayEntry.new(id:123) +    HCl::DayEntry.expects(:delete) +    assert entry.cancel +  end + +  def test_cancel_failure +    entry = HCl::DayEntry.new(id:123) +    HCl::DayEntry.expects(:delete).raises(HCl::TimesheetResource::Failure) +    assert !entry.cancel +  end + +  def test_to_s +    entry = HCl::DayEntry.new \ +      hours: '1.2', client: 'Taco Town', project:'Pizza Taco', task:'Preparation' +    assert_equal "Taco Town - Pizza Taco - Preparation (1:12)", entry.to_s +  end +    def test_from_xml      entries = HCl::DayEntry.from_xml(<<-EOD)  <daily> diff --git a/test/task_test.rb b/test/task_test.rb index e313f73..f5c30b8 100644 --- a/test/task_test.rb +++ b/test/task_test.rb @@ -1,5 +1,37 @@ -class Task < HCl::TestCase +class TaskTest < HCl::TestCase +  DAILY_ENTRY = %{<daily> +    <for_day type="date">Wed, 18 Oct 2006</for_day> +    <day_entries> +      <day_entry> +        <id type="integer">195168</id> +        <client>Iridesco</client> +        <project>Harvest</project> +        <task>Backend Programming</task> +        <hours type="float">2.06</hours> +        <notes>Test api support</notes> +        <timer_started_at type="datetime"> +          Wed, 18 Oct 2006 09:53:06 -0000 +        </timer_started_at> +        <created_at type="datetime">Wed, 18 Oct 2006 09:53:06 -0000</created_at> +      </day_entry> +    </day_entries> +  </daily>} + +  def test_add_task +    task = HCl::Task.new(id:456, project:HCl::Project.new(id:123)) +    Date.expects(:today).returns('now') +    HCl::Task.expects(:post).with('daily/add', <<-EOT).returns(DAILY_ENTRY) +      <request> +        <notes>hi world</notes> +        <hours>0.5</hours> +        <project_id type="integer">123</project_id> +        <task_id type="integer">456</task_id> +        <spent_at type="date">now</spent_at> +      </request> +      EOT +    task.add note:'hi world', starting_time:0.5 +  end    def test_cache_file      assert_equal "#{HCl::App::HCL_DIR}/cache/tasks.yml", HCl::Task.cache_file    end | 
