main
rb 47 lines 1.44 KB
Raw
1 # frozen_string_literal: true
2
3 require "rails_helper"
4
5 RSpec.describe Repository, type: :model do
6 let(:user) { User.create!(smbcloud_id: 8001, email: "alice@example.com", username: "alice") }
7
8 def build_repo(**attrs)
9 user.repositories.create!(
10 { name: "widget", kind: "code", default_branch: "main",
11 disk_path: "/nonexistent/alice/widget.git" }.merge(attrs)
12 )
13 end
14
15 describe "#seo_description" do
16 it "uses the description when present" do
17 repo = build_repo(description: "A tiny widget library.")
18 expect(repo.seo_description).to eq("A tiny widget library.")
19 end
20
21 it "falls back for a code repo without a description" do
22 repo = build_repo(description: nil)
23 expect(repo.seo_description).to include("@alice")
24 expect(repo.seo_description).to include("Git hosting built for AI workflows")
25 end
26
27 it "falls back for a model repo without a description" do
28 repo = build_repo(name: "Qwen2.5-GGUF", kind: "model", description: nil)
29 expect(repo.seo_description).to include("open-weights model")
30 end
31 end
32
33 describe "#og_version" do
34 it "changes when a share-card input changes" do
35 repo = build_repo(stars_count: 1)
36 before = repo.og_version
37 repo.stars_count = 2
38 expect(repo.og_version).not_to eq(before)
39 end
40 end
41
42 describe "#primary_language" do
43 it "is nil for an uninitialized repo" do
44 expect(build_repo.primary_language).to be_nil
45 end
46 end
47 end