From ee15295f54b5c4e165506b43f4e801a3db92fa90 Mon Sep 17 00:00:00 2001 From: Marko Lovic Date: Thu, 2 Aug 2018 15:43:00 +0200 Subject: [PATCH 01/10] Add migration for all collaborative legislation translations --- ..._collaborative_legislation_translations.rb | 33 ++++++++++++ db/schema.rb | 51 +++++++++++++++++++ 2 files changed, 84 insertions(+) create mode 100644 db/migrate/20180801140800_add_collaborative_legislation_translations.rb diff --git a/db/migrate/20180801140800_add_collaborative_legislation_translations.rb b/db/migrate/20180801140800_add_collaborative_legislation_translations.rb new file mode 100644 index 000000000..7c0fb9eb3 --- /dev/null +++ b/db/migrate/20180801140800_add_collaborative_legislation_translations.rb @@ -0,0 +1,33 @@ +class AddCollaborativeLegislationTranslations < ActiveRecord::Migration + + def self.up + Legislation::Process.create_translation_table!( + title: :string, + summary: :text, + description: :text, + additional_info: :text, + ) + + Legislation::Question.create_translation_table!( + title: :text + ) + + Legislation::DraftVersion.create_translation_table!( + title: :string, + changelog: :text, + body: :text, + body_html: :text, + toc_html: :text + ) + Legislation::QuestionOption.create_translation_table!( + value: :string + ) + end + + def self.down + Legislation::Process.drop_translation_table! + Legislation::DraftVersion.drop_translation_table! + Legislation::Question.drop_translation_table! + Legislation::QuestionOption.drop_translation_table! + end +end diff --git a/db/schema.rb b/db/schema.rb index b6370693a..9f3d4b22b 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -575,6 +575,21 @@ ActiveRecord::Schema.define(version: 20180813141443) do add_index "legislation_answers", ["legislation_question_option_id"], name: "index_legislation_answers_on_legislation_question_option_id", using: :btree add_index "legislation_answers", ["user_id"], name: "index_legislation_answers_on_user_id", using: :btree + create_table "legislation_draft_version_translations", force: :cascade do |t| + t.integer "legislation_draft_version_id", null: false + t.string "locale", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.text "title" + t.text "changelog" + t.text "body" + t.text "body_html" + t.text "toc_html" + end + + add_index "legislation_draft_version_translations", ["legislation_draft_version_id"], name: "index_900e5ba94457606e69e89193db426e8ddff809bc", using: :btree + add_index "legislation_draft_version_translations", ["locale"], name: "index_legislation_draft_version_translations_on_locale", using: :btree + create_table "legislation_draft_versions", force: :cascade do |t| t.integer "legislation_process_id" t.string "title" @@ -593,6 +608,20 @@ ActiveRecord::Schema.define(version: 20180813141443) do add_index "legislation_draft_versions", ["legislation_process_id"], name: "index_legislation_draft_versions_on_legislation_process_id", using: :btree add_index "legislation_draft_versions", ["status"], name: "index_legislation_draft_versions_on_status", using: :btree + create_table "legislation_process_translations", force: :cascade do |t| + t.integer "legislation_process_id", null: false + t.string "locale", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.string "title" + t.text "summary" + t.text "description" + t.text "additional_info" + end + + add_index "legislation_process_translations", ["legislation_process_id"], name: "index_199e5fed0aca73302243f6a1fca885ce10cdbb55", using: :btree + add_index "legislation_process_translations", ["locale"], name: "index_legislation_process_translations_on_locale", using: :btree + create_table "legislation_processes", force: :cascade do |t| t.string "title" t.text "description" @@ -662,6 +691,17 @@ ActiveRecord::Schema.define(version: 20180813141443) do add_index "legislation_proposals", ["legislation_process_id"], name: "index_legislation_proposals_on_legislation_process_id", using: :btree + create_table "legislation_question_option_translations", force: :cascade do |t| + t.integer "legislation_question_option_id", null: false + t.string "locale", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.string "value" + end + + add_index "legislation_question_option_translations", ["legislation_question_option_id"], name: "index_61bcec8729110b7f8e1e9e5ce08780878597a209", using: :btree + add_index "legislation_question_option_translations", ["locale"], name: "index_legislation_question_option_translations_on_locale", using: :btree + create_table "legislation_question_options", force: :cascade do |t| t.integer "legislation_question_id" t.string "value" @@ -674,6 +714,17 @@ ActiveRecord::Schema.define(version: 20180813141443) do add_index "legislation_question_options", ["hidden_at"], name: "index_legislation_question_options_on_hidden_at", using: :btree add_index "legislation_question_options", ["legislation_question_id"], name: "index_legislation_question_options_on_legislation_question_id", using: :btree + create_table "legislation_question_translations", force: :cascade do |t| + t.integer "legislation_question_id", null: false + t.string "locale", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.text "title" + end + + add_index "legislation_question_translations", ["legislation_question_id"], name: "index_d34cc1e1fe6d5162210c41ce56533c5afabcdbd3", using: :btree + add_index "legislation_question_translations", ["locale"], name: "index_legislation_question_translations_on_locale", using: :btree + create_table "legislation_questions", force: :cascade do |t| t.integer "legislation_process_id" t.text "title" From d78aea1fd3c498d5d1e92b03fc06fd725947a0dc Mon Sep 17 00:00:00 2001 From: Marko Lovic Date: Thu, 2 Aug 2018 16:05:16 +0200 Subject: [PATCH 02/10] Make Legistlation Processes translatable --- .../admin/legislation/processes_controller.rb | 7 ++++ app/models/legislation/process.rb | 6 ++++ .../legislation/processes/_form.html.erb | 34 +++++++++---------- .../admin/legislation/processes_spec.rb | 13 ++++--- 4 files changed, 39 insertions(+), 21 deletions(-) diff --git a/app/controllers/admin/legislation/processes_controller.rb b/app/controllers/admin/legislation/processes_controller.rb index 976318958..2cb20d0ba 100644 --- a/app/controllers/admin/legislation/processes_controller.rb +++ b/app/controllers/admin/legislation/processes_controller.rb @@ -1,4 +1,6 @@ class Admin::Legislation::ProcessesController < Admin::Legislation::BaseController + include Translatable + has_filters %w{open next past all}, only: :index load_and_authorize_resource :process, class: "Legislation::Process" @@ -61,6 +63,7 @@ class Admin::Legislation::ProcessesController < Admin::Legislation::BaseControll :result_publication_enabled, :published, :custom_list, + *translation_params(Legislation::Process), documents_attributes: [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy] ) end @@ -69,4 +72,8 @@ class Admin::Legislation::ProcessesController < Admin::Legislation::BaseControll @process.set_tag_list_on(:customs, process_params[:custom_list]) @process.save end + + def resource + @process || Legislation::Process.find(params[:id]) + end end diff --git a/app/models/legislation/process.rb b/app/models/legislation/process.rb index ff683aa00..39c3cb8e6 100644 --- a/app/models/legislation/process.rb +++ b/app/models/legislation/process.rb @@ -9,6 +9,12 @@ class Legislation::Process < ActiveRecord::Base acts_as_paranoid column: :hidden_at acts_as_taggable_on :customs + translates :title, touch: :true + translates :summary, touch: :true + translates :description, touch: :true + translates :additional_info, touch: :true + globalize_accessors + PHASES_AND_PUBLICATIONS = %i(debate_phase allegations_phase proposals_phase draft_publication result_publication).freeze has_many :draft_versions, -> { order(:id) }, class_name: 'Legislation::DraftVersion', diff --git a/app/views/admin/legislation/processes/_form.html.erb b/app/views/admin/legislation/processes/_form.html.erb index a0010c8ba..9eb587777 100644 --- a/app/views/admin/legislation/processes/_form.html.erb +++ b/app/views/admin/legislation/processes/_form.html.erb @@ -1,4 +1,6 @@ -<%= form_for [:admin, @process], html: {data: {watch_changes: true}} do |f| %> +<%= render "admin/shared/globalize_locales", resource: @process %> + +<%= translatable_form_for [:admin, @process], html: {data: {watch_changes: true}} do |f| %> <% if @process.errors.any? %> @@ -172,37 +174,35 @@
- <%= f.label :title %> - <%= f.text_field :title, - label: false, - placeholder: t("admin.legislation.processes.form.title_placeholder") %> + <%= f.translatable_text_field :title, + placeholder: t("admin.legislation.processes.form.title_placeholder") %>
<%= f.label :summary %> <%= t("admin.legislation.processes.form.use_markdown") %> - <%= f.text_area :summary, - label: false, - rows: 2, - placeholder: t("admin.legislation.processes.form.summary_placeholder") %> + <%= f.translatable_text_field :summary, + rows: 2, + placeholder: t("admin.legislation.processes.form.summary_placeholder"), + label: false %>
<%= f.label :description %> <%= t("admin.legislation.processes.form.use_markdown") %> - <%= f.text_area :description, - label: false, - rows: 5, - placeholder: t("admin.legislation.processes.form.description_placeholder") %> + <%= f.translatable_text_field :description, + rows: 5, + placeholder: t("admin.legislation.processes.form.description_placeholder"), + label: false %>
<%= f.label :additional_info %> <%= t("admin.legislation.processes.form.use_markdown") %> - <%= f.text_area :additional_info, - label: false, - rows: 10, - placeholder: t("admin.legislation.processes.form.additional_info_placeholder") %> + <%= f.translatable_text_area :additional_info, + rows: 10, + placeholder: t("admin.legislation.processes.form.additional_info_placeholder"), + label: false %>
diff --git a/spec/features/admin/legislation/processes_spec.rb b/spec/features/admin/legislation/processes_spec.rb index eabe40f37..1fee8cbf0 100644 --- a/spec/features/admin/legislation/processes_spec.rb +++ b/spec/features/admin/legislation/processes_spec.rb @@ -7,6 +7,11 @@ feature 'Admin legislation processes' do login_as(admin.user) end + it_behaves_like "translatable", + "legislation_process", + "edit_admin_legislation_process_path", + %w[title summary description additional_info] + context "Feature flag" do scenario 'Disabled with a feature flag' do @@ -38,9 +43,9 @@ feature 'Admin legislation processes' do click_link "New process" - fill_in 'legislation_process_title', with: 'An example legislation process' - fill_in 'legislation_process_summary', with: 'Summary of the process' - fill_in 'legislation_process_description', with: 'Describing the process' + fill_in 'legislation_process_title_en', with: 'An example legislation process' + fill_in 'legislation_process_summary_en', with: 'Summary of the process' + fill_in 'legislation_process_description_en', with: 'Describing the process' base_date = Date.current fill_in 'legislation_process[start_date]', with: base_date.strftime("%d/%m/%Y") @@ -93,7 +98,7 @@ feature 'Admin legislation processes' do expect(find("#legislation_process_debate_phase_enabled")).to be_checked expect(find("#legislation_process_published")).to be_checked - fill_in 'legislation_process_summary', with: '' + fill_in 'legislation_process_summary_en', with: '' click_button "Save changes" expect(page).to have_content "Process updated successfully" From 06347062ddb9a24479129cb634bf2aa45b05728b Mon Sep 17 00:00:00 2001 From: Marko Lovic Date: Fri, 3 Aug 2018 14:20:12 +0200 Subject: [PATCH 03/10] Make Legislation Questions translatable --- app/assets/javascripts/globalize.js.coffee | 4 ++ .../javascripts/legislation_admin.js.coffee | 2 + .../admin/legislation/questions_controller.rb | 10 ++- app/models/legislation/question.rb | 5 +- app/models/legislation/question_option.rb | 3 + .../legislation/questions/_form.html.erb | 20 +++--- .../_question_option_fields.html.erb | 4 +- .../admin/legislation/questions_spec.rb | 65 ++++++++++++++++++- 8 files changed, 100 insertions(+), 13 deletions(-) diff --git a/app/assets/javascripts/globalize.js.coffee b/app/assets/javascripts/globalize.js.coffee index 027ac498e..068ca88c8 100644 --- a/app/assets/javascripts/globalize.js.coffee +++ b/app/assets/javascripts/globalize.js.coffee @@ -36,6 +36,10 @@ App.Globalize = disable_locale: (locale) -> $("#enabled_translations_" + locale).val(0) + refresh_visible_translations: -> + locale = $('.js-globalize-locale-link.is-active').data("locale") + App.Globalize.display_translations(locale) + initialize: -> $('.js-globalize-locale').on 'change', -> App.Globalize.display_translations($(this).val()) diff --git a/app/assets/javascripts/legislation_admin.js.coffee b/app/assets/javascripts/legislation_admin.js.coffee index fc1d7cab4..f7f9ea17a 100644 --- a/app/assets/javascripts/legislation_admin.js.coffee +++ b/app/assets/javascripts/legislation_admin.js.coffee @@ -12,3 +12,5 @@ App.LegislationAdmin = else $(this).val("") + $("#nested-question-options").on "cocoon:after-insert", -> + App.Globalize.refresh_visible_translations() diff --git a/app/controllers/admin/legislation/questions_controller.rb b/app/controllers/admin/legislation/questions_controller.rb index bac16295e..da73e905c 100644 --- a/app/controllers/admin/legislation/questions_controller.rb +++ b/app/controllers/admin/legislation/questions_controller.rb @@ -1,4 +1,6 @@ class Admin::Legislation::QuestionsController < Admin::Legislation::BaseController + include Translatable + load_and_authorize_resource :process, class: "Legislation::Process" load_and_authorize_resource :question, class: "Legislation::Question", through: :process @@ -46,7 +48,13 @@ class Admin::Legislation::QuestionsController < Admin::Legislation::BaseControll def question_params params.require(:legislation_question).permit( :title, - question_options_attributes: [:id, :value, :_destroy] + *translation_params(::Legislation::Question), + question_options_attributes: [:id, :value, + *translation_params(::Legislation::QuestionOption)] ) end + + def resource + @question || ::Legislation::Question.find(params[:id]) + end end diff --git a/app/models/legislation/question.rb b/app/models/legislation/question.rb index 2ca5fb39a..859990928 100644 --- a/app/models/legislation/question.rb +++ b/app/models/legislation/question.rb @@ -3,6 +3,9 @@ class Legislation::Question < ActiveRecord::Base include ActsAsParanoidAliases include Notifiable + translates :title, touch: :true + globalize_accessors + belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id' belongs_to :process, class_name: 'Legislation::Process', foreign_key: 'legislation_process_id' @@ -11,7 +14,7 @@ class Legislation::Question < ActiveRecord::Base has_many :answers, class_name: 'Legislation::Answer', foreign_key: 'legislation_question_id', dependent: :destroy, inverse_of: :question has_many :comments, as: :commentable, dependent: :destroy - accepts_nested_attributes_for :question_options, reject_if: proc { |attributes| attributes[:value].blank? }, allow_destroy: true + accepts_nested_attributes_for :question_options, reject_if: proc { |attributes| attributes.all? { |k, v| v.blank? } }, allow_destroy: true validates :process, presence: true validates :title, presence: true diff --git a/app/models/legislation/question_option.rb b/app/models/legislation/question_option.rb index f7927dd1a..2282c31d3 100644 --- a/app/models/legislation/question_option.rb +++ b/app/models/legislation/question_option.rb @@ -2,6 +2,9 @@ class Legislation::QuestionOption < ActiveRecord::Base acts_as_paranoid column: :hidden_at include ActsAsParanoidAliases + translates :value, touch: :true + globalize_accessors + belongs_to :question, class_name: 'Legislation::Question', foreign_key: 'legislation_question_id', inverse_of: :question_options has_many :answers, class_name: 'Legislation::Answer', foreign_key: 'legislation_question_id', dependent: :destroy, inverse_of: :question diff --git a/app/views/admin/legislation/questions/_form.html.erb b/app/views/admin/legislation/questions/_form.html.erb index f31e5a61d..10902b78d 100644 --- a/app/views/admin/legislation/questions/_form.html.erb +++ b/app/views/admin/legislation/questions/_form.html.erb @@ -1,4 +1,6 @@ -<%= form_for [:admin, @process, @question], url: url, html: {data: {watch_changes: true}} do |f| %> +<%= render "admin/shared/globalize_locales", resource: @question %> + +<%= translatable_form_for [:admin, @process, @question], url: url, html: {data: {watch_changes: true}} do |f| %> <% if @question.errors.any? %>
@@ -16,23 +18,25 @@ <% end %>
- <%= f.label :title, t("admin.legislation.questions.form.title") %> - <%= f.text_area :title, rows: 5, label: false, placeholder: t("admin.legislation.questions.form.title_placeholder") %> + <%= f.translatable_text_area :title, + rows: 5, + placeholder: t("admin.legislation.questions.form.title_placeholder"), + label: t("admin.legislation.questions.form.title") %>
<%= f.label :question_options, t("admin.legislation.questions.form.question_options") %>
-
+
<%= f.fields_for :question_options do |ff| %> <%= render 'question_option_fields', f: ff %> <% end %> -
-
- <%= link_to_add_association t("admin.legislation.questions.form.add_option"), - f, :question_options, class: "button hollow" %> +
+ <%= link_to_add_association t("admin.legislation.questions.form.add_option"), + f, :question_options, class: "button hollow" %> +
diff --git a/app/views/admin/legislation/questions/_question_option_fields.html.erb b/app/views/admin/legislation/questions/_question_option_fields.html.erb index 6da8dbd4c..204e7b27a 100644 --- a/app/views/admin/legislation/questions/_question_option_fields.html.erb +++ b/app/views/admin/legislation/questions/_question_option_fields.html.erb @@ -1,7 +1,9 @@
- <%= f.text_field :value, label: false, placeholder: t("admin.legislation.questions.form.value_placeholder") %> + <%= f.translatable_text_field :value, + placeholder: t("admin.legislation.questions.form.value_placeholder"), + label: false %>
<%= link_to_remove_association t("admin.legislation.questions.question_option_fields.remove_option"), f, class: "delete"%> diff --git a/spec/features/admin/legislation/questions_spec.rb b/spec/features/admin/legislation/questions_spec.rb index d79429e30..b176ecaac 100644 --- a/spec/features/admin/legislation/questions_spec.rb +++ b/spec/features/admin/legislation/questions_spec.rb @@ -7,6 +7,11 @@ feature 'Admin legislation questions' do login_as(admin.user) end + it_behaves_like "translatable", + "legislation_question", + "edit_admin_legislation_process_question_path", + %w[title] + context "Feature flag" do background do @@ -60,7 +65,7 @@ feature 'Admin legislation questions' do click_link 'Create question' - fill_in 'legislation_question_title', with: 'Question 3' + fill_in 'legislation_question_title_en', with: 'Question 3' click_button 'Create question' expect(page).to have_content 'Question 3' @@ -87,7 +92,7 @@ feature 'Admin legislation questions' do click_link 'Question 2' - fill_in 'legislation_question_title', with: 'Question 2b' + fill_in 'legislation_question_title_en', with: 'Question 2b' click_button 'Save changes' expect(page).to have_content 'Question 2b' @@ -111,4 +116,60 @@ feature 'Admin legislation questions' do expect(page).not_to have_content 'Question 2' end end + + context "Special translation behaviour" do + + let!(:question) { create(:legislation_question, + title_en: "Title in English", + title_es: "Título en Español") } + + before do + @edit_question_url = edit_admin_legislation_process_question_path(question.process, question) + end + + scenario 'Add translation for question option', :js do + visit @edit_question_url + + click_on 'Add option' + + find('#nested-question-options input').set('Option 1') + + click_link "Español" + + find('#nested-question-options input').set('Opción 1') + + click_button "Save changes" + visit @edit_question_url + + expect(page).to have_field('legislation_question_question_options_attributes_0_value_en', with: 'Option 1') + + click_link "Español" + + expect(page).to have_field('legislation_question_question_options_attributes_0_value_es', with: 'Opción 1') + end + + scenario 'Add new question option after changing active locale', :js do + visit @edit_question_url + + click_link "Español" + + click_on 'Add option' + + find('#nested-question-options input').set('Opción 1') + + click_link "English" + + find('#nested-question-options input').set('Option 1') + + click_button "Save changes" + + visit @edit_question_url + + expect(page).to have_field('legislation_question_question_options_attributes_0_value_en', with: 'Option 1') + + click_link "Español" + + expect(page).to have_field('legislation_question_question_options_attributes_0_value_es', with: 'Opción 1') + end + end end From 05bfa193cdc55433a5b099887f505d1d02463cb6 Mon Sep 17 00:00:00 2001 From: Marko Lovic Date: Sun, 12 Aug 2018 21:43:47 +0200 Subject: [PATCH 04/10] Make Legislation Draft Versions translatable --- .../javascripts/markdown_editor.js.coffee | 24 +-- .../legislation/draft_versions_controller.rb | 13 +- app/models/legislation/draft_version.rb | 14 ++ .../legislation/draft_versions/_form.html.erb | 17 +- .../admin/legislation/draft_versions_spec.rb | 146 +++++++++++++++++- spec/models/legislation/draft_version_spec.rb | 9 ++ 6 files changed, 201 insertions(+), 22 deletions(-) diff --git a/app/assets/javascripts/markdown_editor.js.coffee b/app/assets/javascripts/markdown_editor.js.coffee index 510bf83ec..29e74e51c 100644 --- a/app/assets/javascripts/markdown_editor.js.coffee +++ b/app/assets/javascripts/markdown_editor.js.coffee @@ -1,10 +1,15 @@ App.MarkdownEditor = refresh_preview: (element, md) -> - textarea_content = element.find('textarea').val() + textarea_content = App.MarkdownEditor.find_textarea(element).val() result = md.render(textarea_content) element.find('#markdown-preview').html(result) + # Multi-locale (translatable) form fields work by hiding inputs of locales + # which are not "active". + find_textarea: (editor) -> + editor.find('textarea:visible') + initialize: -> $('.markdown-editor').each -> md = window.markdownit({ @@ -13,18 +18,18 @@ App.MarkdownEditor = typographer: true, }) - App.MarkdownEditor.refresh_preview($(this), md) + editor = $(this) - $(this).on 'change input paste keyup', -> + editor.on 'input', -> App.MarkdownEditor.refresh_preview($(this), md) $('.legislation-draft-versions-edit .warning').show() return - $(this).find('textarea').on 'scroll', -> + editor.find('textarea').on 'scroll', -> $('#markdown-preview').scrollTop($(this).scrollTop()) - $(this).find('.fullscreen-toggle').on 'click', -> - $('.markdown-editor').toggleClass('fullscreen') + editor.find('.fullscreen-toggle').on 'click', -> + editor.toggleClass('fullscreen') $('.fullscreen-container').toggleClass('medium-8', 'medium-12') span = $(this).find('span') current_html = span.html() @@ -33,7 +38,8 @@ App.MarkdownEditor = else span.html(span.data('open-text')) - if $('.markdown-editor').hasClass('fullscreen') - $('.markdown-editor textarea').height($(window).height() - 100) + if editor.hasClass('fullscreen') + App.MarkdownEditor.find_textarea(editor).height($(window).height() - 100) + App.MarkdownEditor.refresh_preview(editor, md) else - $('.markdown-editor textarea').height("10em") + App.MarkdownEditor.find_textarea(editor).height("10em") diff --git a/app/controllers/admin/legislation/draft_versions_controller.rb b/app/controllers/admin/legislation/draft_versions_controller.rb index 4e7ae18a8..703d8a543 100644 --- a/app/controllers/admin/legislation/draft_versions_controller.rb +++ b/app/controllers/admin/legislation/draft_versions_controller.rb @@ -1,6 +1,8 @@ class Admin::Legislation::DraftVersionsController < Admin::Legislation::BaseController - load_and_authorize_resource :process, class: "Legislation::Process" - load_and_authorize_resource :draft_version, class: "Legislation::DraftVersion", through: :process + include Translatable + + load_and_authorize_resource :draft_version, class: "Legislation::DraftVersion", through: :process, prepend: true + load_and_authorize_resource :process, class: "Legislation::Process", prepend: true def index @draft_versions = @process.draft_versions @@ -44,7 +46,12 @@ class Admin::Legislation::DraftVersionsController < Admin::Legislation::BaseCont :status, :final_version, :body, - :body_html + :body_html, + *translation_params(Legislation::DraftVersion) ) end + + def resource + @draft_version + end end diff --git a/app/models/legislation/draft_version.rb b/app/models/legislation/draft_version.rb index 7b9e6a0aa..14bc210c8 100644 --- a/app/models/legislation/draft_version.rb +++ b/app/models/legislation/draft_version.rb @@ -4,6 +4,13 @@ class Legislation::DraftVersion < ActiveRecord::Base acts_as_paranoid column: :hidden_at include ActsAsParanoidAliases + translates :title, touch: true + translates :changelog, touch: true + translates :body, touch: true + translates :body_html, touch: true + translates :toc_html, touch: true + globalize_accessors locales: [:en, :es, :fr, :nl, :val, :pt_br] + belongs_to :process, class_name: 'Legislation::Process', foreign_key: 'legislation_process_id' has_many :annotations, class_name: 'Legislation::Annotation', foreign_key: 'legislation_draft_version_id', dependent: :destroy @@ -21,6 +28,13 @@ class Legislation::DraftVersion < ActiveRecord::Base self.body_html = Redcarpet::Markdown.new(renderer).render(body) self.toc_html = Redcarpet::Markdown.new(toc_renderer).render(body) + + translations.each do |translation| + if translation.body_changed? + translation.body_html = Redcarpet::Markdown.new(renderer).render(translation.body) + translation.toc_html = Redcarpet::Markdown.new(toc_renderer).render(translation.body) + end + end end def display_title diff --git a/app/views/admin/legislation/draft_versions/_form.html.erb b/app/views/admin/legislation/draft_versions/_form.html.erb index 45c04f3a6..672f1b119 100644 --- a/app/views/admin/legislation/draft_versions/_form.html.erb +++ b/app/views/admin/legislation/draft_versions/_form.html.erb @@ -1,4 +1,6 @@ -<%= form_for [:admin, @process, @draft_version], url: url, html: {data: {watch_changes: true}} do |f| %> +<%= render "admin/shared/globalize_locales", resource: @draft_version %> + +<%= translatable_form_for [:admin, @process, @draft_version], url: url, html: {data: {watch_changes: true}} do |f| %> <% if @draft_version.errors.any? %>
@@ -14,14 +16,17 @@ <% end %>
- <%= f.label :title %> - <%= f.text_field :title, label: false, placeholder: t("admin.legislation.draft_versions.form.title_placeholder") %> + <%= f.translatable_text_field :title, + placeholder: t("admin.legislation.draft_versions.form.title_placeholder") %>
<%= f.label :changelog %> <%= t("admin.legislation.draft_versions.form.use_markdown") %> - <%= f.text_area :changelog, label: false, rows: 5, placeholder: t("admin.legislation.draft_versions.form.changelog_placeholder") %> + <%= f.translatable_text_area :changelog, + label: false, + rows: 5, + placeholder: t("admin.legislation.draft_versions.form.changelog_placeholder") %>
@@ -65,7 +70,9 @@ <% end %>
- <%= f.text_area :body, label: false, placeholder: t("admin.legislation.draft_versions.form.body_placeholder") %> + <%= f.translatable_text_area :body, + label: false, + placeholder: t("admin.legislation.draft_versions.form.body_placeholder") %>
diff --git a/spec/features/admin/legislation/draft_versions_spec.rb b/spec/features/admin/legislation/draft_versions_spec.rb index 9bb07f9a3..9ea09bc49 100644 --- a/spec/features/admin/legislation/draft_versions_spec.rb +++ b/spec/features/admin/legislation/draft_versions_spec.rb @@ -7,6 +7,11 @@ feature 'Admin legislation draft versions' do login_as(admin.user) end + it_behaves_like "translatable", + "legislation_draft_version", + "edit_admin_legislation_process_draft_version_path", + %w[title changelog] + context "Feature flag" do scenario 'Disabled with a feature flag' do @@ -53,9 +58,9 @@ feature 'Admin legislation draft versions' do click_link 'Create version' - fill_in 'legislation_draft_version_title', with: 'Version 3' - fill_in 'legislation_draft_version_changelog', with: 'Version 3 changes' - fill_in 'legislation_draft_version_body', with: 'Version 3 body' + fill_in 'legislation_draft_version_title_en', with: 'Version 3' + fill_in 'legislation_draft_version_changelog_en', with: 'Version 3 changes' + fill_in 'legislation_draft_version_body_en', with: 'Version 3 body' within('.end') do click_button 'Create version' @@ -86,11 +91,11 @@ feature 'Admin legislation draft versions' do click_link 'Version 1' - fill_in 'legislation_draft_version_title', with: 'Version 1b' + fill_in 'legislation_draft_version_title_en', with: 'Version 1b' click_link 'Launch text editor' - fill_in 'legislation_draft_version_body', with: '# Version 1 body\r\n\r\nParagraph\r\n\r\n>Quote' + fill_in 'legislation_draft_version_body_en', with: '# Version 1 body\r\n\r\nParagraph\r\n\r\n>Quote' within('.fullscreen') do click_link 'Close text editor' @@ -101,4 +106,135 @@ feature 'Admin legislation draft versions' do expect(page).to have_content 'Version 1b' end end + + context "Translations" do + + let!(:draft_version) { create(:legislation_draft_version, + title_en: "Title in English", + title_es: "Título en Español", + changelog_en: "Changes in English", + changelog_es: "Cambios en Español", + body_en: "Body in English", + body_es: "Texto en Español") } + + before do + @edit_draft_version_url = edit_admin_legislation_process_draft_version_path(draft_version.process, draft_version) + end + + scenario "Add a translation", :js do + visit @edit_draft_version_url + + select "Français", from: "translation_locale" + fill_in 'legislation_draft_version_title_fr', with: 'Titre en Français' + + click_button 'Save changes' + + visit @edit_draft_version_url + expect(page).to have_field('legislation_draft_version_title_en', with: 'Title in English') + + click_link "Español" + expect(page).to have_field('legislation_draft_version_title_es', with: 'Título en Español') + + click_link "Français" + expect(page).to have_field('legislation_draft_version_title_fr', with: 'Titre en Français') + end + + scenario "Update a translation", :js do + draft_version.update!(status: 'published') + draft_version.process.update!(title_es: 'Título de proceso') + + visit @edit_draft_version_url + + click_link "Español" + fill_in 'legislation_draft_version_title_es', with: 'Título correcto en Español' + + click_button 'Save changes' + + visit legislation_process_draft_version_path(draft_version.process, draft_version) + + expect(page).to have_content("Title in English") + + select('Español', from: 'locale-switcher') + + expect(page).to have_content('Título correcto en Español') + end + + scenario "Remove a translation", :js do + visit @edit_draft_version_url + + click_link "Español" + click_link "Remove language" + + expect(page).not_to have_link "Español" + + click_button "Save changes" + visit @edit_draft_version_url + expect(page).not_to have_link "Español" + end + + scenario 'Add translation through markup editor', :js do + visit @edit_draft_version_url + + select "Français", from: "translation_locale" + + click_link 'Launch text editor' + + fill_in 'legislation_draft_version_body_fr', with: 'Texte en Français' + + click_link 'Close text editor' + click_button "Save changes" + + visit @edit_draft_version_url + + click_link "Français" + click_link 'Launch text editor' + + expect(page).to have_field('legislation_draft_version_body_fr', with: 'Texte en Français') + end + + context "Globalize javascript interface" do + + scenario "Highlight current locale", :js do + visit @edit_draft_version_url + + expect(find("a.js-globalize-locale-link.is-active")).to have_content "English" + + select('Español', from: 'locale-switcher') + + expect(find("a.js-globalize-locale-link.is-active")).to have_content "Español" + end + + scenario "Highlight selected locale", :js do + visit @edit_draft_version_url + + expect(find("a.js-globalize-locale-link.is-active")).to have_content "English" + + click_link "Español" + + expect(find("a.js-globalize-locale-link.is-active")).to have_content "Español" + end + + scenario "Show selected locale form", :js do + visit @edit_draft_version_url + + expect(page).to have_field('legislation_draft_version_title_en', with: 'Title in English') + + click_link "Español" + + expect(page).to have_field('legislation_draft_version_title_es', with: 'Título en Español') + end + + scenario "Select a locale and add it to the draft_version form", :js do + visit @edit_draft_version_url + + select "Français", from: "translation_locale" + + expect(page).to have_link "Français" + + click_link "Français" + + expect(page).to have_field('legislation_draft_version_title_fr') + end + end + end end diff --git a/spec/models/legislation/draft_version_spec.rb b/spec/models/legislation/draft_version_spec.rb index 1b0427a6c..d88cdcee6 100644 --- a/spec/models/legislation/draft_version_spec.rb +++ b/spec/models/legislation/draft_version_spec.rb @@ -16,6 +16,15 @@ RSpec.describe Legislation::DraftVersion, type: :model do expect(legislation_draft_version.toc_html).to eq(toc_html) end + it "renders and saves the html from the markdown body field with alternative translation" do + legislation_draft_version.body_fr = body_markdown + + legislation_draft_version.save! + + expect(legislation_draft_version.body_html_fr).to eq(body_html) + expect(legislation_draft_version.toc_html_fr).to eq(toc_html) + end + def body_markdown <<-BODY_MARKDOWN # Title 1 From 64d72ca8e759139b77e158d8ef1b03f03cb234da Mon Sep 17 00:00:00 2001 From: Marko Lovic Date: Wed, 29 Aug 2018 16:35:40 +0200 Subject: [PATCH 05/10] Enable JS in shared translatable test Due to its markdown editor, the admin draft version page requires JS to correctly render the draft version form. --- app/models/legislation/draft_version.rb | 2 +- config/initializers/routes_hierarchy.rb | 2 +- db/dev_seeds/legislation_processes.rb | 8 +- .../admin/legislation/draft_versions_spec.rb | 121 ++---------------- spec/shared/features/translatable.rb | 2 +- 5 files changed, 20 insertions(+), 115 deletions(-) diff --git a/app/models/legislation/draft_version.rb b/app/models/legislation/draft_version.rb index 14bc210c8..858a23391 100644 --- a/app/models/legislation/draft_version.rb +++ b/app/models/legislation/draft_version.rb @@ -9,7 +9,7 @@ class Legislation::DraftVersion < ActiveRecord::Base translates :body, touch: true translates :body_html, touch: true translates :toc_html, touch: true - globalize_accessors locales: [:en, :es, :fr, :nl, :val, :pt_br] + globalize_accessors belongs_to :process, class_name: 'Legislation::Process', foreign_key: 'legislation_process_id' has_many :annotations, class_name: 'Legislation::Annotation', foreign_key: 'legislation_draft_version_id', dependent: :destroy diff --git a/config/initializers/routes_hierarchy.rb b/config/initializers/routes_hierarchy.rb index 6ed938732..f06acf5c9 100644 --- a/config/initializers/routes_hierarchy.rb +++ b/config/initializers/routes_hierarchy.rb @@ -11,7 +11,7 @@ module ActionDispatch::Routing::UrlFor [resource.investment.budget, resource.investment, resource] when "Legislation::Annotation" [resource.draft_version.process, resource.draft_version, resource] - when "Legislation::Proposal", "Legislation::Question" + when "Legislation::Proposal", "Legislation::Question", "Legislation::DraftVersion" [resource.process, resource] when "Topic" [resource.community, resource] diff --git a/db/dev_seeds/legislation_processes.rb b/db/dev_seeds/legislation_processes.rb index d65e7cb3b..fd4c5a190 100644 --- a/db/dev_seeds/legislation_processes.rb +++ b/db/dev_seeds/legislation_processes.rb @@ -25,8 +25,12 @@ section "Creating legislation processes" do Legislation::Process.find_each do |process| (1..3).each do |i| - process.draft_versions.create!(title: "Version #{i}", - body: Faker::Lorem.paragraphs.join("\n\n")) + process.draft_versions.create!(title_en: "Version #{i}", + title_es: "Versión #{i}", + body_en: ["Draft version in English", + *Faker::Lorem.paragraphs].join("\n\n"), + body_es: ["Versión borrador en Español", + *Faker::Lorem.paragraphs].join("\n\n")) end end end diff --git a/spec/features/admin/legislation/draft_versions_spec.rb b/spec/features/admin/legislation/draft_versions_spec.rb index 9ea09bc49..eb02e9fe8 100644 --- a/spec/features/admin/legislation/draft_versions_spec.rb +++ b/spec/features/admin/legislation/draft_versions_spec.rb @@ -2,6 +2,11 @@ require 'rails_helper' feature 'Admin legislation draft versions' do + it_behaves_like "translatable", + "legislation_draft_version", + "edit_admin_legislation_process_draft_version_path", + %w[title changelog] + background do admin = create(:administrator) login_as(admin.user) @@ -107,73 +112,14 @@ feature 'Admin legislation draft versions' do end end - context "Translations" do + context "Special translation behaviour" do - let!(:draft_version) { create(:legislation_draft_version, - title_en: "Title in English", - title_es: "Título en Español", - changelog_en: "Changes in English", - changelog_es: "Cambios en Español", - body_en: "Body in English", - body_es: "Texto en Español") } + let!(:draft_version) { create(:legislation_draft_version) } - before do - @edit_draft_version_url = edit_admin_legislation_process_draft_version_path(draft_version.process, draft_version) - end + scenario 'Add body translation through markup editor', :js do + edit_path = edit_admin_legislation_process_draft_version_path(draft_version.process, draft_version) - scenario "Add a translation", :js do - visit @edit_draft_version_url - - select "Français", from: "translation_locale" - fill_in 'legislation_draft_version_title_fr', with: 'Titre en Français' - - click_button 'Save changes' - - visit @edit_draft_version_url - expect(page).to have_field('legislation_draft_version_title_en', with: 'Title in English') - - click_link "Español" - expect(page).to have_field('legislation_draft_version_title_es', with: 'Título en Español') - - click_link "Français" - expect(page).to have_field('legislation_draft_version_title_fr', with: 'Titre en Français') - end - - scenario "Update a translation", :js do - draft_version.update!(status: 'published') - draft_version.process.update!(title_es: 'Título de proceso') - - visit @edit_draft_version_url - - click_link "Español" - fill_in 'legislation_draft_version_title_es', with: 'Título correcto en Español' - - click_button 'Save changes' - - visit legislation_process_draft_version_path(draft_version.process, draft_version) - - expect(page).to have_content("Title in English") - - select('Español', from: 'locale-switcher') - - expect(page).to have_content('Título correcto en Español') - end - - scenario "Remove a translation", :js do - visit @edit_draft_version_url - - click_link "Español" - click_link "Remove language" - - expect(page).not_to have_link "Español" - - click_button "Save changes" - visit @edit_draft_version_url - expect(page).not_to have_link "Español" - end - - scenario 'Add translation through markup editor', :js do - visit @edit_draft_version_url + visit edit_path select "Français", from: "translation_locale" @@ -184,57 +130,12 @@ feature 'Admin legislation draft versions' do click_link 'Close text editor' click_button "Save changes" - visit @edit_draft_version_url + visit edit_path click_link "Français" click_link 'Launch text editor' expect(page).to have_field('legislation_draft_version_body_fr', with: 'Texte en Français') end - - context "Globalize javascript interface" do - - scenario "Highlight current locale", :js do - visit @edit_draft_version_url - - expect(find("a.js-globalize-locale-link.is-active")).to have_content "English" - - select('Español', from: 'locale-switcher') - - expect(find("a.js-globalize-locale-link.is-active")).to have_content "Español" - end - - scenario "Highlight selected locale", :js do - visit @edit_draft_version_url - - expect(find("a.js-globalize-locale-link.is-active")).to have_content "English" - - click_link "Español" - - expect(find("a.js-globalize-locale-link.is-active")).to have_content "Español" - end - - scenario "Show selected locale form", :js do - visit @edit_draft_version_url - - expect(page).to have_field('legislation_draft_version_title_en', with: 'Title in English') - - click_link "Español" - - expect(page).to have_field('legislation_draft_version_title_es', with: 'Título en Español') - end - - scenario "Select a locale and add it to the draft_version form", :js do - visit @edit_draft_version_url - - select "Français", from: "translation_locale" - - expect(page).to have_link "Français" - - click_link "Français" - - expect(page).to have_field('legislation_draft_version_title_fr') - end - end end end diff --git a/spec/shared/features/translatable.rb b/spec/shared/features/translatable.rb index 9757b134c..c9bc5fd45 100644 --- a/spec/shared/features/translatable.rb +++ b/spec/shared/features/translatable.rb @@ -84,7 +84,7 @@ shared_examples "translatable" do |factory_name, path_name, fields| expect(page).not_to have_link "Español" end - scenario 'Change value of a translated field to blank' do + scenario 'Change value of a translated field to blank', :js do possible_blanks = fields.select do |field| translatable.dup.tap { |duplicate| duplicate.send(:"#{field}=", '') }.valid? end From cc6da6be2827b376658aba35ab689fe99b6b1e97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Wed, 5 Sep 2018 16:34:10 +0200 Subject: [PATCH 06/10] Fix inputs in legislation process translations They were accidentally changed from `text_area` to `text_field` when making them translatable. --- .../admin/legislation/processes/_form.html.erb | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/app/views/admin/legislation/processes/_form.html.erb b/app/views/admin/legislation/processes/_form.html.erb index 9eb587777..845f08503 100644 --- a/app/views/admin/legislation/processes/_form.html.erb +++ b/app/views/admin/legislation/processes/_form.html.erb @@ -181,19 +181,19 @@
<%= f.label :summary %> <%= t("admin.legislation.processes.form.use_markdown") %> - <%= f.translatable_text_field :summary, - rows: 2, - placeholder: t("admin.legislation.processes.form.summary_placeholder"), - label: false %> + <%= f.translatable_text_area :summary, + rows: 2, + placeholder: t("admin.legislation.processes.form.summary_placeholder"), + label: false %>
<%= f.label :description %> <%= t("admin.legislation.processes.form.use_markdown") %> - <%= f.translatable_text_field :description, - rows: 5, - placeholder: t("admin.legislation.processes.form.description_placeholder"), - label: false %> + <%= f.translatable_text_area :description, + rows: 5, + placeholder: t("admin.legislation.processes.form.description_placeholder"), + label: false %>
From a0f1a9ec1bf963c1bfec29edc4da4c3bd2c91854 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Wed, 5 Sep 2018 16:40:58 +0200 Subject: [PATCH 07/10] Be consistent checking changes in draft versions There's no reason to only convert Markdown to HTML in translations when their body changes but to always convert it when the "main" body field changes. Whether we should always use the condition or never use it is something we can debate about, though. --- app/models/legislation/draft_version.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/models/legislation/draft_version.rb b/app/models/legislation/draft_version.rb index 858a23391..02020dda9 100644 --- a/app/models/legislation/draft_version.rb +++ b/app/models/legislation/draft_version.rb @@ -26,8 +26,10 @@ class Legislation::DraftVersion < ActiveRecord::Base renderer = Redcarpet::Render::HTML.new(with_toc_data: true) toc_renderer = Redcarpet::Render::HTML_TOC.new(with_toc_data: true) - self.body_html = Redcarpet::Markdown.new(renderer).render(body) - self.toc_html = Redcarpet::Markdown.new(toc_renderer).render(body) + if body_changed? + self.body_html = Redcarpet::Markdown.new(renderer).render(body) + self.toc_html = Redcarpet::Markdown.new(toc_renderer).render(body) + end translations.each do |translation| if translation.body_changed? From 3fb98b175272dd5dc1ad5afa62f906c244605ce3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Wed, 5 Sep 2018 19:43:51 +0200 Subject: [PATCH 08/10] Fix typos --- app/models/admin_notification.rb | 4 ++-- app/models/legislation/draft_version.rb | 2 +- app/models/legislation/process.rb | 8 ++++---- app/models/legislation/question.rb | 2 +- app/models/legislation/question_option.rb | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/app/models/admin_notification.rb b/app/models/admin_notification.rb index ef632b1f1..4291206bc 100644 --- a/app/models/admin_notification.rb +++ b/app/models/admin_notification.rb @@ -1,8 +1,8 @@ class AdminNotification < ActiveRecord::Base include Notifiable - translates :title, touch: :true - translates :body, touch: :true + translates :title, touch: true + translates :body, touch: true globalize_accessors validates :title, presence: true diff --git a/app/models/legislation/draft_version.rb b/app/models/legislation/draft_version.rb index 02020dda9..18e4489b7 100644 --- a/app/models/legislation/draft_version.rb +++ b/app/models/legislation/draft_version.rb @@ -7,7 +7,7 @@ class Legislation::DraftVersion < ActiveRecord::Base translates :title, touch: true translates :changelog, touch: true translates :body, touch: true - translates :body_html, touch: true + translates :body_html, touch: true translates :toc_html, touch: true globalize_accessors diff --git a/app/models/legislation/process.rb b/app/models/legislation/process.rb index 39c3cb8e6..bc3df6be4 100644 --- a/app/models/legislation/process.rb +++ b/app/models/legislation/process.rb @@ -9,10 +9,10 @@ class Legislation::Process < ActiveRecord::Base acts_as_paranoid column: :hidden_at acts_as_taggable_on :customs - translates :title, touch: :true - translates :summary, touch: :true - translates :description, touch: :true - translates :additional_info, touch: :true + translates :title, touch: true + translates :summary, touch: true + translates :description, touch: true + translates :additional_info, touch: true globalize_accessors PHASES_AND_PUBLICATIONS = %i(debate_phase allegations_phase proposals_phase draft_publication result_publication).freeze diff --git a/app/models/legislation/question.rb b/app/models/legislation/question.rb index 859990928..0c9a5703f 100644 --- a/app/models/legislation/question.rb +++ b/app/models/legislation/question.rb @@ -3,7 +3,7 @@ class Legislation::Question < ActiveRecord::Base include ActsAsParanoidAliases include Notifiable - translates :title, touch: :true + translates :title, touch: true globalize_accessors belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id' diff --git a/app/models/legislation/question_option.rb b/app/models/legislation/question_option.rb index 2282c31d3..1ee46ee90 100644 --- a/app/models/legislation/question_option.rb +++ b/app/models/legislation/question_option.rb @@ -2,7 +2,7 @@ class Legislation::QuestionOption < ActiveRecord::Base acts_as_paranoid column: :hidden_at include ActsAsParanoidAliases - translates :value, touch: :true + translates :value, touch: true globalize_accessors belongs_to :question, class_name: 'Legislation::Question', foreign_key: 'legislation_question_id', inverse_of: :question_options From 58ad33379162dc4ec6bd2b7e7aea6715e2b62655 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Thu, 6 Sep 2018 13:13:02 +0200 Subject: [PATCH 09/10] Remove duplicate lines --- spec/features/admin/legislation/draft_versions_spec.rb | 5 ----- 1 file changed, 5 deletions(-) diff --git a/spec/features/admin/legislation/draft_versions_spec.rb b/spec/features/admin/legislation/draft_versions_spec.rb index eb02e9fe8..185bc05ab 100644 --- a/spec/features/admin/legislation/draft_versions_spec.rb +++ b/spec/features/admin/legislation/draft_versions_spec.rb @@ -2,11 +2,6 @@ require 'rails_helper' feature 'Admin legislation draft versions' do - it_behaves_like "translatable", - "legislation_draft_version", - "edit_admin_legislation_process_draft_version_path", - %w[title changelog] - background do admin = create(:administrator) login_as(admin.user) From 4d238c5d078460880cdf9d892316b32a8d9e24a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Thu, 6 Sep 2018 13:12:50 +0200 Subject: [PATCH 10/10] Fix crash updating legislation process categories We were expecting translation parameters in legislation processes `update` action. However, those parameters aren't sent when we get to that action through the "proposals" tab. --- app/controllers/concerns/translatable.rb | 2 ++ spec/features/admin/legislation/processes_spec.rb | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/app/controllers/concerns/translatable.rb b/app/controllers/concerns/translatable.rb index aecf42fb4..b75d242c0 100644 --- a/app/controllers/concerns/translatable.rb +++ b/app/controllers/concerns/translatable.rb @@ -8,6 +8,8 @@ module Translatable private def translation_params(resource_model) + return [] unless params[:enabled_translations] + resource_model.translated_attribute_names.product(enabled_translations).map do |attr_name, loc| resource_model.localized_attr_name_for(attr_name, loc) end diff --git a/spec/features/admin/legislation/processes_spec.rb b/spec/features/admin/legislation/processes_spec.rb index 1fee8cbf0..47aff8078 100644 --- a/spec/features/admin/legislation/processes_spec.rb +++ b/spec/features/admin/legislation/processes_spec.rb @@ -130,5 +130,16 @@ feature 'Admin legislation processes' do expect(page).not_to have_content 'Draft publication' end + + scenario "Change proposal categories" do + visit edit_admin_legislation_process_path(process) + within(".admin-content") { click_link "Proposals" } + + fill_in "Categories", with: "recycling,bicycles" + click_button "Save changes" + + visit admin_legislation_process_proposals_path(process) + expect(page).to have_field("Categories", with: "bicycles, recycling") + end end end