require 'rails_helper'

describe DayTimeSeconds do
  describe "initialization" do
    it "can be initialized using a string" do
      described_class.new('17:48:23').number.should eq 17 * 3600 + 48 * 60 + 23
    end
  end

  describe '#inspect' do
    it "works with sub hour float values" do
      described_class.new(474.56).inspect.should eq "00:07:55"
    end
  end

  describe "#to_s" do
    it "is the same as inspect" do
      described_class.new(7).to_s.should eq "00:00:07"
    end
  end

  describe "comparison" do
    subject { described_class.new 11656 }
    describe "equality" do
      it "works with numbers and object as base" do
        (subject == 11656).should be true
        (subject == 7992).should be false

        (subject == '03:14:16' ).should be true
        (subject == '00:54:32' ).should be false
      end

      it "works the other way around" do
        (11656 == subject).should be true
        (79 == subject).should be false

        # cannot coerce strings aparently
        ('03:14:16' == subject.to_s).should be true
        ('00:54:33' == subject.to_s).should be false
      end

      it "works with missing minutes and seconds" do
        described_class.new('15').should    eq '15:00:00'
        described_class.new('15:24').should eq '15:24:00'
      end
    end

    describe ">" do
      it "works with numbers and object as base" do
        (subject > 77    ).should be true
        (subject > 11656 ).should be false
        (subject > 12379 ).should be false

        (subject > '02:17'    ).should be true
        (subject > '03:14:15' ).should be true
        (subject > '03:14:17' ).should be false
        (subject > '16:05'    ).should be false
      end

      it "works the other way around" do
        (77352 > subject).should be true
        (11656 > subject).should be false
        (79    > subject).should be false

        ('01:17:24' > subject.to_s).should be false
        ('03:14:16' > subject.to_s).should be false
        ('03:18:25' > subject.to_s).should be true
      end
    end
  end
end
