summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2014-02-22 08:52:13 -0700
committermo khan <mo@mokhan.ca>2014-02-22 08:52:13 -0700
commit7947414c935aa6a20a2de068b343df2a0f141384 (patch)
tree46fc01930169f48a5debf42092baebb141bd18ba /app
parent1388b346450b975703b7890eb87505e975713c22 (diff)
add status to license and fix broken jbuilder spec.
Diffstat (limited to 'app')
-rw-r--r--app/models/license.rb4
-rw-r--r--app/models/license_status.rb5
-rw-r--r--app/models/license_status/active.rb5
-rw-r--r--app/models/license_status/confidential.rb4
-rw-r--r--app/models/license_status/expired.rb4
-rw-r--r--app/views/v1/company_licenses/index.jbuilder6
-rw-r--r--app/views/v1/licenses/_license.json.jbuilder2
7 files changed, 27 insertions, 3 deletions
diff --git a/app/models/license.rb b/app/models/license.rb
index 2b4fc3c..12bb387 100644
--- a/app/models/license.rb
+++ b/app/models/license.rb
@@ -4,6 +4,10 @@ class License < ActiveRecord::Base
has_one :location
belongs_to :applicant, class_name: 'User', foreign_key: 'user_id'
+ def status
+ LicenseStatus.status_for(self)
+ end
+
def self.most_recent(page: 1, per_page: 10)
offset = (page - 1) * per_page
offset = offset >= 0 ? offset : 0
diff --git a/app/models/license_status.rb b/app/models/license_status.rb
index 41b54c5..d5da68f 100644
--- a/app/models/license_status.rb
+++ b/app/models/license_status.rb
@@ -2,10 +2,15 @@ class LicenseStatus
ACTIVE=Active.new
EXPIRED=Expired.new
CONFIDENTIAL=Confidential.new
+ UNKNOWN=Object.new
ALL=[ACTIVE, EXPIRED, CONFIDENTIAL]
def self.find_match(status = "")
ALL.find { |x| x.matches?("#{status}".downcase) } || ACTIVE
end
+
+ def self.status_for(license)
+ ALL.find { |x| x.best_represents?(license) } || UNKNOWN
+ end
end
diff --git a/app/models/license_status/active.rb b/app/models/license_status/active.rb
index 864ee1a..f959efb 100644
--- a/app/models/license_status/active.rb
+++ b/app/models/license_status/active.rb
@@ -8,6 +8,11 @@ class LicenseStatus::Active
to_s == name
end
+ def best_represents?(license)
+ today = Date.today
+ license.issued_at < today && license.expired_at > today
+ end
+
def to_s
'active'
end
diff --git a/app/models/license_status/confidential.rb b/app/models/license_status/confidential.rb
index d108491..b2354cd 100644
--- a/app/models/license_status/confidential.rb
+++ b/app/models/license_status/confidential.rb
@@ -7,6 +7,10 @@ class LicenseStatus::Confidential
to_s == name
end
+ def best_represents?(license)
+ license.confidential?
+ end
+
def to_s
'confidential'
end
diff --git a/app/models/license_status/expired.rb b/app/models/license_status/expired.rb
index adbc3fb..8e24af9 100644
--- a/app/models/license_status/expired.rb
+++ b/app/models/license_status/expired.rb
@@ -8,6 +8,10 @@ class LicenseStatus::Expired
to_s == name
end
+ def best_represents?(license)
+ license.expired_at < Date.today
+ end
+
def to_s
'expired'
end
diff --git a/app/views/v1/company_licenses/index.jbuilder b/app/views/v1/company_licenses/index.jbuilder
index db62113..8228f3e 100644
--- a/app/views/v1/company_licenses/index.jbuilder
+++ b/app/views/v1/company_licenses/index.jbuilder
@@ -1,5 +1,7 @@
-json.array! @licenses do |license|
- json.partial! 'v1/licenses/license', license: license
+json.licenses do
+ json.array! @licenses do |license|
+ json.partial! 'v1/licenses/license', license: license
+ end
end
json.partial! 'v1/shared/well_types', well_types: @well_types
json.partial! 'v1/shared/license_statuses', license_statuses: @license_statuses
diff --git a/app/views/v1/licenses/_license.json.jbuilder b/app/views/v1/licenses/_license.json.jbuilder
index 33109d8..c66fb3f 100644
--- a/app/views/v1/licenses/_license.json.jbuilder
+++ b/app/views/v1/licenses/_license.json.jbuilder
@@ -1,5 +1,5 @@
json.id license.id
-json.status license.status
+json.status license.status.to_s
json.partial! 'v1/licenses/location', location: license.location
if license.confidential?
json.partial! 'v1/licenses/confidential_well_type', well_type: license.well_type