summaryrefslogtreecommitdiff
path: root/spec/models/license_spec.rb
blob: 1093d17b8aa9cccc4abc2a5499e2a3b041c50636 (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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
require "spec_helper"

describe License do
  describe ".most_recent" do
    let!(:oldest_license) { License.create }
    let!(:newest_license) { License.create }

    it "returns the most recently created well licenses" do
      results = License.most_recent(page: 1, per_page: 2)
      results.first.should == newest_license
      results.last.should == oldest_license
    end

    it "returns the first page of results" do
      results = License.most_recent(page: 1, per_page: 1)
      results.count.should == 1
      results.first.should == newest_license
    end

    it "returns the next page of results" do
      results = License.most_recent(page: 2, per_page: 1)
      results.count.should == 1
      results.first.should == oldest_license
    end

    it "returns the first page of results when the page is below 1" do
      results = License.most_recent(page: -1, per_page: 1)
      results.count.should == 1
      results.first.should == newest_license
    end
  end

  describe ".township" do
    let(:location) { Location.create(township: "2") }
    let!(:license) { License.create(location: location) }
    let(:other_location) { Location.create(township: "1") }
    let!(:other_license) { License.create(location: other_location) }

    it "returns a license in the township" do
      results = License.township("2")
      results.count.should == 1
      results.should include(license)
    end
  end

  describe ".status" do
    let(:today) { DateTime.now }
    let!(:active_license) { License.create(issued_at: 1.day.ago, expired_at: 1.day.from_now) }
    let!(:expired_license) { License.create(issued_at: 2.days.ago, expired_at: 1.day.ago ) }
    let!(:confidential_license) { License.create(issued_at: 2.days.from_now, expired_at: 3.days.from_now, confidential: true) }

    it "returns all the licenses that are active" do
      licenses = License.status(LicenseStatus::ACTIVE)
      licenses.count.should == 1
      licenses.should include(active_license)
    end

    it "returns all expired licenses" do
      licenses = License.status(LicenseStatus::EXPIRED)
      licenses.count.should == 1
      licenses.should include(expired_license)
    end

    it "returns all confidential licenses" do
      licenses = License.status(LicenseStatus::CONFIDENTIAL)
      licenses.count.should == 1
      licenses.should include(confidential_license)
    end
  end

  describe "#status" do
    let!(:active_license) { License.new(issued_at: 1.day.ago, expired_at: 1.day.from_now) }
    let!(:expired_license) { License.new(issued_at: 2.days.ago, expired_at: 1.day.ago ) }
    let!(:confidential_license) { License.new(issued_at: 2.days.from_now, expired_at: 3.days.from_now, confidential: true) }

    it "returns an active status" do
      active_license.status.should == LicenseStatus::ACTIVE
    end

    it "returns an expired status" do
      expired_license.status.should == LicenseStatus::EXPIRED
    end

    it "returns an confidential status" do
      confidential_license.status.should == LicenseStatus::CONFIDENTIAL
    end
  end
end