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.
Files changed (119) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +11 -3
  3. data/app/assets/javascripts/spotlight/translation_progress.js +23 -0
  4. data/app/assets/stylesheets/spotlight/_spotlight.scss +2 -0
  5. data/app/assets/stylesheets/spotlight/_translations.scss +47 -0
  6. data/app/assets/stylesheets/spotlight/_utilities.scss +3 -0
  7. data/app/assets/stylesheets/spotlight/_variables.scss +5 -0
  8. data/app/controllers/concerns/spotlight/controller.rb +12 -1
  9. data/app/controllers/spotlight/about_pages_controller.rb +6 -0
  10. data/app/controllers/spotlight/browse_controller.rb +1 -1
  11. data/app/controllers/spotlight/catalog_controller.rb +6 -1
  12. data/app/controllers/spotlight/exhibits_controller.rb +10 -2
  13. data/app/controllers/spotlight/feature_pages_controller.rb +6 -0
  14. data/app/controllers/spotlight/filters_controller.rb +2 -2
  15. data/app/controllers/spotlight/home_pages_controller.rb +10 -0
  16. data/app/controllers/spotlight/languages_controller.rb +46 -0
  17. data/app/controllers/spotlight/pages_controller.rb +57 -3
  18. data/app/controllers/spotlight/solr_controller.rb +3 -3
  19. data/app/controllers/spotlight/translations_controller.rb +34 -0
  20. data/app/helpers/spotlight/application_helper.rb +1 -0
  21. data/app/helpers/spotlight/languages_helper.rb +33 -0
  22. data/app/helpers/spotlight/translations_helper.rb +13 -0
  23. data/app/models/concerns/spotlight/custom_translation_extension.rb +4 -0
  24. data/app/models/concerns/spotlight/translatables.rb +30 -0
  25. data/app/models/spotlight/ability.rb +5 -2
  26. data/app/models/spotlight/about_page.rb +1 -1
  27. data/app/models/spotlight/exhibit.rb +14 -6
  28. data/app/models/spotlight/feature_page.rb +1 -2
  29. data/app/models/spotlight/home_page.rb +1 -3
  30. data/app/models/spotlight/language.rb +24 -0
  31. data/app/models/spotlight/main_navigation.rb +12 -0
  32. data/app/models/spotlight/page.rb +53 -1
  33. data/app/models/spotlight/resources/upload.rb +6 -1
  34. data/app/models/spotlight/search.rb +4 -0
  35. data/app/services/spotlight/clone_translated_page_from_locale.rb +32 -0
  36. data/app/views/_user_util_links.html.erb +1 -0
  37. data/app/views/devise/mailer/invitation_instructions.html.erb +2 -2
  38. data/app/views/layouts/spotlight/spotlight.html.erb +2 -2
  39. data/app/views/shared/_curated_features_navbar.html.erb +2 -2
  40. data/app/views/spotlight/about_pages/_sidebar.html.erb +1 -1
  41. data/app/views/spotlight/admin_users/index.html.erb +1 -1
  42. data/app/views/spotlight/catalog/_edit_default.html.erb +1 -1
  43. data/app/views/spotlight/exhibits/_export.html.erb +1 -1
  44. data/app/views/spotlight/exhibits/_form.html.erb +1 -1
  45. data/app/views/spotlight/exhibits/_import.html.erb +2 -1
  46. data/app/views/spotlight/exhibits/_languages.html.erb +56 -0
  47. data/app/views/spotlight/exhibits/edit.html.erb +11 -5
  48. data/app/views/spotlight/feature_pages/_sidebar.html.erb +1 -1
  49. data/app/views/spotlight/filters/_form.html.erb +2 -1
  50. data/app/views/spotlight/resources/upload/_form.html.erb +1 -1
  51. data/app/views/spotlight/shared/_curation_sidebar.html.erb +5 -0
  52. data/app/views/spotlight/shared/_locale_picker.html.erb +14 -0
  53. data/app/views/spotlight/translations/_browse_categories.html.erb +67 -0
  54. data/app/views/spotlight/translations/_general.html.erb +176 -0
  55. data/app/views/spotlight/translations/_metadata.html.erb +67 -0
  56. data/app/views/spotlight/translations/_page.html.erb +45 -0
  57. data/app/views/spotlight/translations/_pages.html.erb +37 -0
  58. data/app/views/spotlight/translations/_pages_table.html.erb +15 -0
  59. data/app/views/spotlight/translations/_search_fields.html.erb +97 -0
  60. data/app/views/spotlight/translations/edit.html.erb +55 -0
  61. data/config/i18n-tasks.yml +81 -0
  62. data/config/locales/devise.en.yml +2 -1
  63. data/config/locales/spotlight.en.yml +657 -614
  64. data/config/routes.rb +19 -1
  65. data/db/migrate/20180308203409_create_spotlight_languages.rb +12 -0
  66. data/db/migrate/20180403130857_translation_uniqueness.rb +5 -0
  67. data/db/migrate/20180405044000_add_locale_to_pages.rb +6 -0
  68. data/db/migrate/20180406212516_add_default_locale_reference_to_spotlight_pages.rb +7 -0
  69. data/lib/generators/spotlight/templates/catalog_controller.rb +2 -2
  70. data/lib/generators/spotlight/templates/config/initializers/spotlight_initializer.rb +14 -4
  71. data/lib/generators/spotlight/templates/config/initializers/translation.rb +4 -2
  72. data/lib/migration/page_language.rb +27 -0
  73. data/lib/spotlight/engine.rb +32 -4
  74. data/lib/spotlight/upload_field_config.rb +27 -0
  75. data/lib/spotlight/version.rb +1 -1
  76. data/lib/tasks/spotlight_tasks.rake +6 -0
  77. data/spec/controllers/spotlight/about_pages_controller_spec.rb +67 -1
  78. data/spec/controllers/spotlight/feature_pages_controller_spec.rb +50 -0
  79. data/spec/controllers/spotlight/filters_controller_spec.rb +4 -4
  80. data/spec/controllers/spotlight/home_pages_controller_spec.rb +25 -0
  81. data/spec/controllers/spotlight/languages_controller_spec.rb +66 -0
  82. data/spec/controllers/spotlight/pages_controller_spec.rb +45 -0
  83. data/spec/controllers/spotlight/solr_controller_spec.rb +1 -1
  84. data/spec/controllers/spotlight/translations_controller_spec.rb +67 -0
  85. data/spec/examples.txt +1171 -1281
  86. data/spec/factories/exhibits.rb +1 -1
  87. data/spec/factories/language.rb +6 -0
  88. data/spec/factories/main_navigation.rb +7 -0
  89. data/spec/factories/searches.rb +1 -0
  90. data/spec/factories/tags.rb +1 -0
  91. data/spec/features/exhibits/language_create_edit_spec.rb +53 -0
  92. data/spec/features/exhibits/translation_editing_spec.rb +397 -0
  93. data/spec/features/javascript/locale_selector_spec.rb +61 -0
  94. data/spec/helpers/spotlight/languages_helper_spec.rb +73 -0
  95. data/spec/helpers/spotlight/translations_helper_spec.rb +16 -0
  96. data/spec/i18n_spec.rb +29 -0
  97. data/spec/lib/migration/page_language_spec.rb +21 -0
  98. data/spec/lib/spotlight/upload_field_config_spec.rb +24 -0
  99. data/spec/models/spotlight/ability_spec.rb +17 -4
  100. data/spec/models/spotlight/exhibit_spec.rb +49 -0
  101. data/spec/models/spotlight/language_spec.rb +41 -0
  102. data/spec/models/spotlight/page_spec.rb +109 -0
  103. data/spec/models/translation_spec.rb +11 -0
  104. data/spec/services/spotlight/clone_translated_page_from_locale_spec.rb +29 -0
  105. data/spec/spec_helper.rb +1 -13
  106. data/spec/support/disable_friendly_id_deprecation_warnings.rb +7 -6
  107. data/spec/test_app_templates/Gemfile.extra +3 -0
  108. data/spec/test_app_templates/catalog_controller.rb +31 -31
  109. data/spec/test_app_templates/lib/generators/test_app_generator.rb +9 -6
  110. data/spec/views/spotlight/contacts/edit.html.erb_spec.rb +13 -0
  111. data/spec/views/spotlight/exhibits/_form.html.erb_spec.rb +33 -0
  112. data/spec/views/spotlight/exhibits/edit.html.erb_spec.rb +4 -1
  113. data/spec/views/spotlight/resources/_external_resources_form.html.erb_spec.rb +13 -0
  114. data/spec/views/spotlight/resources/new.html.erb_spec.rb +10 -4
  115. data/spec/views/spotlight/translations/_page.html.erb_spec.rb +75 -0
  116. metadata +88 -28
  117. data/app/assets/javascripts/spotlight/sir-trevor.js +0 -0
  118. data/app/views/shared/_share_follow.html.erb +0 -5
  119. 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
