|
3 | 3 | RSpec.describe 'API::V1::Deploys', type: :request, api: true do |
4 | 4 | let(:account) { create(:account) } |
5 | 5 | let(:user) { create(:user, account: account) } |
6 | | - let(:project) { create(:project, user: user, account: account) } |
7 | | - let(:token) { create(:api_token, project: project, account: account) } |
8 | | - let(:headers) { { 'CONTENT_TYPE' => 'application/json', 'X-Project-Token' => token.token } } |
9 | | - |
10 | | - before do |
11 | | - ActsAsTenant.current_tenant = account |
| 6 | + let(:project) do |
| 7 | + ActsAsTenant.with_tenant(account) do |
| 8 | + create(:project, user: user, account: account) |
| 9 | + end |
12 | 10 | end |
| 11 | + let(:token) do |
| 12 | + ActsAsTenant.with_tenant(account) do |
| 13 | + create(:api_token, project: project, account: account) |
| 14 | + end |
| 15 | + end |
| 16 | + let(:headers) { { 'CONTENT_TYPE' => 'application/json', 'X-Project-Token' => token.token } } |
13 | 17 |
|
14 | 18 | describe 'POST /api/v1/deploys' do |
15 | 19 | it 'creates a deploy and associated release' do |
|
25 | 29 |
|
26 | 30 | expect { |
27 | 31 | post '/api/v1/deploys', params: body, headers: headers |
28 | | - }.to change { Deploy.count }.by(1) |
29 | | - .and change { Release.count }.by(1) |
| 32 | + }.to change { ActsAsTenant.with_tenant(account) { Deploy.count } }.by(1) |
| 33 | + .and change { ActsAsTenant.with_tenant(account) { Release.count } }.by(1) |
30 | 34 |
|
31 | 35 | expect(response).to have_http_status(:ok) |
32 | 36 | json = JSON.parse(response.body) |
|
36 | 40 |
|
37 | 41 | it 'reuses existing release for same version/environment' do |
38 | 42 | # Pre-create a release for this project/version/environment |
39 | | - existing_release = create( |
40 | | - :release, |
41 | | - project: project, |
42 | | - account: account, |
43 | | - version: 'v1.0.1', |
44 | | - environment: 'staging' |
45 | | - ) |
| 43 | + existing_release = ActsAsTenant.with_tenant(account) do |
| 44 | + create( |
| 45 | + :release, |
| 46 | + project: project, |
| 47 | + account: account, |
| 48 | + version: 'v1.0.1', |
| 49 | + environment: 'staging' |
| 50 | + ) |
| 51 | + end |
46 | 52 |
|
47 | 53 | body = { |
48 | 54 | project_slug: project.slug, |
|
54 | 60 | finished_at: Time.current.iso8601 |
55 | 61 | }.to_json |
56 | 62 |
|
57 | | - deploy_count_before = Deploy.count |
58 | | - release_count_before = Release.count |
| 63 | + deploy_count_before = ActsAsTenant.with_tenant(account) { Deploy.count } |
| 64 | + release_count_before = ActsAsTenant.with_tenant(account) { Release.count } |
59 | 65 |
|
60 | 66 | post '/api/v1/deploys', params: body, headers: headers |
61 | 67 |
|
62 | 68 | expect(response).to have_http_status(:ok) |
63 | 69 | json = JSON.parse(response.body) |
64 | 70 | expect(json['ok']).to eq(true) |
65 | 71 |
|
66 | | - expect(Deploy.count).to eq(deploy_count_before + 1) |
67 | | - expect(Release.count).to eq(release_count_before) |
| 72 | + expect(ActsAsTenant.with_tenant(account) { Deploy.count }).to eq(deploy_count_before + 1) |
| 73 | + expect(ActsAsTenant.with_tenant(account) { Release.count }).to eq(release_count_before) |
68 | 74 | end |
69 | 75 |
|
70 | 76 | it 'returns not_found for unknown project slug' do |
|
0 commit comments