-
-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
85 additions
and
10 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,17 @@ | ||
module Admin::CitationsHelper | ||
ICONS = { | ||
journalism: '🗞️', | ||
campaigning: '📣', | ||
academic: '🎓', | ||
other: '🌐' | ||
}.with_indifferent_access.freeze | ||
|
||
def citation_icon(citation) | ||
html_attrs = { | ||
title: citation.type.humanize, | ||
class: "citation-icon citation-icon--#{citation.type}" | ||
} | ||
|
||
tag.span(ICONS.fetch(citation.type), **html_attrs) | ||
end | ||
end |
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
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
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
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
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,22 @@ | ||
class ChangeCitationTypeValues < ActiveRecord::Migration[7.0] | ||
CHANGES = { | ||
'news_story' => 'journalism', | ||
'academic_paper' => 'academic' | ||
} | ||
|
||
def up | ||
perform(CHANGES) | ||
end | ||
|
||
def down | ||
perform(CHANGES.invert) | ||
end | ||
|
||
private | ||
|
||
def perform(data) | ||
data.each_pair do |before, after| | ||
Citation.where(type: before).update_all(type: after) | ||
end | ||
end | ||
end |
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
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,27 @@ | ||
require 'spec_helper' | ||
|
||
RSpec.describe Admin::CitationsHelper do | ||
include Admin::CitationsHelper | ||
|
||
describe '#citation_icon' do | ||
subject { citation_icon(citation) } | ||
|
||
context 'with a journalism link' do | ||
let(:citation) { FactoryBot.build(:citation, type: 'journalism') } | ||
it { is_expected.to include('🗞️') } | ||
it { is_expected.to include('citation-icon--journalism') } | ||
end | ||
|
||
context 'with an academic link' do | ||
let(:citation) { FactoryBot.build(:citation, type: 'academic') } | ||
it { is_expected.to include('🎓') } | ||
it { is_expected.to include('citation-icon--academic') } | ||
end | ||
|
||
context 'with a generic link' do | ||
let(:citation) { FactoryBot.build(:citation, type: 'other') } | ||
it { is_expected.to include('🌐') } | ||
it { is_expected.to include('citation-icon--other') } | ||
end | ||
end | ||
end |
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