diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 10f108e7b..01e74400a 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -50,8 +50,7 @@ //= require markdown_editor //= require cocoon //= require allegations -//= require legislation_debate -//= require legislation_questions +//= require legislation //= require custom var initialize_modules = function() { @@ -76,8 +75,7 @@ var initialize_modules = function() { App.SocialShare.initialize(); App.MarkdownEditor.initialize(); App.Allegations.initialize(); - App.LegislationDebate.initialize(); - App.LegislationQuestions.initialize(); + App.Legislation.initialize(); }; $(function(){ diff --git a/app/assets/javascripts/legislation.js.coffee b/app/assets/javascripts/legislation.js.coffee new file mode 100644 index 000000000..8ed109482 --- /dev/null +++ b/app/assets/javascripts/legislation.js.coffee @@ -0,0 +1,16 @@ +App.Legislation = + + initialize: -> + $('#js-toggle-debate').on + click: -> + $('#debate-info').toggle() + + $('form#new_legislation_answer input.button').hide() + $('form#new_legislation_answer input[type=radio]').on + click: -> + $('form#new_legislation_answer').submit() + + $('form#draft_version_go_to_version input.button').hide() + $('form#draft_version_go_to_version select').on + change: -> + $('form#draft_version_go_to_version').submit() diff --git a/app/assets/javascripts/legislation_debate.js.coffee b/app/assets/javascripts/legislation_debate.js.coffee deleted file mode 100644 index 17091e946..000000000 --- a/app/assets/javascripts/legislation_debate.js.coffee +++ /dev/null @@ -1,6 +0,0 @@ -App.LegislationDebate = - - initialize: -> - $('#js-toggle-debate').on - click: -> - $('#debate-info').toggle() diff --git a/app/assets/javascripts/legislation_questions.js.coffee b/app/assets/javascripts/legislation_questions.js.coffee deleted file mode 100644 index f8bea46f3..000000000 --- a/app/assets/javascripts/legislation_questions.js.coffee +++ /dev/null @@ -1,8 +0,0 @@ -App.LegislationQuestions = - - initialize: -> - $('form#new_legislation_answer input.button').hide() - $('form#new_legislation_answer input[type=radio]').on - click: -> - $('form#new_legislation_answer').submit() - diff --git a/app/assets/javascripts/markdown_editor.js.coffee b/app/assets/javascripts/markdown_editor.js.coffee index 9065717fc..121f74ce4 100644 --- a/app/assets/javascripts/markdown_editor.js.coffee +++ b/app/assets/javascripts/markdown_editor.js.coffee @@ -4,7 +4,6 @@ App.MarkdownEditor = textarea_content = element.find('textarea').val() result = md.render(textarea_content) element.find('#markdown-preview').html(result) - element.find('#markdown-result input').val(result) initialize: -> $('.markdown-editor').each -> diff --git a/app/controllers/legislation/draft_versions_controller.rb b/app/controllers/legislation/draft_versions_controller.rb index 6956f11b6..0b6af46a6 100644 --- a/app/controllers/legislation/draft_versions_controller.rb +++ b/app/controllers/legislation/draft_versions_controller.rb @@ -6,9 +6,33 @@ class Legislation::DraftVersionsController < Legislation::BaseController end def show + @draft_versions_list = visible_draft_versions + @draft_version = @draft_versions_list.find(params[:id]) end def changes - @draft_version = @process.draft_versions.find(params[:draft_version_id]) + @draft_versions_list = visible_draft_versions + @draft_version = @draft_versions_list.find(params[:draft_version_id]) end + + def go_to_version + version = visible_draft_versions.find(params[:draft_version_id]) + + if params[:redirect_action] == 'changes' + redirect_to legislation_process_draft_version_changes_path(@process, version) + else + redirect_to legislation_process_draft_version_path(@process, version) + end + end + + private + + def visible_draft_versions + if current_user && current_user.administrator? + @process.draft_versions + else + @process.draft_versions.published + end + end + end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 1f52f0eea..313375e3f 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -18,6 +18,8 @@ module ApplicationHelper end def markdown(text) + return text if text.blank? + # See https://github.com/vmg/redcarpet for options render_options = { filter_html: false, diff --git a/app/models/abilities/everyone.rb b/app/models/abilities/everyone.rb index 466b6a5ba..b71e1f7d5 100644 --- a/app/models/abilities/everyone.rb +++ b/app/models/abilities/everyone.rb @@ -12,7 +12,7 @@ module Abilities can [:search, :read], Annotation can :new, DirectMessage can [:read, :draft_publication, :allegations, :final_version_publication], Legislation::Process - can [:read], Legislation::DraftVersion + can [:read, :changes, :go_to_version], Legislation::DraftVersion can [:read], Legislation::Question can [:create], Legislation::Answer end diff --git a/app/models/legislation/draft_version.rb b/app/models/legislation/draft_version.rb index 562e48cea..29b22e5a6 100644 --- a/app/models/legislation/draft_version.rb +++ b/app/models/legislation/draft_version.rb @@ -10,13 +10,19 @@ class Legislation::DraftVersion < ActiveRecord::Base validates :body, presence: true validates :status, presence: true, inclusion: { in: VALID_STATUSES } - def body_in_html + scope :published, -> { where(status: 'published').order('id DESC') } + + before_save :render_html + + def render_html renderer = Redcarpet::Render::HTML.new(with_toc_data: true) toc_renderer = Redcarpet::Render::HTML_TOC.new(with_toc_data: true) - body_html = Redcarpet::Markdown.new(renderer).render(body) - toc = Redcarpet::Markdown.new(toc_renderer).render(body) + self.body_html = Redcarpet::Markdown.new(renderer).render(body) + self.toc_html = Redcarpet::Markdown.new(toc_renderer).render(body) + end - return toc, body_html + def display_title + status == 'draft' ? "#{title} *" : title end end diff --git a/app/models/legislation/process.rb b/app/models/legislation/process.rb index 995aedb9e..566ff075e 100644 --- a/app/models/legislation/process.rb +++ b/app/models/legislation/process.rb @@ -3,7 +3,7 @@ class Legislation::Process < ActiveRecord::Base include ActsAsParanoidAliases has_many :draft_versions, -> { order(:id) }, class_name: 'Legislation::DraftVersion', foreign_key: 'legislation_process_id' - has_one :final_draft_version, -> { where final_version: true }, class_name: 'Legislation::DraftVersion', foreign_key: 'legislation_process_id' + has_one :final_draft_version, -> { where final_version: true, status: 'published' }, class_name: 'Legislation::DraftVersion', foreign_key: 'legislation_process_id' has_many :questions, -> { order(:id) }, class_name: 'Legislation::Question', foreign_key: 'legislation_process_id' validates :title, presence: true diff --git a/app/views/admin/legislation/draft_versions/_form.html.erb b/app/views/admin/legislation/draft_versions/_form.html.erb index a217580d6..be3c5067f 100644 --- a/app/views/admin/legislation/draft_versions/_form.html.erb +++ b/app/views/admin/legislation/draft_versions/_form.html.erb @@ -69,7 +69,6 @@
Consul | Editando Versión 3 del proceso Licencias urbanísticas, declaraciones
- Previsualizar <%= f.submit(class: "button", value: t("admin.legislation.draft_versions.#{admin_submit_action(@draft_version)}.submit_button")) %>
@@ -82,9 +81,6 @@
-
- <%= f.hidden_field :body_html, label: false %> -
@@ -92,8 +88,5 @@
<%= f.submit(class: "button expanded", value: t("admin.legislation.draft_versions.#{admin_submit_action(@draft_version)}.submit_button")) %>
-
- Previsualizar -
<% end %> diff --git a/app/views/admin/legislation/draft_versions/edit.html.erb b/app/views/admin/legislation/draft_versions/edit.html.erb index 0a27ccd97..5ad6d9501 100644 --- a/app/views/admin/legislation/draft_versions/edit.html.erb +++ b/app/views/admin/legislation/draft_versions/edit.html.erb @@ -4,7 +4,7 @@
- <%= link_to admin_legislation_processes_path, class: "back" do %> + <%= link_to admin_legislation_process_draft_versions_path(@process), class: "back" do %> <%= t("admin.legislation.draft_versions.edit.back") %> <% end %> diff --git a/app/views/admin/legislation/draft_versions/index.html.erb b/app/views/admin/legislation/draft_versions/index.html.erb index d86b61e26..6d9418c99 100644 --- a/app/views/admin/legislation/draft_versions/index.html.erb +++ b/app/views/admin/legislation/draft_versions/index.html.erb @@ -40,7 +40,7 @@ <%= link_to draft_version.title, edit_admin_legislation_process_draft_version_path(@process, draft_version) %> <%= draft_version.created_at.to_date %> - <%= draft_version.status %> + <%= draft_version.status %> <%= link_to "(#{t('.preview')})", legislation_process_draft_version_path(@process, draft_version) if draft_version.status == 'draft' %> <%#= draft_version.comments %> <%= draft_version.final_version %> diff --git a/app/views/admin/legislation/draft_versions/new.html.erb b/app/views/admin/legislation/draft_versions/new.html.erb index e71bab339..b43bfc276 100644 --- a/app/views/admin/legislation/draft_versions/new.html.erb +++ b/app/views/admin/legislation/draft_versions/new.html.erb @@ -4,7 +4,7 @@
- <%= link_to admin_legislation_process_path(@process), class: "back" do %> + <%= link_to admin_legislation_process_draft_versions_path(@process), class: "back" do %> <%= t("admin.legislation.draft_versions.new.back") %> <% end %> diff --git a/app/views/admin/legislation/questions/edit.html.erb b/app/views/admin/legislation/questions/edit.html.erb index d3f1f2df8..47b44b11a 100644 --- a/app/views/admin/legislation/questions/edit.html.erb +++ b/app/views/admin/legislation/questions/edit.html.erb @@ -4,7 +4,7 @@
- <%= link_to admin_legislation_processes_path, class: "back" do %> + <%= link_to admin_legislation_process_questions_path(@process), class: "back" do %> <%= t("admin.legislation.questions.edit.back") %> <% end %> diff --git a/app/views/admin/legislation/questions/new.html.erb b/app/views/admin/legislation/questions/new.html.erb index 4c657f92d..243815aff 100644 --- a/app/views/admin/legislation/questions/new.html.erb +++ b/app/views/admin/legislation/questions/new.html.erb @@ -4,7 +4,7 @@
- <%= link_to admin_legislation_process_path(@process), class: "back" do %> + <%= link_to admin_legislation_process_questions_path(@process), class: "back" do %> <%= t("admin.legislation.questions.new.back") %> <% end %> diff --git a/app/views/legislation/draft_versions/_process_header.html.erb b/app/views/legislation/draft_versions/_process_header.html.erb new file mode 100644 index 000000000..3c0c94d3f --- /dev/null +++ b/app/views/legislation/draft_versions/_process_header.html.erb @@ -0,0 +1,19 @@ +
+
+
+

