From dcb8cddfc3adeb3be6885c00933f1354d3d1e576 Mon Sep 17 00:00:00 2001 From: mo khan Date: Fri, 21 Feb 2014 22:59:41 -0700 Subject: rename method and use relation to create new license. --- app/models/user.rb | 10 ++-------- 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 -- cgit v1.2.3