summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/models/location.rb4
-rw-r--r--app/models/user.rb16
-rw-r--r--app/models/well_type.rb10
-rw-r--r--db/migrate/20140222051253_create_well_types.rb8
-rw-r--r--db/schema.rb7
-rw-r--r--db/seeds.rb10
-rw-r--r--spec/models/license_spec.rb14
-rw-r--r--spec/spec_helper.rb3
8 files changed, 64 insertions, 8 deletions
diff --git a/app/models/location.rb b/app/models/location.rb
new file mode 100644
index 0000000..611ae87
--- /dev/null
+++ b/app/models/location.rb
@@ -0,0 +1,4 @@
+class Location
+ def initialize(latitude: 0, longitude: 0, township: 'unknown')
+ end
+end
diff --git a/app/models/user.rb b/app/models/user.rb
new file mode 100644
index 0000000..7085ac2
--- /dev/null
+++ b/app/models/user.rb
@@ -0,0 +1,16 @@
+class User
+ attr_reader :company
+
+ def initialize(company: nil)
+ @company = company
+ end
+
+ def apply_for(well_type, location)
+ license = License.new
+ license.company = company
+ license.well_type = well_type
+ license.location = location
+ license.applicant = self
+ license
+ end
+end
diff --git a/app/models/well_type.rb b/app/models/well_type.rb
index 5367ce2..361dd99 100644
--- a/app/models/well_type.rb
+++ b/app/models/well_type.rb
@@ -1,3 +1,9 @@
-class WellType
- ALL=[]
+class WellType < ActiveRecord::Base
+ NFW=WellType.find_by_id(1)
+ NPW=WellType.find_by_id(2)
+ DPT=WellType.find_by_id(3)
+ SPT=WellType.find_by_id(4)
+ DEV=WellType.find_by_id(5)
+
+ ALL=[NFW, NPW, DPT, SPT, DEV]
end
diff --git a/db/migrate/20140222051253_create_well_types.rb b/db/migrate/20140222051253_create_well_types.rb
new file mode 100644
index 0000000..aa22bca
--- /dev/null
+++ b/db/migrate/20140222051253_create_well_types.rb
@@ -0,0 +1,8 @@
+class CreateWellTypes < ActiveRecord::Migration
+ def change
+ create_table :well_types do |t|
+ t.string :name
+ t.string :acronym
+ end
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 453bf07..aa1c471 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: 20140222032401) do
+ActiveRecord::Schema.define(version: 20140222051253) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@@ -32,4 +32,9 @@ ActiveRecord::Schema.define(version: 20140222032401) do
t.boolean "confidential", default: false
end
+ create_table "well_types", force: true do |t|
+ t.string "name"
+ t.string "acronym"
+ end
+
end
diff --git a/db/seeds.rb b/db/seeds.rb
index 4edb1e8..b9d9ff1 100644
--- a/db/seeds.rb
+++ b/db/seeds.rb
@@ -1,7 +1,7 @@
# This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
-#
-# Examples:
-#
-# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
-# Mayor.create(name: 'Emanuel', city: cities.first)
+WellType.create(id: 1, acronym: "NFW", name: "New Field Wildcat") unless WellType.exists?(1)
+WellType.create(id: 2, acronym: "NPW", name: "New Pool Wildcat") unless WellType.exists?(2)
+WellType.create(id: 3, acronym: "DPT", name: "Deeper Pool Test") unless WellType.exists?(3)
+WellType.create(id: 4, acronym: "SPT", name: "Shallower Pool Test") unless WellType.exists?(4)
+WellType.create(id: 5, acronym: "DEV", name: "Development Well") unless WellType.exists?(5)
diff --git a/spec/models/license_spec.rb b/spec/models/license_spec.rb
index a939372..d35c51f 100644
--- a/spec/models/license_spec.rb
+++ b/spec/models/license_spec.rb
@@ -29,4 +29,18 @@ describe License do
results.first.should == newest_license
end
end
+
+ describe "model" do
+ it "looks like this" do
+ company = Company.create(name: 'ABC Resources Ltd.')
+ user = User.new(company: company)
+ location = Location.new(latitude: 51.06, longitude: -114.09, township: '1')
+ license = user.apply_for(WellType::NFW, location)
+
+ license.company.should == user.company
+ license.well_type.should == WellType::NFW
+ license.location.should == location
+ license.applicant.should == user
+ end
+ end
end
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 943bc19..09b0309 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -39,4 +39,7 @@ RSpec.configure do |config|
# the seed, which is printed after each run.
# --seed 1234
config.order = "random"
+ config.before(:suite) do
+ require "#{Rails.root}/db/seeds"
+ end
end