summaryrefslogtreecommitdiff
path: root/spec/models/company_spec.rb
blob: 4f0a3221c7577a0aad363a5ea3aeed822bdfd130 (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
require "spec_helper"

describe Company do
  describe "#filter_licenses_using" do
    let(:company) { Company.create }
    let(:calgary) { Location.create(township: 'calgary') }
    let(:edmonton) { Location.create(township: 'edmonton') }
    let!(:active_license) { company.licenses.create(issued_at: 1.day.ago, expired_at: 1.day.from_now) }
    let!(:expired_license) { company.licenses.create(issued_at: 2.days.ago, expired_at: 1.day.ago, location: calgary) }
    let!(:other_expired_license) { company.licenses.create(issued_at: 2.days.ago, expired_at: 1.day.ago, location: edmonton) }

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

    it "returns all expired licenses" do
      results = company.filter_licenses_using(status: LicenseStatus::EXPIRED)
      results.count.should == 2
      results.should include(expired_license)
      results.should include(other_expired_license)
    end

    it "returns expired licenses in township" do
      results = company.filter_licenses_using(status: LicenseStatus::EXPIRED, township: 'edmonton')
      results.count.should == 1
      results.should include(other_expired_license)
    end
  end
end