@@ -67,5 +67,19 @@ describe Practice do
 
       expect(practice.incomplete_trails).to be_empty
     end
+
+    context "sorting" do
+      it "returns all started trails before any unstarted trails" do
+        user = build_stubbed(:user)
+        started_trail = create(:trail, :published, name: "Started")
+        create(:status, completeable: started_trail, user: user)
+        create(:trail, :published, name: "Unstarted")
+        practice = Practice.new(user)
+
+        result = practice.incomplete_trails
+
+        expect(result.map(&:name)).to eq(["Started", "Unstarted"])
+      end
+    end
   end
 end
require "rails_helper"

describe Practice do
  describe "#has_completed_trails?" do
    it "returns false if it has no completed trails" do
      user = build_stubbed(:user)
      practice = Practice.new(user)

      expect(practice).not_to have_completed_trails
    end

    it "returns true if it has completed published trails" do
      user = create(:user)
      trail = create(:trail, :published)
      create(:status, :completed, completeable: trail, user: user)
      practice = Practice.new(user)

      expect(practice).to have_completed_trails
    end
  end

  describe "#just_finished_trails" do
    it "when there are recently completed trails" do
      user = create(:user)
      trail = create(:trail, :published)
      create(:status, :completed, completeable: trail, user: user)
      practice = Practice.new(user)

      expect(practice.just_finished_trails).to eq([trail])
    end

    it "when there are incomplete trails" do
      user = create(:user)
      trail = create(:trail, :published)
      create(:status, completeable: trail, user: user)
      practice = Practice.new(user)

      expect(practice.just_finished_trails).to be_empty
    end
  end

  describe "#incomplete_trails" do
    it "when there are unstarted trails" do
      user = build_stubbed(:user)
      trail = create(:trail, :published)
      practice = Practice.new(user)

      expect(practice.incomplete_trails).to eq([trail])
    end

    it "when there are started trails" do
      user = build_stubbed(:user)
      trail = create(:trail, :published)
      create(:status, completeable: trail, user: user)
      practice = Practice.new(user)

      expect(practice.incomplete_trails).to eq([trail])
    end

    it "when there are completed trails" do
      user = build_stubbed(:user)
      trail = create(:trail, :published)
      Timecop.travel(1.week.ago) do
        create(:status, :completed, completeable: trail, user: user)
      end
      practice = Practice.new(user)

      expect(practice.incomplete_trails).to be_empty
    end
  end
end

Useless assignment to variable - `unstarted_trail`. Did you mean `started_trail`?