diff --git a/app/controllers/admin/legislation/base_controller.rb b/app/controllers/admin/legislation/base_controller.rb
new file mode 100644
index 000000000..047180ab3
--- /dev/null
+++ b/app/controllers/admin/legislation/base_controller.rb
@@ -0,0 +1,5 @@
+class Admin::Legislation::BaseController < Admin::BaseController
+ include FeatureFlags
+
+ feature_flag :legislation
+end
diff --git a/app/controllers/admin/legislation/processes_controller.rb b/app/controllers/admin/legislation/processes_controller.rb
new file mode 100644
index 000000000..83fae8812
--- /dev/null
+++ b/app/controllers/admin/legislation/processes_controller.rb
@@ -0,0 +1,54 @@
+class Admin::Legislation::ProcessesController < Admin::Legislation::BaseController
+ has_filters %w{open next past all}, only: :index
+
+ load_and_authorize_resource :process, class: "Legislation::Process"
+
+ def index
+ @processes = ::Legislation::Process.send(@current_filter).page(params[:page])
+ end
+
+ def create
+ @process = ::Legislation::Process.new(process_params)
+ if @process.save
+ redirect_to admin_legislation_processes_path
+ else
+ render :new
+ end
+ end
+
+ def update
+ @process.assign_attributes(process_params)
+ if @process.update(process_params)
+ redirect_to admin_legislation_processes_path
+ else
+ render :edit
+ end
+ end
+
+ def destroy
+ @process.destroy
+ redirect_to admin_legislation_processes_path
+ end
+
+ private
+
+ def process_params
+ params.require(:legislation_process).permit(
+ :title,
+ :description_summary,
+ :target_summary,
+ :description,
+ :target,
+ :how_to_participate,
+ :additional_info,
+ :start_date,
+ :end_date,
+ :debate_start_date,
+ :debate_end_date,
+ :draft_publication_date,
+ :allegations_start_date,
+ :allegations_end_date,
+ :final_publication_date
+ )
+ end
+end
diff --git a/app/controllers/legislation/base_controller.rb b/app/controllers/legislation/base_controller.rb
new file mode 100644
index 000000000..ca609ecba
--- /dev/null
+++ b/app/controllers/legislation/base_controller.rb
@@ -0,0 +1,5 @@
+class Legislation::BaseController < ApplicationController
+ include FeatureFlags
+
+ feature_flag :legislation
+end
diff --git a/app/controllers/legislation/processes_controller.rb b/app/controllers/legislation/processes_controller.rb
new file mode 100644
index 000000000..75ca3f5dd
--- /dev/null
+++ b/app/controllers/legislation/processes_controller.rb
@@ -0,0 +1,2 @@
+class Legislation::ProcessesController < Legislation::BaseController
+end
diff --git a/app/helpers/admin_helper.rb b/app/helpers/admin_helper.rb
index 62d31cd05..f14269fb3 100644
--- a/app/helpers/admin_helper.rb
+++ b/app/helpers/admin_helper.rb
@@ -5,7 +5,7 @@ module AdminHelper
end
def official_level_options
- options = [["", 0]]
+ options = [["",0]]
(1..5).each do |i|
options << [[t("admin.officials.level_#{i}"), setting["official_level_#{i}_name"]].compact.join(': '), i]
end
@@ -16,10 +16,14 @@ module AdminHelper
Administrator.all.order('users.username asc').includes(:user).collect { |v| [ v.name, v.id ] }
end
+ def admin_submit_action(resource)
+ resource.persisted? ? "edit" : "new"
+ end
+
private
def namespace
- controller.class.parent.name.downcase
+ controller.class.parent.name.downcase.gsub("::", "/")
end
end
diff --git a/app/models/abilities/administrator.rb b/app/models/abilities/administrator.rb
index 0dfce6d3e..b866d226e 100644
--- a/app/models/abilities/administrator.rb
+++ b/app/models/abilities/administrator.rb
@@ -43,6 +43,8 @@ module Abilities
can [:read, :update, :destroy, :summary], SpendingProposal
can [:search, :edit, :update, :create, :index, :destroy], Banner
+
+ can [:manage], ::Legislation::Process
end
end
end
diff --git a/app/models/legislation.rb b/app/models/legislation.rb
new file mode 100644
index 000000000..5aa217fd0
--- /dev/null
+++ b/app/models/legislation.rb
@@ -0,0 +1,5 @@
+module Legislation
+ def self.table_name_prefix
+ 'legislation_'
+ end
+end
diff --git a/app/models/legislation/process.rb b/app/models/legislation/process.rb
new file mode 100644
index 000000000..487a7e70e
--- /dev/null
+++ b/app/models/legislation/process.rb
@@ -0,0 +1,21 @@
+class Legislation::Process < ActiveRecord::Base
+ acts_as_paranoid column: :hidden_at
+ include ActsAsParanoidAliases
+
+ validates :title, presence: true
+ validates :description, presence: true
+ validates :target, presence: true
+ validates :how_to_participate, presence: true
+ validates :start_date, presence: true
+ validates :end_date, presence: true
+ validates :debate_start_date, presence: true
+ validates :debate_end_date, presence: true
+ validates :draft_publication_date, presence: true
+ validates :allegations_start_date, presence: true
+ validates :allegations_end_date, presence: true
+ validates :final_publication_date, presence: true
+
+ scope :open, -> {where("start_date <= ? and end_date >= ?", Time.current, Time.current) }
+ scope :next, -> {where("start_date > ?", Time.current) }
+ scope :past, -> {where("end_date < ?", Time.current) }
+end
diff --git a/app/views/admin/_menu.html.erb b/app/views/admin/_menu.html.erb
index 7ea48b2c6..0fb898e8e 100644
--- a/app/views/admin/_menu.html.erb
+++ b/app/views/admin/_menu.html.erb
@@ -35,6 +35,14 @@
<% end %>
+ <% if feature?(:legislation) %>
+
>
+ <%= link_to admin_legislation_processes_path do %>
+ <%= t("admin.menu.legislation") %>
+ <% end %>
+
+ <% end %>
+
>
<%= link_to admin_banners_path do %>
<%= t("admin.menu.banner") %>
diff --git a/app/views/admin/legislation/_menu.html.erb b/app/views/admin/legislation/_menu.html.erb
new file mode 100644
index 000000000..38c8bc5c4
--- /dev/null
+++ b/app/views/admin/legislation/_menu.html.erb
@@ -0,0 +1 @@
+<%= render "admin/menu" %>
diff --git a/app/views/admin/legislation/processes/_form.html.erb b/app/views/admin/legislation/processes/_form.html.erb
new file mode 100644
index 000000000..fa1ddf54e
--- /dev/null
+++ b/app/views/admin/legislation/processes/_form.html.erb
@@ -0,0 +1,155 @@
+<%= form_for [:admin, @process] do |f| %>
+
+ <% if @process.errors.any? %>
+
+
+
+
+
+ <%= @process.errors.count %>
+ <%= t("admin.legislation.processes.errors.form.error", count: @process.errors.count) %>
+
+
+
+<% end %>
+
+
+
+ <%= f.label :title %>
+
+
+ <%= f.text_field :title,
+ label: false %>
+
+
+
+
+
+ <%= f.label :description %>
+
+
+ <%= f.text_area :description,
+ label: false,
+ rows: 5 %>
+
+
+
+
+
+ <%= f.label :target %>
+
+
+ <%= f.text_area :target,
+ label: false,
+ rows: 5 %>
+
+
+
+
+
+ <%= f.label :how_to_participate %>
+
+
+ <%= f.text_area :how_to_participate,
+ label: false,
+ rows: 5 %>
+
+
+
+
+
+ <%= f.label :additional_info %>
+
+
+ <%= f.text_area :additional_info,
+ label: false,
+ rows: 10 %>
+
+
+
+
+
+ <%= f.label :start_date %>
+
+
+ <%= f.text_field :start_date,
+ label: false,
+ class: "js-calendar-full",
+ id: "start_date" %>
+
+
+ <%= f.label :end_date %>
+
+
+ <%= f.text_field :end_date,
+ label: false,
+ class: "js-calendar-full",
+ id: "end_date" %>
+
+
+
+
+
+ <%= f.label :debate_start_date %>
+
+
+ <%= f.text_field :debate_start_date,
+ label: false,
+ class: "js-calendar-full",
+ id: "debate_start_date" %>
+
+
+ <%= f.label :debate_end_date %>
+
+
+ <%= f.text_field :debate_end_date,
+ label: false,
+ class: "js-calendar-full",
+ id: "debate_end_date" %>
+
+
+ <%= f.label :draft_publication_date %>
+
+
+ <%= f.text_field :draft_publication_date,
+ label: false,
+ class: "js-calendar-full",
+ id: "draft_publication_date" %>
+
+
+ <%= f.label :allegations_start_date %>
+
+
+ <%= f.text_field :allegations_start_date,
+ label: false,
+ class: "js-calendar-full",
+ id: "allegations_start_date" %>
+
+
+ <%= f.label :allegations_end_date %>
+
+
+ <%= f.text_field :allegations_end_date,
+ label: false,
+ class: "js-calendar-full",
+ id: "allegations_end_date" %>
+
+
+ <%= f.label :final_publication_date %>
+
+
+ <%= f.text_field :final_publication_date,
+ label: false,
+ class: "js-calendar-full",
+ id: "final_publication_date" %>
+
+
+
+
+
+ <%= f.submit(class: "button expanded", value: t("admin.legislation.processes.#{admin_submit_action(@process)}.submit_button")) %>
+
+
+<% end %>
diff --git a/app/views/admin/legislation/processes/edit.html.erb b/app/views/admin/legislation/processes/edit.html.erb
new file mode 100644
index 000000000..013bebaa3
--- /dev/null
+++ b/app/views/admin/legislation/processes/edit.html.erb
@@ -0,0 +1,13 @@
+
+
+
+ <%= link_to admin_legislation_processes_path, class: "back" do %>
+
+ <%= t("admin.legislation.processes.edit.back") %>
+ <% end %>
+
+
<%= @process.title %>
+
+ <%= render "form" %>
+
+
diff --git a/app/views/admin/legislation/processes/index.html.erb b/app/views/admin/legislation/processes/index.html.erb
new file mode 100644
index 000000000..812812856
--- /dev/null
+++ b/app/views/admin/legislation/processes/index.html.erb
@@ -0,0 +1,33 @@
+<%= link_to t("admin.legislation.processes.index.create"),
+ new_admin_legislation_process_path, class: "button success float-right" %>
+
+<%= t("admin.legislation.processes.index.title") %>
+
+<%= render 'shared/filter_subnav', i18n_namespace: "admin.legislation.processes.index" %>
+
+<%= page_entries_info @processes %>
+
+
+
+ | <%= t("admin.legislation.processes.process.title") %> |
+ |
+
+ <% @processes.each do |process| %>
+
+ |
+ <%= link_to process.title, edit_admin_legislation_process_path(process) %>
+ |
+
+
+ <%= link_to t("admin.legislation.processes.index.edit"), edit_admin_legislation_process_path(process),
+ class: 'edit-banner button hollow' %>
+
+ <%= link_to t("admin.legislation.processes.index.delete"), admin_legislation_process_path(process),
+ method: :delete,
+ class: 'button hollow alert' %>
+ |
+
+ <% end %>
+
+
+<%= paginate @processes %>
diff --git a/app/views/admin/legislation/processes/new.html.erb b/app/views/admin/legislation/processes/new.html.erb
new file mode 100644
index 000000000..21d5f01a7
--- /dev/null
+++ b/app/views/admin/legislation/processes/new.html.erb
@@ -0,0 +1,13 @@
+
+
+
+ <%= link_to admin_legislation_processes_path, class: "back" do %>
+
+ <%= t("admin.legislation.processes.new.back") %>
+ <% end %>
+
+
<%= t("admin.legislation.processes.new.title") %>
+
+ <%= render "form" %>
+
+
diff --git a/config/i18n-tasks.yml b/config/i18n-tasks.yml
index edaaa0958..55edc13a1 100644
--- a/config/i18n-tasks.yml
+++ b/config/i18n-tasks.yml
@@ -117,6 +117,8 @@ ignore_unused:
- 'admin.organizations.index.filter*'
- 'admin.users.index.filter*'
- 'admin.activity.show.filter*'
+ - 'admin.legislation.processes.index.filter*'
+ - 'admin.legislation.processes.*.submit_button'
- 'admin.comments.index.hidden_*'
- 'admin.settings.index.features.*'
- 'moderation.comments.index.filter*'
diff --git a/config/locales/activerecord.en.yml b/config/locales/activerecord.en.yml
index 7de5b340e..91d4458a4 100644
--- a/config/locales/activerecord.en.yml
+++ b/config/locales/activerecord.en.yml
@@ -34,6 +34,9 @@ en:
spending_proposal:
one: "Spending proposal"
other: "Spending proposals"
+ legislation/process:
+ one: "Process"
+ other: "Processes"
attributes:
comment:
body: "Comment"
@@ -69,6 +72,20 @@ en:
external_url: "Link to additional documentation"
geozone_id: "Scope of operation"
title: "Title"
+ legislation/process:
+ title: Process Title
+ description: Description
+ target: Target
+ how_to_participate: How to participate
+ additional_info: Additional info
+ start_date: Start date
+ end_date: End date
+ debate_start_date: Debate start date
+ debate_end_date: Debate end date
+ 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
errors:
models:
user:
@@ -90,4 +107,4 @@ en:
proposal_notification:
attributes:
minimum_interval:
- invalid: "You have to wait a minium of %{interval} days between notifications"
\ No newline at end of file
+ invalid: "You have to wait a minium of %{interval} days between notifications"
diff --git a/config/locales/activerecord.es.yml b/config/locales/activerecord.es.yml
index 4dae4cb56..d4a6e2800 100644
--- a/config/locales/activerecord.es.yml
+++ b/config/locales/activerecord.es.yml
@@ -34,6 +34,9 @@ es:
spending_proposal:
one: "Propuesta de inversión"
other: "Propuestas de inversión"
+ legislation/process:
+ one: "Proceso"
+ other: "Procesos"
attributes:
comment:
body: "Comentario"
@@ -69,6 +72,20 @@ es:
external_url: "Enlace a documentación adicional"
geozone_id: "Ámbito de actuación"
title: "Título"
+ legislation/process:
+ title: Título del proceso
+ description: En qué consiste
+ target: A quién afecta
+ how_to_participate: Cómo participar
+ additional_info: Información adicional
+ start_date: Fecha de inicio del proceso
+ end_date: Fecha de fin del proceso
+ debate_start_date: Fecha de inicio del debate
+ debate_end_date: Fecha de fin del debate
+ 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
errors:
models:
user:
@@ -90,4 +107,4 @@ es:
proposal_notification:
attributes:
minimum_interval:
- invalid: "Debes esperar un mínimo de %{interval} días entre notificaciones"
\ No newline at end of file
+ invalid: "Debes esperar un mínimo de %{interval} días entre notificaciones"
diff --git a/config/locales/admin.en.yml b/config/locales/admin.en.yml
index 2f73f64d8..3514f9bd6 100755
--- a/config/locales/admin.en.yml
+++ b/config/locales/admin.en.yml
@@ -82,6 +82,30 @@ en:
with_confirmed_hide: Confirmed
without_confirmed_hide: Pending
title: Hidden debates
+ legislation:
+ processes:
+ edit:
+ back: Back
+ submit_button: Save changes
+ errors:
+ form:
+ error: Error
+ index:
+ create: New process
+ delete: Delete
+ edit: Edit
+ title: Legislation processess
+ filters:
+ open: Open
+ next: Next
+ past: Past
+ all: All
+ new:
+ back: Back
+ title: Create new collaborative legislation process
+ submit_button: Create process
+ process:
+ title: Collaborative legislation process title
managers:
index:
title: Managers
@@ -110,6 +134,7 @@ en:
settings: Configuration settings
spending_proposals: Spending proposals
stats: Statistics
+ legislation: Collaborative Legislation
moderators:
index:
title: Moderators
diff --git a/config/locales/admin.es.yml b/config/locales/admin.es.yml
index 5aada1ce1..aa638f455 100644
--- a/config/locales/admin.es.yml
+++ b/config/locales/admin.es.yml
@@ -80,6 +80,30 @@ es:
with_confirmed_hide: Confirmados
without_confirmed_hide: Pendientes
title: Debates ocultos
+ legislation:
+ processes:
+ edit:
+ back: Volver
+ submit_button: Guardar cambios
+ errors:
+ form:
+ error: Error
+ index:
+ create: Nuevo proceso
+ delete: Borrar
+ edit: Editar
+ title: Procesos de legislación colaborativa
+ filters:
+ open: Abiertos
+ next: Próximamente
+ past: Pasados
+ all: Todos
+ new:
+ back: Volver
+ title: Crear nuevo proceso de legislación colaborativa
+ submit_button: Crear proceso
+ process:
+ title: Título del proceso de legislación colaborativa
managers:
index:
title: Gestores
@@ -108,6 +132,7 @@ es:
settings: Configuración global
spending_proposals: Propuestas de inversión
stats: Estadísticas
+ legislation: Legislación colaborativa
moderators:
index:
title: Moderadores
diff --git a/config/locales/settings.en.yml b/config/locales/settings.en.yml
index 0de4e5feb..f3cfe261f 100755
--- a/config/locales/settings.en.yml
+++ b/config/locales/settings.en.yml
@@ -30,3 +30,4 @@ en:
spending_proposals: Investment projects
spending_proposal_features:
voting_allowed: Voting on investment projects
+ legislation: Legislation
diff --git a/config/locales/settings.es.yml b/config/locales/settings.es.yml
index 05ba6c076..78dfb8912 100644
--- a/config/locales/settings.es.yml
+++ b/config/locales/settings.es.yml
@@ -29,4 +29,5 @@ es:
debates: Debates
spending_proposals: Propuestas de inversión
spending_proposal_features:
- voting_allowed: Votaciones sobre propuestas de inversión.
\ No newline at end of file
+ voting_allowed: Votaciones sobre propuestas de inversión.
+ legislation: Legislación
diff --git a/config/routes.rb b/config/routes.rb
index 037b107ae..e7043d327 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -189,6 +189,10 @@ Rails.application.routes.draw do
get :direct_messages, on: :collection
end
+ namespace :legislation do
+ resources :processes
+ end
+
namespace :api do
resource :stats, only: :show
end
diff --git a/db/dev_seeds.rb b/db/dev_seeds.rb
index 9f47873ce..086751ac0 100644
--- a/db/dev_seeds.rb
+++ b/db/dev_seeds.rb
@@ -30,6 +30,7 @@ Setting.create(key: 'feature.spending_proposal_features.voting_allowed', value:
Setting.create(key: 'feature.twitter_login', value: "true")
Setting.create(key: 'feature.facebook_login', value: "true")
Setting.create(key: 'feature.google_login', value: "true")
+Setting.create(key: 'feature.legislation', value: "true")
Setting.create(key: 'per_page_code', value: "")
Setting.create(key: 'comments_body_max_length', value: '1000')
diff --git a/db/migrate/20161117135624_create_legislation_processes.rb b/db/migrate/20161117135624_create_legislation_processes.rb
new file mode 100644
index 000000000..099a84e65
--- /dev/null
+++ b/db/migrate/20161117135624_create_legislation_processes.rb
@@ -0,0 +1,23 @@
+class CreateLegislationProcesses < ActiveRecord::Migration
+ def change
+ create_table :legislation_processes do |t|
+ t.string :title
+ t.text :description
+ t.text :target
+ t.text :how_to_participate
+ t.text :additional_info
+ t.date :start_date, index: true
+ t.date :end_date, index: true
+ t.date :debate_start_date, index: true
+ t.date :debate_end_date, index: true
+ t.date :draft_publication_date, index: true
+ t.date :allegations_start_date, index: true
+ t.date :allegations_end_date, index: true
+ t.date :final_publication_date, index: true
+
+ t.datetime :hidden_at, index: true
+
+ t.timestamps null: false
+ end
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 149851a2b..213ecffbc 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: 20161117115841) do
+ActiveRecord::Schema.define(version: 20161117135624) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@@ -228,6 +228,35 @@ ActiveRecord::Schema.define(version: 20161117115841) do
t.datetime "updated_at", null: false
end
+ create_table "legislation_processes", force: :cascade do |t|
+ t.string "title"
+ t.text "description"
+ t.text "target"
+ t.text "how_to_participate"
+ t.text "additional_info"
+ t.date "start_date"
+ t.date "end_date"
+ t.date "debate_start_date"
+ t.date "debate_end_date"
+ t.date "draft_publication_date"
+ t.date "allegations_start_date"
+ t.date "allegations_end_date"
+ t.date "final_publication_date"
+ t.datetime "hidden_at"
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
+ end
+
+ add_index "legislation_processes", ["allegations_end_date"], name: "index_legislation_processes_on_allegations_end_date", using: :btree
+ add_index "legislation_processes", ["allegations_start_date"], name: "index_legislation_processes_on_allegations_start_date", using: :btree
+ add_index "legislation_processes", ["debate_end_date"], name: "index_legislation_processes_on_debate_end_date", using: :btree
+ 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", ["start_date"], name: "index_legislation_processes_on_start_date", using: :btree
+
create_table "locks", force: :cascade do |t|
t.integer "user_id"
t.integer "tries", default: 0
diff --git a/db/seeds.rb b/db/seeds.rb
index 1607a0aff..82d6d6cdd 100644
--- a/db/seeds.rb
+++ b/db/seeds.rb
@@ -64,6 +64,7 @@ Setting['feature.twitter_login'] = true
Setting['feature.facebook_login'] = true
Setting['feature.google_login'] = true
Setting['feature.public_stats'] = true
+Setting['feature.legislation'] = true
# Spending proposals feature flags
Setting['feature.spending_proposal_features.voting_allowed'] = true
diff --git a/spec/factories.rb b/spec/factories.rb
index 1445ac3c1..cdfede19b 100644
--- a/spec/factories.rb
+++ b/spec/factories.rb
@@ -1,4 +1,19 @@
FactoryGirl.define do
+ factory :legislation_process, class: 'Legislation::Process' do
+ title "A collaborative legislation process"
+ description "Description of the process"
+ target "Who will affected by this law?"
+ how_to_participate "You can participate by answering some questions"
+ start_date "2016-11-16"
+ end_date "2016-11-16"
+ debate_start_date "2016-11-16"
+ debate_end_date "2016-11-16"
+ draft_publication_date "2016-11-16"
+ allegations_start_date "2016-11-16"
+ allegations_end_date "2016-11-16"
+ final_publication_date "2016-11-16"
+ end
+
sequence(:document_number) { |n| "#{n.to_s.rjust(8, '0')}X" }
factory :user do
diff --git a/spec/features/admin/legislation/processes_spec.rb b/spec/features/admin/legislation/processes_spec.rb
new file mode 100644
index 000000000..03aae2768
--- /dev/null
+++ b/spec/features/admin/legislation/processes_spec.rb
@@ -0,0 +1,62 @@
+require 'rails_helper'
+
+feature 'Admin legislation processes' do
+
+ background do
+ admin = create(:administrator)
+ login_as(admin.user)
+ end
+
+ context "Feature flag" do
+
+ scenario 'Disabled with a feature flag' do
+ Setting['feature.legislation'] = nil
+ expect{ visit admin_legislation_processes_path }.to raise_exception(FeatureFlags::FeatureDisabled)
+ end
+
+ end
+
+ context "Index" do
+
+ scenario 'Displaying legislation processes' do
+ process = create(:legislation_process)
+ visit admin_legislation_processes_path(filter: 'all')
+
+ expect(page).to have_content(process.title)
+ end
+ end
+
+ context 'Create' do
+ scenario 'Valid legislation process' do
+ visit admin_root_path
+
+ within('#side_menu') do
+ click_link "Collaborative Legislation"
+ end
+
+ expect(page).to_not have_content 'An example legislation process'
+
+ click_link "New process"
+
+ fill_in 'legislation_process_title', with: 'An example legislation process'
+ fill_in 'legislation_process_description', with: 'Describing the process'
+ fill_in 'legislation_process_target', with: 'This thing affects people'
+ fill_in 'legislation_process_how_to_participate', with: 'You can partipate in this thing by doing...'
+
+ base_date = Date.current
+ fill_in 'start_date', with: base_date.strftime("%d/%m/%Y")
+ fill_in 'end_date', with: (base_date + 5.days).strftime("%d/%m/%Y")
+
+ fill_in 'debate_start_date', with: base_date.strftime("%d/%m/%Y")
+ fill_in 'debate_end_date', with: (base_date + 2.days).strftime("%d/%m/%Y")
+ fill_in 'draft_publication_date', with: (base_date + 3.days).strftime("%d/%m/%Y")
+ fill_in 'allegations_start_date', with: (base_date + 3.days).strftime("%d/%m/%Y")
+ fill_in 'allegations_end_date', with: (base_date + 5.days).strftime("%d/%m/%Y")
+ fill_in 'final_publication_date', with: (base_date + 7.days).strftime("%d/%m/%Y")
+
+ click_button 'Create process'
+
+ expect(page).to have_content 'An example legislation process'
+ end
+ end
+end
diff --git a/spec/models/legislation/process_spec.rb b/spec/models/legislation/process_spec.rb
new file mode 100644
index 000000000..4302293bd
--- /dev/null
+++ b/spec/models/legislation/process_spec.rb
@@ -0,0 +1,41 @@
+require 'rails_helper'
+
+RSpec.describe Legislation::Process, type: :model do
+ let(:legislation_process) { build(:legislation_process) }
+
+ it "should be valid" do
+ expect(legislation_process).to be_valid
+ end
+
+ describe "filter scopes" do
+ before(:each) do
+ @process_1 = create(:legislation_process, start_date: Date.current - 2.days, end_date: Date.current + 1.day)
+ @process_2 = create(:legislation_process, start_date: Date.current + 1.days, end_date: Date.current + 3.days)
+ @process_3 = create(:legislation_process, start_date: Date.current - 4.days, end_date: Date.current - 3.days)
+ end
+
+ it "filter open" do
+ open_processes = ::Legislation::Process.open
+
+ expect(open_processes).to include(@process_1)
+ expect(open_processes).to_not include(@process_2)
+ expect(open_processes).to_not include(@process_3)
+ end
+
+ it "filter next" do
+ next_processes = ::Legislation::Process.next
+
+ expect(next_processes).to include(@process_2)
+ expect(next_processes).to_not include(@process_1)
+ expect(next_processes).to_not include(@process_3)
+ end
+
+ it "filter past" do
+ past_processes = ::Legislation::Process.past
+
+ expect(past_processes).to include(@process_3)
+ expect(past_processes).to_not include(@process_2)
+ expect(past_processes).to_not include(@process_1)
+ end
+ end
+end