main
rb 41 lines 1.46 KB
Raw
1 # frozen_string_literal: true
2
3 require "rails_helper"
4
5 RSpec.describe IssueService do
6 let(:owner) { User.create!(smbcloud_id: 9001, email: "owner@example.com", username: "owner") }
7 let(:reader) { User.create!(smbcloud_id: 9002, email: "reader@example.com", username: "reader") }
8 let(:repo) do
9 owner.repositories.create!(
10 name: "app", kind: "code", default_branch: "main",
11 disk_path: GitRepositoryService.repo_path("owner", "app")
12 )
13 end
14
15 it "opens an issue authored by the given user" do
16 issue = described_class.create(repository: repo, author: owner, title: "Bug", body: "Details")
17
18 expect(issue).to be_persisted
19 expect(issue.number).to eq(1)
20 expect(issue.state).to eq("open")
21 expect(issue.author).to eq(owner)
22 expect(issue.body).to eq("Details")
23 end
24
25 it "lets any reader open an issue, not only the owner" do
26 issue = described_class.create(repository: repo, author: reader, title: "Feature request")
27 expect(issue.author).to eq(reader)
28 end
29
30 it "shares one number space with pull requests" do
31 repo.pull_requests.create!(user: owner, number: 3, title: "PR", head_ref: "feature", base_ref: "main")
32 issue = described_class.create(repository: repo, author: owner, title: "Bug")
33 expect(issue.number).to eq(4)
34 end
35
36 it "rejects a blank title via model validation" do
37 expect do
38 described_class.create(repository: repo, author: owner, title: "")
39 end.to raise_error(ActiveRecord::RecordInvalid)
40 end
41 end