<%= process.title %>

+
+ +
+ +
+ + + +
+
diff --git a/app/views/legislation/draft_versions/changes.html.erb b/app/views/legislation/draft_versions/changes.html.erb index 8b97de7f4..0f2015cda 100644 --- a/app/views/legislation/draft_versions/changes.html.erb +++ b/app/views/legislation/draft_versions/changes.html.erb @@ -1,14 +1,32 @@ <% provide :title do %><%= "#{@draft_version.title} - #{t('.title')} - #{@process.title}" %><% end %> -
-

<%= @process.title %>

-

<%= @draft_version.title %>

+<%= render 'process_header', process: @process %> -
- <%= link_to t('.see_text'), legislation_process_draft_version_path(@process, @draft_version) %> -
+
+ <%= render 'legislation/processes/key_dates', process: @process, phase: :allegations %> -
- <%= markdown @draft_version.changelog %> +
+
+
+

<%= t('.seeing_changelog_version') %>

+
+ <%= form_tag go_to_version_legislation_process_draft_versions_path(@process), method: :get, id: "draft_version_go_to_version" do %> + <%= select_tag "draft_version_id", options_from_collection_for_select(@draft_versions_list, 'id', 'display_title', @draft_version.id), "aria-label": t('legislation.draft_versions.show.select_draft_version') %> + <%= hidden_field_tag "redirect_action", "changes" %> + <%= submit_tag t('legislation.draft_versions.show.select_version_submit'), class: "button" %> + <% end %> +
+ <%= t('legislation.draft_versions.show.updated_at', date: format_date(@draft_version.updated_at)) %> +
+
+ <%= link_to t('.see_text'), legislation_process_draft_version_path(@process, @draft_version), title: t('.see_text'), class: "button strong" %> +
+
+ +
+
+ <%= markdown @draft_version.changelog %> +
+
diff --git a/app/views/legislation/draft_versions/show.html.erb b/app/views/legislation/draft_versions/show.html.erb index 0c220c03b..5ff3a76ba 100644 --- a/app/views/legislation/draft_versions/show.html.erb +++ b/app/views/legislation/draft_versions/show.html.erb @@ -1,27 +1,69 @@ <% provide :title do %><%= "#{@draft_version.title} - #{@process.title}" %><% end %> -
-

