Pārlūkot izejas kodu

Add routing specs

Andrew Swistak 6 gadi atpakaļ
vecāks
revīzija
2288c9c916
2 mainītis faili ar 47 papildinājumiem un 0 dzēšanām
  1. 27 0
      spec/routing/api_spec.rb
  2. 20 0
      spec/routing/routing_spec.rb

+ 27 - 0
spec/routing/api_spec.rb

@@ -0,0 +1,27 @@
+# frozen_string_literal: true
+
+require 'rails_helper'
+
+RSpec.describe '/api', type: :routing do
+  context 'graphql' do
+    it 'routes to the GraphqlController' do
+      expect(post('/api/graphql')).to route_to(
+        controller: 'api/graphql',
+        action: 'execute',
+        formats: :json,
+      )
+    end
+  end
+
+  context 'all other paths' do
+    it 'routes to application#not_found' do
+      path = Faker::Lorem.word
+      expect(post("/api/#{path}")).to route_to(
+        controller: 'api/application',
+        action: 'not_found',
+        formats: :json,
+        path: path,
+      )
+    end
+  end
+end

+ 20 - 0
spec/routing/routing_spec.rb

@@ -0,0 +1,20 @@
+# frozen_string_literal: true
+
+require 'rails_helper'
+
+RSpec.describe WelcomeController, type: :routing do
+  it 'routes to #root' do
+    expect(get('/')).to route_to('welcome#root')
+  end
+
+  context 'all other paths' do
+    it 'routes to welcome#root' do
+      path = Faker::Lorem.word
+      expect(get("/#{path}")).to route_to(
+        controller: 'welcome',
+        action: 'root',
+        path: path,
+      )
+    end
+  end
+end