Skip to content

Commit

Permalink
Merge pull request #529 from commercekitchen/develop
Browse files Browse the repository at this point in the history
Custom Footer Link languages
  • Loading branch information
tmichaelreis authored Aug 23, 2021
2 parents b30f505 + bc847fd commit 7328f9a
Show file tree
Hide file tree
Showing 16 changed files with 87 additions and 36 deletions.
2 changes: 1 addition & 1 deletion app/controllers/admin/footer_links_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def destroy
private

def footer_link_params
params.require(:footer_link).permit(:label, :url)
params.require(:footer_link).permit(:label, :url, :language_id)
end
end
end
2 changes: 1 addition & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def set_cms_footer_pages
org_id = current_organization.id

@footer_pages = CmsPage.where(pub_status: 'P', language: current_language, organization_id: org_id, audience: user_audience_list)
@footer_links = FooterLink.where(organization_id: org_id)
@footer_links = FooterLink.where(organization_id: org_id, language: current_language)
end

def set_cms_marketing_pages
Expand Down
1 change: 1 addition & 0 deletions app/models/footer_link.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class FooterLink < ApplicationRecord
belongs_to :organization
belongs_to :language

validates :label, presence: true
validates :url, presence: true
Expand Down
3 changes: 3 additions & 0 deletions app/views/admin/footer_links/_footer_link_row.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
<div class="resource-cell">
<%= link.url %>
</div>
<div class="resource-cell">
<%= link.language.name %>
</div>
<div class="resource-cell">
<%= link_to 'Delete', admin_footer_link_path(link), method: :delete, remote: true, data: { confirm: "Delete #{link.label} (#{link.url})?" }, id: "delete_footer_link_link_#{link.id}" %>
</div>
Expand Down
3 changes: 2 additions & 1 deletion app/views/admin/footer_links/create.js.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
$('#footer_link_list').append("<%= escape_javascript(render partial: 'footer_link_row', locals: { link: @link }) %>");
$('#footer_link_section').append("<%= escape_javascript(render partial: "shared/layout/footer_link", locals: { link: @link }) %>");
$('#footer_link_label').val('');
$('#footer_link_url').val('');
$('#footer_link_url').val('');
$('#footer_link_language_id').val(<%= Language.first.id %>); // Reset language to default
4 changes: 4 additions & 0 deletions app/views/admin/footer_links/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
<%= f.label :url, "URL", class: "plain" %>
<%= f.text_field :url %>
</div>
<div class="inline-input">
<%= f.label :language_id, "Language", class: "plain" %>
<%= f.collection_select :language_id, Language.all, :id, :name, { selected: Language.find_by(name: "English") } %>
</div>
<%= f.submit "Add Link", class: "skinny" %>
</div>
</fieldset>
Expand Down
4 changes: 2 additions & 2 deletions config/locales/es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -265,10 +265,10 @@ es:
practice_skills: "Ahora usar mis habilidades"
there_are_no_notes_for_course: "No hay notas o recursos de los asociados para este curso"
certificate:
this_award: "Este certificado acredita que ha completado"
this_award: "Este certificado acredita que"
name_fill: "_____________________"
name_fill_long: "_________________________________________"
has_completed: "ha completado el curso de"
has_completed: "ha completado"
as_of: "el"
att:
disclaimer: "<strong>Exención de responsabilidad:</strong> Ninguna de las otras compañías cuyos nombres o logotipos aparecen en estos materiales educativos han participado en la creación de estos materiales, ni los han aprobado ni patrocinado. Tampoco están afiliadas de ninguna manera con estos materiales."
Expand Down
1 change: 1 addition & 0 deletions db/migrate/20190509152342_add_organization_id_to_course.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
class AddOrganizationIdToCourse < ActiveRecord::Migration[4.2]
def change
add_reference :courses, :organization, index: true

OrganizationCourse.find_each do |org_course|
next if org_course.course.nil?
org_course.course.update(organization: org_course.organization)
Expand Down
6 changes: 6 additions & 0 deletions db/migrate/20210823165603_add_language_to_footer_links.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class AddLanguageToFooterLinks < ActiveRecord::Migration[5.2]
def change
add_reference :footer_links, :language, index: true
add_foreign_key :footer_links, :languages
end
end
38 changes: 19 additions & 19 deletions db/structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -389,15 +389,6 @@ CREATE SEQUENCE public.courses_id_seq
ALTER SEQUENCE public.courses_id_seq OWNED BY public.courses.id;


--
-- Name: data_migrations; Type: TABLE; Schema: public; Owner: -
--

CREATE TABLE public.data_migrations (
version character varying NOT NULL
);


--
-- Name: footer_links; Type: TABLE; Schema: public; Owner: -
--
Expand All @@ -408,7 +399,8 @@ CREATE TABLE public.footer_links (
label character varying NOT NULL,
url character varying NOT NULL,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL
updated_at timestamp without time zone NOT NULL,
language_id bigint
);


Expand Down Expand Up @@ -1299,14 +1291,6 @@ ALTER TABLE ONLY public.courses
ADD CONSTRAINT courses_pkey PRIMARY KEY (id);


--
-- Name: data_migrations data_migrations_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.data_migrations
ADD CONSTRAINT data_migrations_pkey PRIMARY KEY (version);


--
-- Name: footer_links footer_links_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
Expand Down Expand Up @@ -1507,6 +1491,13 @@ CREATE INDEX index_courses_on_slug ON public.courses USING btree (slug);
CREATE INDEX index_courses_on_title ON public.courses USING btree (title);


--
-- Name: index_footer_links_on_language_id; Type: INDEX; Schema: public; Owner: -
--

