summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/models/company.rb2
-rw-r--r--app/models/license.rb8
-rw-r--r--spec/controllers/v1/company_licenses_controller_spec.rb13
3 files changed, 22 insertions, 1 deletions
diff --git a/app/models/company.rb b/app/models/company.rb
index 4b6e798..7691bf5 100644
--- a/app/models/company.rb
+++ b/app/models/company.rb
@@ -2,6 +2,6 @@ class Company < ActiveRecord::Base
has_many :licenses
def status(status)
- status.filter(licenses)
+ licenses.status(status)
end
end
diff --git a/app/models/license.rb b/app/models/license.rb
index 6170683..77aad5f 100644
--- a/app/models/license.rb
+++ b/app/models/license.rb
@@ -9,4 +9,12 @@ class License < ActiveRecord::Base
offset = offset >= 0 ? offset : 0
License.order(created_at: :desc).offset(offset).limit(per_page)
end
+
+ def self.township(township)
+ joins(:location).where('locations.township = ?', township)
+ end
+
+ def self.status(status)
+ status.filter(self)
+ end
end
diff --git a/spec/controllers/v1/company_licenses_controller_spec.rb b/spec/controllers/v1/company_licenses_controller_spec.rb
index 2784a1d..198b4f3 100644
--- a/spec/controllers/v1/company_licenses_controller_spec.rb
+++ b/spec/controllers/v1/company_licenses_controller_spec.rb
@@ -28,4 +28,17 @@ describe V1::CompanyLicensesController do
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