1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
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 :each do
Company.stub(:find).with(company_id).and_return(company)
active_licenses.stub(:township).with("123").and_return(active_licenses_in_township)
end
it "returns the active licenses" do
company.stub(:filter_licenses_using).with({status: LicenseStatus::ACTIVE, township: nil}).and_return(active_licenses)
xhr :get, :index, company_id: company_id
assigns(:active_licenses).should == active_licenses
end
it "returns a json response" do
xhr :get, :index, company_id: company_id
expect(-> { JSON.parse(response.body) }).not_to raise_error
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)
xhr :get, :index, company_id: company_id, township: "123"
assigns(:active_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
xhr :get, :index, company_id: company.id, status: "expired", township: "1"
assigns(:active_licenses).should include(license)
end
end
end
end
|