diff options
| -rw-r--r-- | README.md | 1 | ||||
| -rw-r--r-- | app/views/v1/company_licenses/index.jbuilder | 19 | ||||
| -rw-r--r-- | spec/views/v1/company_licenses/index.json.jbuilder_spec.rb | 29 | ||||
| -rw-r--r-- | spec/views/v1/licenses/index.json.jbuilder_spec.rb | 21 |
4 files changed, 57 insertions, 13 deletions
@@ -101,6 +101,7 @@ LicenseStatus (flyweight, state) * error handling * finish json views * add well statuses and well types to json response. +* rename license to well license * update deploy script to seed db. * update license status to use a hash * add pagination to company licenses controller diff --git a/app/views/v1/company_licenses/index.jbuilder b/app/views/v1/company_licenses/index.jbuilder index ff31792..b6afb2d 100644 --- a/app/views/v1/company_licenses/index.jbuilder +++ b/app/views/v1/company_licenses/index.jbuilder @@ -1,9 +1,18 @@ json.array! @licenses do |license| - json.issued_at license.issued_at.to_s - json.expired_at license.expired_at.to_s + json.id license.id json.well_type do - json.id 1 - json.pneumonic "NFW" - json.name "New Field Wildcat" + json.id license.well_type.id + json.acronym license.well_type.acronym + json.name license.well_type.name + end + json.location do + json.township license.location.township + json.latitude license.location.latitude + json.longitude license.location.longitude end + json.company do + json.name license.company.name + end + json.issued_at license.issued_at.to_s + json.expired_at license.expired_at.to_s end diff --git a/spec/views/v1/company_licenses/index.json.jbuilder_spec.rb b/spec/views/v1/company_licenses/index.json.jbuilder_spec.rb index 52b5fe5..6d85141 100644 --- a/spec/views/v1/company_licenses/index.json.jbuilder_spec.rb +++ b/spec/views/v1/company_licenses/index.json.jbuilder_spec.rb @@ -1,18 +1,41 @@ require "spec_helper" describe 'v1/company_licenses/index' do - let!(:company) { Company.create(name: 'acme') } - let!(:license) { company.licenses.create(issued_at: 2.days.ago, expired_at: 1.day.from_now) } + let(:company) { Company.new(name: 'ABC Resources Ltd.') } + let(:user) { User.new(company: company) } + let(:location) { Location.new(latitude: 51.06, longitude: -114.09, township: '1') } + let(:well_type) { WellType::DEV } + let(:license) { License.new(id: SecureRandom.uuid, company: company, applicant: user, location: location, issued_at: 2.days.ago, expired_at: 1.day.from_now, well_type: well_type) } before :each do - assign(:licenses, company.licenses) + assign(:licenses, [license]) render end let(:result) { JSON.parse(rendered) } + it "includes the license id" do + result.first["id"].should == license.id + end + it "includes the license date range" do result.first["issued_at"].should == license.issued_at.to_s result.first["expired_at"].should == license.expired_at.to_s end + + it "includes the company information" do + result.first["company"]["name"].should == license.company.name + end + + it "includes information on the type of well" do + result.first["well_type"]["id"].should == well_type.id + result.first["well_type"]["acronym"].should == well_type.acronym + result.first["well_type"]["name"].should == well_type.name + end + + it "includes location information" do + result.first["location"]["latitude"].should == location.latitude + result.first["location"]["longitude"].should == location.longitude + result.first["location"]["township"].should == location.township + end end diff --git a/spec/views/v1/licenses/index.json.jbuilder_spec.rb b/spec/views/v1/licenses/index.json.jbuilder_spec.rb index 412f6fb..c3743a5 100644 --- a/spec/views/v1/licenses/index.json.jbuilder_spec.rb +++ b/spec/views/v1/licenses/index.json.jbuilder_spec.rb @@ -5,26 +5,37 @@ describe 'v1/licenses/index' do let(:user) { User.new(company: company) } let(:location) { Location.new(latitude: 51.06, longitude: -114.09, township: '1') } let(:well_type) { WellType::DEV } - let!(:license) { License.new(id: SecureRandom.uuid, company: company, applicant: user, location: location, issued_at: 2.days.ago, expired_at: 1.day.from_now, well_type: well_type) } + let(:license) { License.new(id: SecureRandom.uuid, company: company, applicant: user, location: location, issued_at: 2.days.ago, expired_at: 1.day.from_now, well_type: well_type) } before :each do assign(:licenses, [license]) render - puts rendered end let(:result) { JSON.parse(rendered) } - it "includes the license date range" do + it "includes the license id" do result.first["id"].should == license.id + end + + it "includes the license date range" do + result.first["issued_at"].should == license.issued_at.to_s + result.first["expired_at"].should == license.expired_at.to_s + end + + it "includes the company information" do result.first["company"]["name"].should == license.company.name + end + + it "includes information on the type of well" do result.first["well_type"]["id"].should == well_type.id result.first["well_type"]["acronym"].should == well_type.acronym result.first["well_type"]["name"].should == well_type.name + end + + it "includes location information" do result.first["location"]["latitude"].should == location.latitude result.first["location"]["longitude"].should == location.longitude result.first["location"]["township"].should == location.township - result.first["issued_at"].should == license.issued_at.to_s - result.first["expired_at"].should == license.expired_at.to_s end end |
