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