<%= link_to @process.title, @process %>

-

<%= @draft_version.title %>

+<%= render 'process_header', process: @process %> -
- <%= link_to t('.see_changes'), legislation_process_draft_version_changes_path(@process, @draft_version) %> -
+
+ <%= render 'legislation/processes/key_dates', process: @process, phase: :allegations %> - <% toc, body = @draft_version.body_in_html %> - -
- <%= toc.html_safe %> -
- -
-
- -
- <%= body.html_safe %> +
+
+
+

<%= t('.seeing_version') %>

+
+ <%= form_tag go_to_version_legislation_process_draft_versions_path(@process), method: :get, id: "draft_version_go_to_version" do %> + <%= select_tag "draft_version_id", options_from_collection_for_select(@draft_versions_list, 'id', 'display_title', @draft_version.id), "aria-label": t('.select_draft_version') %> + <%= submit_tag t('.select_version_submit'), class: "button" %> + <% end %> + <%= link_to t('.see_changes'), legislation_process_draft_version_changes_path(@process, @draft_version) %> +
+ <%= t('.updated_at', date: format_date(@draft_version.updated_at)) %>
-
+
+ <%= link_to t('.see_comments'), legislation_process_draft_version_annotations_path(@process, @draft_version), title: t('.see_comments'), class: "button strong" %> +
+
+ +
+
+
+
+ <%= t('.text_toc') %> +
+
+ +
+ <%= t('.text_toc') %> +
+ +
+ <%= @draft_version.toc_html.html_safe %> +
+
+
+
+
<%= t('.text_body') %>
+
+
+ <%= @draft_version.body_html.html_safe %> +
+
+ +
+
+
+ <%= t('.text_comments') %> +
+
+ +
+ <%= t('.text_comments') %> +
+ +
+
+ +
+
diff --git a/app/views/legislation/processes/_phase_allegations.html.erb b/app/views/legislation/processes/_phase_allegations.html.erb index be31ddf43..0087b9ca5 100644 --- a/app/views/legislation/processes/_phase_allegations.html.erb +++ b/app/views/legislation/processes/_phase_allegations.html.erb @@ -1,6 +1,6 @@ <% if process.draft_versions.any? %>
    - <% process.draft_versions.each do |draft_version| %> + <% process.draft_versions.published.each do |draft_version| %>
  • <%= link_to draft_version.title, legislation_process_draft_version_path(process, draft_version) %>
  • <% end %>
