require "spec_helper" describe V1::CompanyLicensesController do describe :index do let(:company) { Company.new } let(:company_id) { SecureRandom.uuid } let(:active_licenses) { ["active"] } let(:active_licenses_in_township) { ["active township"] } before { Company.stub(:find).with(company_id).and_return(company) } it "returns the active licenses" do company.stub(:filter_licenses_using).with(status: LicenseStatus::ACTIVE, township: nil).and_return(active_licenses) get :index, company_id: company_id assigns(:licenses).should == active_licenses end it "returns the active licenses for a given township" do company.stub(:filter_licenses_using).with(status: LicenseStatus::ACTIVE, township: "123").and_return(active_licenses_in_township) get :index, company_id: company_id, township: "123" assigns(:licenses).should == active_licenses_in_township end end describe :integration do describe :index do let(:company) { Company.create(name: 'ABC Resources Ltd.') } let(:location) { Location.new(latitude: 51.06, longitude: -114.09, township: '1') } let!(:license) { company.licenses.create(well_type: WellType::DEV, location: location, issued_at: 2.days.ago, expired_at: 1.day.ago) } it "finds expired licenses from a specific township" do get :index, company_id: company.id, status: "expired", township: "1" assigns(:licenses).should include(license) end end end end