summaryrefslogtreecommitdiff
path: root/spec/helpers/application_helper_spec.rb
blob: 4e2ba8d4ae3d510c6f7d48984abd91994e507cfb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
require 'spec_helper'

describe ApplicationHelper do
  describe "#duration_in_words" do
    it "returns minutes and seconds" do
      intervals_in_words = {
        100 => "1 minute 40 seconds",
        121 => "2 minutes 1 second",
        3721 => "62 minutes 1 second",
        0 => "0 seconds"
      }

      intervals_in_words.each do |interval, expectation|
        duration_in_words(Time.now + interval, Time.now).should eq expectation
      end
    end

    it "calculates interval from now if there is no finished_at" do
      duration_in_words(nil, Time.now - 5).should eq "5 seconds"
    end
  end

  describe "#time_interval_in_words" do
    it "returns minutes and seconds" do
      intervals_in_words = {
        100 => "1 minute 40 seconds",
        121 => "2 minutes 1 second",
        3721 => "62 minutes 1 second",
        0 => "0 seconds"
      }

      intervals_in_words.each do |interval, expectation|
        time_interval_in_words(interval).should eq expectation
      end
    end
  end
end