diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 3c6feb6b3..756f86698 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -52,6 +52,7 @@ //= require markdown-it //= require markdown_editor //= require cocoon +//= require legislation_admin //= require legislation //= require legislation_allegations //= require legislation_annotatable @@ -83,6 +84,7 @@ var initialize_modules = function() { App.Banners.initialize(); App.SocialShare.initialize(); App.MarkdownEditor.initialize(); + App.LegislationAdmin.initialize(); App.LegislationAllegations.initialize(); App.Legislation.initialize(); if ( $(".legislation-annotatable").length ) diff --git a/app/assets/javascripts/legislation_admin.js.coffee b/app/assets/javascripts/legislation_admin.js.coffee new file mode 100644 index 000000000..c61d9cea1 --- /dev/null +++ b/app/assets/javascripts/legislation_admin.js.coffee @@ -0,0 +1,14 @@ +App.LegislationAdmin = + + initialize: -> + $("input[type='checkbox'][data-disable-date]").on + change: -> + checkbox = $(this) + parent = $(this).parents('.row:eq(0)') + date_selector = $(this).data('disable-date') + parent.find("input[type='text'][id^='"+date_selector+"']").each -> + if checkbox.is(':checked') + $(this).removeAttr("disabled") + else + $(this).val("") + diff --git a/app/assets/javascripts/legislation_annotatable.js.coffee b/app/assets/javascripts/legislation_annotatable.js.coffee index 76fc97ed6..16d5d94b2 100644 --- a/app/assets/javascripts/legislation_annotatable.js.coffee +++ b/app/assets/javascripts/legislation_annotatable.js.coffee @@ -56,7 +56,14 @@ App.LegislationAnnotatable = return $('[data-annotation-id]').removeClass('current-annotation') - $(this).addClass('current-annotation') + + parent = $(this).parents('[data-annotation-id]:eq(0)') + if parent.length + target = parent + else + target = $(this) + annotation_id = target.data('annotation-id') + $('[data-annotation-id="'+annotation_id+'"]').addClass('current-annotation') App.LegislationAllegations.show_comments() $("#comments-box").show() diff --git a/app/controllers/legislation/processes_controller.rb b/app/controllers/legislation/processes_controller.rb index 1b51cec07..7aff709d0 100644 --- a/app/controllers/legislation/processes_controller.rb +++ b/app/controllers/legislation/processes_controller.rb @@ -8,8 +8,20 @@ class Legislation::ProcessesController < Legislation::BaseController end def show + if @process.active_phase?(:allegations) && @process.show_phase?(:allegations) && draft_version = @process.draft_versions.published.last + redirect_to legislation_process_draft_version_path(@process, draft_version) + elsif @process.active_phase?(:debate) + redirect_to legislation_process_debate_path(@process) + else + redirect_to legislation_process_allegations_path(@process) + end + end + + def debate + phase :debate + if @process.show_phase?(:debate) - render :show + render :debate else render :phase_not_open end diff --git a/app/models/abilities/everyone.rb b/app/models/abilities/everyone.rb index 4d44f14eb..c86305862 100644 --- a/app/models/abilities/everyone.rb +++ b/app/models/abilities/everyone.rb @@ -16,7 +16,7 @@ module Abilities can [:read], Budget::Group can [:read, :print], Budget::Investment can :new, DirectMessage - can [:read, :draft_publication, :allegations, :final_version_publication], Legislation::Process + can [:read, :debate, :draft_publication, :allegations, :final_version_publication], Legislation::Process can [:read, :changes, :go_to_version], Legislation::DraftVersion can [:read], Legislation::Question can [:create], Legislation::Answer diff --git a/app/models/legislation/annotation.rb b/app/models/legislation/annotation.rb index f9f612abd..05eaad6f5 100644 --- a/app/models/legislation/annotation.rb +++ b/app/models/legislation/annotation.rb @@ -14,7 +14,7 @@ class Legislation::Annotation < ActiveRecord::Base validates :draft_version, presence: true validates :author, presence: true - before_save :store_range + before_save :store_range, :store_context after_create :create_first_comment def store_range @@ -24,6 +24,26 @@ class Legislation::Annotation < ActiveRecord::Base self.range_end_offset = ranges.first["endOffset"] end + def store_context + begin + html = draft_version.body_html + doc = Nokogiri::HTML(html) + + selector_start = "/html/body/#{range_start}" + el_start = doc.at_xpath(selector_start) + + selector_end = "/html/body/#{range_end}" + el_end = doc.at_xpath(selector_end) + + remainder_el_start = el_start.text[0 .. range_start_offset-1] unless range_start_offset.zero? + remainder_el_end = el_end.text[range_end_offset .. -1] + + self.context = "#{remainder_el_start}#{quote}#{remainder_el_end}" + rescue + "#{quote}" + end + end + def create_first_comment comments.create(body: self.text, user: self.author) end diff --git a/app/models/legislation/process.rb b/app/models/legislation/process.rb index 489dccffb..a68e667e3 100644 --- a/app/models/legislation/process.rb +++ b/app/models/legislation/process.rb @@ -9,12 +9,10 @@ class Legislation::Process < ActiveRecord::Base validates :title, presence: true validates :start_date, presence: true validates :end_date, presence: true - validates :debate_start_date, presence: true - validates :debate_end_date, presence: true - validates :draft_publication_date, presence: true - validates :allegations_start_date, presence: true - validates :allegations_end_date, presence: true - validates :final_publication_date, presence: true + validates :debate_start_date, presence: true, if: :debate_end_date? + validates :debate_end_date, presence: true, if: :debate_start_date? + validates :allegations_start_date, presence: true, if: :allegations_end_date? + validates :allegations_end_date, presence: true, if: :allegations_start_date? validate :valid_date_ranges scope :open, -> { where("start_date <= ? and end_date >= ?", Date.current, Date.current).order('id DESC') } @@ -26,13 +24,13 @@ class Legislation::Process < ActiveRecord::Base case phase when :debate - today >= debate_start_date && today <= debate_end_date + active_phase?(:debate) && today >= debate_start_date && today <= debate_end_date when :draft_publication - today >= draft_publication_date + active_phase?(:draft_publication) && today >= draft_publication_date when :allegations - today >= allegations_start_date && today <= allegations_end_date + active_phase?(:allegations) && today >= allegations_start_date && today <= allegations_end_date when :final_version_publication - today >= final_publication_date + active_phase?(:final_version_publication) && today >= final_publication_date end end @@ -42,13 +40,26 @@ class Legislation::Process < ActiveRecord::Base case phase when :debate - today >= debate_start_date + active_phase?(:debate) && today >= debate_start_date when :draft_publication - today >= draft_publication_date + active_phase?(:draft_publication) && today >= draft_publication_date when :allegations - today >= allegations_start_date + active_phase?(:allegations) && today >= allegations_start_date when :final_version_publication - today >= final_publication_date + active_phase?(:final_version_publication) && today >= final_publication_date + end + end + + def active_phase?(phase) + case phase + when :debate + debate_start_date.present? && debate_end_date.present? + when :draft_publication + draft_publication_date.present? + when :allegations + allegations_start_date.present? && allegations_end_date.present? + when :final_version_publication + final_publication_date.present? end end diff --git a/app/views/admin/legislation/processes/_form.html.erb b/app/views/admin/legislation/processes/_form.html.erb index b796049e1..d78675890 100644 --- a/app/views/admin/legislation/processes/_form.html.erb +++ b/app/views/admin/legislation/processes/_form.html.erb @@ -63,6 +63,10 @@ class: "js-calendar-full", id: "debate_end_date" %> +
+ <%= check_box_tag :debate_phase_active, @process.active_phase?(:debate), @process.new_record? || @process.active_phase?(:debate), data: {disable_date: "debate"} %> + <%= label_tag :debate_phase_active, t('admin.legislation.processes.form.active') %> +
@@ -87,7 +91,13 @@ class: "js-calendar-full", id: "allegations_end_date" %>
+
+ <%= check_box_tag :allegations_phase_active, @process.active_phase?(:allegations), @process.new_record? || @process.active_phase?(:allegations), data: {disable_date: "allegations"} %> + <%= label_tag :allegations_phase_active, t('admin.legislation.processes.form.active') %> +
+ +
<%= f.label :draft_publication_date %>
@@ -98,6 +108,10 @@ class: "js-calendar-full", id: "draft_publication_date" %>
+
+ <%= check_box_tag :draft_publication_phase_active, @process.active_phase?(:draft_publication), @process.new_record? || @process.active_phase?(:draft_publication), data: {disable_date: "draft_publication"} %> + <%= label_tag :draft_publication_phase_active, t('admin.legislation.processes.form.active') %> +
@@ -111,6 +125,10 @@ class: "js-calendar-full", id: "final_publication_date" %>
+
+ <%= check_box_tag :final_version_publication_phase_active, @process.active_phase?(:final_version_publication), @process.new_record? || @process.active_phase?(:final_version_publication), data: {disable_date: "final_publication"} %> + <%= label_tag :final_version_publication_phase_active, t('admin.legislation.processes.form.active') %> +
diff --git a/app/views/legislation/annotations/index.html.erb b/app/views/legislation/annotations/index.html.erb index 7553276f1..db0b79d4f 100644 --- a/app/views/legislation/annotations/index.html.erb +++ b/app/views/legislation/annotations/index.html.erb @@ -7,7 +7,7 @@
<%= render 'version_chooser', process: @process, draft_version: @draft_version %> - +
- +
- + <% @annotations.each do |annotation| %>
<%= t('.comments_about') %> @@ -28,7 +28,7 @@ <% end %>
- <%= annotation.quote %> + <%= annotation.context.try(:html_safe).presence || annotation.quote %>
<%= link_to legislation_process_draft_version_annotation_path(@process, @draft_version, annotation) do %> <%= t('.comments_count', count: annotation.comments_count) %> diff --git a/app/views/legislation/annotations/show.html.erb b/app/views/legislation/annotations/show.html.erb index 0d261d27a..765169246 100644 --- a/app/views/legislation/annotations/show.html.erb +++ b/app/views/legislation/annotations/show.html.erb @@ -15,7 +15,7 @@
- <%= @annotation.quote %> + <%= @annotation.context.try(:html_safe).presence || @annotation.quote %>
diff --git a/app/views/legislation/processes/_key_dates.html.erb b/app/views/legislation/processes/_key_dates.html.erb index e64d99f08..3e5823ae2 100644 --- a/app/views/legislation/processes/_key_dates.html.erb +++ b/app/views/legislation/processes/_key_dates.html.erb @@ -1,32 +1,43 @@ -
diff --git a/app/views/legislation/processes/show.html.erb b/app/views/legislation/processes/show.html.erb deleted file mode 100644 index 5b29dc292..000000000 --- a/app/views/legislation/processes/show.html.erb +++ /dev/null @@ -1,13 +0,0 @@ -<% provide :title do %><%= @process.title %><% end %> - -<%= render 'legislation/processes/header', process: @process, header: :full %> - -<%= render 'key_dates', process: @process, phase: :debate %> - -
-
-
- <%= render 'debate', process: @process %> -
-
-
diff --git a/config/locales/admin.en.yml b/config/locales/admin.en.yml index 4d00955da..c229561bc 100755 --- a/config/locales/admin.en.yml +++ b/config/locales/admin.en.yml @@ -193,6 +193,7 @@ en: form: error: Error form: + active: Active process: Process debate_phase: Debate phase allegations_phase: Allegations phase diff --git a/config/locales/admin.es.yml b/config/locales/admin.es.yml index 79bf53187..e30df44c2 100644 --- a/config/locales/admin.es.yml +++ b/config/locales/admin.es.yml @@ -193,6 +193,7 @@ es: form: error: Error form: + active: Activa process: Proceso debate_phase: Fase previa allegations_phase: Fase de alegaciones diff --git a/config/routes.rb b/config/routes.rb index f5b65420e..c2639389f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -102,6 +102,7 @@ Rails.application.routes.draw do namespace :legislation do resources :processes, only: [:index, :show] do + get :debate get :draft_publication get :allegations get :final_version_publication diff --git a/db/migrate/20170210083026_add_context_for_legislation_annotations.rb b/db/migrate/20170210083026_add_context_for_legislation_annotations.rb new file mode 100644 index 000000000..8bf19a64c --- /dev/null +++ b/db/migrate/20170210083026_add_context_for_legislation_annotations.rb @@ -0,0 +1,5 @@ +class AddContextForLegislationAnnotations < ActiveRecord::Migration + def change + add_column :legislation_annotations, :context, :text + end +end diff --git a/db/schema.rb b/db/schema.rb index a847e445e..278ba8e60 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: 20170125093101) do +ActiveRecord::Schema.define(version: 20170210083026) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -339,6 +339,7 @@ ActiveRecord::Schema.define(version: 20170125093101) do t.integer "range_start_offset" t.string "range_end" t.integer "range_end_offset" + t.text "context" end add_index "legislation_annotations", ["author_id"], name: "index_legislation_annotations_on_author_id", using: :btree diff --git a/spec/controllers/legislation/annotations_controller_spec.rb b/spec/controllers/legislation/annotations_controller_spec.rb index b8be3c630..5b1fd3d39 100644 --- a/spec/controllers/legislation/annotations_controller_spec.rb +++ b/spec/controllers/legislation/annotations_controller_spec.rb @@ -16,8 +16,8 @@ describe Legislation::AnnotationsController do post :create, process_id: @process.id, draft_version_id: @draft_version.id, legislation_annotation: { - "quote"=>"Ordenación Territorial", - "ranges"=>[{"start"=>"/p[1]", "startOffset"=>1, "end"=>"/p[1]", "endOffset"=>3}], + "quote"=>"ipsum", + "ranges"=>[{"start"=>"/p[1]", "startOffset"=>6, "end"=>"/p[1]", "endOffset"=>11}], "text": "una anotacion" } expect(Ahoy::Event.where(name: :legislation_annotation_created).count).to eq 1 @@ -30,8 +30,8 @@ describe Legislation::AnnotationsController do post :create, process_id: @process.id, draft_version_id: @final_version.id, legislation_annotation: { - "quote"=>"Ordenación Territorial", - "ranges"=>[{"start"=>"/p[1]", "startOffset"=>1, "end"=>"/p[1]", "endOffset"=>3}], + "quote"=>"ipsum", + "ranges"=>[{"start"=>"/p[1]", "startOffset"=>6, "end"=>"/p[1]", "endOffset"=>11}], "text": "una anotacion" } @@ -45,8 +45,8 @@ describe Legislation::AnnotationsController do xhr :post, :create, process_id: @process.id, draft_version_id: @draft_version.id, legislation_annotation: { - "quote"=>"Ordenación Territorial", - "ranges"=>[{"start"=>"/p[1]", "startOffset"=>1, "end"=>"/p[1]", "endOffset"=>3}], + "quote"=>"ipsum", + "ranges"=>[{"start"=>"/p[1]", "startOffset"=>6, "end"=>"/p[1]", "endOffset"=>11}], "text": "una anotacion" } end.to change { @draft_version.annotations.count }.by(1) @@ -60,8 +60,8 @@ describe Legislation::AnnotationsController do xhr :post, :create, process_id: @process.id, draft_version_id: @draft_version.id, legislation_annotation: { - "quote"=>"Ordenación Territorial", - "ranges"=>[{"start"=>"/p[1]", "startOffset"=>1, "end"=>"/p[1]", "endOffset"=>3}], + "quote"=>"ipsum", + "ranges"=>[{"start"=>"/p[1]", "startOffset"=>6, "end"=>"/p[1]", "endOffset"=>11}], "text": "una anotacion" } end.to_not change { @draft_version.annotations.count } @@ -74,8 +74,8 @@ describe Legislation::AnnotationsController do xhr :post, :create, process_id: @process.id, draft_version_id: @draft_version.id, legislation_annotation: { - "quote"=>"Ordenación Territorial", - "ranges"=>[{"start"=>"/p[1]", "startOffset"=>1, "end"=>"/p[1]", "endOffset"=>3}].to_json, + "quote"=>"ipsum", + "ranges"=>[{"start"=>"/p[1]", "startOffset"=>6, "end"=>"/p[1]", "endOffset"=>11}].to_json, "text": "una anotacion" } end.to change { @draft_version.annotations.count }.by(1) @@ -83,16 +83,16 @@ describe Legislation::AnnotationsController do it 'should create a new comment on an existing annotation when range is the same' do annotation = create(:legislation_annotation, draft_version: @draft_version, text: "my annotation", - ranges: [{"start"=>"/p[1]", "startOffset"=>5, "end"=>"/p[1]", "endOffset"=>10}], - range_start: "/p[1]", range_start_offset: 5, range_end: "/p[1]", range_end_offset: 10) + ranges: [{"start"=>"/p[1]", "startOffset"=>6, "end"=>"/p[1]", "endOffset"=>11}], + range_start: "/p[1]", range_start_offset: 6, range_end: "/p[1]", range_end_offset: 11) sign_in @user expect do xhr :post, :create, process_id: @process.id, draft_version_id: @draft_version.id, legislation_annotation: { - "quote"=>"Ordenación Territorial", - "ranges"=>[{"start"=>"/p[1]", "startOffset"=>5, "end"=>"/p[1]", "endOffset"=>10}], + "quote"=>"ipsum", + "ranges"=>[{"start"=>"/p[1]", "startOffset"=>6, "end"=>"/p[1]", "endOffset"=>11}], "text": "una anotacion" } end.to_not change { @draft_version.annotations.count } diff --git a/spec/factories.rb b/spec/factories.rb index 5c08ae1d9..437df8ea6 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -505,7 +505,19 @@ FactoryGirl.define do changelog "What changed in this version" status "draft" final_version false - body "Body of the legislation text" + body <<-LOREM_IPSUM +Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. + +Expetenda tincidunt in sed, ex partem placerat sea, porro commodo ex eam. His putant aeterno interesset at. Usu ea mundi tincidunt, omnium virtute aliquando ius ex. Ea aperiri sententiae duo. Usu nullam dolorum quaestio ei, sit vidit facilisis ea. Per ne impedit iracundia neglegentur. Consetetur neglegentur eum ut, vis animal legimus inimicus id. + +His audiam deserunt in, eum ubique voluptatibus te. In reque dicta usu. Ne rebum dissentiet eam, vim omnis deseruisse id. Ullum deleniti vituperata at quo, insolens complectitur te eos, ea pri dico munere propriae. Vel ferri facilis ut, qui paulo ridens praesent ad. Possim alterum qui cu. Accusamus consulatu ius te, cu decore soleat appareat usu. + +Est ei erat mucius quaeque. Ei his quas phaedrum, efficiantur mediocritatem ne sed, hinc oratio blandit ei sed. Blandit gloriatur eam et. Brute noluisse per et, verear disputando neglegentur at quo. Sea quem legere ei, unum soluta ne duo. Ludus complectitur quo te, ut vide autem homero pro. + +Vis id minim dicant sensibus. Pri aliquip conclusionemque ad, ad malis evertitur torquatos his. Has ei solum harum reprimique, id illum saperet tractatos his. Ei omnis soleat antiopam quo. Ad augue inani postulant mel, mel ea qualisque forensibus. + +Lorem salutandi eu mea, eam in soleat iriure assentior. Tamquam lobortis id qui. Ea sanctus democritum mei, per eu alterum electram adversarium. Ea vix probo dicta iuvaret, posse epicurei suavitate eam an, nam et vidit menandri. Ut his accusata petentium. +LOREM_IPSUM trait :published do status "published" @@ -520,12 +532,12 @@ FactoryGirl.define do draft_version factory: :legislation_draft_version author factory: :user quote "ipsum" - text "Loremp ipsum dolor" - ranges [{"start"=>"/div[1]", "startOffset"=>5, "end"=>"/div[1]", "endOffset"=>10}] - range_start "/div[1]" - range_start_offset 5 - range_end "/div[1]" - range_end_offset 10 + text "a comment" + ranges [{"start"=>"/p[1]", "startOffset"=>6, "end"=>"/p[1]", "endOffset"=>11}] + range_start "/p[1]" + range_start_offset 6 + range_end "/p[1]" + range_end_offset 11 end factory :legislation_question, class: 'Legislation::Question' do diff --git a/spec/features/admin/legislation/processes_spec.rb b/spec/features/admin/legislation/processes_spec.rb index 0f1114f51..2218ae8d5 100644 --- a/spec/features/admin/legislation/processes_spec.rb +++ b/spec/features/admin/legislation/processes_spec.rb @@ -59,4 +59,27 @@ feature 'Admin legislation processes' do expect(page).to have_content 'An example legislation process' end end + + context 'Update' do + scenario 'Deactivate debate phase', js: true do + process = create(:legislation_process, title: 'An example legislation process') + visit admin_root_path + + within('#side_menu') do + click_link "Collaborative Legislation" + end + + click_link "An example legislation process" + + expect(page).to have_selector("h1", text: "An example legislation process") + expect(find("#debate_phase_active")).to be_checked + + uncheck "debate_phase_active" + click_button "Save changes" + + expect(page).to have_content "Process updated successfully" + expect(find("#debate_start_date").value).to be_blank + expect(find("#debate_end_date").value).to be_blank + end + end end diff --git a/spec/features/legislation/draft_versions_spec.rb b/spec/features/legislation/draft_versions_spec.rb index fc6a1b88f..5b2192d46 100644 --- a/spec/features/legislation/draft_versions_spec.rb +++ b/spec/features/legislation/draft_versions_spec.rb @@ -137,7 +137,7 @@ feature 'Legislation Draft Versions' do scenario 'Visit as anonymous' do logout - draft_version = create(:legislation_draft_version, :published, body: Faker::Lorem.paragraph) + draft_version = create(:legislation_draft_version, :published) visit legislation_process_draft_version_path(draft_version.process, draft_version) @@ -148,7 +148,7 @@ feature 'Legislation Draft Versions' do end scenario 'Create' do - draft_version = create(:legislation_draft_version, :published, body: Faker::Lorem.paragraph) + draft_version = create(:legislation_draft_version, :published) visit legislation_process_draft_version_path(draft_version.process, draft_version) @@ -172,7 +172,7 @@ feature 'Legislation Draft Versions' do end scenario 'View annotations and comments' do - draft_version = create(:legislation_draft_version, :published, body: Faker::Lorem.paragraph) + draft_version = create(:legislation_draft_version, :published) annotation1 = create(:legislation_annotation, draft_version: draft_version, text: "my annotation", ranges: [{"start"=>"/p[1]", "startOffset"=>5, "end"=>"/p[1]", "endOffset"=>10}]) annotation2 = create(:legislation_annotation, draft_version: draft_version, text: "my other annotation", ranges: [{"start"=>"/p[1]", "startOffset"=>12, "end"=>"/p[1]", "endOffset"=>19}]) @@ -187,8 +187,8 @@ feature 'Legislation Draft Versions' do end scenario "Publish new comment for an annotation from comments box" do - draft_version = create(:legislation_draft_version, :published, body: Faker::Lorem.paragraph) - annotation = create(:legislation_annotation, draft_version: draft_version, text: "my annotation", ranges: [{"start"=>"/p[1]", "startOffset"=>5, "end"=>"/p[1]", "endOffset"=>10}]) + draft_version = create(:legislation_draft_version, :published) + annotation = create(:legislation_annotation, draft_version: draft_version, text: "my annotation", ranges: [{"start"=>"/p[1]", "startOffset"=>6, "end"=>"/p[1]", "endOffset"=>11}]) visit legislation_process_draft_version_path(draft_version.process, draft_version) @@ -205,25 +205,25 @@ feature 'Legislation Draft Versions' do context "Annotations page" do background do - @draft_version = create(:legislation_draft_version, :published, body: Faker::Lorem.paragraph) - @annotation_1 = create(:legislation_annotation, draft_version: @draft_version, text: "my annotation", quote: "first quote") - @annotation_2 = create(:legislation_annotation, draft_version: @draft_version, text: "my other annotation", quote: "second quote") + @draft_version = create(:legislation_draft_version, :published) + @annotation_1 = create(:legislation_annotation, draft_version: @draft_version, text: "my annotation", quote: "ipsum", ranges: [{"start"=>"/p[1]", "startOffset"=>6, "end"=>"/p[1]", "endOffset"=>11}]) + @annotation_2 = create(:legislation_annotation, draft_version: @draft_version, text: "my other annotation", quote: "audiam", ranges: [{"start"=>"/p[3]", "startOffset"=>6, "end"=>"/p[3]", "endOffset"=>11}]) end scenario "See all annotations for a draft version" do visit legislation_process_draft_version_annotations_path(@draft_version.process, @draft_version) - expect(page).to have_content "first quote" - expect(page).to have_content "second quote" + expect(page).to have_content "ipsum" + expect(page).to have_content "audiam" end context "switching versions" do background do @process = create(:legislation_process) - @draft_version_1 = create(:legislation_draft_version, :published, process: @process, title: "Version 1", body: Faker::Lorem.paragraph) - @annotation_1 = create(:legislation_annotation, draft_version: @draft_version_1, text: "annotation for version 1", quote: "quote for version 1") - @draft_version_2 = create(:legislation_draft_version, :published, process: @process, title: "Version 2", body: Faker::Lorem.paragraph) - @annotation_1 = create(:legislation_annotation, draft_version: @draft_version_2, text: "annotation for version 2", quote: "quote for version 2") + @draft_version_1 = create(:legislation_draft_version, :published, process: @process, title: "Version 1", body: "Text with quote for version 1") + @annotation_1 = create(:legislation_annotation, draft_version: @draft_version_1, text: "annotation for version 1", quote: "quote for version 1", ranges: [{"start"=>"/p[1]", "startOffset"=>11, "end"=>"/p[1]", "endOffset"=>30}]) + @draft_version_2 = create(:legislation_draft_version, :published, process: @process, title: "Version 2", body: "Text with quote for version 2") + @annotation_1 = create(:legislation_annotation, draft_version: @draft_version_2, text: "annotation for version 2", quote: "quote for version 2", ranges: [{"start"=>"/p[1]", "startOffset"=>11, "end"=>"/p[1]", "endOffset"=>30}]) end scenario "without js" do @@ -251,17 +251,18 @@ feature 'Legislation Draft Versions' do context "Annotation comments page" do background do - @draft_version = create(:legislation_draft_version, :published, body: Faker::Lorem.paragraph) - @annotation_1 = create(:legislation_annotation, draft_version: @draft_version, text: "my annotation", quote: "first quote") - @annotation_2 = create(:legislation_annotation, draft_version: @draft_version, text: "my other annotation", quote: "second quote") + @draft_version = create(:legislation_draft_version, :published) + @annotation_1 = create(:legislation_annotation, draft_version: @draft_version, text: "my annotation", quote: "ipsum", ranges: [{"start"=>"/p[1]", "startOffset"=>6, "end"=>"/p[1]", "endOffset"=>11}]) + @annotation_2 = create(:legislation_annotation, draft_version: @draft_version, text: "my other annotation", quote: "audiam", ranges: [{"start"=>"/p[3]", "startOffset"=>6, "end"=>"/p[3]", "endOffset"=>11}]) end scenario "See one annotation with replies for a draft version" do visit legislation_process_draft_version_annotation_path(@draft_version.process, @draft_version, @annotation_2) - expect(page).to_not have_content "first quote" - expect(page).to have_content "second quote" + expect(page).to_not have_content "ipsum" expect(page).to_not have_content "my annotation" + + expect(page).to have_content "audiam" expect(page).to have_content "my other annotation" end end diff --git a/spec/models/legislation/annotation_spec.rb b/spec/models/legislation/annotation_spec.rb new file mode 100644 index 000000000..4cf5c6f59 --- /dev/null +++ b/spec/models/legislation/annotation_spec.rb @@ -0,0 +1,47 @@ +require 'rails_helper' + +RSpec.describe Legislation::Annotation, type: :model do + let(:draft_version) { create(:legislation_draft_version) } + let(:annotation) { create(:legislation_annotation, draft_version: draft_version) } + + it "should be valid" do + expect(draft_version).to be_valid + expect(annotation).to be_valid + end + + it "calculates the context for multinode annotations" do + annotation = create(:legislation_annotation, + draft_version: draft_version, + quote: "ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. + +Expetenda tincidunt in sed, ex partem placerat sea, porro commodo ex eam. His putant aeterno interesset at. Usu ea mundi tincidunt, omnium virtute aliquando ius ex. Ea aperiri sententiae duo. Usu nullam dolorum quaestio ei, sit vidit facilisis ea. Per ne impedit iracundia neglegentur. Consetetur neglegentur eum ut, vis animal legimus inimicus id. + +His audiam", + ranges: [{"start"=>"/p[1]", "startOffset"=>6, "end"=>"/p[3]", "endOffset"=>11}] + ) + + expect(annotation.context).to eq("Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.\n\nExpetenda tincidunt in sed, ex partem placerat sea, porro commodo ex eam. His putant aeterno interesset at. Usu ea mundi tincidunt, omnium virtute aliquando ius ex. Ea aperiri sententiae duo. Usu nullam dolorum quaestio ei, sit vidit facilisis ea. Per ne impedit iracundia neglegentur. Consetetur neglegentur eum ut, vis animal legimus inimicus id.\n\nHis audiamdeserunt in, eum ubique voluptatibus te. In reque dicta usu. Ne rebum dissentiet eam, vim omnis deseruisse id. Ullum deleniti vituperata at quo, insolens complectitur te eos, ea pri dico munere propriae. Vel ferri facilis ut, qui paulo ridens praesent ad. Possim alterum qui cu. Accusamus consulatu ius te, cu decore soleat appareat usu.") + end + + it "calculates the context for multinode annotations 2" do + annotation = create(:legislation_annotation, + draft_version: draft_version, + quote: "Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.\r\n\r\nExpetenda tincidunt in sed, ex partem placerat sea, porro commodo ex eam. His putant aeterno interesset at. Usu ea mundi tincidunt, omnium virtute aliquando ius ex. Ea aperiri sententiae duo", + ranges: [{"start"=>"/p[1]", "startOffset"=>273, "end"=>"/p[2]", "endOffset"=>190}] + ) + + expect(annotation.context).to eq("Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.\r\n\r\nExpetenda tincidunt in sed, ex partem placerat sea, porro commodo ex eam. His putant aeterno interesset at. Usu ea mundi tincidunt, omnium virtute aliquando ius ex. Ea aperiri sententiae duo. Usu nullam dolorum quaestio ei, sit vidit facilisis ea. Per ne impedit iracundia neglegentur. Consetetur neglegentur eum ut, vis animal legimus inimicus id.") + end + + it "calculates the context for multinode annotations 3" do + draft_version = create(:legislation_draft_version, body: "The GNU Affero General Public License is a free, copyleft license for software and other kinds of works, specifically designed to ensure cooperation with the community in the case of network server software.\r\n\r\nThe licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, our General Public Licenses are intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users.\r\n\r\nWhen we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things.\r\n\r\nDevelopers that use our General Public Licenses protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License which gives you legal permission to copy, distribute and/or modify the software.\r\n\r\nA secondary benefit of defending all users' freedom is that improvements made in alternate versions of the program, if they receive widespread use, become available for other developers to incorporate. Many developers of free software are heartened and encouraged by the resulting cooperation. However, in the case of software used on network servers, this result may fail to come about. The GNU General Public License permits making a modified version and letting the public access it on a server without ever releasing its source code to the public.\r\n\r\nThe GNU Affero General Public License is designed specifically to ensure that, in such cases, the modified source code becomes available to the community. It requires the operator of a network server to provide the source code of the modified version running there to the users of that server. Therefore, public use of a modified version, on a publicly accessible server, gives the public access to the source code of the modified version.\r\n\r\nAn older license, called the Affero General Public License and published by Affero, was designed to accomplish similar goals. This is a different license, not a version of the Affero GPL, but Affero has released a new version of the Affero GPL which permits relicensing under this license.") + + annotation = create(:legislation_annotation, + draft_version: draft_version, + quote: "By contrast, our General Public Licenses are intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users.\r\n\r\nWhen we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish)", + ranges: [{"start"=>"/p[2]", "startOffset"=>127, "end"=>"/p[3]", "endOffset"=>223}] + ) + + expect(annotation.context).to eq("The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, our General Public Licenses are intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users.\r\n\r\nWhen we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things.") + end +end diff --git a/spec/models/legislation/process_spec.rb b/spec/models/legislation/process_spec.rb index fd83d8989..f89a4bfcf 100644 --- a/spec/models/legislation/process_spec.rb +++ b/spec/models/legislation/process_spec.rb @@ -7,6 +7,32 @@ RSpec.describe Legislation::Process, type: :model do expect(process).to be_valid end + describe "dates validations" do + it "is invalid if debate_start_date is present but debate_end_date is not" do + process = build(:legislation_process, debate_start_date: Date.current, debate_end_date: "") + expect(process).to be_invalid + expect(process.errors.messages[:debate_end_date]).to include("can't be blank") + end + + it "is invalid if debate_end_date is present but debate_start_date is not" do + process = build(:legislation_process, debate_start_date: nil, debate_end_date: Date.current) + expect(process).to be_invalid + expect(process.errors.messages[:debate_start_date]).to include("can't be blank") + end + + it "is invalid if allegations_start_date is present but debate_end_date is not" do + process = build(:legislation_process, allegations_start_date: Date.current, allegations_end_date: "") + expect(process).to be_invalid + expect(process.errors.messages[:allegations_end_date]).to include("can't be blank") + end + + it "is invalid if debate_end_date is present but allegations_start_date is not" do + process = build(:legislation_process, allegations_start_date: nil, allegations_end_date: Date.current) + expect(process).to be_invalid + expect(process.errors.messages[:allegations_start_date]).to include("can't be blank") + end + end + describe "date ranges validations" do it "is invalid if end_date is before start_date" do process = build(:legislation_process, start_date: Date.current, end_date: Date.current - 1.day)