CREATE INDEX index_footer_links_on_language_id ON public.footer_links USING btree (language_id);


--
-- Name: index_footer_links_on_organization_id; Type: INDEX; Schema: public; Owner: -
--
Expand Down Expand Up @@ -1736,6 +1727,14 @@ ALTER TABLE ONLY public.users
ADD CONSTRAINT fk_rails_b517ecf66a FOREIGN KEY (partner_id) REFERENCES public.partners(id);


--
-- Name: footer_links fk_rails_bd7708fd9c; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY public.footer_links
ADD CONSTRAINT fk_rails_bd7708fd9c FOREIGN KEY (language_id) REFERENCES public.languages(id);


--
-- Name: lesson_completions fk_rails_d03dba97f9; Type: FK CONSTRAINT; Schema: public; Owner: -
--
Expand Down Expand Up @@ -1887,6 +1886,7 @@ INSERT INTO "schema_migrations" (version) VALUES
('20200618155234'),
('20200707133604'),
('20210726182520'),
('20210812220205');
('20210812220205'),
('20210823165603');


2 changes: 1 addition & 1 deletion spec/controllers/admin/footer_links_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
end

describe 'POST #create' do
let(:link_params) { { label: 'Test Link', url: 'https://example.com' } }
let(:link_params) { { label: 'Test Link', url: 'https://example.com', language_id: @english.id } }

it 'should create a footer link' do
expect do
Expand Down
1 change: 1 addition & 0 deletions spec/factories/footer_links.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
organization
label { Faker::Lorem.sentence(word_count: 3) }
url { Faker::Internet.url }
language
end
end
26 changes: 20 additions & 6 deletions spec/features/admin/footer_link_management_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,15 @@
expect(page).to have_content('These links will appear in addition to any of your subsite\'s CMS Pages in the "LEARN MORE" section of the footer.')
end

scenario 'admin sees existing footer links' do
scenario 'admin sees existing footer link entries' do
link = FactoryBot.create(:footer_link, organization: organization)
visit admin_footer_links_path
expect(page).to have_content link.label
expect(page).to have_content link.url

within('#footer_link_list') do
expect(page).to have_content link.label
expect(page).to have_content link.url
expect(page).to have_content 'English'
end
end

scenario 'admin can add new footer link', js: true do
Expand All @@ -32,12 +36,22 @@
visit admin_footer_links_path
fill_in 'Label', with: label
fill_in 'URL', with: url
expect(page).to have_select('Language', selected: 'English')
select 'Spanish', from: 'Language'
click_on 'Add Link'
expect(page).to have_content label
expect(page).to have_link(label, href: url)
expect(page).to have_content url

within('#footer_link_list') do
expect(page).to have_content label
expect(page).to have_content url
expect(page).to have_content 'Spanish'
end

expect(page).to have_field('Label', with: '')
expect(page).to have_field('URL', with: '')
expect(page).to have_select('Language', selected: 'English')

# Link in footer
expect(page).to have_link(label, href: url)
end

scenario 'admin can delete existing footer link', js: true do
Expand Down
8 changes: 4 additions & 4 deletions spec/features/user/user_completes_course_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@
visit course_completion_path(course)
click_link 'Español'

message = "Este diploma certifica que\n"\
message = "Este certificado acredita que\n"\
"#{user.full_name}\n"\
"ha completado el curso de\n"\
"ha completado\n"\
"#{course.title}\n"\
'el 10/3/2021'
expect(page).to have_content(message)
Expand Down Expand Up @@ -103,9 +103,9 @@
visit course_completion_path(course)
click_link 'Español'

message = "Este diploma certifica que\n"\
message = "Este certificado acredita que\n"\
"_____________________\n"\
"ha completado el curso de\n"\
"ha completado\n"\
"#{course.title}\n"\
'el 10/3/2021'
expect(page).to have_content(message)
Expand Down
17 changes: 16 additions & 1 deletion spec/features/user/user_walkthrough_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,28 @@
let!(:link2) { FactoryBot.create(:footer_link, organization: org) }
let!(:other_org_link) { FactoryBot.create(:footer_link) }
let!(:cms_page) { FactoryBot.create(:cms_page, organization: org, pub_status: 'P') }
let!(:other_org_cms_page) { FactoryBot.create(:cms_page, pub_status: 'P') }
let!(:spanish_cms_page) { FactoryBot.create(:cms_page, organization: org, pub_status: 'P', language: @spanish) }
let!(:spanish_link) { FactoryBot.create(:footer_link, organization: org, language: @spanish) }

scenario 'correct LEARN MORE links display' do
scenario 'english LEARN MORE links display' do
visit root_path
expect(page).to have_link(cms_page.title, href: cms_page_path(cms_page))
expect(page).to have_link(link1.label, href: link1.url)
expect(page).to have_link(link2.label, href: link2.url)
expect(page).not_to have_link(other_org_link.label)
expect(page).not_to have_link(other_org_cms_page.title)
expect(page).not_to have_link(spanish_cms_page.title)
expect(page).not_to have_link(spanish_link.label)
end

scenario 'spanish LEARN MORE links display' do
visit root_path
click_link 'Español'
expect(page).to have_link(spanish_cms_page.title)
expect(page).to have_link(spanish_link.label)
expect(page).not_to have_link(cms_page.title)
expect(page).not_to have_link(link1.label)
end
end

Expand Down
5 changes: 5 additions & 0 deletions spec/models/footer_link_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,9 @@
link.organization = nil
expect(link).not_to be_valid
end

it 'should require a language' do
link.language = nil
expect(link).not_to be_valid
end
end

0 comments on commit 7328f9a

Please sign in to comment.