diff options
| -rw-r--r-- | app/models/user.rb | 10 | ||||
| -rw-r--r-- | spec/models/user_spec.rb | 4 |
2 files changed, 4 insertions, 10 deletions
diff --git a/app/models/user.rb b/app/models/user.rb index 446d3e2..056039b 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,13 +1,7 @@ class User < ActiveRecord::Base belongs_to :company - def apply_for(well_type, location) - license = License.new - license.company = company - license.well_type = well_type - license.location = location - license.applicant = self - license.save! - license + def apply_for_license(well_type, location) + company.licenses.create(well_type: well_type, location: location, applicant: self) end end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 02e52be..4db73fd 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -1,13 +1,13 @@ require "spec_helper" describe User do - describe "#apply_for" do + describe "#apply_for_license" do context "when applying for a license" do it "creates a new license" do company = Company.create(name: 'ABC Resources Ltd.') user = User.create(company: company) location = Location.new(latitude: 51.06, longitude: -114.09, township: '1') - license = user.apply_for(WellType::NFW, location) + license = user.apply_for_license(WellType::NFW, location) license.company.should == user.company license.well_type.should == WellType::NFW |
