summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2014-02-21 23:50:52 -0700
committermo khan <mo@mokhan.ca>2014-02-21 23:50:52 -0700
commit842ee349392844ff08e818151a8eb5ca00b67d10 (patch)
treedf0566008cf97f05e45930e023106ea14646356e
parent39fc3e184c1c185ffc9fc1f17bd19c5a8d9d0106 (diff)
refactor specs to target the filter licenses method.
-rw-r--r--app/models/company.rb4
-rw-r--r--spec/models/company_spec.rb30
2 files changed, 16 insertions, 18 deletions
diff --git a/app/models/company.rb b/app/models/company.rb
index 630610f..c1c2d9f 100644
--- a/app/models/company.rb
+++ b/app/models/company.rb
@@ -1,10 +1,6 @@
class Company < ActiveRecord::Base
has_many :licenses
- def status(status)
- licenses.status(status)
- end
-
def filter_licenses_using(search_filters)
result = self.licenses
search_filters.each { |key, value| result = result.public_send(key, value) if value.present? }
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