require "spec_helper" describe 'v1/licenses/show' do let(:company) { Company.new(name: 'ABC Resources Ltd.') } let(:user) { User.new(first_name: 'john', last_name: 'dielwart', company: company) } let(:location) { Location.new(latitude: 51.06, longitude: -114.09, township: '1') } let(:well_type) { WellType::DEV } context "for public licenses" do let(:public_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 public_license.stub(:status).and_return(LicenseStatus::ACTIVE) assign(:license, public_license) render end let(:result) { JSON.parse(rendered) } it "includes the license date range" do result["issued_at"].should == public_license.issued_at.to_s result["expired_at"].should == public_license.expired_at.to_s end it "includes the license id" do result["id"].should == public_license.id end it "includes the company information" do result["company"]["name"].should == public_license.company.name result["company"]["applicant_name"].should == user.full_name end it "includes information on the type of well" do result["well_type"]["id"].should == well_type.id result["well_type"]["acronym"].should == well_type.acronym result["well_type"]["name"].should == well_type.name end it "includes location information" do result["location"]["latitude"].should == location.latitude result["location"]["longitude"].should == location.longitude result["location"]["township"].should == location.township end it "includes the license status" do result['status'].should == 'active' end end context "for confidential licenses" do let(:confidential_license) { License.new(confidential: true, company: company, applicant: user, location: location, well_type: well_type) } before :each do confidential_license.stub(:status).and_return(LicenseStatus::CONFIDENTIAL) assign(:license, confidential_license) render end let(:result) { JSON.parse(rendered) } it "should hide the name of the applicant" do result["company"]["applicant_name"].should == "CONFIDENTIAL" end it "should hide the type of well" do result['well_type']['id'].should == '' result['well_type']['acronym'].should == '' result['well_type']['name'].should == 'CONFIDENTIAL' end it "should hide the company name" do result["company"]["name"].should == "CONFIDENTIAL" end it "includes the license status" do result['status'].should == 'confidential' end end end