@@ -0,0 +1,12 @@
1
+ class CreateSpotlightLanguages < ActiveRecord::Migration[5.0]
2
+ def change
3
+ create_table :spotlight_languages do |t|
4
+ t.string :locale, null: false
5
+ t.boolean :public
6
+ t.string :text
7
+ t.references :exhibit
8
+
9
+ t.timestamps
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,5 @@
1
+ class TranslationUniqueness < ActiveRecord::Migration[5.0]
2
+ def change
3
+ add_index(:translations, [:exhibit_id, :key, :locale], unique: true)
4
+ end
5
+ end
@@ -0,0 +1,6 @@
1
+ class AddLocaleToPages < ActiveRecord::Migration[5.0]
2
+ def change
3
+ add_column :spotlight_pages, :locale, :string, default: I18n.default_locale
4
+ add_index :spotlight_pages, :locale
5
+ end
6
+ end
@@ -0,0 +1,7 @@
1
+ class AddDefaultLocaleReferenceToSpotlightPages < ActiveRecord::Migration[5.0]
2
+ def change
3
+ change_table :spotlight_pages do |t|
4
+ t.references :default_locale_page
5
+ end
6
+ end
7
+ end
@@ -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: 'Everything'
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: 'Relevance'
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
- # OpenStruct.new(field_name: :spotlight_upload_description_tesim, label: 'Description', form_field_type: :text_area),
41
- # OpenStruct.new(field_name: :spotlight_upload_attribution_tesim, label: 'Attribution'),
42
- # OpenStruct.new(field_name: :spotlight_upload_date_tesim, label: 'Date')
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 # OpenStruct.new(...)
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
- # I18n.backend = I18n::Backend::ActiveRecord.new
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
- # I18n.backend = I18n::Backend::Chain.new(I18n.backend, I18n::Backend::Simple.new)
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
@@ -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 # OpenStruct.new(...)
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
- OpenStruct.new(field_name: config.upload_description_field, label: 'Description', form_field_type: :text_area),
134
- OpenStruct.new(field_name: :spotlight_upload_attribution_tesim, label: 'Attribution'),
135
- OpenStruct.new(field_name: :spotlight_upload_date_tesim, label: 'Date')
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
@@ -1,3 +1,3 @@
1
1
  module Spotlight
2
- VERSION = '1.5.1'.freeze
2
+ VERSION = '2.0.0.rc1'.freeze
3
3
  end
@@ -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