From 842ee349392844ff08e818151a8eb5ca00b67d10 Mon Sep 17 00:00:00 2001 From: mo khan Date: Fri, 21 Feb 2014 23:50:52 -0700 Subject: refactor specs to target the filter licenses method. --- spec/models/company_spec.rb | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) (limited to 'spec') diff --git a/spec/models/company_spec.rb b/spec/models/company_spec.rb index 1acef1c..4f0a322 100644 --- a/spec/models/company_spec.rb +++ b/spec/models/company_spec.rb @@ -1,29 +1,31 @@ require "spec_helper" describe Company do - describe ".status" do + describe "#filter_licenses_using" do let(:company) { Company.create } - let(:today) { DateTime.now } + 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 ) } - let!(:confidential_license) { company.licenses.create(issued_at: 2.days.from_now, expired_at: 3.days.from_now, confidential: true) } + 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 - licenses = company.status(LicenseStatus::ACTIVE) - licenses.count.should == 1 - licenses.should include(active_license) + results = company.filter_licenses_using(status: LicenseStatus::ACTIVE) + results.count.should == 1 + results.should include(active_license) end it "returns all expired licenses" do - licenses = company.status(LicenseStatus::EXPIRED) - licenses.count.should == 1 - licenses.should include(expired_license) + 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 all confidential licenses" do - licenses = company.status(LicenseStatus::CONFIDENTIAL) - licenses.count.should == 1 - licenses.should include(confidential_license) + 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 -- cgit v1.2.3