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