Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Increase test coverage to a minimum of 80% #93

Open
wants to merge 14 commits into
base: develop
Choose a base branch
from
Open
2 changes: 0 additions & 2 deletions app/controllers/admin/app_configs_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
class Admin::AppConfigsController < AdminController
def index; end

def edit; end

def update
Expand Down
1 change: 1 addition & 0 deletions app/controllers/admin/transcripts_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class Admin::TranscriptsController < ApplicationController
include ActionController::MimeResponds
include IndexTemplate

before_action :authenticate_admin!

Expand Down
4 changes: 3 additions & 1 deletion app/controllers/admin/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ def update
def destroy
authorize User

unless @user.delete
if @user.delete
head :no_content
else
render json: @user.errors, status: :unprocessable_entity
end
end
Expand Down
41 changes: 22 additions & 19 deletions app/controllers/collections_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,32 +21,35 @@ def list
# GET /collections/the-uid.json
def show; end

# NOTE (jonjon): Based on routes.rb line 35
# these actions below is not being used anymore

# POST /collections.json
def create
@collection = Collection.new(collection_params)
# def create
# @collection = Collection.new(collection_params)

if @collection.save
render json: @collection, status: :created, location: @collection
else
render json: @collection.errors, status: :unprocessable_entity
end
end
# if @collection.save
# render json: @collection, status: :created, location: @collection
# else
# render json: @collection.errors, status: :unprocessable_entity
# end
# end

# PATCH/PUT /collections/the-uid.json
def update
if @collection.update(collection_params)
head :no_content
else
render json: @collection.errors, status: :unprocessable_entity
end
end
# def update
# if @collection.update(collection_params)
# head :no_content
# else
# render json: @collection.errors, status: :unprocessable_entity
# end
# end

# DELETE /collections//the-uid.json
def destroy
@collection.destroy
# def destroy
# @collection.destroy

head :no_content
end
# head :no_content
# end

private

Expand Down
26 changes: 14 additions & 12 deletions app/controllers/transcript_edits_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,22 +83,24 @@ def create
end

# PATCH/PUT /transcript_edits/1.json
def update
@transcript_edit = TranscriptEdit.find(params[:id])
# Note (jonjon): As per routes, this action is not included
# def update
# @transcript_edit = TranscriptEdit.find(params[:id])

if @transcript_edit.update(transcript_edit_params)
head :no_content
else
render json: @transcript_edit.errors, status: :unprocessable_entity
end
end
# if @transcript_edit.update(transcript_edit_params)
# head :no_content
# else
# render json: @transcript_edit.errors, status: :unprocessable_entity
# end
# end

# DELETE /transcript_edits/1.json
def destroy
@transcript_edit.destroy
# Note (jonjon): As per routes, this action is not included
# def destroy
# @transcript_edit.destroy

head :no_content
end
# head :no_content
# end

private

Expand Down
54 changes: 27 additions & 27 deletions app/controllers/transcript_speaker_edits_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@ class TranscriptSpeakerEditsController < ApplicationController
before_action :authenticate_user, only: [:create]

before_action :set_transcript_speaker_edit, only: [:show, :update, :destroy]
# Note (jonjon): As per the routes, only :create action is included
# # GET /transcript_speaker_edits.json
# def index
# @transcript_speaker_edits = []

# GET /transcript_speaker_edits.json
def index
@transcript_speaker_edits = []
# render json: @transcript_speaker_edits
# end

render json: @transcript_speaker_edits
end

# GET /transcript_speaker_edits/1.json
def show
@transcript_speaker_edit = nil
# # GET /transcript_speaker_edits/1.json
# def show
# @transcript_speaker_edit = nil

render json: @transcript_speaker_edit
end
# render json: @transcript_speaker_edit
# end

# POST /transcript_speaker_edits.json
def create
Expand Down Expand Up @@ -65,22 +65,22 @@ def create
end

# PATCH/PUT /transcript_speaker_edits/1.json
def update
@transcript_speaker_edit = TranscriptSpeakerEdit.find(params[:id])

if @transcript_speaker_edit.update(transcript_speaker_edit_params)
head :no_content
else
render json: @transcript_speaker_edit.errors, status: :unprocessable_entity
end
end

# DELETE /transcript_speaker_edits/1.json
def destroy
@transcript_speaker_edit.destroy

head :no_content
end
# def update
# @transcript_speaker_edit = TranscriptSpeakerEdit.find(params[:id])

