Sha256: 08814c169106c5f9f8dd33407e85e8753bba8a96bc40e4470f2a8bac9960f6f7

Contents?: true

Size: 1.46 KB

Versions: 2

Compression:

Stored size: 1.46 KB

Contents

# frozen_string_literal: true

require "rails_helper"

module Archangel
  module Frontend
    RSpec.describe PagesController, type: :controller do
      describe "loads correct layout" do
        it "loads correct view" do
          page = create(:page)

          get :show, params: { path: page.path }

          expect(response).to render_with_layout("frontend")
        end
      end

      describe "GET #show" do
        it "assigns the requested page as @page" do
          page = create(:page)

          get :show, params: { path: page.path }

          expect(response.content_type).to eq "text/html"
          expect(assigns(:page)).to eq(page)
        end

        it "assigns the requested page as @page for JSON request" do
          page = create(:page)

          get :show, params: { path: page.path }, format: :json

          expect(response.content_type).to eq "application/json"
          expect(assigns(:page)).to eq(page)
        end

        it "redirects to homepage" do
          page = create(:page, :homepage)

          get :show, params: { path: page.path }

          expect(response).to redirect_to(root_path)
          expect(response.status).to eq(301)
        end

        it "returns a 404 status code when page is not found" do
          get :show, params: { path: "not-a-real-page" }

          expect(response).to render_template("archangel/errors/error_404")
          expect(response).to have_http_status(:not_found)
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
archangel-0.0.8 spec/controllers/archangel/frontend/pages_controller_spec.rb
archangel-0.0.7 spec/controllers/archangel/frontend/pages_controller_spec.rb