diff options
| author | mo khan <mo@mokhan.ca> | 2014-02-22 08:00:50 -0700 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2014-02-22 08:00:50 -0700 |
| commit | 86036fa0e99d77b34edf16349b1e681db660558f (patch) | |
| tree | 107d8bb986c3ebfe90aa39f1a38cb89487369fa2 | |
| parent | b675903ccb615c1f1868cd46095fec140a4198ae (diff) | |
add applicant name to json response.
| -rw-r--r-- | app/models/user.rb | 4 | ||||
| -rw-r--r-- | app/views/v1/licenses/_company.json.jbuilder | 1 | ||||
| -rw-r--r-- | app/views/v1/licenses/_confidential_company.json.jbuilder | 1 | ||||
| -rw-r--r-- | app/views/v1/licenses/_license.json.jbuilder | 2 | ||||
| -rw-r--r-- | db/migrate/20140222145409_add_name_to_users.rb | 6 | ||||
| -rw-r--r-- | db/schema.rb | 4 | ||||
| -rw-r--r-- | spec/models/user_spec.rb | 6 | ||||
| -rw-r--r-- | spec/views/v1/licenses/show.json.jbuilder_spec.rb | 5 |
8 files changed, 25 insertions, 4 deletions
diff --git a/app/models/user.rb b/app/models/user.rb index 056039b..c298241 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,6 +1,10 @@ class User < ActiveRecord::Base belongs_to :company + def full_name + "#{first_name} #{last_name}" + end + def apply_for_license(well_type, location) company.licenses.create(well_type: well_type, location: location, applicant: self) end diff --git a/app/views/v1/licenses/_company.json.jbuilder b/app/views/v1/licenses/_company.json.jbuilder index 223a2b1..91a79da 100644 --- a/app/views/v1/licenses/_company.json.jbuilder +++ b/app/views/v1/licenses/_company.json.jbuilder @@ -1,3 +1,4 @@ json.company do json.name company.name + json.applicant_name applicant.full_name end diff --git a/app/views/v1/licenses/_confidential_company.json.jbuilder b/app/views/v1/licenses/_confidential_company.json.jbuilder index 676c5a1..312961a 100644 --- a/app/views/v1/licenses/_confidential_company.json.jbuilder +++ b/app/views/v1/licenses/_confidential_company.json.jbuilder @@ -1,3 +1,4 @@ json.company do json.name "CONFIDENTIAL" + json.applicant_name "CONFIDENTIAL" end diff --git a/app/views/v1/licenses/_license.json.jbuilder b/app/views/v1/licenses/_license.json.jbuilder index 0035ea4..9fd0ce8 100644 --- a/app/views/v1/licenses/_license.json.jbuilder +++ b/app/views/v1/licenses/_license.json.jbuilder @@ -5,7 +5,7 @@ if license.confidential? json.partial! 'v1/licenses/confidential_company' else json.partial! 'v1/licenses/well_type', well_type: license.well_type - json.partial! 'v1/licenses/company', company: license.company + json.partial! 'v1/licenses/company', company: license.company, applicant: license.applicant end json.issued_at license.issued_at.to_s json.expired_at license.expired_at.to_s diff --git a/db/migrate/20140222145409_add_name_to_users.rb b/db/migrate/20140222145409_add_name_to_users.rb new file mode 100644 index 0000000..2f30a88 --- /dev/null +++ b/db/migrate/20140222145409_add_name_to_users.rb @@ -0,0 +1,6 @@ +class AddNameToUsers < ActiveRecord::Migration + def change + add_column :users, :first_name, :string + add_column :users, :last_name, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index d58c3ae..f102db8 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20140222055630) do +ActiveRecord::Schema.define(version: 20140222145409) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -47,6 +47,8 @@ ActiveRecord::Schema.define(version: 20140222055630) do t.uuid "company_id" t.datetime "created_at" t.datetime "updated_at" + t.string "first_name" + t.string "last_name" end create_table "well_types", force: true do |t| diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 71d9e18..1117f00 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -16,4 +16,10 @@ describe User do end end end + + describe "#full_name" do + it "returns the full name" do + User.new(first_name: "mo", last_name: "khan").full_name.should == "mo khan" + end + end end diff --git a/spec/views/v1/licenses/show.json.jbuilder_spec.rb b/spec/views/v1/licenses/show.json.jbuilder_spec.rb index 576c1bb..db8730f 100644 --- a/spec/views/v1/licenses/show.json.jbuilder_spec.rb +++ b/spec/views/v1/licenses/show.json.jbuilder_spec.rb @@ -2,7 +2,7 @@ require "spec_helper" describe 'v1/licenses/show' do let(:company) { Company.new(name: 'ABC Resources Ltd.') } - let(:user) { User.new(company: company) } + 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 } @@ -27,6 +27,7 @@ describe 'v1/licenses/show' do 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 @@ -53,7 +54,7 @@ describe 'v1/licenses/show' do 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 |
