blacklight-spotlight 1.5.1 → 2.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +11 -3
- data/app/assets/javascripts/spotlight/translation_progress.js +23 -0
- data/app/assets/stylesheets/spotlight/_spotlight.scss +2 -0
- data/app/assets/stylesheets/spotlight/_translations.scss +47 -0
- data/app/assets/stylesheets/spotlight/_utilities.scss +3 -0
- data/app/assets/stylesheets/spotlight/_variables.scss +5 -0
- data/app/controllers/concerns/spotlight/controller.rb +12 -1
- data/app/controllers/spotlight/about_pages_controller.rb +6 -0
- data/app/controllers/spotlight/browse_controller.rb +1 -1
- data/app/controllers/spotlight/catalog_controller.rb +6 -1
- data/app/controllers/spotlight/exhibits_controller.rb +10 -2
- data/app/controllers/spotlight/feature_pages_controller.rb +6 -0
- data/app/controllers/spotlight/filters_controller.rb +2 -2
- data/app/controllers/spotlight/home_pages_controller.rb +10 -0
- data/app/controllers/spotlight/languages_controller.rb +46 -0
- data/app/controllers/spotlight/pages_controller.rb +57 -3
- data/app/controllers/spotlight/solr_controller.rb +3 -3
- data/app/controllers/spotlight/translations_controller.rb +34 -0
- data/app/helpers/spotlight/application_helper.rb +1 -0
- data/app/helpers/spotlight/languages_helper.rb +33 -0
- data/app/helpers/spotlight/translations_helper.rb +13 -0
- data/app/models/concerns/spotlight/custom_translation_extension.rb +4 -0
- data/app/models/concerns/spotlight/translatables.rb +30 -0
- data/app/models/spotlight/ability.rb +5 -2
- data/app/models/spotlight/about_page.rb +1 -1
- data/app/models/spotlight/exhibit.rb +14 -6
- data/app/models/spotlight/feature_page.rb +1 -2
- data/app/models/spotlight/home_page.rb +1 -3
- data/app/models/spotlight/language.rb +24 -0
- data/app/models/spotlight/main_navigation.rb +12 -0
- data/app/models/spotlight/page.rb +53 -1
- data/app/models/spotlight/resources/upload.rb +6 -1
- data/app/models/spotlight/search.rb +4 -0
- data/app/services/spotlight/clone_translated_page_from_locale.rb +32 -0
- data/app/views/_user_util_links.html.erb +1 -0
- data/app/views/devise/mailer/invitation_instructions.html.erb +2 -2
- data/app/views/layouts/spotlight/spotlight.html.erb +2 -2
- data/app/views/shared/_curated_features_navbar.html.erb +2 -2
- data/app/views/spotlight/about_pages/_sidebar.html.erb +1 -1
- data/app/views/spotlight/admin_users/index.html.erb +1 -1
- data/app/views/spotlight/catalog/_edit_default.html.erb +1 -1
- data/app/views/spotlight/exhibits/_export.html.erb +1 -1
- data/app/views/spotlight/exhibits/_form.html.erb +1 -1
- data/app/views/spotlight/exhibits/_import.html.erb +2 -1
- data/app/views/spotlight/exhibits/_languages.html.erb +56 -0
- data/app/views/spotlight/exhibits/edit.html.erb +11 -5
- data/app/views/spotlight/feature_pages/_sidebar.html.erb +1 -1
- data/app/views/spotlight/filters/_form.html.erb +2 -1
- data/app/views/spotlight/resources/upload/_form.html.erb +1 -1
- data/app/views/spotlight/shared/_curation_sidebar.html.erb +5 -0
- data/app/views/spotlight/shared/_locale_picker.html.erb +14 -0
- data/app/views/spotlight/translations/_browse_categories.html.erb +67 -0
- data/app/views/spotlight/translations/_general.html.erb +176 -0
- data/app/views/spotlight/translations/_metadata.html.erb +67 -0
- data/app/views/spotlight/translations/_page.html.erb +45 -0
- data/app/views/spotlight/translations/_pages.html.erb +37 -0
- data/app/views/spotlight/translations/_pages_table.html.erb +15 -0
- data/app/views/spotlight/translations/_search_fields.html.erb +97 -0
- data/app/views/spotlight/translations/edit.html.erb +55 -0
- data/config/i18n-tasks.yml +81 -0
- data/config/locales/devise.en.yml +2 -1
- data/config/locales/spotlight.en.yml +657 -614
- data/config/routes.rb +19 -1
- data/db/migrate/20180308203409_create_spotlight_languages.rb +12 -0
- data/db/migrate/20180403130857_translation_uniqueness.rb +5 -0
- data/db/migrate/20180405044000_add_locale_to_pages.rb +6 -0
- data/db/migrate/20180406212516_add_default_locale_reference_to_spotlight_pages.rb +7 -0
- data/lib/generators/spotlight/templates/catalog_controller.rb +2 -2
- data/lib/generators/spotlight/templates/config/initializers/spotlight_initializer.rb +14 -4
- data/lib/generators/spotlight/templates/config/initializers/translation.rb +4 -2
- data/lib/migration/page_language.rb +27 -0
- data/lib/spotlight/engine.rb +32 -4
- data/lib/spotlight/upload_field_config.rb +27 -0
- data/lib/spotlight/version.rb +1 -1
- data/lib/tasks/spotlight_tasks.rake +6 -0
- data/spec/controllers/spotlight/about_pages_controller_spec.rb +67 -1
- data/spec/controllers/spotlight/feature_pages_controller_spec.rb +50 -0
- data/spec/controllers/spotlight/filters_controller_spec.rb +4 -4
- data/spec/controllers/spotlight/home_pages_controller_spec.rb +25 -0
- data/spec/controllers/spotlight/languages_controller_spec.rb +66 -0
- data/spec/controllers/spotlight/pages_controller_spec.rb +45 -0
- data/spec/controllers/spotlight/solr_controller_spec.rb +1 -1
- data/spec/controllers/spotlight/translations_controller_spec.rb +67 -0
- data/spec/examples.txt +1171 -1281
- data/spec/factories/exhibits.rb +1 -1
- data/spec/factories/language.rb +6 -0
- data/spec/factories/main_navigation.rb +7 -0
- data/spec/factories/searches.rb +1 -0
- data/spec/factories/tags.rb +1 -0
- data/spec/features/exhibits/language_create_edit_spec.rb +53 -0
- data/spec/features/exhibits/translation_editing_spec.rb +397 -0
- data/spec/features/javascript/locale_selector_spec.rb +61 -0
- data/spec/helpers/spotlight/languages_helper_spec.rb +73 -0
- data/spec/helpers/spotlight/translations_helper_spec.rb +16 -0
- data/spec/i18n_spec.rb +29 -0
- data/spec/lib/migration/page_language_spec.rb +21 -0
- data/spec/lib/spotlight/upload_field_config_spec.rb +24 -0
- data/spec/models/spotlight/ability_spec.rb +17 -4
- data/spec/models/spotlight/exhibit_spec.rb +49 -0
- data/spec/models/spotlight/language_spec.rb +41 -0
- data/spec/models/spotlight/page_spec.rb +109 -0
- data/spec/models/translation_spec.rb +11 -0
- data/spec/services/spotlight/clone_translated_page_from_locale_spec.rb +29 -0
- data/spec/spec_helper.rb +1 -13
- data/spec/support/disable_friendly_id_deprecation_warnings.rb +7 -6
- data/spec/test_app_templates/Gemfile.extra +3 -0
- data/spec/test_app_templates/catalog_controller.rb +31 -31
- data/spec/test_app_templates/lib/generators/test_app_generator.rb +9 -6
- data/spec/views/spotlight/contacts/edit.html.erb_spec.rb +13 -0
- data/spec/views/spotlight/exhibits/_form.html.erb_spec.rb +33 -0
- data/spec/views/spotlight/exhibits/edit.html.erb_spec.rb +4 -1
- data/spec/views/spotlight/resources/_external_resources_form.html.erb_spec.rb +13 -0
- data/spec/views/spotlight/resources/new.html.erb_spec.rb +10 -4
- data/spec/views/spotlight/translations/_page.html.erb_spec.rb +75 -0
- metadata +88 -28
- data/app/assets/javascripts/spotlight/sir-trevor.js +0 -0
- data/app/views/shared/_share_follow.html.erb +0 -5
- data/config/locales/social_share_button.en.yml +0 -18
data/config/routes.rb
CHANGED
@@ -36,6 +36,7 @@ Spotlight::Engine.routes.draw do
|
|
36
36
|
resource :view_configuration, only: [:show]
|
37
37
|
|
38
38
|
resources :filters, only: [:create, :update]
|
39
|
+
resources :languages, only: [:create, :destroy]
|
39
40
|
|
40
41
|
concern :searchable, Blacklight::Routes::Searchable.new
|
41
42
|
|
@@ -95,7 +96,16 @@ Spotlight::Engine.routes.draw do
|
|
95
96
|
resources :tags, only: [:index, :destroy]
|
96
97
|
|
97
98
|
resources :contacts, only: [:edit, :update, :destroy]
|
99
|
+
|
100
|
+
resources :pages, only: [:update_all] do
|
101
|
+
collection do
|
102
|
+
patch :update_all
|
103
|
+
end
|
104
|
+
end
|
98
105
|
resources :about_pages, path: 'about' do
|
106
|
+
member do
|
107
|
+
get :clone
|
108
|
+
end
|
99
109
|
collection do
|
100
110
|
patch 'contacts' => 'about_pages#update_contacts'
|
101
111
|
resources :contacts, only: [:new, :create]
|
@@ -103,11 +113,18 @@ Spotlight::Engine.routes.draw do
|
|
103
113
|
end
|
104
114
|
end
|
105
115
|
resources :feature_pages, path: 'feature' do
|
116
|
+
member do
|
117
|
+
get :clone
|
118
|
+
end
|
106
119
|
collection do
|
107
120
|
patch :update_all
|
108
121
|
end
|
109
122
|
end
|
110
|
-
resource :home_page, path: 'home', controller: 'home_pages'
|
123
|
+
resource :home_page, path: 'home', controller: 'home_pages' do
|
124
|
+
member do
|
125
|
+
get :clone
|
126
|
+
end
|
127
|
+
end
|
111
128
|
post '/pages/:id/preview' => 'pages#preview', as: :preview_block
|
112
129
|
get '/pages' => 'pages#index', constraints: { format: 'json' }
|
113
130
|
|
@@ -119,6 +136,7 @@ Spotlight::Engine.routes.draw do
|
|
119
136
|
end
|
120
137
|
end
|
121
138
|
post 'solr/update' => 'solr#update'
|
139
|
+
resource :translations, only: [:edit, :update]
|
122
140
|
end
|
123
141
|
|
124
142
|
get '/:exhibit_id' => 'home_pages#show', as: :exhibit_root
|
@@ -17,9 +17,9 @@ class CatalogController < ApplicationController
|
|
17
17
|
# solr field configuration for search results/index views
|
18
18
|
config.index.title_field = 'full_title_tesim'
|
19
19
|
|
20
|
-
config.add_search_field 'all_fields', label: '
|
20
|
+
config.add_search_field 'all_fields', label: I18n.t('spotlight.search.fields.search.all_fields')
|
21
21
|
|
22
|
-
config.add_sort_field 'relevance', sort: 'score desc', label: '
|
22
|
+
config.add_sort_field 'relevance', sort: 'score desc', label: I18n.t('spotlight.search.fields.sort.relevance')
|
23
23
|
|
24
24
|
config.add_field_configuration_to_solr_request!
|
25
25
|
|
@@ -37,11 +37,21 @@
|
|
37
37
|
|
38
38
|
# ==> Uploaded item configuration
|
39
39
|
# Spotlight::Engine.config.upload_fields = [
|
40
|
-
#
|
41
|
-
#
|
42
|
-
#
|
40
|
+
# UploadFieldConfig.new(
|
41
|
+
# field_name: config.upload_description_field,
|
42
|
+
# label: -> { I18n.t(:"spotlight.search.fields.#{config.upload_description_field}") },
|
43
|
+
# form_field_type: :text_area
|
44
|
+
# ),
|
45
|
+
# UploadFieldConfig.new(
|
46
|
+
# field_name: :spotlight_upload_attribution_tesim,
|
47
|
+
# label: -> { I18n.t(:'spotlight.search.fields.spotlight_upload_attribution_tesim') }
|
48
|
+
# ),
|
49
|
+
# UploadFieldConfig.new(
|
50
|
+
# field_name: :spotlight_upload_date_tesim,
|
51
|
+
# label: -> { I18n.t(:'spotlight.search.fields.spotlight_upload_date_tesim') }
|
52
|
+
# )
|
43
53
|
# ]
|
44
|
-
# Spotlight::Engine.config.upload_title_field = nil #
|
54
|
+
# Spotlight::Engine.config.upload_title_field = nil # UploadFieldConfig.new(...)
|
45
55
|
# Spotlight::Engine.config.uploader_storage = :file
|
46
56
|
# Spotlight::Engine.config.allowed_upload_extensions = %w(jpg jpeg png)
|
47
57
|
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'i18n/backend/active_record'
|
2
|
+
require 'i18n/backend/fallbacks'
|
2
3
|
|
3
4
|
Translation = I18n::Backend::ActiveRecord::Translation
|
4
5
|
|
@@ -7,11 +8,12 @@ if Translation.table_exists?
|
|
7
8
|
# Sets up the new Spotlight Translation backend, backed by ActiveRecord. To
|
8
9
|
# turn on the ActiveRecord backend, uncomment the following lines.
|
9
10
|
|
10
|
-
|
11
|
+
I18n.backend = I18n::Backend::ActiveRecord.new
|
11
12
|
I18n::Backend::ActiveRecord.send(:include, I18n::Backend::Memoize)
|
12
13
|
Translation.send(:include, Spotlight::CustomTranslationExtension)
|
13
14
|
I18n::Backend::Simple.send(:include, I18n::Backend::Memoize)
|
14
15
|
I18n::Backend::Simple.send(:include, I18n::Backend::Pluralization)
|
16
|
+
I18n::Backend::Simple.send(:include, I18n::Backend::Fallbacks)
|
15
17
|
|
16
|
-
|
18
|
+
I18n.backend = I18n::Backend::Chain.new(I18n.backend, I18n::Backend::Simple.new)
|
17
19
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Migration
|
2
|
+
##
|
3
|
+
# This migration sets the Spotlight::Page locale to the I18n.default_locale.
|
4
|
+
# Needed for migrating Exhibits to internationalization work.
|
5
|
+
class PageLanguage
|
6
|
+
def self.run
|
7
|
+
new.run
|
8
|
+
end
|
9
|
+
|
10
|
+
def initialize; end
|
11
|
+
|
12
|
+
def run
|
13
|
+
migrate_pages
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def migrate_pages
|
19
|
+
FriendlyId::Slug.where(sluggable_type: 'Spotlight::Page').find_each do |slug|
|
20
|
+
unless /locale:\w+/ =~ slug.scope
|
21
|
+
slug.scope += ",locale:#{I18n.default_locale}"
|
22
|
+
slug.save
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/spotlight/engine.rb
CHANGED
@@ -13,6 +13,7 @@ require 'paper_trail'
|
|
13
13
|
require 'clipboard/rails'
|
14
14
|
require 'leaflet-rails'
|
15
15
|
require 'i18n/active_record'
|
16
|
+
require 'spotlight/upload_field_config'
|
16
17
|
|
17
18
|
module Spotlight
|
18
19
|
##
|
@@ -126,13 +127,23 @@ module Spotlight
|
|
126
127
|
config.thumbnail_field = :thumbnail_url_ssm
|
127
128
|
|
128
129
|
# Defaults to the blacklight_config.index.title_field:
|
129
|
-
config.upload_title_field = nil #
|
130
|
+
config.upload_title_field = nil # UploadFieldConfig.new(...)
|
130
131
|
config.upload_description_field = :spotlight_upload_description_tesim
|
131
132
|
|
132
133
|
config.upload_fields = [
|
133
|
-
|
134
|
-
|
135
|
-
|
134
|
+
UploadFieldConfig.new(
|
135
|
+
field_name: config.upload_description_field,
|
136
|
+
label: -> { I18n.t(:"spotlight.search.fields.#{config.upload_description_field}") },
|
137
|
+
form_field_type: :text_area
|
138
|
+
),
|
139
|
+
UploadFieldConfig.new(
|
140
|
+
field_name: :spotlight_upload_attribution_tesim,
|
141
|
+
label: -> { I18n.t(:'spotlight.search.fields.spotlight_upload_attribution_tesim') }
|
142
|
+
),
|
143
|
+
UploadFieldConfig.new(
|
144
|
+
field_name: :spotlight_upload_date_tesim,
|
145
|
+
label: -> { I18n.t(:'spotlight.search.fields.spotlight_upload_date_tesim') }
|
146
|
+
)
|
136
147
|
]
|
137
148
|
|
138
149
|
config.iiif_manifest_field = :iiif_manifest_url_ssi
|
@@ -176,6 +187,23 @@ module Spotlight
|
|
176
187
|
|
177
188
|
Blacklight::Engine.config.inject_blacklight_helpers = false
|
178
189
|
|
190
|
+
config.i18n_locales = {
|
191
|
+
de: 'Deutsch',
|
192
|
+
en: 'English',
|
193
|
+
es: 'Español',
|
194
|
+
fr: 'Français',
|
195
|
+
it: 'Italiano',
|
196
|
+
hu: 'Magyar',
|
197
|
+
nl: 'Nederlands',
|
198
|
+
'pt-br': 'Português brasileiro',
|
199
|
+
sq: 'Shqip',
|
200
|
+
zh: '中文'
|
201
|
+
}
|
202
|
+
|
203
|
+
# Whitelisting the available_locales is necessary here, as any dependency we
|
204
|
+
# add could add an available locale which could break things if unexpected.
|
205
|
+
config.i18n.available_locales = config.i18n_locales.keys
|
206
|
+
|
179
207
|
# Query parameters for autocomplete requests
|
180
208
|
config.autocomplete_search_field = 'autocomplete'
|
181
209
|
config.default_autocomplete_params = { qf: 'id^1000 full_title_tesim^100 id_ng full_title_ng',
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Spotlight
|
4
|
+
##
|
5
|
+
# A class to model the configuration required to build the Document Upload form.
|
6
|
+
# This configuration is also used in other places around the application (e.g. Metadata Field Config)
|
7
|
+
# See Spotlight::Engine.config.upload_fields for where this is consumed
|
8
|
+
# We should look into changing this to a standard blacklight field config in Blacklight 7
|
9
|
+
class UploadFieldConfig
|
10
|
+
attr_reader :blacklight_options, :field_name, :form_field_type
|
11
|
+
def initialize(blacklight_options: {}, field_name:, form_field_type: :text_field, label: nil)
|
12
|
+
@blacklight_options = blacklight_options
|
13
|
+
@field_name = field_name
|
14
|
+
@form_field_type = form_field_type
|
15
|
+
@label = label || field_name
|
16
|
+
end
|
17
|
+
|
18
|
+
# aliasing for backwards compatability and consistency with blacklight config
|
19
|
+
alias solr_field field_name
|
20
|
+
|
21
|
+
# Allows a proc to be set as the label
|
22
|
+
def label
|
23
|
+
return @label.call if @label.is_a?(Proc)
|
24
|
+
@label
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/spotlight/version.rb
CHANGED
@@ -69,6 +69,12 @@ namespace :spotlight do
|
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
72
|
+
desc 'Migrate page\'s FriendlyId::Slug to a scoped language'
|
73
|
+
task migrate_pages_language: :environment do
|
74
|
+
require 'migration/page_language'
|
75
|
+
Migration::PageLanguage.run
|
76
|
+
end
|
77
|
+
|
72
78
|
def prompt_to_create_user
|
73
79
|
Spotlight::Engine.user_class.find_or_create_by!(email: prompt_for_email) do |u|
|
74
80
|
puts 'User not found. Enter a password to create the user.'
|
@@ -3,13 +3,23 @@ describe Spotlight::AboutPagesController, type: :controller, versioning: true do
|
|
3
3
|
let(:valid_attributes) { { 'title' => 'MyString', thumbnail: { iiif_url: '' } } }
|
4
4
|
|
5
5
|
describe 'when not logged in' do
|
6
|
+
let(:exhibit) { FactoryBot.create(:exhibit) }
|
6
7
|
describe 'POST update_all' do
|
7
|
-
let(:exhibit) { FactoryBot.create(:exhibit) }
|
8
8
|
it 'is not allowed' do
|
9
9
|
post :update_all, params: { exhibit_id: exhibit }
|
10
10
|
expect(response).to redirect_to main_app.new_user_session_path
|
11
11
|
end
|
12
12
|
end
|
13
|
+
|
14
|
+
describe 'GET clone' do
|
15
|
+
let(:page) { FactoryBot.create(:about_page, exhibit: exhibit) }
|
16
|
+
|
17
|
+
it 'is not allowed' do
|
18
|
+
get :clone, params: { exhibit_id: exhibit.id, id: page.id, language: 'es' }
|
19
|
+
expect(flash['alert']).to eq 'You need to sign in or sign up before continuing.'
|
20
|
+
expect(response).to redirect_to main_app.new_user_session_path
|
21
|
+
end
|
22
|
+
end
|
13
23
|
end
|
14
24
|
|
15
25
|
describe 'when signed in as a curator' do
|
@@ -39,6 +49,50 @@ describe Spotlight::AboutPagesController, type: :controller, versioning: true do
|
|
39
49
|
expect(assigns(:exhibit)).to eq exhibit
|
40
50
|
end
|
41
51
|
end
|
52
|
+
|
53
|
+
describe 'under a non-default locale' do
|
54
|
+
let!(:page_es) do
|
55
|
+
FactoryBot.create(
|
56
|
+
:about_page,
|
57
|
+
title: page.title,
|
58
|
+
weight: 0,
|
59
|
+
exhibit: exhibit,
|
60
|
+
locale: 'es',
|
61
|
+
default_locale_page: page
|
62
|
+
)
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'renders the locale specific page' do
|
66
|
+
get :show, params: { exhibit_id: exhibit.id, id: page.slug, locale: 'es' }
|
67
|
+
|
68
|
+
expect(assigns[:page]).to eq page_es
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
describe 'when "switching" locales for pages that have updated their title/slug' do
|
73
|
+
let(:page) { FactoryBot.create(:about_page, exhibit: exhibit) }
|
74
|
+
let!(:page_es) do
|
75
|
+
FactoryBot.create(
|
76
|
+
:about_page,
|
77
|
+
exhibit: exhibit,
|
78
|
+
title: 'Page in spanish',
|
79
|
+
locale: 'es',
|
80
|
+
default_locale_page: page
|
81
|
+
)
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'redirects from the spanish slug to the english page when the english locale is selected' do
|
85
|
+
expect(page_es.slug).not_to eq page.slug # Ensure the slugs are different
|
86
|
+
get :show, params: { exhibit_id: exhibit.id, id: page_es.slug, locale: 'en' }
|
87
|
+
expect(response).to redirect_to(exhibit_about_page_path(exhibit, page))
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'redirects from the english slug to the spanish page when the spanish locale is selected' do
|
91
|
+
expect(page_es.slug).not_to eq page.slug # Ensure the slugs are different
|
92
|
+
get :show, params: { exhibit_id: exhibit.id, id: page.slug, locale: 'es' }
|
93
|
+
expect(response).to redirect_to(exhibit_about_page_path(exhibit, page_es))
|
94
|
+
end
|
95
|
+
end
|
42
96
|
end
|
43
97
|
|
44
98
|
describe 'GET edit' do
|
@@ -150,5 +204,17 @@ describe Spotlight::AboutPagesController, type: :controller, versioning: true do
|
|
150
204
|
expect(response).to render_template('index')
|
151
205
|
end
|
152
206
|
end
|
207
|
+
|
208
|
+
describe 'GET clone' do
|
209
|
+
let(:page) { FactoryBot.create(:about_page, exhibit: exhibit) }
|
210
|
+
|
211
|
+
it 'calls the CloneTranslatedPageFromLocale service' do
|
212
|
+
expect(
|
213
|
+
Spotlight::CloneTranslatedPageFromLocale
|
214
|
+
).to receive(:call).with(locale: 'es', page: page).and_call_original
|
215
|
+
|
216
|
+
get :clone, params: { exhibit_id: exhibit.id, id: page.id, language: 'es' }
|
217
|
+
end
|
218
|
+
end
|
153
219
|
end
|
154
220
|
end
|
@@ -1,6 +1,19 @@
|
|
1
1
|
describe Spotlight::FeaturePagesController, type: :controller, versioning: true do
|
2
2
|
routes { Spotlight::Engine.routes }
|
3
3
|
|
4
|
+
describe 'when not logged in' do
|
5
|
+
let(:exhibit) { FactoryBot.create(:exhibit) }
|
6
|
+
describe 'GET clone' do
|
7
|
+
let(:page) { FactoryBot.create(:feature_page, exhibit: exhibit) }
|
8
|
+
|
9
|
+
it 'is not allowed' do
|
10
|
+
get :clone, params: { exhibit_id: exhibit.id, id: page.id, language: 'es' }
|
11
|
+
expect(flash['alert']).to eq 'You need to sign in or sign up before continuing.'
|
12
|
+
expect(response).to redirect_to main_app.new_user_session_path
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
4
17
|
# This should return the minimal set of attributes required to create a valid
|
5
18
|
# Page. As you add validations to Page, be sure to
|
6
19
|
# adjust the attributes here as well.
|
@@ -42,6 +55,31 @@ describe Spotlight::FeaturePagesController, type: :controller, versioning: true
|
|
42
55
|
expect(assigns(:page)).to eq(page)
|
43
56
|
end
|
44
57
|
end
|
58
|
+
|
59
|
+
describe 'when "switching" locales for pages that have updated their title/slug' do
|
60
|
+
let(:page) { FactoryBot.create(:feature_page, exhibit: exhibit) }
|
61
|
+
let!(:page_es) do
|
62
|
+
FactoryBot.create(
|
63
|
+
:feature_page,
|
64
|
+
exhibit: exhibit,
|
65
|
+
title: 'Page in spanish',
|
66
|
+
locale: 'es',
|
67
|
+
default_locale_page: page
|
68
|
+
)
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'redirects from the spanish slug to the english page when the english locale is selected' do
|
72
|
+
expect(page_es.slug).not_to eq page.slug # Ensure the slugs are different
|
73
|
+
get :show, params: { exhibit_id: exhibit.id, id: page_es.slug, locale: 'en' }
|
74
|
+
expect(response).to redirect_to(exhibit_feature_page_path(exhibit, page))
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'redirects from the english slug to the spanish page when the spanish locale is selected' do
|
78
|
+
expect(page_es.slug).not_to eq page.slug # Ensure the slugs are different
|
79
|
+
get :show, params: { exhibit_id: exhibit.id, id: page.slug, locale: 'es' }
|
80
|
+
expect(response).to redirect_to(exhibit_feature_page_path(exhibit, page_es))
|
81
|
+
end
|
82
|
+
end
|
45
83
|
end
|
46
84
|
|
47
85
|
describe 'GET new' do
|
@@ -166,5 +204,17 @@ describe Spotlight::FeaturePagesController, type: :controller, versioning: true
|
|
166
204
|
expect(response).to redirect_to(exhibit_feature_pages_path(page.exhibit))
|
167
205
|
end
|
168
206
|
end
|
207
|
+
|
208
|
+
describe 'GET clone' do
|
209
|
+
let!(:page) { FactoryBot.create(:feature_page, exhibit: exhibit) }
|
210
|
+
|
211
|
+
it 'calls the CloneTranslatedPageFromLocale service' do
|
212
|
+
expect(
|
213
|
+
Spotlight::CloneTranslatedPageFromLocale
|
214
|
+
).to receive(:call).with(locale: 'es', page: page).and_call_original
|
215
|
+
|
216
|
+
get :clone, params: { exhibit_id: exhibit.id, id: page.id, language: 'es' }
|
217
|
+
end
|
218
|
+
end
|
169
219
|
end
|
170
220
|
end
|