-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added tests for helpers/application_helper.rb
- Loading branch information
1 parent
27e66e7
commit 366bc44
Showing
1 changed file
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# frozen_string_literal: true | ||
|
||
# spec/helpers/application_helper_spec.rb | ||
|
||
require 'rails_helper' | ||
|
||
RSpec.describe ApplicationHelper, type: :helper do | ||
describe '#signed_in' do | ||
it 'returns true if admin is signed in' do | ||
session[:admin] = true | ||
expect(signed_in).to eq(true) | ||
end | ||
|
||
it 'returns submitter_id if submitter is signed in' do | ||
session[:submitter_id] = 5 | ||
expect(signed_in).to eq(5) | ||
end | ||
|
||
it 'returns nil if no one is signed in' do | ||
expect(signed_in).to be_nil | ||
end | ||
end | ||
|
||
describe '#shorten_long' do | ||
it 'shortens a long string' do | ||
expect(shorten_long('thisisaverylongstringwithmorecharacters')).to eq('thisisaverylongs... ') | ||
end | ||
|
||
it 'does not shorten a short string' do | ||
expect(shorten_long('short')).to eq('short ') | ||
end | ||
|
||
it 'returns an empty string if an empty string is provided' do | ||
expect(shorten_long('')).to eq('') | ||
end | ||
end | ||
|
||
describe '#csv_route' do | ||
it 'returns the correct csv route' do | ||
allow(ENV).to receive(:[]).with('RAILS_RELATIVE_URL_ROOT').and_return('/root') | ||
expect(csv_route('test')).to eq('/root/csv/test.csv') | ||
end | ||
|
||
it 'returns the correct csv route when ENV is not set' do | ||
allow(ENV).to receive(:[]).with('RAILS_RELATIVE_URL_ROOT').and_return(nil) | ||
expect(csv_route('test')).to eq('/csv/test.csv') | ||
end | ||
end | ||
|
||
describe '#page_route' do | ||
it 'returns the correct page route' do | ||
allow(ENV).to receive(:[]).with('RAILS_RELATIVE_URL_ROOT').and_return('/root') | ||
expect(page_route('test')).to eq('/root/pages/test') | ||
end | ||
|
||
it 'returns the correct page route when ENV is not set' do | ||
allow(ENV).to receive(:[]).with('RAILS_RELATIVE_URL_ROOT').and_return(nil) | ||
expect(page_route('test')).to eq('/pages/test') | ||
end | ||
end | ||
end |