summaryrefslogtreecommitdiff
path: root/spec/models/license_spec.rb
blob: d35c51f8fd0623015a5e46de7e7f2e0a0698c0fd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
require "spec_helper"

describe License do
  describe ".most_recent" do
    let!(:oldest_license) { License.create }
    let!(:newest_license) { License.create }

    it "returns the most recently created well licenses" do
      results = License.most_recent(page: 1, per_page: 2)
      results.first.should == newest_license
      results.last.should == oldest_license
    end

    it "returns the first page of results" do
      results = License.most_recent(page: 1, per_page: 1)
      results.count.should == 1
      results.first.should == newest_license
    end

    it "returns the next page of results" do
      results = License.most_recent(page: 2, per_page: 1)
      results.count.should == 1
      results.first.should == oldest_license
    end

    it "returns the first page of results when the page is below 1" do
      results = License.most_recent(page: -1, per_page: 1)
      results.count.should == 1
      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