# if @transcript_speaker_edit.update(transcript_speaker_edit_params)
# head :no_content
# else
# render json: @transcript_speaker_edit.errors, status: :unprocessable_entity
# end
# end

# # DELETE /transcript_speaker_edits/1.json
# def destroy
# @transcript_speaker_edit.destroy

# head :no_content
# end

private

Expand Down
52 changes: 52 additions & 0 deletions spec/controllers/admin/app_configs_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
require 'rails_helper'

RSpec.describe Admin::AppConfigsController, type: :controller do
render_views

let(:user) { create(:user, :admin, email: "user@email.com", password: "password") }
let!(:config) { AppConfig.instance }

before { sign_in user }

describe '#edit' do
it 'can view edit page' do
get :edit, params: { id: config.id }

page = response.body

expect(page).to have_content('Show theme')
expect(page).to have_content('Show institutions')
expect(page).to have_content('Main title')
expect(page).to have_content('Intro title')
expect(page).to have_content('Intro text')
expect(page).to have_content('Hero image')
expect(page).to include('Save')
end
end

describe '#update' do
it 'updates app config' do
params = {
id: config.id,
app_config: {
show_theme: true,
show_institutions: true,
main_title: 'Any title possible',
image: nil,
intro_title: 'Any intro title',
intro_text: 'Any intro text'
}
}

put :update, params: params
expect(response.body).to have_content('redirected')

config.reload
expect(config.show_theme).to be_truthy
expect(config.show_institutions).to be_truthy
expect(config.main_title).to eq 'Any title possible'
expect(config.intro_title).to eq 'Any intro title'
expect(config.intro_text).to eq 'Any intro text'
end
end
end
41 changes: 41 additions & 0 deletions spec/controllers/admin/collections_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
require 'rails_helper'

RSpec.describe CollectionsController, type: :controller do
render_views

let(:admin) { create(:user, :admin) }
let(:collection) { create(:collection) }
let!(:institution) { collection.institution }

before { sign_in admin }

let(:page) { response.body }

describe "#index" do
it "visits index page" do
create(:page, page_type: "collection")

get :index

expect(response).to have_http_status(:success)
end
end

describe "#list" do
it "visit list page" do
post :list, params: { institution_slug: institution.slug }, format: :js

expect(response).to have_http_status(:success)
end
end

describe "#show" do
it "visit show page" do
collection = create(:collection)

get :show, params: { id: collection.uid }, format: :json

expect(response).to have_http_status(:success)
end
end
end
104 changes: 104 additions & 0 deletions spec/controllers/admin/pages_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
require 'rails_helper'
include Rack::Test::Methods

RSpec.describe Admin::PagesController, type: :controller do
render_views

let(:user) { create(:user, :admin, email: "user@email.com", password: "password") }
let!(:page) { create(:page) }

before { sign_in user }

describe '#index' do
it 'list pages' do
get :index

expect(response.body).to include("Pages")
expect(response.body).to include("faq")
end
end

describe '#create' do
it 'create page' do
params = {
page: {
content: 'Any content',
page_type: 'about',
published: true,
admin_access: true
}
}

expect { post(:create, params: params ) }.to(
change { Page.count }
)
end
end

describe '#edit' do
it 'can view edit page' do
get :edit, params: { id: page.id }

expect(response.body).to include 'Editing Page'
expect(response.body).to include page.page_type
expect(response.body).to include page.content
end
end

describe '#show' do
it 'can preview page' do
get :show, params: { id: page.id }

expect(response.body).to include page.page_type
expect(response.body).to include page.content
end
end

describe '#update' do
it 'update page' do
params = {
id: page.id,
page: {
content: 'Any content',
page_type: 'faqs',
published: true,
admin_access: true
}
}

put(:update, params: params )

page.reload

expect(page.content).to eq 'Any content'
expect(page.page_type).to eq 'faqs'
end
end

describe '#destroy' do
it 'deletes a page' do
expect { delete :destroy, params: { id: page.id } }.to(
change { Page.count }.by(-1)
)
end
end

describe '#upload' do
it 'create page' do
params = {
id: page.id,
page: {
image: Rack::Test::UploadedFile.new("spec/fixtures/image.jpg", "image/jpg")
}
}

expect { post :upload, params: params }.to(
change { CmsImageUpload.count }.by(1)
)

response_json = JSON.parse(response.body)
expect(response_json['url']).to be_present
expect(response_json['upload_id']).to be_present
end
end
end
Loading