summaryrefslogtreecommitdiff
path: root/spec/routing/uploads_routing_spec.rb
blob: d1ddf8a6d6a7692475b9e75656e86869a65fb49b (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'Uploads', 'routing' do
  it 'allows creating uploads for personal snippets' do
    expect(post('/uploads/personal_snippet?id=1')).to route_to(
      controller: 'uploads',
      action: 'create',
      model: 'personal_snippet',
      id: '1'
    )
  end

  it 'allows creating uploads for users' do
    expect(post('/uploads/user?id=1')).to route_to(
      controller: 'uploads',
      action: 'create',
      model: 'user',
      id: '1'
    )
  end

  it 'does not allow creating uploads for other models' do
    unroutable_models = UploadsController::MODEL_CLASSES.keys.compact - %w(personal_snippet user)

    unroutable_models.each do |model|
      expect(post("/uploads/#{model}?id=1")).not_to be_routable
    end
  end

  describe 'legacy paths' do
    include RSpec::Rails::RequestExampleGroup

    it 'redirects project uploads to canonical path under project namespace' do
      expect(get('/uploads/namespace/project/12345/test.png')).to redirect_to('/namespace/project/uploads/12345/test.png')
    end
  end
end