From 0c27f1ffde2ba3292abcc7d906bef5a7edca19d6 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Tue, 13 Jun 2017 19:47:12 +0200 Subject: [PATCH 01/25] Rename Legislation Process final_publication_date field to more descriptive result_publication_date --- .../admin/legislation/processes_controller.rb | 2 +- app/views/admin/legislation/processes/_form.html.erb | 8 ++++---- app/views/legislation/processes/_key_dates.html.erb | 4 ++-- app/views/legislation/processes/_process.html.erb | 4 ++-- app/views/sandbox/admin_legislation_info.html.erb | 4 ++-- config/locales/activerecord.en.yml | 2 +- config/locales/activerecord.es.yml | 2 +- config/locales/legislation.en.yml | 2 +- config/locales/legislation.es.yml | 2 +- db/dev_seeds.rb | 2 +- ...me_legislation_process_final_pub_to_result_pub.rb | 5 +++++ db/schema.rb | 6 +++--- spec/factories.rb | 8 ++++---- spec/features/admin/legislation/processes_spec.rb | 2 +- spec/features/legislation/processes_spec.rb | 4 ++-- spec/models/legislation/process_spec.rb | 12 ++++++------ 16 files changed, 37 insertions(+), 32 deletions(-) create mode 100644 db/migrate/20170613174317_rename_legislation_process_final_pub_to_result_pub.rb diff --git a/app/controllers/admin/legislation/processes_controller.rb b/app/controllers/admin/legislation/processes_controller.rb index 8d349633b..2c352a2db 100644 --- a/app/controllers/admin/legislation/processes_controller.rb +++ b/app/controllers/admin/legislation/processes_controller.rb @@ -45,7 +45,7 @@ class Admin::Legislation::ProcessesController < Admin::Legislation::BaseControll :draft_publication_date, :allegations_start_date, :allegations_end_date, - :final_publication_date + :result_publication_date ) end end diff --git a/app/views/admin/legislation/processes/_form.html.erb b/app/views/admin/legislation/processes/_form.html.erb index ac49f8a7d..9d877a3da 100644 --- a/app/views/admin/legislation/processes/_form.html.erb +++ b/app/views/admin/legislation/processes/_form.html.erb @@ -135,14 +135,14 @@
- <%= f.label :final_publication_date %> + <%= f.label :result_publication_date %>
- <%= f.text_field :final_publication_date, + <%= f.text_field :result_publication_date, label: false, - value: format_date_for_calendar_form(@process.final_publication_date), + value: format_date_for_calendar_form(@process.result_publication_date), class: "js-calendar-full", - id: "final_publication_date" %> + id: "result_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"} %> diff --git a/app/views/legislation/processes/_key_dates.html.erb b/app/views/legislation/processes/_key_dates.html.erb index bf6a3b2de..ab2bd72c9 100644 --- a/app/views/legislation/processes/_key_dates.html.erb +++ b/app/views/legislation/processes/_key_dates.html.erb @@ -37,8 +37,8 @@ <% if process.active_phase?(:final_version_publication) %>
  • > <%= link_to legislation_process_final_version_publication_path(process) do %> -

    <%= t('legislation.processes.shared.final_publication_date') %>

    -

    <%= format_date(process.final_publication_date) %>

    +

    <%= t('legislation.processes.shared.result_publication_date') %>

    +

    <%= format_date(process.result_publication_date) %>

    <% end %>
  • <% end %> diff --git a/app/views/legislation/processes/_process.html.erb b/app/views/legislation/processes/_process.html.erb index 77ee985d9..a0a2d2e37 100644 --- a/app/views/legislation/processes/_process.html.erb +++ b/app/views/legislation/processes/_process.html.erb @@ -37,8 +37,8 @@

    <%= format_date(process.allegations_start_date) %> - <%= format_date(process.allegations_end_date) %>

    -
    <%= t('legislation.processes.shared.final_publication_date') %>
    -

    <%= format_date(process.final_publication_date) %>

    +
    <%= t('legislation.processes.shared.result_publication_date') %>
    +

    <%= format_date(process.result_publication_date) %>

    diff --git a/app/views/sandbox/admin_legislation_info.html.erb b/app/views/sandbox/admin_legislation_info.html.erb index fe53bc724..969a57014 100644 --- a/app/views/sandbox/admin_legislation_info.html.erb +++ b/app/views/sandbox/admin_legislation_info.html.erb @@ -71,10 +71,10 @@
    - +
    - +
    diff --git a/config/locales/activerecord.en.yml b/config/locales/activerecord.en.yml index d36a481ae..0af387a50 100644 --- a/config/locales/activerecord.en.yml +++ b/config/locales/activerecord.en.yml @@ -176,7 +176,7 @@ en: draft_publication_date: Draft publication date allegations_start_date: Allegations start date allegations_end_date: Allegations end date - final_publication_date: Final result publication date + result_publication_date: Final result publication date legislation/draft_version: title: Version title body: Text diff --git a/config/locales/activerecord.es.yml b/config/locales/activerecord.es.yml index f42577ef2..b2b5fc20e 100644 --- a/config/locales/activerecord.es.yml +++ b/config/locales/activerecord.es.yml @@ -171,7 +171,7 @@ es: draft_publication_date: Fecha de publicación del borrador allegations_start_date: Fecha de inicio de alegaciones allegations_end_date: Fecha de fin de alegaciones - final_publication_date: Fecha de publicación del resultado final + result_publication_date: Fecha de publicación del resultado final legislation/draft_version: title: Título de la version body: Texto diff --git a/config/locales/legislation.en.yml b/config/locales/legislation.en.yml index 7faa3b44c..793341bac 100644 --- a/config/locales/legislation.en.yml +++ b/config/locales/legislation.en.yml @@ -76,7 +76,7 @@ en: debate_dates: Debate draft_publication_date: Draft publication allegations_dates: Allegations - final_publication_date: Final result publication + result_publication_date: Final result publication questions: comments: comment_button: Publish answer diff --git a/config/locales/legislation.es.yml b/config/locales/legislation.es.yml index acb6583ee..59ed9b64c 100644 --- a/config/locales/legislation.es.yml +++ b/config/locales/legislation.es.yml @@ -76,7 +76,7 @@ es: debate_dates: Debate previo draft_publication_date: Publicación borrador allegations_dates: Alegaciones - final_publication_date: Publicación resultados + result_publication_date: Publicación resultados questions: comments: comment_button: Publicar respuesta diff --git a/db/dev_seeds.rb b/db/dev_seeds.rb index 5dd5bc0c7..d828262bf 100644 --- a/db/dev_seeds.rb +++ b/db/dev_seeds.rb @@ -643,7 +643,7 @@ print "Creating legislation processes" draft_publication_date: Date.current + 1.day, allegations_start_date: Date.current + 2.days, allegations_end_date: Date.current + 3.days, - final_publication_date: Date.current + 4.days + result_publication_date: Date.current + 4.days ) end diff --git a/db/migrate/20170613174317_rename_legislation_process_final_pub_to_result_pub.rb b/db/migrate/20170613174317_rename_legislation_process_final_pub_to_result_pub.rb new file mode 100644 index 000000000..e71314531 --- /dev/null +++ b/db/migrate/20170613174317_rename_legislation_process_final_pub_to_result_pub.rb @@ -0,0 +1,5 @@ +class RenameLegislationProcessFinalPubToResultPub < ActiveRecord::Migration + def change + rename_column :legislation_processes, :final_publication_date, :result_publication_date + end +end diff --git a/db/schema.rb b/db/schema.rb index ad8bffd24..39c9d97a5 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: 20170610211027) do +ActiveRecord::Schema.define(version: 20170613174317) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -412,7 +412,7 @@ ActiveRecord::Schema.define(version: 20170610211027) do t.date "draft_publication_date" t.date "allegations_start_date" t.date "allegations_end_date" - t.date "final_publication_date" + t.date "result_publication_date" t.datetime "hidden_at" t.datetime "created_at", null: false t.datetime "updated_at", null: false @@ -425,8 +425,8 @@ ActiveRecord::Schema.define(version: 20170610211027) do add_index "legislation_processes", ["debate_start_date"], name: "index_legislation_processes_on_debate_start_date", using: :btree add_index "legislation_processes", ["draft_publication_date"], name: "index_legislation_processes_on_draft_publication_date", using: :btree add_index "legislation_processes", ["end_date"], name: "index_legislation_processes_on_end_date", using: :btree - add_index "legislation_processes", ["final_publication_date"], name: "index_legislation_processes_on_final_publication_date", using: :btree add_index "legislation_processes", ["hidden_at"], name: "index_legislation_processes_on_hidden_at", using: :btree + add_index "legislation_processes", ["result_publication_date"], name: "index_legislation_processes_on_result_publication_date", using: :btree add_index "legislation_processes", ["start_date"], name: "index_legislation_processes_on_start_date", using: :btree create_table "legislation_question_options", force: :cascade do |t| diff --git a/spec/factories.rb b/spec/factories.rb index 80c8b23d0..cc39af5d7 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -611,7 +611,7 @@ FactoryGirl.define do draft_publication_date Date.current - 1.day allegations_start_date Date.current allegations_end_date Date.current + 3.days - final_publication_date Date.current + 5.days + result_publication_date Date.current + 5.days trait :next do start_date Date.current + 2.days @@ -621,7 +621,7 @@ FactoryGirl.define do draft_publication_date Date.current + 5.day allegations_start_date Date.current + 5.days allegations_end_date Date.current + 7.days - final_publication_date Date.current + 8.days + result_publication_date Date.current + 8.days end trait :past do @@ -632,7 +632,7 @@ FactoryGirl.define do draft_publication_date Date.current - 8.day allegations_start_date Date.current - 8.days allegations_end_date Date.current - 4.days - final_publication_date Date.current - 2.days + result_publication_date Date.current - 2.days end trait :in_debate_phase do @@ -643,7 +643,7 @@ FactoryGirl.define do draft_publication_date Date.current + 1.day allegations_start_date Date.current + 2.days allegations_end_date Date.current + 3.days - final_publication_date Date.current + 5.days + result_publication_date Date.current + 5.days end end diff --git a/spec/features/admin/legislation/processes_spec.rb b/spec/features/admin/legislation/processes_spec.rb index 60a872190..2c8de0d95 100644 --- a/spec/features/admin/legislation/processes_spec.rb +++ b/spec/features/admin/legislation/processes_spec.rb @@ -51,7 +51,7 @@ feature 'Admin legislation processes' do fill_in 'legislation_process[draft_publication_date]', with: (base_date + 3.days).strftime("%d/%m/%Y") fill_in 'legislation_process[allegations_start_date]', with: (base_date + 3.days).strftime("%d/%m/%Y") fill_in 'legislation_process[allegations_end_date]', with: (base_date + 5.days).strftime("%d/%m/%Y") - fill_in 'legislation_process[final_publication_date]', with: (base_date + 7.days).strftime("%d/%m/%Y") + fill_in 'legislation_process[result_publication_date]', with: (base_date + 7.days).strftime("%d/%m/%Y") click_button 'Create process' diff --git a/spec/features/legislation/processes_spec.rb b/spec/features/legislation/processes_spec.rb index 66356dff8..caae66490 100644 --- a/spec/features/legislation/processes_spec.rb +++ b/spec/features/legislation/processes_spec.rb @@ -104,7 +104,7 @@ feature 'Legislation' do context 'final version publication phase' do scenario 'not open' do - process = create(:legislation_process, final_publication_date: Date.current + 1.day) + process = create(:legislation_process, result_publication_date: Date.current + 1.day) visit legislation_process_final_version_publication_path(process) @@ -112,7 +112,7 @@ feature 'Legislation' do end scenario 'open' do - process = create(:legislation_process, final_publication_date: Date.current) + process = create(:legislation_process, result_publication_date: Date.current) visit legislation_process_final_version_publication_path(process) diff --git a/spec/models/legislation/process_spec.rb b/spec/models/legislation/process_spec.rb index f89a4bfcf..239abad1b 100644 --- a/spec/models/legislation/process_spec.rb +++ b/spec/models/legislation/process_spec.rb @@ -154,15 +154,15 @@ RSpec.describe Legislation::Process, type: :model do it "checks final version publication phase" do # future - process.update_attributes(final_publication_date: Date.current + 2.days) + process.update_attributes(result_publication_date: Date.current + 2.days) expect(process.open_phase?(:final_version_publication)).to be false # past - process.update_attributes(final_publication_date: Date.current - 2.days) + process.update_attributes(result_publication_date: Date.current - 2.days) expect(process.open_phase?(:final_version_publication)).to be true # starts today - process.update_attributes(final_publication_date: Date.current) + process.update_attributes(result_publication_date: Date.current) expect(process.open_phase?(:final_version_publication)).to be true end end @@ -220,15 +220,15 @@ RSpec.describe Legislation::Process, type: :model do it "checks final version publication phase" do # future - process.update_attributes(final_publication_date: Date.current + 2.days) + process.update_attributes(result_publication_date: Date.current + 2.days) expect(process.show_phase?(:final_version_publication)).to be false # past - process.update_attributes(final_publication_date: Date.current - 2.days) + process.update_attributes(result_publication_date: Date.current - 2.days) expect(process.show_phase?(:final_version_publication)).to be true # starts today - process.update_attributes(final_publication_date: Date.current) + process.update_attributes(result_publication_date: Date.current) expect(process.show_phase?(:final_version_publication)).to be true end end From edee908fc1ab565408d0f99043e99435fa7ea33d Mon Sep 17 00:00:00 2001 From: Bertocq Date: Tue, 13 Jun 2017 19:52:28 +0200 Subject: [PATCH 02/25] Create Legislation Process Phase and Publication classes to enclose enabled?/started?/open? logic --- app/models/legislation/process/phase.rb | 22 +++++++++++++++++++ app/models/legislation/process/publication.rb | 21 ++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 app/models/legislation/process/phase.rb create mode 100644 app/models/legislation/process/publication.rb diff --git a/app/models/legislation/process/phase.rb b/app/models/legislation/process/phase.rb new file mode 100644 index 000000000..1b8482a9a --- /dev/null +++ b/app/models/legislation/process/phase.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +class Legislation::Process::Phase + + def initialize(start_date, end_date) + @start_date = start_date + @end_date = end_date + end + + def enabled? + @start_date.present? && @end_date.present? + end + + def started? + enabled? && Date.current >= @start_date + end + + def open? + started? && Date.current <= @end_date + end + +end diff --git a/app/models/legislation/process/publication.rb b/app/models/legislation/process/publication.rb new file mode 100644 index 000000000..10110f0e7 --- /dev/null +++ b/app/models/legislation/process/publication.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +class Legislation::Process::Publication + + def initialize(publication_date) + @publication_date = publication_date + end + + def enabled? + @publication_date.present? + end + + def started? + enabled? && Date.current >= @publication_date + end + + def open? + started? + end + +end From e55328caf49b694e26a5ef44e1abfb8f82e9faf9 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Tue, 13 Jun 2017 19:59:49 +0200 Subject: [PATCH 03/25] Rename legislation process final_version_publication phase name to more descriptive result_publication --- app/controllers/legislation/processes_controller.rb | 4 ++-- app/models/abilities/everyone.rb | 2 +- app/models/legislation/process.rb | 10 +++++----- app/views/admin/legislation/processes/_form.html.erb | 4 ++-- app/views/legislation/processes/_key_dates.html.erb | 6 +++--- config/routes.rb | 2 +- spec/features/legislation/processes_spec.rb | 4 ++-- spec/models/legislation/process_spec.rb | 12 ++++++------ 8 files changed, 22 insertions(+), 22 deletions(-) diff --git a/app/controllers/legislation/processes_controller.rb b/app/controllers/legislation/processes_controller.rb index 7aff709d0..a10bb5637 100644 --- a/app/controllers/legislation/processes_controller.rb +++ b/app/controllers/legislation/processes_controller.rb @@ -55,8 +55,8 @@ class Legislation::ProcessesController < Legislation::BaseController end end - def final_version_publication - phase :final_version_publication + def result_publication + phase :result_publication if @process.show_phase?(@phase) if final_version = @process.final_draft_version diff --git a/app/models/abilities/everyone.rb b/app/models/abilities/everyone.rb index c22a3f7e4..eaa971016 100644 --- a/app/models/abilities/everyone.rb +++ b/app/models/abilities/everyone.rb @@ -19,7 +19,7 @@ module Abilities can [:read, :print], Budget::Investment can :read_results, Budget, phase: "finished" can :new, DirectMessage - can [:read, :debate, :draft_publication, :allegations, :final_version_publication], Legislation::Process + can [:read, :debate, :draft_publication, :allegations, :result_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/process.rb b/app/models/legislation/process.rb index 32468b834..c63d5ef1b 100644 --- a/app/models/legislation/process.rb +++ b/app/models/legislation/process.rb @@ -29,8 +29,8 @@ class Legislation::Process < ActiveRecord::Base active_phase?(:draft_publication) && today >= draft_publication_date when :allegations active_phase?(:allegations) && today >= allegations_start_date && today <= allegations_end_date - when :final_version_publication - active_phase?(:final_version_publication) && today >= final_publication_date + when :result_publication + active_phase?(:result_publication) && today >= final_publication_date end end @@ -45,8 +45,8 @@ class Legislation::Process < ActiveRecord::Base active_phase?(:draft_publication) && today >= draft_publication_date when :allegations active_phase?(:allegations) && today >= allegations_start_date - when :final_version_publication - active_phase?(:final_version_publication) && today >= final_publication_date + when :result_publication + active_phase?(:result_publication) && today >= final_publication_date end end @@ -58,7 +58,7 @@ class Legislation::Process < ActiveRecord::Base draft_publication_date.present? when :allegations allegations_start_date.present? && allegations_end_date.present? - when :final_version_publication + when :result_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 9d877a3da..88cb6560b 100644 --- a/app/views/admin/legislation/processes/_form.html.erb +++ b/app/views/admin/legislation/processes/_form.html.erb @@ -145,8 +145,8 @@ id: "result_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') %> + <%= check_box_tag :result_publication_phase_active, @process.active_phase?(:result_publication), @process.new_record? || @process.active_phase?(:result_publication), data: {disable_date: "final_publication"} %> + <%= label_tag :result_publication_phase_active, t('admin.legislation.processes.form.active') %>

    diff --git a/app/views/legislation/processes/_key_dates.html.erb b/app/views/legislation/processes/_key_dates.html.erb index ab2bd72c9..23471d217 100644 --- a/app/views/legislation/processes/_key_dates.html.erb +++ b/app/views/legislation/processes/_key_dates.html.erb @@ -34,9 +34,9 @@ <% end %> - <% if process.active_phase?(:final_version_publication) %> -
  • > - <%= link_to legislation_process_final_version_publication_path(process) do %> + <% if process.active_phase?(:result_publication) %> +
  • > + <%= link_to legislation_process_result_publication_path(process) do %>

    <%= t('legislation.processes.shared.result_publication_date') %>

    <%= format_date(process.result_publication_date) %>

    <% end %> diff --git a/config/routes.rb b/config/routes.rb index 6cbd69c3a..05d58ffab 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -112,7 +112,7 @@ Rails.application.routes.draw do get :debate get :draft_publication get :allegations - get :final_version_publication + get :result_publication resources :questions, only: [:show] do resources :answers, only: [:create] end diff --git a/spec/features/legislation/processes_spec.rb b/spec/features/legislation/processes_spec.rb index caae66490..3ed4ccb74 100644 --- a/spec/features/legislation/processes_spec.rb +++ b/spec/features/legislation/processes_spec.rb @@ -106,7 +106,7 @@ feature 'Legislation' do scenario 'not open' do process = create(:legislation_process, result_publication_date: Date.current + 1.day) - visit legislation_process_final_version_publication_path(process) + visit legislation_process_result_publication_path(process) expect(page).to have_content("This phase is not open yet") end @@ -114,7 +114,7 @@ feature 'Legislation' do scenario 'open' do process = create(:legislation_process, result_publication_date: Date.current) - visit legislation_process_final_version_publication_path(process) + visit legislation_process_result_publication_path(process) expect(page).to have_content("Nothing published yet") end diff --git a/spec/models/legislation/process_spec.rb b/spec/models/legislation/process_spec.rb index 239abad1b..1f831aee8 100644 --- a/spec/models/legislation/process_spec.rb +++ b/spec/models/legislation/process_spec.rb @@ -155,15 +155,15 @@ RSpec.describe Legislation::Process, type: :model do it "checks final version publication phase" do # future process.update_attributes(result_publication_date: Date.current + 2.days) - expect(process.open_phase?(:final_version_publication)).to be false + expect(process.open_phase?(:result_publication)).to be false # past process.update_attributes(result_publication_date: Date.current - 2.days) - expect(process.open_phase?(:final_version_publication)).to be true + expect(process.open_phase?(:result_publication)).to be true # starts today process.update_attributes(result_publication_date: Date.current) - expect(process.open_phase?(:final_version_publication)).to be true + expect(process.open_phase?(:result_publication)).to be true end end @@ -221,15 +221,15 @@ RSpec.describe Legislation::Process, type: :model do it "checks final version publication phase" do # future process.update_attributes(result_publication_date: Date.current + 2.days) - expect(process.show_phase?(:final_version_publication)).to be false + expect(process.show_phase?(:result_publication)).to be false # past process.update_attributes(result_publication_date: Date.current - 2.days) - expect(process.show_phase?(:final_version_publication)).to be true + expect(process.show_phase?(:result_publication)).to be true # starts today process.update_attributes(result_publication_date: Date.current) - expect(process.show_phase?(:final_version_publication)).to be true + expect(process.show_phase?(:result_publication)).to be true end end From 10954859c75b534351b4670c694f55c5c723831e Mon Sep 17 00:00:00 2001 From: Bertocq Date: Tue, 13 Jun 2017 20:10:38 +0200 Subject: [PATCH 04/25] Add debate/allegations phases and draft/result publications helper methods to Legislation Process --- app/models/legislation/process.rb | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/app/models/legislation/process.rb b/app/models/legislation/process.rb index c63d5ef1b..6fa46a606 100644 --- a/app/models/legislation/process.rb +++ b/app/models/legislation/process.rb @@ -30,7 +30,7 @@ class Legislation::Process < ActiveRecord::Base when :allegations active_phase?(:allegations) && today >= allegations_start_date && today <= allegations_end_date when :result_publication - active_phase?(:result_publication) && today >= final_publication_date + active_phase?(:result_publication) && today >= result_publication_date end end @@ -46,7 +46,7 @@ class Legislation::Process < ActiveRecord::Base when :allegations active_phase?(:allegations) && today >= allegations_start_date when :result_publication - active_phase?(:result_publication) && today >= final_publication_date + active_phase?(:result_publication) && today >= result_publication_date end end @@ -59,10 +59,26 @@ class Legislation::Process < ActiveRecord::Base when :allegations allegations_start_date.present? && allegations_end_date.present? when :result_publication - final_publication_date.present? + result_publication_date.present? end end + def debate_phase + Legislation::Process::Phase.new(debate_start_date, debate_end_date) + end + + def allegations_phase + Legislation::Process::Phase.new(allegations_start_date, allegations_end_date) + end + + def draft_publication + Legislation::Process::Publication.new(draft_publication_date) + end + + def result_publication + Legislation::Process::Publication.new(result_publication_date) + end + def total_comments questions.sum(:comments_count) + draft_versions.map(&:total_comments).sum end From 12dc7a47902bd691324c00966c5caa86ec6c3e67 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Tue, 13 Jun 2017 20:33:00 +0200 Subject: [PATCH 05/25] Add specs for Legislation::Process Phase and Publication enabled?/started?/open? methods --- spec/models/legislation/process/phase_spec.rb | 99 +++++++++++++++++++ .../legislation/process/publication_spec.rb | 81 +++++++++++++++ 2 files changed, 180 insertions(+) create mode 100644 spec/models/legislation/process/phase_spec.rb create mode 100644 spec/models/legislation/process/publication_spec.rb diff --git a/spec/models/legislation/process/phase_spec.rb b/spec/models/legislation/process/phase_spec.rb new file mode 100644 index 000000000..a92b36f78 --- /dev/null +++ b/spec/models/legislation/process/phase_spec.rb @@ -0,0 +1,99 @@ +require 'rails_helper' + +RSpec.describe Legislation::Process::Phase, type: :model do + let(:process) { create(:legislation_process) } + + describe "#enabled?" do + it "checks debate phase" do + expect(process.debate_phase.enabled?).to be true + + process.update_attributes(debate_start_date: nil, debate_end_date: nil) + expect(process.debate_phase.enabled?).to be false + end + + it "checks allegations phase" do + expect(process.allegations_phase.enabled?).to be true + + process.update_attributes(allegations_start_date: nil, allegations_end_date: nil) + expect(process.allegations_phase.enabled?).to be false + end + end + + describe "#started?" do + it "checks debate phase" do + # future + process.update_attributes(debate_start_date: Date.current + 2.days, debate_end_date: Date.current + 3.days) + expect(process.debate_phase.started?).to be false + + # started + process.update_attributes(debate_start_date: Date.current - 2.days, debate_end_date: Date.current + 1.day) + expect(process.debate_phase.started?).to be true + + # starts today + process.update_attributes(debate_start_date: Date.current, debate_end_date: Date.current + 1.day) + expect(process.debate_phase.started?).to be true + + # past + process.update_attributes(debate_start_date: Date.current - 2.days, debate_end_date: Date.current - 1.day) + expect(process.debate_phase.started?).to be true + end + + it "checks allegations phase" do + # future + process.update_attributes(allegations_start_date: Date.current + 2.days, allegations_end_date: Date.current + 3.days) + expect(process.allegations_phase.started?).to be false + + # started + process.update_attributes(allegations_start_date: Date.current - 2.days, allegations_end_date: Date.current + 1.day) + expect(process.allegations_phase.started?).to be true + + # starts today + process.update_attributes(allegations_start_date: Date.current, allegations_end_date: Date.current + 1.day) + expect(process.allegations_phase.started?).to be true + + # past + process.update_attributes(allegations_start_date: Date.current - 2.days, allegations_end_date: Date.current - 1.day) + expect(process.allegations_phase.started?).to be true + end + end + + describe "#open?" do + it "checks debate phase" do + # future + process.update_attributes(debate_start_date: Date.current + 2.days, debate_end_date: Date.current + 3.days) + expect(process.debate_phase.open?).to be false + + # started + process.update_attributes(debate_start_date: Date.current - 2.days, debate_end_date: Date.current + 1.day) + expect(process.debate_phase.open?).to be true + + # starts today + process.update_attributes(debate_start_date: Date.current, debate_end_date: Date.current + 1.day) + expect(process.debate_phase.open?).to be true + + # past + process.update_attributes(debate_start_date: Date.current - 2.days, debate_end_date: Date.current - 1.day) + expect(process.debate_phase.open?).to be false + end + + it "checks allegations phase" do + + # future + process.update_attributes(allegations_start_date: Date.current + 2.days, allegations_end_date: Date.current + 3.days) + expect(process.allegations_phase.open?).to be false + + # started + process.update_attributes(allegations_start_date: Date.current - 2.days, allegations_end_date: Date.current + 1.day) + expect(process.allegations_phase.open?).to be true + + # starts today + process.update_attributes(allegations_start_date: Date.current, allegations_end_date: Date.current + 1.day) + expect(process.allegations_phase.open?).to be true + + # past + process.update_attributes(allegations_start_date: Date.current - 2.days, allegations_end_date: Date.current - 1.day) + expect(process.allegations_phase.open?).to be false + end + end + +end diff --git a/spec/models/legislation/process/publication_spec.rb b/spec/models/legislation/process/publication_spec.rb new file mode 100644 index 000000000..4731d14b2 --- /dev/null +++ b/spec/models/legislation/process/publication_spec.rb @@ -0,0 +1,81 @@ +require 'rails_helper' + +RSpec.describe Legislation::Process::Publication, type: :model do + let(:process) { create(:legislation_process) } + + describe "#enabled?" do + it "checks draft publication" do + expect(process.draft_publication.enabled?).to be true + + process.update_attributes(draft_publication_date: nil) + expect(process.draft_publication.enabled?).to be false + end + + it "checks result publication" do + expect(process.result_publication.enabled?).to be true + + process.update_attributes(result_publication_date: nil) + expect(process.result_publication.enabled?).to be false + end + end + + describe "#started?" do + it "checks draft publication" do + # future + process.update_attributes(draft_publication_date: Date.current + 2.days) + expect(process.draft_publication.started?).to be false + + # past + process.update_attributes(draft_publication_date: Date.current - 2.days) + expect(process.draft_publication.started?).to be true + + # starts today + process.update_attributes(draft_publication_date: Date.current) + expect(process.draft_publication.started?).to be true + end + + it "checks result publication" do + # future + process.update_attributes(result_publication_date: Date.current + 2.days) + expect(process.result_publication.started?).to be false + + # past + process.update_attributes(result_publication_date: Date.current - 2.days) + expect(process.result_publication.started?).to be true + + # starts today + process.update_attributes(result_publication_date: Date.current) + expect(process.result_publication.started?).to be true + end + end + + describe "#open?" do + it "checks draft publication" do + # future + process.update_attributes(draft_publication_date: Date.current + 2.days) + expect(process.draft_publication.open?).to be false + + # past + process.update_attributes(draft_publication_date: Date.current - 2.days) + expect(process.draft_publication.open?).to be true + + # starts today + process.update_attributes(draft_publication_date: Date.current) + expect(process.draft_publication.open?).to be true + end + + it "checks result publication" do + # future + process.update_attributes(result_publication_date: Date.current + 2.days) + expect(process.result_publication.open?).to be false + + # past + process.update_attributes(result_publication_date: Date.current - 2.days) + expect(process.result_publication.open?).to be true + + # starts today + process.update_attributes(result_publication_date: Date.current) + expect(process.result_publication.open?).to be true + end + end +end From 523988a29101bee7e4eda1a66425c4618c07818d Mon Sep 17 00:00:00 2001 From: Bertocq Date: Tue, 13 Jun 2017 20:33:41 +0200 Subject: [PATCH 06/25] Replace old open_phase? method for new phase/publication open? on Legislative Process --- app/controllers/legislation/annotations_controller.rb | 2 +- app/controllers/legislation/answers_controller.rb | 2 +- app/models/legislation/question.rb | 2 +- app/views/legislation/annotations/_comments_box.html.erb | 4 ++-- app/views/legislation/annotations/_form.html.erb | 2 +- app/views/legislation/draft_versions/show.html.erb | 2 +- app/views/legislation/questions/_answer_form.html.erb | 2 +- .../legislation/questions/_participation_not_allowed.html.erb | 2 +- 8 files changed, 9 insertions(+), 9 deletions(-) diff --git a/app/controllers/legislation/annotations_controller.rb b/app/controllers/legislation/annotations_controller.rb index dc3ff4834..56f851316 100644 --- a/app/controllers/legislation/annotations_controller.rb +++ b/app/controllers/legislation/annotations_controller.rb @@ -29,7 +29,7 @@ class Legislation::AnnotationsController < ApplicationController end def create - if !@process.open_phase?(:allegations) || @draft_version.final_version? + if !@process.allegations_phase.open? || @draft_version.final_version? render json: {}, status: :not_found and return end diff --git a/app/controllers/legislation/answers_controller.rb b/app/controllers/legislation/answers_controller.rb index 372398e41..6d3c33580 100644 --- a/app/controllers/legislation/answers_controller.rb +++ b/app/controllers/legislation/answers_controller.rb @@ -9,7 +9,7 @@ class Legislation::AnswersController < Legislation::BaseController respond_to :html, :js def create - if @process.open_phase?(:debate) + if @process.debate_phase.open? @answer.user = current_user @answer.save track_event diff --git a/app/models/legislation/question.rb b/app/models/legislation/question.rb index 374c43eb5..4381b752a 100644 --- a/app/models/legislation/question.rb +++ b/app/models/legislation/question.rb @@ -37,6 +37,6 @@ class Legislation::Question < ActiveRecord::Base end def comments_open? - process.open_phase?(:debate) + process.debate_phase.open? end end diff --git a/app/views/legislation/annotations/_comments_box.html.erb b/app/views/legislation/annotations/_comments_box.html.erb index 79fdbef4b..d76d273c1 100644 --- a/app/views/legislation/annotations/_comments_box.html.erb +++ b/app/views/legislation/annotations/_comments_box.html.erb @@ -15,12 +15,12 @@ <% end %> <% end %> - <% if @process.open_phase?(:allegations) %> + <% if @process.allegations_phase.open? %> <%= t('legislation.annotations.comments.publish_comment') %>   <% end %> - <% if @process.open_phase?(:allegations) %> + <% if @process.allegations_phase.open? %> <% if user_signed_in? %> <% css_id = parent_or_commentable_dom_id(nil, annotation) %>
    - <%= check_box_tag :allegations_phase_active, @process.active_phase?(:allegations), @process.new_record? || @process.active_phase?(:allegations), data: {disable_date: "allegations"} %> + <%= check_box_tag :allegations_phase_active, @process.allegations_phase.enabled?, @process.new_record? || @process.allegations_phase.enabled?, data: {disable_date: "allegations"} %> <%= label_tag :allegations_phase_active, t('admin.legislation.processes.form.active') %>
    @@ -125,7 +125,7 @@ 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"} %> + <%= check_box_tag :draft_publication_phase_active, @process.draft_publication.enabled?, @process.new_record? || @process.draft_publication.enabled?, data: {disable_date: "draft_publication"} %> <%= label_tag :draft_publication_phase_active, t('admin.legislation.processes.form.active') %>
    @@ -145,7 +145,7 @@ id: "result_publication_date" %>
    - <%= check_box_tag :result_publication_phase_active, @process.active_phase?(:result_publication), @process.new_record? || @process.active_phase?(:result_publication), data: {disable_date: "final_publication"} %> + <%= check_box_tag :result_publication_phase_active, @process.result_publication.enabled?, @process.new_record? || @process.result_publication.enabled?, data: {disable_date: "final_publication"} %> <%= label_tag :result_publication_phase_active, t('admin.legislation.processes.form.active') %>
    diff --git a/app/views/legislation/processes/_key_dates.html.erb b/app/views/legislation/processes/_key_dates.html.erb index 23471d217..5e4d37ccf 100644 --- a/app/views/legislation/processes/_key_dates.html.erb +++ b/app/views/legislation/processes/_key_dates.html.erb @@ -7,7 +7,7 @@
      - <% if process.active_phase?(:debate) %> + <% if process.debate_phase.enabled? %>
    • > <%= link_to legislation_process_debate_path(process) do %>

      <%= t('legislation.processes.shared.debate_dates') %>

      @@ -16,7 +16,7 @@
    • <% end %> - <% if process.active_phase?(:draft_publication) %> + <% if process.draft_publication.enabled? %>
    • > <%= link_to legislation_process_draft_publication_path(process) do %>

      <%= t('legislation.processes.shared.draft_publication_date') %>

      @@ -25,7 +25,7 @@
    • <% end %> - <% if process.active_phase?(:allegations) %> + <% if process.allegations_phase.enabled? %>
    • > <%= link_to legislation_process_allegations_path(process) do %>

      <%= t('legislation.processes.shared.allegations_dates') %>

      @@ -34,7 +34,7 @@
    • <% end %> - <% if process.active_phase?(:result_publication) %> + <% if process.result_publication.enabled? %>
    • > <%= link_to legislation_process_result_publication_path(process) do %>

      <%= t('legislation.processes.shared.result_publication_date') %>

      From 990437dc406e629dabd59181720528c7acee3877 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Tue, 13 Jun 2017 20:43:40 +0200 Subject: [PATCH 09/25] Remove no longer used active/show/open _phase helper methods from Legislation Process, and specs --- app/models/legislation/process.rb | 44 -------- spec/models/legislation/process_spec.rb | 133 ------------------------ 2 files changed, 177 deletions(-) diff --git a/app/models/legislation/process.rb b/app/models/legislation/process.rb index 6fa46a606..d7ad6cf62 100644 --- a/app/models/legislation/process.rb +++ b/app/models/legislation/process.rb @@ -19,50 +19,6 @@ class Legislation::Process < ActiveRecord::Base scope :next, -> { where("start_date > ?", Date.current).order('id DESC') } scope :past, -> { where("end_date < ?", Date.current).order('id DESC') } - def open_phase?(phase) - today = Date.current - - case phase - when :debate - active_phase?(:debate) && today >= debate_start_date && today <= debate_end_date - when :draft_publication - active_phase?(:draft_publication) && today >= draft_publication_date - when :allegations - active_phase?(:allegations) && today >= allegations_start_date && today <= allegations_end_date - when :result_publication - active_phase?(:result_publication) && today >= result_publication_date - end - end - - def show_phase?(phase) - # show past phases even if they're finished - today = Date.current - - case phase - when :debate - active_phase?(:debate) && today >= debate_start_date - when :draft_publication - active_phase?(:draft_publication) && today >= draft_publication_date - when :allegations - active_phase?(:allegations) && today >= allegations_start_date - when :result_publication - active_phase?(:result_publication) && today >= result_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 :result_publication - result_publication_date.present? - end - end - def debate_phase Legislation::Process::Phase.new(debate_start_date, debate_end_date) end diff --git a/spec/models/legislation/process_spec.rb b/spec/models/legislation/process_spec.rb index 1f831aee8..f14e81c8e 100644 --- a/spec/models/legislation/process_spec.rb +++ b/spec/models/legislation/process_spec.rb @@ -100,139 +100,6 @@ RSpec.describe Legislation::Process, type: :model do end end - describe "#open_phase?" do - it "checks debate phase" do - # future - process.update_attributes(debate_start_date: Date.current + 2.days, debate_end_date: Date.current + 3.days) - expect(process.open_phase?(:debate)).to be false - - # started - process.update_attributes(debate_start_date: Date.current - 2.days, debate_end_date: Date.current + 1.day) - expect(process.open_phase?(:debate)).to be true - - # starts today - process.update_attributes(debate_start_date: Date.current, debate_end_date: Date.current + 1.day) - expect(process.open_phase?(:debate)).to be true - - # past - process.update_attributes(debate_start_date: Date.current - 2.days, debate_end_date: Date.current - 1.day) - expect(process.open_phase?(:debate)).to be false - end - - it "checks allegations phase" do - - # future - process.update_attributes(allegations_start_date: Date.current + 2.days, allegations_end_date: Date.current + 3.days) - expect(process.open_phase?(:allegations)).to be false - - # started - process.update_attributes(allegations_start_date: Date.current - 2.days, allegations_end_date: Date.current + 1.day) - expect(process.open_phase?(:allegations)).to be true - - # starts today - process.update_attributes(allegations_start_date: Date.current, allegations_end_date: Date.current + 1.day) - expect(process.open_phase?(:allegations)).to be true - - # past - process.update_attributes(allegations_start_date: Date.current - 2.days, allegations_end_date: Date.current - 1.day) - expect(process.open_phase?(:allegations)).to be false - end - - it "checks draft publication phase" do - # future - process.update_attributes(draft_publication_date: Date.current + 2.days) - expect(process.open_phase?(:draft_publication)).to be false - - # past - process.update_attributes(draft_publication_date: Date.current - 2.days) - expect(process.open_phase?(:draft_publication)).to be true - - # starts today - process.update_attributes(draft_publication_date: Date.current) - expect(process.open_phase?(:draft_publication)).to be true - end - - it "checks final version publication phase" do - # future - process.update_attributes(result_publication_date: Date.current + 2.days) - expect(process.open_phase?(:result_publication)).to be false - - # past - process.update_attributes(result_publication_date: Date.current - 2.days) - expect(process.open_phase?(:result_publication)).to be true - - # starts today - process.update_attributes(result_publication_date: Date.current) - expect(process.open_phase?(:result_publication)).to be true - end - end - - describe "#show_phase?" do - it "checks debate phase" do - # future - process.update_attributes(debate_start_date: Date.current + 2.days, debate_end_date: Date.current + 3.days) - expect(process.show_phase?(:debate)).to be false - - # started - process.update_attributes(debate_start_date: Date.current - 2.days, debate_end_date: Date.current + 1.day) - expect(process.show_phase?(:debate)).to be true - - # starts today - process.update_attributes(debate_start_date: Date.current, debate_end_date: Date.current + 1.day) - expect(process.show_phase?(:debate)).to be true - - # past - process.update_attributes(debate_start_date: Date.current - 2.days, debate_end_date: Date.current - 1.day) - expect(process.show_phase?(:debate)).to be true - end - - it "checks allegations phase" do - # future - process.update_attributes(allegations_start_date: Date.current + 2.days, allegations_end_date: Date.current + 3.days) - expect(process.show_phase?(:allegations)).to be false - - # started - process.update_attributes(allegations_start_date: Date.current - 2.days, allegations_end_date: Date.current + 1.day) - expect(process.show_phase?(:allegations)).to be true - - # starts today - process.update_attributes(allegations_start_date: Date.current, allegations_end_date: Date.current + 1.day) - expect(process.show_phase?(:allegations)).to be true - - # past - process.update_attributes(allegations_start_date: Date.current - 2.days, allegations_end_date: Date.current - 1.day) - expect(process.show_phase?(:allegations)).to be true - end - - it "checks draft publication phase" do - # future - process.update_attributes(draft_publication_date: Date.current + 2.days) - expect(process.show_phase?(:draft_publication)).to be false - - # past - process.update_attributes(draft_publication_date: Date.current - 2.days) - expect(process.show_phase?(:draft_publication)).to be true - - # starts today - process.update_attributes(draft_publication_date: Date.current) - expect(process.show_phase?(:draft_publication)).to be true - end - - it "checks final version publication phase" do - # future - process.update_attributes(result_publication_date: Date.current + 2.days) - expect(process.show_phase?(:result_publication)).to be false - - # past - process.update_attributes(result_publication_date: Date.current - 2.days) - expect(process.show_phase?(:result_publication)).to be true - - # starts today - process.update_attributes(result_publication_date: Date.current) - expect(process.show_phase?(:result_publication)).to be true - end - end - describe "#status" do it "should detect planned phase" do process.update_attributes(start_date: Date.current + 2.days) From 2018fc0b7d954478f670b06b4f662f7713849d98 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Tue, 13 Jun 2017 21:27:59 +0200 Subject: [PATCH 10/25] Fix Legislation Process Controller to correctly set both @phase and @process --- .../legislation/processes_controller.rb | 46 ++++++++++++------- 1 file changed, 29 insertions(+), 17 deletions(-) diff --git a/app/controllers/legislation/processes_controller.rb b/app/controllers/legislation/processes_controller.rb index b9a6e65fa..21951fa6f 100644 --- a/app/controllers/legislation/processes_controller.rb +++ b/app/controllers/legislation/processes_controller.rb @@ -8,17 +8,20 @@ class Legislation::ProcessesController < Legislation::BaseController end def show - if process.allegations_phase.enabled? && process.allegations_phase.started? && draft_version = process.draft_versions.published.last - redirect_to legislation_process_draft_version_path(process, draft_version) - elsif process.debate_phase.enabled? - redirect_to legislation_process_debate_path(process) + if @process.allegations_phase.enabled? && @process.allegations_phase.started? && draft_version = @process.draft_versions.published.last + redirect_to legislation_process_draft_version_path(@process, draft_version) + elsif @process.debate_phase.enabled? + redirect_to legislation_process_debate_path(@process) else - redirect_to legislation_process_allegations_path(process) + redirect_to legislation_process_allegations_path(@process) end end def debate - if process.debate_phase.started? + set_process + @phase = :debate_phase + + if @process.debate_phase.started? render :debate else render :phase_not_open @@ -26,9 +29,12 @@ class Legislation::ProcessesController < Legislation::BaseController end def draft_publication - if process.draft_publication.started? - if draft_version = process.draft_versions.published.last - redirect_to legislation_process_draft_version_path(process, draft_version) + set_process + @phase = :draft_publication + + if @process.draft_publication.started? + if draft_version = @process.draft_versions.published.last + redirect_to legislation_process_draft_version_path(@process, draft_version) else render :phase_empty end @@ -38,9 +44,12 @@ class Legislation::ProcessesController < Legislation::BaseController end def allegations - if process.allegations_phase.started? - if draft_version = process.draft_versions.published.last - redirect_to legislation_process_draft_version_path(process, draft_version) + set_process + @phase = :allegations_phase + + if @process.allegations_phase.started? + if draft_version = @process.draft_versions.published.last + redirect_to legislation_process_draft_version_path(@process, draft_version) else render :phase_empty end @@ -50,9 +59,12 @@ class Legislation::ProcessesController < Legislation::BaseController end def result_publication - if process.result_publication.started? - if final_version = process.final_draft_version - redirect_to legislation_process_draft_version_path(process, final_version) + set_process + @phase = :result_publication + + if @process.result_publication.started? + if final_version = @process.final_draft_version + redirect_to legislation_process_draft_version_path(@process, final_version) else render :phase_empty end @@ -63,7 +75,7 @@ class Legislation::ProcessesController < Legislation::BaseController private - def process - @process ||= ::Legislation::Process.find(params[:process_id]) + def set_process + @process = ::Legislation::Process.find(params[:process_id]) end end From 004c128b6c5ed89bfc10d22871bddbf5e5aa2ac4 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Tue, 13 Jun 2017 21:28:22 +0200 Subject: [PATCH 11/25] Fix phase name symbol on legislation process key_dates view --- app/views/legislation/processes/_key_dates.html.erb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/legislation/processes/_key_dates.html.erb b/app/views/legislation/processes/_key_dates.html.erb index 5e4d37ccf..d6131034b 100644 --- a/app/views/legislation/processes/_key_dates.html.erb +++ b/app/views/legislation/processes/_key_dates.html.erb @@ -8,7 +8,7 @@
        <% if process.debate_phase.enabled? %> -
      • > +
      • > <%= link_to legislation_process_debate_path(process) do %>

        <%= t('legislation.processes.shared.debate_dates') %>

        <%= format_date(process.debate_start_date) %> - <%= format_date(process.debate_end_date) %>

        @@ -26,7 +26,7 @@ <% end %> <% if process.allegations_phase.enabled? %> -
      • > +
      • > <%= link_to legislation_process_allegations_path(process) do %>

        <%= t('legislation.processes.shared.allegations_dates') %>

        <%= format_date(process.allegations_start_date) %> - <%= format_date(process.allegations_end_date) %>

        From bae9d105fa4c22869afbe9b1d9996c1b97ec018d Mon Sep 17 00:00:00 2001 From: Bertocq Date: Tue, 13 Jun 2017 22:50:38 +0200 Subject: [PATCH 12/25] Add phase and publications enabled column flags to Legislative Process table --- ...add_phase_pub_enabled_status_to_legislative_process.rb | 8 ++++++++ db/schema.rb | 6 +++++- 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20170613203256_add_phase_pub_enabled_status_to_legislative_process.rb diff --git a/db/migrate/20170613203256_add_phase_pub_enabled_status_to_legislative_process.rb b/db/migrate/20170613203256_add_phase_pub_enabled_status_to_legislative_process.rb new file mode 100644 index 000000000..7e6ecda96 --- /dev/null +++ b/db/migrate/20170613203256_add_phase_pub_enabled_status_to_legislative_process.rb @@ -0,0 +1,8 @@ +class AddPhasePubEnabledStatusToLegislativeProcess < ActiveRecord::Migration + def change + add_column :legislation_processes, :debate_phase_enabled, :boolean, default: false + add_column :legislation_processes, :allegations_phase_enabled, :boolean, default: false + add_column :legislation_processes, :draft_publication_enabled, :boolean, default: false + add_column :legislation_processes, :result_publication_enabled, :boolean, default: false + end +end diff --git a/db/schema.rb b/db/schema.rb index 39c9d97a5..1062b3f91 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: 20170613174317) do +ActiveRecord::Schema.define(version: 20170613203256) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -417,6 +417,10 @@ ActiveRecord::Schema.define(version: 20170613174317) do t.datetime "created_at", null: false t.datetime "updated_at", null: false t.text "summary" + t.boolean "debate_phase_enabled", default: false + t.boolean "allegations_phase_enabled", default: false + t.boolean "draft_publication_enabled", default: false + t.boolean "result_publication_enabled", default: false end add_index "legislation_processes", ["allegations_end_date"], name: "index_legislation_processes_on_allegations_end_date", using: :btree From cb7358bb974f1009be7035b0256db0e13c92fd73 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Tue, 13 Jun 2017 23:47:14 +0200 Subject: [PATCH 13/25] Send to both Phase and Publication classes the enabled flag and use for enabled? helper method --- app/models/legislation/process.rb | 10 ++++++---- app/models/legislation/process/phase.rb | 5 +++-- app/models/legislation/process/publication.rb | 5 +++-- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/app/models/legislation/process.rb b/app/models/legislation/process.rb index d7ad6cf62..0370d8913 100644 --- a/app/models/legislation/process.rb +++ b/app/models/legislation/process.rb @@ -20,19 +20,21 @@ class Legislation::Process < ActiveRecord::Base scope :past, -> { where("end_date < ?", Date.current).order('id DESC') } def debate_phase - Legislation::Process::Phase.new(debate_start_date, debate_end_date) + Legislation::Process::Phase.new(debate_start_date, debate_end_date, debate_phase_enabled) end def allegations_phase - Legislation::Process::Phase.new(allegations_start_date, allegations_end_date) + Legislation::Process::Phase.new(allegations_start_date, allegations_end_date, allegations_phase_enabled) end def draft_publication - Legislation::Process::Publication.new(draft_publication_date) + Legislation::Process::Publication.new(draft_publication_date, draft_publication_enabled) end def result_publication - Legislation::Process::Publication.new(result_publication_date) + Legislation::Process::Publication.new(result_publication_date, result_publication_enabled) + end + end def total_comments diff --git a/app/models/legislation/process/phase.rb b/app/models/legislation/process/phase.rb index 1b8482a9a..5d677251d 100644 --- a/app/models/legislation/process/phase.rb +++ b/app/models/legislation/process/phase.rb @@ -2,13 +2,14 @@ class Legislation::Process::Phase - def initialize(start_date, end_date) + def initialize(start_date, end_date, enabled) @start_date = start_date @end_date = end_date + @enabled = enabled end def enabled? - @start_date.present? && @end_date.present? + @enabled end def started? diff --git a/app/models/legislation/process/publication.rb b/app/models/legislation/process/publication.rb index 10110f0e7..650914f95 100644 --- a/app/models/legislation/process/publication.rb +++ b/app/models/legislation/process/publication.rb @@ -2,12 +2,13 @@ class Legislation::Process::Publication - def initialize(publication_date) + def initialize(publication_date, enabled) @publication_date = publication_date + @enabled = enabled end def enabled? - @publication_date.present? + @enabled end def started? From 9a97d09cabc6073bdf33571e26399bfe67c313e6 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Tue, 13 Jun 2017 23:47:53 +0200 Subject: [PATCH 14/25] Add new phase/publication enabled flags on seeds and legislation process factory --- db/dev_seeds.rb | 6 +++++- spec/factories.rb | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/db/dev_seeds.rb b/db/dev_seeds.rb index d828262bf..2ac996f44 100644 --- a/db/dev_seeds.rb +++ b/db/dev_seeds.rb @@ -643,7 +643,11 @@ print "Creating legislation processes" draft_publication_date: Date.current + 1.day, allegations_start_date: Date.current + 2.days, allegations_end_date: Date.current + 3.days, - result_publication_date: Date.current + 4.days + result_publication_date: Date.current + 4.days, + debate_phase_enabled: true, + allegations_phase_enabled: true, + draft_publication_enabled: true, + result_publication_enabled: true ) end diff --git a/spec/factories.rb b/spec/factories.rb index cc39af5d7..8076537e4 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -612,6 +612,10 @@ FactoryGirl.define do allegations_start_date Date.current allegations_end_date Date.current + 3.days result_publication_date Date.current + 5.days + debate_phase_enabled true + allegations_phase_enabled true + draft_publication_enabled true + result_publication_enable true trait :next do start_date Date.current + 2.days From a147765273f6c588cb48cbc3935f56621a7384c5 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Tue, 13 Jun 2017 23:48:31 +0200 Subject: [PATCH 15/25] Add enabled_phases_and_publications_count helper method on legislation process for views --- app/models/legislation/process.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/models/legislation/process.rb b/app/models/legislation/process.rb index 0370d8913..61dc1f7a0 100644 --- a/app/models/legislation/process.rb +++ b/app/models/legislation/process.rb @@ -2,6 +2,8 @@ class Legislation::Process < ActiveRecord::Base acts_as_paranoid column: :hidden_at include ActsAsParanoidAliases + PHASES_AND_PUBLICATIONS = %i(debate_phase allegations_phase draft_publication result_publication).freeze + has_many :draft_versions, -> { order(:id) }, class_name: 'Legislation::DraftVersion', foreign_key: 'legislation_process_id', dependent: :destroy 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', dependent: :destroy @@ -35,6 +37,8 @@ class Legislation::Process < ActiveRecord::Base Legislation::Process::Publication.new(result_publication_date, result_publication_enabled) end + def enabled_phases_and_publications_count + PHASES_AND_PUBLICATIONS.count { |process| send(process).enabled? } end def total_comments From 73ff68815d7da1c16840baa54356f1ee24bb0d81 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Tue, 13 Jun 2017 23:50:12 +0200 Subject: [PATCH 16/25] Update admin legislation process controller and form to allow enabling/disabling phase/publications --- .../admin/legislation/processes_controller.rb | 6 +++++- app/views/admin/legislation/processes/_form.html.erb | 12 ++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/app/controllers/admin/legislation/processes_controller.rb b/app/controllers/admin/legislation/processes_controller.rb index 2c352a2db..995e34eee 100644 --- a/app/controllers/admin/legislation/processes_controller.rb +++ b/app/controllers/admin/legislation/processes_controller.rb @@ -45,7 +45,11 @@ class Admin::Legislation::ProcessesController < Admin::Legislation::BaseControll :draft_publication_date, :allegations_start_date, :allegations_end_date, - :result_publication_date + :result_publication_date, + :debate_phase_enabled, + :allegations_phase_enabled, + :draft_publication_enabled, + :result_publication_enabled ) end end diff --git a/app/views/admin/legislation/processes/_form.html.erb b/app/views/admin/legislation/processes/_form.html.erb index 8233d5f14..f1c446029 100644 --- a/app/views/admin/legislation/processes/_form.html.erb +++ b/app/views/admin/legislation/processes/_form.html.erb @@ -70,8 +70,7 @@ id: "debate_end_date" %>
        - <%= check_box_tag :debate_phase_active, @process.debate_phase.enabled?, @process.new_record? || @process.debate_phase.enabled?, data: {disable_date: "debate"} %> - <%= label_tag :debate_phase_active, t('admin.legislation.processes.form.active') %> + <%= f.check_box :debate_phase_enabled, checked: @process.debate_phase.enabled?, label: t('admin.legislation.processes.form.active') %>
        @@ -104,8 +103,7 @@ id: "allegations_end_date" %>
        - <%= check_box_tag :allegations_phase_active, @process.allegations_phase.enabled?, @process.new_record? || @process.allegations_phase.enabled?, data: {disable_date: "allegations"} %> - <%= label_tag :allegations_phase_active, t('admin.legislation.processes.form.active') %> + <%= f.check_box :allegations_phase_enabled, checked: @process.allegations_phase.enabled?, label: t('admin.legislation.processes.form.active') %>
        @@ -125,8 +123,7 @@ id: "draft_publication_date" %>
        - <%= check_box_tag :draft_publication_phase_active, @process.draft_publication.enabled?, @process.new_record? || @process.draft_publication.enabled?, data: {disable_date: "draft_publication"} %> - <%= label_tag :draft_publication_phase_active, t('admin.legislation.processes.form.active') %> + <%= f.check_box :draft_publication_enabled, checked: @process.draft_publication.enabled?, label: t('admin.legislation.processes.form.active') %>

        @@ -145,8 +142,7 @@ id: "result_publication_date" %>
        - <%= check_box_tag :result_publication_phase_active, @process.result_publication.enabled?, @process.new_record? || @process.result_publication.enabled?, data: {disable_date: "final_publication"} %> - <%= label_tag :result_publication_phase_active, t('admin.legislation.processes.form.active') %> + <%= f.check_box :result_publication_enabled, checked: @process.result_publication.enabled?, label: t('admin.legislation.processes.form.active') %>

        From 4ea5df40120dffca9b5125b71385c22c6e6d7424 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Tue, 13 Jun 2017 23:50:45 +0200 Subject: [PATCH 17/25] Display only the Legislation Process dates for those phase/publication enabled --- .../legislation/processes/_process.html.erb | 56 ++++++++++++------- 1 file changed, 35 insertions(+), 21 deletions(-) diff --git a/app/views/legislation/processes/_process.html.erb b/app/views/legislation/processes/_process.html.erb index a0a2d2e37..d5e44076a 100644 --- a/app/views/legislation/processes/_process.html.erb +++ b/app/views/legislation/processes/_process.html.erb @@ -17,28 +17,42 @@
        -
        -
        -

        <%= t('legislation.processes.shared.key_dates') %>

        + <% if process.enabled_phases_and_publications_count.positive? %> + <% column_width = 12 / process.enabled_phases_and_publications_count %> +
        +
        +

        <%= t('legislation.processes.shared.key_dates') %>

        +
        -
        -
        -
        -
        <%= t('legislation.processes.shared.debate_dates') %>
        -

        <%= format_date(process.debate_start_date) %> - <%= format_date(process.debate_end_date) %>

        +
        + <% if process.debate_phase.enabled? %> +
        +
        <%= t('legislation.processes.shared.debate_dates') %>
        +

        <%= format_date(process.debate_start_date) %> - <%= format_date(process.debate_end_date) %>

        +
        + <% end %> + + <% if process.draft_publication.enabled? %> +
        +
        <%= t('legislation.processes.shared.draft_publication_date') %>
        +

        <%= format_date(process.draft_publication_date) %>

        +
        + <% end %> + + <% if process.allegations_phase.enabled? %> +
        +
        <%= t('legislation.processes.shared.allegations_dates') %>
        +

        <%= format_date(process.allegations_start_date) %> - <%= format_date(process.allegations_end_date) %>

        +
        + <% end %> + + <% if process.result_publication.enabled? %> +
        +
        <%= t('legislation.processes.shared.result_publication_date') %>
        +

        <%= format_date(process.result_publication_date) %>

        +
        + <% end %>
        -
        -
        <%= t('legislation.processes.shared.draft_publication_date') %>
        -

        <%= format_date(process.draft_publication_date) %>

        -
        -
        -
        <%= t('legislation.processes.shared.allegations_dates') %>
        -

        <%= format_date(process.allegations_start_date) %> - <%= format_date(process.allegations_end_date) %>

        -
        -
        -
        <%= t('legislation.processes.shared.result_publication_date') %>
        -

        <%= format_date(process.result_publication_date) %>

        -
        -
        + <% end %>
        From 33e825672c992908abc8769962936ab54c4f1239 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Tue, 13 Jun 2017 23:56:31 +0200 Subject: [PATCH 18/25] Rename label for legislation process active checkbox to enabled on both translations and form --- app/views/admin/legislation/processes/_form.html.erb | 8 ++++---- config/locales/admin.en.yml | 2 +- config/locales/admin.es.yml | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/views/admin/legislation/processes/_form.html.erb b/app/views/admin/legislation/processes/_form.html.erb index f1c446029..7d2b21703 100644 --- a/app/views/admin/legislation/processes/_form.html.erb +++ b/app/views/admin/legislation/processes/_form.html.erb @@ -70,7 +70,7 @@ id: "debate_end_date" %>
        - <%= f.check_box :debate_phase_enabled, checked: @process.debate_phase.enabled?, label: t('admin.legislation.processes.form.active') %> + <%= f.check_box :debate_phase_enabled, checked: @process.debate_phase.enabled?, label: t('admin.legislation.processes.form.enabled') %>
        @@ -103,7 +103,7 @@ id: "allegations_end_date" %>
        - <%= f.check_box :allegations_phase_enabled, checked: @process.allegations_phase.enabled?, label: t('admin.legislation.processes.form.active') %> + <%= f.check_box :allegations_phase_enabled, checked: @process.allegations_phase.enabled?, label: t('admin.legislation.processes.form.enabled') %>
        @@ -123,7 +123,7 @@ id: "draft_publication_date" %>
        - <%= f.check_box :draft_publication_enabled, checked: @process.draft_publication.enabled?, label: t('admin.legislation.processes.form.active') %> + <%= f.check_box :draft_publication_enabled, checked: @process.draft_publication.enabled?, label: t('admin.legislation.processes.form.enabled') %>

        @@ -142,7 +142,7 @@ id: "result_publication_date" %>
        - <%= f.check_box :result_publication_enabled, checked: @process.result_publication.enabled?, label: t('admin.legislation.processes.form.active') %> + <%= f.check_box :result_publication_enabled, checked: @process.result_publication.enabled?, label: t('admin.legislation.processes.form.enabled') %>

        diff --git a/config/locales/admin.en.yml b/config/locales/admin.en.yml index 15e0d2ed7..1ba256dfe 100755 --- a/config/locales/admin.en.yml +++ b/config/locales/admin.en.yml @@ -211,7 +211,7 @@ en: form: error: Error form: - active: Active + enabled: Enabled 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 bee867531..1cd133da4 100644 --- a/config/locales/admin.es.yml +++ b/config/locales/admin.es.yml @@ -211,7 +211,7 @@ es: form: error: Error form: - active: Activa + enabled: Habilitado process: Proceso debate_phase: Fase previa allegations_phase: Fase de alegaciones From a279e77c39448a2e751e1b9b765962ee319c1967 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Wed, 14 Jun 2017 00:13:56 +0200 Subject: [PATCH 19/25] Fix typo on legislation process factory --- spec/factories.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/factories.rb b/spec/factories.rb index 8076537e4..c63792dce 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -615,7 +615,7 @@ FactoryGirl.define do debate_phase_enabled true allegations_phase_enabled true draft_publication_enabled true - result_publication_enable true + result_publication_enabled true trait :next do start_date Date.current + 2.days From c18d1b6e8f0a7c4b512b265bf0c41f7af0088747 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Wed, 14 Jun 2017 00:21:08 +0200 Subject: [PATCH 20/25] Check new enabled? logic on both Legislation::Process Phase and Publication classes --- spec/models/legislation/process/phase_spec.rb | 4 ++-- spec/models/legislation/process/publication_spec.rb | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/spec/models/legislation/process/phase_spec.rb b/spec/models/legislation/process/phase_spec.rb index a92b36f78..40d6296b2 100644 --- a/spec/models/legislation/process/phase_spec.rb +++ b/spec/models/legislation/process/phase_spec.rb @@ -7,14 +7,14 @@ RSpec.describe Legislation::Process::Phase, type: :model do it "checks debate phase" do expect(process.debate_phase.enabled?).to be true - process.update_attributes(debate_start_date: nil, debate_end_date: nil) + process.update_attributes(debate_phase_enabled: false) expect(process.debate_phase.enabled?).to be false end it "checks allegations phase" do expect(process.allegations_phase.enabled?).to be true - process.update_attributes(allegations_start_date: nil, allegations_end_date: nil) + process.update_attributes(allegations_phase_enabled: false) expect(process.allegations_phase.enabled?).to be false end end diff --git a/spec/models/legislation/process/publication_spec.rb b/spec/models/legislation/process/publication_spec.rb index 4731d14b2..a489568d4 100644 --- a/spec/models/legislation/process/publication_spec.rb +++ b/spec/models/legislation/process/publication_spec.rb @@ -7,14 +7,14 @@ RSpec.describe Legislation::Process::Publication, type: :model do it "checks draft publication" do expect(process.draft_publication.enabled?).to be true - process.update_attributes(draft_publication_date: nil) + process.update_attributes(draft_publication_enabled: false) expect(process.draft_publication.enabled?).to be false end it "checks result publication" do expect(process.result_publication.enabled?).to be true - process.update_attributes(result_publication_date: nil) + process.update_attributes(result_publication_enabled: false) expect(process.result_publication.enabled?).to be false end end From 1dac73eb48ad30b8891013a176b4c04728e0fa84 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Wed, 14 Jun 2017 00:29:09 +0200 Subject: [PATCH 21/25] Fix debate phase checkbox name on admin legislation process feature spec, as well as expectations --- spec/features/admin/legislation/processes_spec.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/spec/features/admin/legislation/processes_spec.rb b/spec/features/admin/legislation/processes_spec.rb index 2c8de0d95..df2b7faf6 100644 --- a/spec/features/admin/legislation/processes_spec.rb +++ b/spec/features/admin/legislation/processes_spec.rb @@ -87,15 +87,15 @@ feature 'Admin legislation processes' do click_link "An example legislation process" expect(page).to have_selector("h2", text: "An example legislation process") - expect(find("#debate_phase_active")).to be_checked + expect(find("#legislation_process_debate_phase_enabled")).to be_checked - uncheck "debate_phase_active" + uncheck "legislation_process_debate_phase_enabled" fill_in 'legislation_process_summary', with: '' 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 + expect(find("#debate_start_date").value).not_to be_blank + expect(find("#debate_end_date").value).not_to be_blank visit legislation_processes_path expect(page).not_to have_content 'Summarizing the process' From 129e93dd12841e5fba21aacf9c0ab899adb3a2ad Mon Sep 17 00:00:00 2001 From: Bertocq Date: Wed, 14 Jun 2017 01:15:26 +0200 Subject: [PATCH 22/25] Use Time.current converted to Date by the database DirectMessage today scope Why: * Database stores created_at as timestamp with the timezone, so when comparing DATE(created_at) to something we have to convert it to DATE as well with the postresql native function, but using Time.current instead of Date.current to take into account the user timezone --- app/models/direct_message.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/direct_message.rb b/app/models/direct_message.rb index b36cca705..ae14e652d 100644 --- a/app/models/direct_message.rb +++ b/app/models/direct_message.rb @@ -8,7 +8,7 @@ class DirectMessage < ActiveRecord::Base validates :receiver, presence: true validate :max_per_day - scope :today, lambda { where('DATE(created_at) = ?', Date.current) } + scope :today, lambda { where('DATE(created_at) = DATE(?)', Time.current) } def max_per_day return if errors.any? From cc0146e372d237c815410643b9caf333bdf38a94 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Wed, 14 Jun 2017 01:17:32 +0200 Subject: [PATCH 23/25] Use Time in utc on direct message specs when changing created_at directly --- spec/models/direct_message_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/models/direct_message_spec.rb b/spec/models/direct_message_spec.rb index 05c3f75cd..28b30b0ce 100644 --- a/spec/models/direct_message_spec.rb +++ b/spec/models/direct_message_spec.rb @@ -65,9 +65,9 @@ describe DirectMessage do describe "today" do it "should return direct messages created today" do - direct_message1 = create(:direct_message, created_at: Time.current.beginning_of_day + 3.hours) - direct_message2 = create(:direct_message, created_at: Time.current) - direct_message3 = create(:direct_message, created_at: Time.current.end_of_day) + direct_message1 = create(:direct_message, created_at: Time.now.utc.beginning_of_day + 3.hours) + direct_message2 = create(:direct_message, created_at: Time.now.utc) + direct_message3 = create(:direct_message, created_at: Time.now.utc.end_of_day) expect(DirectMessage.today.count).to eq 3 end From 8440f6c74941594733898555936458893a652a94 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Wed, 14 Jun 2017 00:36:07 +0200 Subject: [PATCH 24/25] Increase coverage of admin feature spec for legislation process dates enabling --- .../admin/legislation/processes_spec.rb | 34 ++++++++++++++++--- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/spec/features/admin/legislation/processes_spec.rb b/spec/features/admin/legislation/processes_spec.rb index df2b7faf6..e945f6ce8 100644 --- a/spec/features/admin/legislation/processes_spec.rb +++ b/spec/features/admin/legislation/processes_spec.rb @@ -73,7 +73,7 @@ feature 'Admin legislation processes' do end context 'Update' do - scenario 'Deactivate debate phase', js: true do + scenario 'Remove summary text', js: true do process = create(:legislation_process, title: 'An example legislation process', summary: 'Summarizing the process', @@ -89,17 +89,41 @@ feature 'Admin legislation processes' do expect(page).to have_selector("h2", text: "An example legislation process") expect(find("#legislation_process_debate_phase_enabled")).to be_checked - uncheck "legislation_process_debate_phase_enabled" fill_in 'legislation_process_summary', with: '' click_button "Save changes" + expect(page).to have_content "Process updated successfully" + + visit legislation_processes_path + expect(page).not_to have_content 'Summarizing the process' + expect(page).to have_content 'Description of the process' + end + + scenario 'Deactivate draft publication', js: true do + process = create(:legislation_process, + title: 'An example legislation process', + summary: 'Summarizing the process', + description: 'Description of the process') + visit admin_root_path + + within('#side_menu') do + click_link "Collaborative Legislation" + end + + click_link "An example legislation process" + + expect(find("#legislation_process_draft_publication_enabled")).to be_checked + + uncheck "legislation_process_draft_publication_enabled" + click_button "Save changes" + expect(page).to have_content "Process updated successfully" expect(find("#debate_start_date").value).not_to be_blank expect(find("#debate_end_date").value).not_to be_blank - visit legislation_processes_path - expect(page).not_to have_content 'Summarizing the process' - expect(page).to have_content 'Description of the process' + click_link 'Click to visit' + + expect(page).not_to have_content 'Draft publication' end end end From d99a4da2469f203cdaf3a1bb91e5b7c102054a71 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Tue, 13 Jun 2017 23:31:09 +0200 Subject: [PATCH 25/25] Some style corrections on dev_seeds, along with abreviations and removal of unused blocks --- db/dev_seeds.rb | 174 ++++++++++++++++++++++-------------------------- 1 file changed, 78 insertions(+), 96 deletions(-) diff --git a/db/dev_seeds.rb b/db/dev_seeds.rb index 2ac996f44..6e5c1cbed 100644 --- a/db/dev_seeds.rb +++ b/db/dev_seeds.rb @@ -79,7 +79,7 @@ poll_officer = create_user('poll_officer@consul.dev', 'Paul O. Fisher') poll_officer.create_poll_officer level_2 = create_user('leveltwo@consul.dev', 'level 2') -level_2.update(residence_verified_at: Time.current, confirmed_phone: Faker::PhoneNumber.phone_number, document_number: "2222222222", document_type: "1" ) +level_2.update(residence_verified_at: Time.current, confirmed_phone: Faker::PhoneNumber.phone_number, document_number: "2222222222", document_type: "1") verified = create_user('verified@consul.dev', 'verified') verified.update(residence_verified_at: Time.current, confirmed_phone: Faker::PhoneNumber.phone_number, document_type: "1", verified_at: Time.current, document_number: "3333333333") @@ -91,7 +91,7 @@ verified.update(residence_verified_at: Time.current, confirmed_phone: Faker::Pho org = org_user.create_organization(name: org_name, responsible_name: org_responsible_name) verified = [true, false].sample - if verified then + if verified org.verify else org.reject @@ -107,10 +107,10 @@ end user = create_user("user#{i}@consul.dev") level = [1, 2, 3].sample if level >= 2 - user.update(residence_verified_at: Time.current, confirmed_phone: Faker::PhoneNumber.phone_number, document_number: Faker::Number.number(10), document_type: "1" ) + user.update(residence_verified_at: Time.current, confirmed_phone: Faker::PhoneNumber.phone_number, document_number: Faker::Number.number(10), document_type: "1") end if level == 3 - user.update(verified_at: Time.current, document_number: Faker::Number.number(10) ) + user.update(verified_at: Time.current, document_number: Faker::Number.number(10)) end end @@ -131,7 +131,7 @@ ActsAsTaggableOn::Tag.create!(name: "Sostenibilidad", featured: true, kind: "ca ActsAsTaggableOn::Tag.create!(name: "Participación", featured: true, kind: "category") ActsAsTaggableOn::Tag.create!(name: "Movilidad", featured: true, kind: "category") ActsAsTaggableOn::Tag.create!(name: "Medios", featured: true, kind: "category") -ActsAsTaggableOn::Tag.create!(name: "Salud", featured: true , kind: "category") +ActsAsTaggableOn::Tag.create!(name: "Salud", featured: true, kind: "category") ActsAsTaggableOn::Tag.create!(name: "Transparencia", featured: true, kind: "category") ActsAsTaggableOn::Tag.create!(name: "Seguridad y Emergencias", featured: true, kind: "category") ActsAsTaggableOn::Tag.create!(name: "Medio Ambiente", featured: true, kind: "category") @@ -140,38 +140,36 @@ puts " ✅" print "Creating Debates" tags = Faker::Lorem.words(25) -(1..30).each do +30.times do author = User.reorder("RANDOM()").first description = "

        #{Faker::Lorem.paragraphs.join('

        ')}

        " debate = Debate.create!(author: author, title: Faker::Lorem.sentence(3).truncate(60), - created_at: rand((Time.current - 1.week) .. Time.current), + created_at: rand((Time.current - 1.week)..Time.current), description: description, tag_list: tags.sample(3).join(','), geozone: Geozone.reorder("RANDOM()").first, terms_of_service: "1") end - tags = ActsAsTaggableOn::Tag.where(kind: 'category') -(1..30).each do +30.times do author = User.reorder("RANDOM()").first description = "

        #{Faker::Lorem.paragraphs.join('

        ')}

        " debate = Debate.create!(author: author, title: Faker::Lorem.sentence(3).truncate(60), - created_at: rand((Time.current - 1.week) .. Time.current), + created_at: rand((Time.current - 1.week)..Time.current), description: description, tag_list: tags.sample(3).join(','), geozone: Geozone.reorder("RANDOM()").first, terms_of_service: "1") end - puts " ✅" print "Creating Proposals" tags = Faker::Lorem.words(25) -(1..30).each do |i| +30.times do author = User.reorder("RANDOM()").first description = "

        #{Faker::Lorem.paragraphs.join('

        ')}

        " proposal = Proposal.create!(author: author, @@ -181,7 +179,7 @@ tags = Faker::Lorem.words(25) responsible_name: Faker::Name.name, external_url: Faker::Internet.url, description: description, - created_at: rand((Time.current - 1.week) .. Time.current), + created_at: rand((Time.current - 1.week)..Time.current), tag_list: tags.sample(3).join(','), geozone: Geozone.reorder("RANDOM()").first, terms_of_service: "1") @@ -191,7 +189,7 @@ puts " ✅" print "Creating Archived Proposals" tags = Faker::Lorem.words(25) -(1..5).each do +5.times do author = User.reorder("RANDOM()").first description = "

        #{Faker::Lorem.paragraphs.join('

        ')}

        " proposal = Proposal.create!(author: author, @@ -211,7 +209,7 @@ puts " ✅" print "Creating Successful Proposals" tags = Faker::Lorem.words(25) -(1..10).each do |i| +10.times do author = User.reorder("RANDOM()").first description = "

        #{Faker::Lorem.paragraphs.join('

        ')}

        " proposal = Proposal.create!(author: author, @@ -221,16 +219,15 @@ tags = Faker::Lorem.words(25) responsible_name: Faker::Name.name, external_url: Faker::Internet.url, description: description, - created_at: rand((Time.current - 1.week) .. Time.current), + created_at: rand((Time.current - 1.week)..Time.current), tag_list: tags.sample(3).join(','), geozone: Geozone.reorder("RANDOM()").first, terms_of_service: "1", cached_votes_up: Setting["votes_for_proposal_success"]) end - tags = ActsAsTaggableOn::Tag.where(kind: 'category') -(1..30).each do +30.times do author = User.reorder("RANDOM()").first description = "

        #{Faker::Lorem.paragraphs.join('

        ')}

        " proposal = Proposal.create!(author: author, @@ -240,94 +237,89 @@ tags = ActsAsTaggableOn::Tag.where(kind: 'category') responsible_name: Faker::Name.name, external_url: Faker::Internet.url, description: description, - created_at: rand((Time.current - 1.week) .. Time.current), + created_at: rand((Time.current - 1.week)..Time.current), tag_list: tags.sample(3).join(','), geozone: Geozone.reorder("RANDOM()").first, terms_of_service: "1") end - puts " ✅" print "Commenting Debates" -(1..100).each do +100.times do author = User.reorder("RANDOM()").first debate = Debate.reorder("RANDOM()").first Comment.create!(user: author, - created_at: rand(debate.created_at .. Time.current), + created_at: rand(debate.created_at..Time.current), commentable: debate, body: Faker::Lorem.sentence) end - puts " ✅" print "Commenting Proposals" -(1..100).each do |i| +100.times do author = User.reorder("RANDOM()").first proposal = Proposal.reorder("RANDOM()").first Comment.create!(user: author, - created_at: rand(proposal.created_at .. Time.current), + created_at: rand(proposal.created_at..Time.current), commentable: proposal, body: Faker::Lorem.sentence) end - puts " ✅" print "Commenting Comments" -(1..200).each do +200.times do author = User.reorder("RANDOM()").first parent = Comment.reorder("RANDOM()").first Comment.create!(user: author, - created_at: rand(parent.created_at .. Time.current), + created_at: rand(parent.created_at..Time.current), commentable_id: parent.commentable_id, commentable_type: parent.commentable_type, body: Faker::Lorem.sentence, parent: parent) end - puts " ✅" print "Voting Debates, Proposals & Comments" -(1..100).each do +100.times do voter = not_org_users.reorder("RANDOM()").first vote = [true, false].sample debate = Debate.reorder("RANDOM()").first debate.vote_by(voter: voter, vote: vote) end -(1..100).each do |i| +100.times do voter = not_org_users.reorder("RANDOM()").first vote = [true, false].sample comment = Comment.reorder("RANDOM()").first comment.vote_by(voter: voter, vote: vote) end -(1..100).each do +100.times do voter = User.level_two_or_three_verified.reorder("RANDOM()").first proposal = Proposal.reorder("RANDOM()").first proposal.vote_by(voter: voter, vote: true) end - puts " ✅" print "Flagging Debates & Comments" -(1..40).each do +40.times do debate = Debate.reorder("RANDOM()").first flagger = User.where(["users.id <> ?", debate.author_id]).reorder("RANDOM()").first Flag.flag(flagger, debate) end -(1..40).each do +40.times do comment = Comment.reorder("RANDOM()").first flagger = User.where(["users.id <> ?", comment.user_id]).reorder("RANDOM()").first Flag.flag(flagger, comment) end -(1..40).each do +40.times do proposal = Proposal.reorder("RANDOM()").first flagger = User.where(["users.id <> ?", proposal.author_id]).reorder("RANDOM()").first Flag.flag(flagger, proposal) @@ -338,7 +330,7 @@ print "Creating Spending Proposals" tags = Faker::Lorem.words(10) -(1..60).each do +60.times do geozone = Geozone.reorder("RANDOM()").first author = User.reorder("RANDOM()").first description = "

        #{Faker::Lorem.paragraphs.join('

        ')}

        " @@ -346,17 +338,17 @@ tags = Faker::Lorem.words(10) valuation_finished = [true, false].sample feasible = [true, false].sample spending_proposal = SpendingProposal.create!(author: author, - title: Faker::Lorem.sentence(3).truncate(60), - external_url: Faker::Internet.url, - description: description, - created_at: rand((Time.current - 1.week) .. Time.current), - geozone: [geozone, nil].sample, - feasible: feasible, - feasible_explanation: feasible_explanation, - valuation_finished: valuation_finished, - tag_list: tags.sample(3).join(','), - price: rand(1000000), - terms_of_service: "1") + title: Faker::Lorem.sentence(3).truncate(60), + external_url: Faker::Internet.url, + description: description, + created_at: rand((Time.current - 1.week)..Time.current), + geozone: [geozone, nil].sample, + feasible: feasible, + feasible_explanation: feasible_explanation, + valuation_finished: valuation_finished, + tag_list: tags.sample(3).join(','), + price: rand(1000000), + terms_of_service: "1") end puts " ✅" @@ -366,13 +358,14 @@ print "Creating Valuation Assignments" SpendingProposal.reorder("RANDOM()").first.valuators << valuator.valuator end - puts " ✅" print "Creating Budgets" Budget::PHASES.each_with_index do |phase, i| - descriptions = Hash[Budget::PHASES.map{ |p| ["description_#{p}", - "

        #{Faker::Lorem.paragraphs(2).join('

        ')}

        "] }] + descriptions = Hash[Budget::PHASES.map do |p| + ["description_#{p}", + "

        #{Faker::Lorem.paragraphs(2).join('

        ')}

        "] + end] budget = Budget.create!( descriptions.merge( name: (Date.current - 10 + i).to_s, @@ -387,18 +380,15 @@ Budget::PHASES.each_with_index do |phase, i| geozones = Geozone.reorder("RANDOM()").limit([2, 5, 6, 7].sample) geozones.each do |geozone| group.headings << group.headings.create!(name: geozone.name, - #geozone: geozone, - price: rand(1 .. 100) * 100000) - + price: rand(1..100) * 100000) end end end - puts " ✅" print "Creating Investments" tags = Faker::Lorem.words(10) -(1..100).each do |i| +100.times do heading = Budget::Heading.reorder("RANDOM()").first investment = Budget::Investment.create!( @@ -409,13 +399,14 @@ tags = Faker::Lorem.words(10) title: Faker::Lorem.sentence(3).truncate(60), external_url: Faker::Internet.url, description: "

        #{Faker::Lorem.paragraphs.join('

        ')}

        ", - created_at: rand((Time.current - 1.week) .. Time.current), + created_at: rand((Time.current - 1.week)..Time.current), feasibility: %w{undecided unfeasible feasible feasible feasible feasible}.sample, unfeasibility_explanation: Faker::Lorem.paragraph, valuation_finished: [false, true].sample, tag_list: tags.sample(3).join(','), - price: rand(1 .. 100) * 100000, - terms_of_service: "1") + price: rand(1..100) * 100000, + terms_of_service: "1" + ) end puts " ✅" @@ -428,7 +419,7 @@ puts " ✅" print "Winner Investments" budget = Budget.where(phase: "finished").last -(1..100).each do |i| +100.times do heading = budget.headings.reorder("RANDOM()").first investment = Budget::Investment.create!( author: User.reorder("RANDOM()").first, @@ -438,12 +429,13 @@ budget = Budget.where(phase: "finished").last title: Faker::Lorem.sentence(3).truncate(60), external_url: Faker::Internet.url, description: "

        #{Faker::Lorem.paragraphs.join('

        ')}

        ", - created_at: rand((Time.current - 1.week) .. Time.current), + created_at: rand((Time.current - 1.week)..Time.current), feasibility: "feasible", valuation_finished: true, selected: true, - price: rand(10000 .. heading.price), - terms_of_service: "1") + price: rand(10000..heading.price), + terms_of_service: "1" + ) end budget.headings.each do |heading| Budget::Result.new(budget, heading).calculate_winners @@ -456,16 +448,13 @@ print "Creating Valuation Assignments" Budget::Investment.reorder("RANDOM()").first.valuators << valuator.valuator end - puts " ✅" print "Ignoring flags in Debates, comments & proposals" - Debate.flagged.reorder("RANDOM()").limit(10).each(&:ignore_flag) Comment.flagged.reorder("RANDOM()").limit(30).each(&:ignore_flag) Proposal.flagged.reorder("RANDOM()").limit(10).each(&:ignore_flag) - puts " ✅" print "Hiding debates, comments & proposals" @@ -473,7 +462,6 @@ Comment.with_hidden.flagged.reorder("RANDOM()").limit(30).each(&:hide) Debate.with_hidden.flagged.reorder("RANDOM()").limit(5).each(&:hide) Proposal.with_hidden.flagged.reorder("RANDOM()").limit(10).each(&:hide) - puts " ✅" print "Confirming hiding in debates, comments & proposals" @@ -494,9 +482,9 @@ Proposal.last(3).each do |proposal| image: ["banner-img banner-img-one", "banner-img banner-img-two", "banner-img banner-img-three"].sample, target_url: Rails.application.routes.url_helpers.proposal_path(proposal), - post_started_at: rand((Time.current - 1.week) .. (Time.current - 1.day)), - post_ended_at: rand((Time.current - 1.day) .. (Time.current + 1.week)), - created_at: rand((Time.current - 1.week) .. Time.current)) + post_started_at: rand((Time.current - 1.week)..(Time.current - 1.day)), + post_ended_at: rand((Time.current - 1.day)..(Time.current + 1.week)), + created_at: rand((Time.current - 1.week)..Time.current)) end puts " ✅" @@ -510,19 +498,14 @@ print "Active Polls" ends_at: 1.month.from_now, geozone_restricted: false) end -(4..5).each do |i| +(1..5).each do |i| poll = Poll.create(name: "Active Poll #{i}", starts_at: 1.month.ago, ends_at: 1.month.from_now, geozone_restricted: true, - geozones: Geozone.reorder("RANDOM()").limit(3) - ) + geozones: Geozone.reorder("RANDOM()").limit(3)) end - - - - puts " ✅" print "Upcoming Poll" poll = Poll.create(name: "Upcoming Poll", @@ -532,17 +515,17 @@ poll = Poll.create(name: "Upcoming Poll", puts " ✅" print "Expired Poll" poll = Poll.create(name: "Expired Poll", - starts_at: 2.months.ago, - ends_at: 1.months.ago) + starts_at: 2.months.ago, + ends_at: 1.month.ago) puts " ✅" print "Creating Poll Questions" -(1..50).each do |i| +50.times do poll = Poll.reorder("RANDOM()").first author = User.reorder("RANDOM()").first description = "

        #{Faker::Lorem.paragraphs.join('

        ')}

        " - open_at = rand(2.months.ago .. 2.months.from_now) + open_at = rand(2.months.ago..2.months.from_now) question = Poll::Question.create!(author: author, title: Faker::Lorem.sentence(3).truncate(60), description: description, @@ -574,21 +557,21 @@ end puts " ✅" print "Creating Poll Recounts" do -(1..15).to_a.sample.times do |i| - poll_officer.poll_officer.officer_assignments.all.sample(i).each do |officer_assignment| - Poll::Recount.create(officer_assignment: officer_assignment, - booth_assignment: officer_assignment.booth_assignment, - date: officer_assignment.date, - count: (1..5000).to_a.sample) + (1..15).to_a.sample.times do |i| + poll_officer.poll_officer.officer_assignments.all.sample(i).each do |officer_assignment| + Poll::Recount.create(officer_assignment: officer_assignment, + booth_assignment: officer_assignment.booth_assignment, + date: officer_assignment.date, + count: (1..5000).to_a.sample) + end end -end end puts " ✅" print "Creating Poll Questions from Proposals" -(1..3).each do +3.times do proposal = Proposal.reorder("RANDOM()").first poll = Poll.current.first question = Poll::Question.create(valid_answers: "Yes, No") @@ -599,7 +582,7 @@ end puts " ✅" print "Creating Successful Proposals" -(1..10).each do +10.times do proposal = Proposal.reorder("RANDOM()").first poll = Poll.current.first question = Poll::Question.create(valid_answers: "Yes, No") @@ -610,11 +593,11 @@ end puts " ✅" print "Commenting Poll Questions" -(1..30).each do +30.times do author = User.reorder("RANDOM()").first question = Poll::Question.reorder("RANDOM()").first Comment.create!(user: author, - created_at: rand(question.created_at .. Time.current), + created_at: rand(question.created_at..Time.current), commentable: question, body: Faker::Lorem.sentence) end @@ -622,7 +605,7 @@ end puts " ✅" print "Creating Poll Voters" -(1..10).each do +10.times do poll = Poll.all.sample user = User.level_two_verified.sample Poll::Voter.create(poll: poll, user: user) @@ -631,7 +614,7 @@ end puts " ✅" print "Creating legislation processes" -(1..5).each do |i| +5.times do process = ::Legislation::Process.create!(title: Faker::Lorem.sentence(3).truncate(60), description: Faker::Lorem.paragraphs.join("\n\n"), summary: Faker::Lorem.paragraph, @@ -654,8 +637,7 @@ end ::Legislation::Process.all.each do |process| (1..3).each do |i| version = process.draft_versions.create!(title: "Version #{i}", - body: Faker::Lorem.paragraphs.join("\n\n") - ) + body: Faker::Lorem.paragraphs.join("\n\n")) end end