diff --git a/app/views/legislation/processes/_phase_draft_publication.html.erb b/app/views/legislation/processes/_phase_draft_publication.html.erb index be31ddf43..0087b9ca5 100644 --- a/app/views/legislation/processes/_phase_draft_publication.html.erb +++ b/app/views/legislation/processes/_phase_draft_publication.html.erb @@ -1,6 +1,6 @@ <% if process.draft_versions.any? %>
    - <% process.draft_versions.each do |draft_version| %> + <% process.draft_versions.published.each do |draft_version| %>
  • <%= link_to draft_version.title, legislation_process_draft_version_path(process, draft_version) %>
  • <% end %>
diff --git a/app/views/pages/accessibility.html.erb b/app/views/pages/accessibility.html.erb index a2c2eff30..f6d113c86 100644 --- a/app/views/pages/accessibility.html.erb +++ b/app/views/pages/accessibility.html.erb @@ -38,6 +38,10 @@ P Propuestas + + L + Procesos legislativos + S Presupuestos participativos diff --git a/app/views/shared/_subnavigation.html.erb b/app/views/shared/_subnavigation.html.erb index e8e0f1238..62bd29342 100644 --- a/app/views/shared/_subnavigation.html.erb +++ b/app/views/shared/_subnavigation.html.erb @@ -22,7 +22,10 @@ <% if feature?(:legislation) %>
  • - <%= link_to t("layouts.header.collaborative_legislation"), legislation_processes_path, class: ("active" if controller.class.parent == Legislation ), accesskey: "l" %> + <%= layout_menu_link_to t("layouts.header.collaborative_legislation"), + legislation_processes_path, + controller.class.parent == Legislation, + accesskey: "l" %>
  • <% end %> <% if feature?(:spending_proposals) %> diff --git a/config/locales/admin.en.yml b/config/locales/admin.en.yml index eef45e8ac..a0896d6c4 100755 --- a/config/locales/admin.en.yml +++ b/config/locales/admin.en.yml @@ -137,6 +137,7 @@ en: title: Draft versions create: Create version delete: Delete + preview: Preview new: back: Back title: Create new version diff --git a/config/locales/admin.es.yml b/config/locales/admin.es.yml index d2d8e5685..94676c9f0 100644 --- a/config/locales/admin.es.yml +++ b/config/locales/admin.es.yml @@ -135,6 +135,7 @@ es: title: Versiones del borrador create: Crear versión delete: Borrar + preview: Previsualizar new: back: Volver title: Crear nueva versión diff --git a/config/locales/en.yml b/config/locales/en.yml index c3a60ff67..8fa1cf13f 100755 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -226,9 +226,18 @@ en: draft_versions: changes: title: Changes - see_text: See text + seeing_changelog_version: Revision changes summary + see_text: See text draft show: - see_changes: See changes + seeing_version: You're seeing draft version + select_draft_version: Select draft + select_version_submit: see + updated_at: updated at %{date} + see_changes: see changes summary + see_comments: See all comments + text_toc: Table of contents + text_body: Text + text_comments: Comments processes: debate: empty_questions: There aren't any questions diff --git a/config/locales/es.yml b/config/locales/es.yml index 6c8a99e1d..a93d44d2e 100755 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -226,9 +226,18 @@ es: draft_versions: changes: title: Cambios - see_text: Ver texto + seeing_changelog_version: Resumen de cambios de la revisión + see_text: Ver borrador del texto show: - see_changes: Ver cambios + seeing_version: Estás viendo la revisión + select_draft_version: Seleccionar borrador + select_version_submit: ver + updated_at: actualizada el %{date} + see_changes: ver resumen de cambios + see_comments: Ver todos los comentarios + text_toc: Índice + text_body: Texto + text_comments: Comentarios processes: debate: empty_questions: No hay preguntas diff --git a/config/routes.rb b/config/routes.rb index 5b2fcf9d6..0ef0187f6 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -99,6 +99,7 @@ Rails.application.routes.draw do resources :answers, only: [:create] end resources :draft_versions, only: [:show] do + get :go_to_version, on: :collection get :changes resources :annotations end diff --git a/db/migrate/20161229213217_add_toc_html_to_draft_versions.rb b/db/migrate/20161229213217_add_toc_html_to_draft_versions.rb new file mode 100644 index 000000000..f71070e52 --- /dev/null +++ b/db/migrate/20161229213217_add_toc_html_to_draft_versions.rb @@ -0,0 +1,5 @@ +class AddTocHtmlToDraftVersions < ActiveRecord::Migration + def change + add_column :legislation_draft_versions, :toc_html, :text + end +end diff --git a/db/schema.rb b/db/schema.rb index 5a23f5839..d949dbb3a 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20161229110336) do +ActiveRecord::Schema.define(version: 20161229213217) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -123,10 +123,10 @@ ActiveRecord::Schema.define(version: 20161229110336) do t.string "visit_id" t.datetime "hidden_at" t.integer "flags_count", default: 0 - t.datetime "ignored_flag_at" t.integer "cached_votes_total", default: 0 t.integer "cached_votes_up", default: 0 t.integer "cached_votes_down", default: 0 + t.datetime "ignored_flag_at" t.integer "comments_count", default: 0 t.datetime "confirmed_hide_at" t.integer "cached_anonymous_votes_total", default: 0 @@ -145,6 +145,7 @@ ActiveRecord::Schema.define(version: 20161229110336) do add_index "debates", ["cached_votes_total"], name: "index_debates_on_cached_votes_total", using: :btree add_index "debates", ["cached_votes_up"], name: "index_debates_on_cached_votes_up", using: :btree add_index "debates", ["confidence_score"], name: "index_debates_on_confidence_score", using: :btree + add_index "debates", ["description"], name: "index_debates_on_description", using: :btree add_index "debates", ["geozone_id"], name: "index_debates_on_geozone_id", using: :btree add_index "debates", ["hidden_at"], name: "index_debates_on_hidden_at", using: :btree add_index "debates", ["hot_score"], name: "index_debates_on_hot_score", using: :btree @@ -252,6 +253,7 @@ ActiveRecord::Schema.define(version: 20161229110336) do t.datetime "created_at", null: false t.datetime "updated_at", null: false t.text "body_html" + t.text "toc_html" end add_index "legislation_draft_versions", ["hidden_at"], name: "index_legislation_draft_versions_on_hidden_at", using: :btree @@ -394,6 +396,7 @@ ActiveRecord::Schema.define(version: 20161229110336) do add_index "proposals", ["author_id"], name: "index_proposals_on_author_id", using: :btree add_index "proposals", ["cached_votes_up"], name: "index_proposals_on_cached_votes_up", using: :btree add_index "proposals", ["confidence_score"], name: "index_proposals_on_confidence_score", using: :btree + add_index "proposals", ["description"], name: "index_proposals_on_description", using: :btree add_index "proposals", ["geozone_id"], name: "index_proposals_on_geozone_id", using: :btree add_index "proposals", ["hidden_at"], name: "index_proposals_on_hidden_at", using: :btree add_index "proposals", ["hot_score"], name: "index_proposals_on_hot_score", using: :btree @@ -566,7 +569,7 @@ ActiveRecord::Schema.define(version: 20161229110336) do t.boolean "email_digest", default: true t.boolean "email_on_direct_message", default: true t.boolean "official_position_badge", default: false - t.datetime "password_changed_at", default: '2016-12-21 17:55:08', null: false + t.datetime "password_changed_at", default: '2016-11-02 13:51:14', null: false t.boolean "created_from_signature", default: false end diff --git a/spec/features/admin/legislation/draft_versions_spec.rb b/spec/features/admin/legislation/draft_versions_spec.rb index 0a61f5d97..e1088f24f 100644 --- a/spec/features/admin/legislation/draft_versions_spec.rb +++ b/spec/features/admin/legislation/draft_versions_spec.rb @@ -87,12 +87,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_body', with: '# Version 1 body\r\nParagraph\r\n>Quote' + fill_in 'legislation_draft_version_body', with: '# Version 1 body\r\n\r\nParagraph\r\n\r\n>Quote' click_button 'Save changes' expect(page).to have_content 'Version 1b' - expect(draft_version.reload.body_html).to eq("

    Version 1 body\\r\\nParagraph\\r\\n>Quote

    \r\n") end end end diff --git a/spec/features/legislation/draft_versions_spec.rb b/spec/features/legislation/draft_versions_spec.rb new file mode 100644 index 000000000..594cb8cdc --- /dev/null +++ b/spec/features/legislation/draft_versions_spec.rb @@ -0,0 +1,122 @@ +require 'rails_helper' + +feature 'Legislation Draft Versions' do + let(:user) { create(:user) } + let(:administrator) do + create(:administrator, user: user) + user + end + + context "See draft text page" do + before(:each) do + @process = create(:legislation_process) + @draft_version_1 = create(:legislation_draft_version, process: @process, title: "Version 1", body: "Body of the first version", status: "published") + @draft_version_2 = create(:legislation_draft_version, process: @process, title: "Version 2", body: "Body of the second version", status: "published") + @draft_version_3 = create(:legislation_draft_version, process: @process, title: "Version 3", body: "Body of the third version", status: "draft") + end + + it "shows the text body for this version" do + visit legislation_process_draft_version_path(@process, @draft_version_1) + + expect(page).to have_content("Body of the first version") + + within('select#draft_version_id') do + expect(page).to have_content("Version 1") + expect(page).to have_content("Version 2") + expect(page).to_not have_content("Version 3") + end + end + + it "shows an unpublished version to admins" do + login_as(administrator) + + visit legislation_process_draft_version_path(@process, @draft_version_3) + + expect(page).to have_content("Body of the third version") + + within('select#draft_version_id') do + expect(page).to have_content("Version 1") + expect(page).to have_content("Version 2") + expect(page).to have_content("Version 3 *") + end + end + + it "switches to another version without js" do + visit legislation_process_draft_version_path(@process, @draft_version_1) + expect(page).to have_content("Body of the first version") + + select("Version 2") + click_button "see" + + expect(page).to_not have_content("Body of the first version") + expect(page).to have_content("Body of the second version") + end + + it "switches to another version with js", :js do + visit legislation_process_draft_version_path(@process, @draft_version_1) + expect(page).to have_content("Body of the first version") + + select("Version 2") + + expect(page).to_not have_content("Body of the first version") + expect(page).to have_content("Body of the second version") + end + end + + context "See changes page" do + before(:each) do + @process = create(:legislation_process) + @draft_version_1 = create(:legislation_draft_version, process: @process, title: "Version 1", body: "Body of the first version", changelog: "Changes for first version", status: "published") + @draft_version_2 = create(:legislation_draft_version, process: @process, title: "Version 2", body: "Body of the second version", changelog: "Changes for second version", status: "published") + @draft_version_3 = create(:legislation_draft_version, process: @process, title: "Version 3", body: "Body of the third version", changelog: "Changes for third version", status: "draft") + end + + it "shows the changes for this version" do + visit legislation_process_draft_version_changes_path(@process, @draft_version_1) + + expect(page).to have_content("Changes for first version") + + within('select#draft_version_id') do + expect(page).to have_content("Version 1") + expect(page).to have_content("Version 2") + expect(page).to_not have_content("Version 3") + end + end + + it "shows an unpublished version to admins" do + login_as(administrator) + + visit legislation_process_draft_version_changes_path(@process, @draft_version_3) + + expect(page).to have_content("Changes for third version") + + within('select#draft_version_id') do + expect(page).to have_content("Version 1") + expect(page).to have_content("Version 2") + expect(page).to have_content("Version 3 *") + end + end + + it "switches to another version without js" do + visit legislation_process_draft_version_changes_path(@process, @draft_version_1) + expect(page).to have_content("Changes for first version") + + select("Version 2") + click_button "see" + + expect(page).to_not have_content("Changes for first version") + expect(page).to have_content("Changes for second version") + end + + it "switches to another version with js", :js do + visit legislation_process_draft_version_changes_path(@process, @draft_version_1) + expect(page).to have_content("Changes for first version") + + select("Version 2") + + expect(page).to_not have_content("Changes for first version") + expect(page).to have_content("Changes for second version") + end + end + +end diff --git a/spec/models/legislation/draft_version_spec.rb b/spec/models/legislation/draft_version_spec.rb index a6709110a..384fc4513 100644 --- a/spec/models/legislation/draft_version_spec.rb +++ b/spec/models/legislation/draft_version_spec.rb @@ -6,4 +6,75 @@ RSpec.describe Legislation::DraftVersion, type: :model do it "should be valid" do expect(legislation_draft_version).to be_valid end + + it "renders and saves the html from the markdown body field" do + legislation_draft_version.body = body_markdown + + legislation_draft_version.save! + + expect(legislation_draft_version.body_html).to eq(body_html) + expect(legislation_draft_version.toc_html).to eq(toc_html) + end + + def body_markdown +<<-BODY_MARKDOWN +# Title 1 + +Some paragraph. + +A list: + +- item 1 +- item 2 + +## Subtitle + +Another paragraph. + +# Title 2 + +Something about this. +BODY_MARKDOWN + end + + def body_html +<<-BODY_HTML +

    Title 1

    + +

    Some paragraph.

    + +

    A list:

    + +
      +
    • item 1
    • +
    • item 2
    • +
    + +

    Subtitle

    + +

    Another paragraph.

    + +

    Title 2

    + +

    Something about this.

    +BODY_HTML + end + + def toc_html +<<-TOC_HTML + +TOC_HTML + end end