Legislation Questions model and basic admin
This commit is contained in:
2
Gemfile
2
Gemfile
@@ -67,6 +67,8 @@ gem 'redcarpet'
|
|||||||
|
|
||||||
gem 'rails-assets-markdown-it', source: 'https://rails-assets.org'
|
gem 'rails-assets-markdown-it', source: 'https://rails-assets.org'
|
||||||
|
|
||||||
|
gem 'cocoon'
|
||||||
|
|
||||||
group :development, :test do
|
group :development, :test do
|
||||||
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
|
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
|
||||||
gem 'byebug'
|
gem 'byebug'
|
||||||
|
|||||||
@@ -104,6 +104,7 @@ GEM
|
|||||||
cliver (0.3.2)
|
cliver (0.3.2)
|
||||||
cocaine (0.5.8)
|
cocaine (0.5.8)
|
||||||
climate_control (>= 0.0.3, < 1.0)
|
climate_control (>= 0.0.3, < 1.0)
|
||||||
|
cocoon (1.2.9)
|
||||||
coffee-rails (4.2.1)
|
coffee-rails (4.2.1)
|
||||||
coffee-script (>= 2.2.0)
|
coffee-script (>= 2.2.0)
|
||||||
railties (>= 4.0.0, < 5.2.x)
|
railties (>= 4.0.0, < 5.2.x)
|
||||||
@@ -467,6 +468,7 @@ DEPENDENCIES
|
|||||||
capistrano3-delayed-job (~> 1.0)
|
capistrano3-delayed-job (~> 1.0)
|
||||||
capybara
|
capybara
|
||||||
ckeditor (~> 4.2.0)
|
ckeditor (~> 4.2.0)
|
||||||
|
cocoon
|
||||||
coffee-rails (~> 4.2.1)
|
coffee-rails (~> 4.2.1)
|
||||||
coveralls
|
coveralls
|
||||||
daemons
|
daemons
|
||||||
|
|||||||
@@ -48,6 +48,7 @@
|
|||||||
//= require social_share
|
//= require social_share
|
||||||
//= require markdown-it
|
//= require markdown-it
|
||||||
//= require markdown_editor
|
//= require markdown_editor
|
||||||
|
//= require cocoon
|
||||||
//= require custom
|
//= require custom
|
||||||
|
|
||||||
var initialize_modules = function() {
|
var initialize_modules = function() {
|
||||||
|
|||||||
@@ -31,7 +31,6 @@ class Admin::Legislation::DraftVersionsController < Admin::Legislation::BaseCont
|
|||||||
|
|
||||||
def draft_version_params
|
def draft_version_params
|
||||||
params.require(:legislation_draft_version).permit(
|
params.require(:legislation_draft_version).permit(
|
||||||
:legislation_process_id,
|
|
||||||
:title,
|
:title,
|
||||||
:changelog,
|
:changelog,
|
||||||
:status,
|
:status,
|
||||||
|
|||||||
38
app/controllers/admin/legislation/questions_controller.rb
Normal file
38
app/controllers/admin/legislation/questions_controller.rb
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
class Admin::Legislation::QuestionsController < Admin::Legislation::BaseController
|
||||||
|
load_and_authorize_resource :process, class: "Legislation::Process"
|
||||||
|
load_and_authorize_resource :question, class: "Legislation::Question", through: :process
|
||||||
|
|
||||||
|
def index
|
||||||
|
@questions = @process.questions
|
||||||
|
end
|
||||||
|
|
||||||
|
def create
|
||||||
|
if @question.save
|
||||||
|
redirect_to admin_legislation_process_questions_path
|
||||||
|
else
|
||||||
|
render :new
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def update
|
||||||
|
if @question.update(question_params)
|
||||||
|
redirect_to admin_legislation_process_questions_path
|
||||||
|
else
|
||||||
|
render :edit
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def destroy
|
||||||
|
@question.destroy
|
||||||
|
redirect_to admin_legislation_process_questions_path
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def question_params
|
||||||
|
params.require(:legislation_question).permit(
|
||||||
|
:title,
|
||||||
|
question_options_attributes: [:id, :value, :_destroy]
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -48,6 +48,7 @@ module Abilities
|
|||||||
|
|
||||||
can [:manage], ::Legislation::Process
|
can [:manage], ::Legislation::Process
|
||||||
can [:manage], ::Legislation::DraftVersion
|
can [:manage], ::Legislation::DraftVersion
|
||||||
|
can [:manage], ::Legislation::Question
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ class Comment < ActiveRecord::Base
|
|||||||
|
|
||||||
validates :body, presence: true
|
validates :body, presence: true
|
||||||
validates :user, presence: true
|
validates :user, presence: true
|
||||||
validates_inclusion_of :commentable_type, in: ["Debate", "Proposal"]
|
validates_inclusion_of :commentable_type, in: ["Debate", "Proposal", "Legislation::Question"]
|
||||||
|
|
||||||
validate :validate_body_length
|
validate :validate_body_length
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ class Legislation::Process < ActiveRecord::Base
|
|||||||
include ActsAsParanoidAliases
|
include ActsAsParanoidAliases
|
||||||
|
|
||||||
has_many :draft_versions, class_name: 'Legislation::DraftVersion', foreign_key: 'legislation_process_id'
|
has_many :draft_versions, class_name: 'Legislation::DraftVersion', foreign_key: 'legislation_process_id'
|
||||||
|
has_many :questions, class_name: 'Legislation::Question', foreign_key: 'legislation_process_id'
|
||||||
|
|
||||||
validates :title, presence: true
|
validates :title, presence: true
|
||||||
validates :description, presence: true
|
validates :description, presence: true
|
||||||
|
|||||||
12
app/models/legislation/question.rb
Normal file
12
app/models/legislation/question.rb
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
class Legislation::Question < ActiveRecord::Base
|
||||||
|
belongs_to :process, class_name: 'Legislation::Process', foreign_key: 'legislation_process_id'
|
||||||
|
|
||||||
|
has_many :question_options, class_name: 'Legislation::QuestionOption', foreign_key: 'legislation_question_id', dependent: :destroy, inverse_of: :question
|
||||||
|
# has_many :answers
|
||||||
|
has_many :comments, as: :commentable
|
||||||
|
|
||||||
|
accepts_nested_attributes_for :question_options, :reject_if => proc { |attributes| attributes[:value].blank? }, allow_destroy: true
|
||||||
|
|
||||||
|
validates :process, presence: true
|
||||||
|
validates :title, presence: true
|
||||||
|
end
|
||||||
8
app/models/legislation/question_option.rb
Normal file
8
app/models/legislation/question_option.rb
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
class Legislation::QuestionOption < ActiveRecord::Base
|
||||||
|
belongs_to :question, class_name: 'Legislation::Question', foreign_key: 'legislation_question_id', inverse_of: :question_options
|
||||||
|
|
||||||
|
# has_many :answers
|
||||||
|
|
||||||
|
validates :question, presence: true
|
||||||
|
validates :value, presence: true, uniqueness: { scope: :legislation_question_id }
|
||||||
|
end
|
||||||
@@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
<strong>
|
<strong>
|
||||||
<%= @draft_version.errors.count %>
|
<%= @draft_version.errors.count %>
|
||||||
<%= t("admin.legislation.draft_versions.errors.form.error", count: @process.errors.count) %>
|
<%= t("admin.legislation.draft_versions.errors.form.error", count: @draft_version.errors.count) %>
|
||||||
</strong>
|
</strong>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<div class="legislation-draft-versions-index row">
|
<div class="legislation-draft-versions-index row">
|
||||||
<div class="small-12 column">
|
<div class="small-12 column">
|
||||||
<%= link_to admin_legislation_processes_path, class: "back" do %>
|
<%= link_to admin_legislation_process_path(@process), class: "back" do %>
|
||||||
<span class="icon-angle-left"></span>
|
<span class="icon-angle-left"></span>
|
||||||
<%= t("admin.legislation.draft_versions.edit.back") %>
|
<%= t("admin.legislation.draft_versions.edit.back") %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<div class="legislation-draft-versions-index row">
|
<div class="legislation-draft-versions-index row">
|
||||||
<div class="small-12 column">
|
<div class="small-12 column">
|
||||||
<%= link_to admin_legislation_processes_path, class: "back" do %>
|
<%= link_to admin_legislation_process_path(@process), class: "back" do %>
|
||||||
<span class="icon-angle-left"></span>
|
<span class="icon-angle-left"></span>
|
||||||
<%= t("admin.legislation.draft_versions.new.back") %>
|
<%= t("admin.legislation.draft_versions.new.back") %>
|
||||||
<% end %>
|
<% end %>
|
||||||
@@ -12,6 +12,5 @@
|
|||||||
<h3><%= t("admin.legislation.draft_versions.new.title") %></h3>
|
<h3><%= t("admin.legislation.draft_versions.new.title") %></h3>
|
||||||
|
|
||||||
<%= render 'form', url: admin_legislation_process_draft_versions_path(@process) %>
|
<%= render 'form', url: admin_legislation_process_draft_versions_path(@process) %>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
<ul class="menu simple clear">
|
<ul class="menu simple clear">
|
||||||
<li <%= "class=active" if active == 'info' %>>
|
<li <%= "class=active" if active == 'info' %>>
|
||||||
<%= link_to t("admin.legislation.processes.subnav.info"), edit_admin_legislation_process_path(process) %>
|
<%= link_to t("admin.legislation.processes.subnav.info"), edit_admin_legislation_process_path(process) %>
|
||||||
|
</li>
|
||||||
|
<li <%= "class=active" if active == 'questions' %>>
|
||||||
|
<%= link_to t("admin.legislation.processes.subnav.questions"), admin_legislation_process_questions_path(process) %>
|
||||||
</li>
|
</li>
|
||||||
<li <%= "class=active" if active == 'draft_versions' %>>
|
<li <%= "class=active" if active == 'draft_versions' %>>
|
||||||
<%= link_to t("admin.legislation.processes.subnav.draft_texts"), admin_legislation_process_draft_versions_path(process) %>
|
<%= link_to t("admin.legislation.processes.subnav.draft_texts"), admin_legislation_process_draft_versions_path(process) %>
|
||||||
|
|||||||
46
app/views/admin/legislation/questions/_form.html.erb
Normal file
46
app/views/admin/legislation/questions/_form.html.erb
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
<%= form_for [:admin, @process, @question], url: url do |f| %>
|
||||||
|
|
||||||
|
<% if @question.errors.any? %>
|
||||||
|
|
||||||
|
<div id="error_explanation" data-alert class="callout alert" data-closable>
|
||||||
|
<button class="close-button" aria-label="<%= t("application.close") %>" type="button" data-close>
|
||||||
|
<span aria-hidden="true">×</span>
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<strong>
|
||||||
|
<%= @question.errors.count %>
|
||||||
|
<%= t("admin.legislation.questions.errors.form.error", count: @question.errors.count) %>
|
||||||
|
</strong>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="small-12 medium-4 column">
|
||||||
|
<%= f.label :title %>
|
||||||
|
</div>
|
||||||
|
<div class="small-12 medium-8 column">
|
||||||
|
<%= f.text_area :title, rows: 5, label: false %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="small-12 medium-4 column">
|
||||||
|
<%= f.label :question_options %>
|
||||||
|
</div>
|
||||||
|
<div class="small-12 medium-8 column">
|
||||||
|
<%= f.fields_for :question_options do |ff| %>
|
||||||
|
<%= render 'question_option_fields', f: ff %>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
|
<div class="small-12 medium-8 column">
|
||||||
|
<%= link_to_add_association t('.add_option'), f, :question_options %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="actions small-12 medium-3 column">
|
||||||
|
<%= f.submit(class: "button expanded", value: t("admin.legislation.questions.#{admin_submit_action(@question)}.submit_button")) %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
<div class="nested-fields">
|
||||||
|
<div class="field">
|
||||||
|
<%= f.text_field :value, label: false %>
|
||||||
|
<%= link_to_remove_association t('.remove_option'), f %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
20
app/views/admin/legislation/questions/edit.html.erb
Normal file
20
app/views/admin/legislation/questions/edit.html.erb
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
<div class="legislation-questions-index row">
|
||||||
|
<div class="small-12 column">
|
||||||
|
<%= link_to admin_legislation_process_path(@process), class: "back" do %>
|
||||||
|
<span class="icon-angle-left"></span>
|
||||||
|
<%= t("admin.legislation.questions.edit.back") %>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<h1><%= @process.title %></h1>
|
||||||
|
|
||||||
|
<%= render 'admin/legislation/processes/subnav', process: @process, active: 'questions' %>
|
||||||
|
|
||||||
|
<h3><%= @question.title %></h3>
|
||||||
|
|
||||||
|
<%= render 'form', url: admin_legislation_process_question_path(@process, @question) %>
|
||||||
|
|
||||||
|
<%= link_to t("admin.legislation.processes.index.delete"), admin_legislation_process_question_path(@process, @question),
|
||||||
|
method: :delete,
|
||||||
|
class: 'button hollow alert' %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
42
app/views/admin/legislation/questions/index.html.erb
Normal file
42
app/views/admin/legislation/questions/index.html.erb
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
<div class="legislation-draft-versions-index row">
|
||||||
|
<div class="small-12 column">
|
||||||
|
<%= link_to admin_legislation_processes_path, class: "back" do %>
|
||||||
|
<span class="icon-angle-left"></span>
|
||||||
|
<%= t("admin.legislation.questions.index.back") %>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<h1><%= @process.title %></h1>
|
||||||
|
|
||||||
|
<%= render 'admin/legislation/processes/subnav', process: @process, active: 'questions' %>
|
||||||
|
|
||||||
|
<%= link_to t("admin.legislation.questions.index.create"),
|
||||||
|
new_admin_legislation_process_question_path, class: "button float-right" %>
|
||||||
|
|
||||||
|
<h3><%= t("admin.legislation.questions.index.title") %></h3>
|
||||||
|
|
||||||
|
<table>
|
||||||
|
<tr>
|
||||||
|
<th><%= t("admin.legislation.questions.table.title") %></th>
|
||||||
|
<th><%= t("admin.legislation.questions.table.question_options") %></th>
|
||||||
|
<th><%= t("admin.legislation.questions.table.answers_count") %></th>
|
||||||
|
<th><%= t("admin.legislation.questions.table.comments_count") %></th>
|
||||||
|
</tr>
|
||||||
|
<% @process.questions.each do |question| %>
|
||||||
|
<tr id="<%= dom_id(question) %>">
|
||||||
|
<td>
|
||||||
|
<%= link_to question.title, edit_admin_legislation_process_question_path(@process, question) %>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<%= content_tag :ul do %>
|
||||||
|
<% question.question_options.each do |question_option| %>
|
||||||
|
<%= content_tag :li, question_option.value %>
|
||||||
|
<% end %>
|
||||||
|
<% end %>
|
||||||
|
</td>
|
||||||
|
<td><%= question.answers_count %></td>
|
||||||
|
<td><%= question.comments.count %></td>
|
||||||
|
</tr>
|
||||||
|
<% end %>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
16
app/views/admin/legislation/questions/new.html.erb
Normal file
16
app/views/admin/legislation/questions/new.html.erb
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
<div class="legislation-questions-index row">
|
||||||
|
<div class="small-12 column">
|
||||||
|
<%= link_to admin_legislation_process_path(@process), class: "back" do %>
|
||||||
|
<span class="icon-angle-left"></span>
|
||||||
|
<%= t("admin.legislation.questions.new.back") %>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<h1><%= @process.title %></h1>
|
||||||
|
|
||||||
|
<%= render 'admin/legislation/processes/subnav', process: @process, active: 'questions' %>
|
||||||
|
|
||||||
|
<h3><%= t("admin.legislation.questions.new.title") %></h3>
|
||||||
|
|
||||||
|
<%= render 'form', url: admin_legislation_process_questions_path(@process) %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
@@ -120,6 +120,7 @@ ignore_unused:
|
|||||||
- 'admin.legislation.processes.index.filter*'
|
- 'admin.legislation.processes.index.filter*'
|
||||||
- 'admin.legislation.processes.*.submit_button'
|
- 'admin.legislation.processes.*.submit_button'
|
||||||
- 'admin.legislation.draft_versions.*.submit_button'
|
- 'admin.legislation.draft_versions.*.submit_button'
|
||||||
|
- 'admin.legislation.questions.*.submit_button'
|
||||||
- 'admin.comments.index.hidden_*'
|
- 'admin.comments.index.hidden_*'
|
||||||
- 'admin.settings.index.features.*'
|
- 'admin.settings.index.features.*'
|
||||||
- 'moderation.comments.index.filter*'
|
- 'moderation.comments.index.filter*'
|
||||||
|
|||||||
@@ -108,6 +108,7 @@ en:
|
|||||||
subnav:
|
subnav:
|
||||||
info: Information
|
info: Information
|
||||||
draft_texts: Text
|
draft_texts: Text
|
||||||
|
questions: Debate
|
||||||
draft_versions:
|
draft_versions:
|
||||||
edit:
|
edit:
|
||||||
back: Back
|
back: Back
|
||||||
@@ -128,11 +129,35 @@ en:
|
|||||||
draft: Draft
|
draft: Draft
|
||||||
published: Published
|
published: Published
|
||||||
table:
|
table:
|
||||||
title: Títle
|
title: Title
|
||||||
created_at: Created at
|
created_at: Created at
|
||||||
comments: Comments
|
comments: Comments
|
||||||
final_version: Final version
|
final_version: Final version
|
||||||
status: Status
|
status: Status
|
||||||
|
questions:
|
||||||
|
edit:
|
||||||
|
back: Back
|
||||||
|
submit_button: Save changes
|
||||||
|
errors:
|
||||||
|
form:
|
||||||
|
error: Error
|
||||||
|
form:
|
||||||
|
add_option: Add option
|
||||||
|
index:
|
||||||
|
back: Back
|
||||||
|
title: Questions
|
||||||
|
create: Create question
|
||||||
|
new:
|
||||||
|
back: Back
|
||||||
|
title: Create new question
|
||||||
|
submit_button: Create question
|
||||||
|
table:
|
||||||
|
title: Title
|
||||||
|
question_options: Question options
|
||||||
|
answers_count: Answers count
|
||||||
|
comments_count: Comments count
|
||||||
|
question_option_fields:
|
||||||
|
remove_option: Remove option
|
||||||
managers:
|
managers:
|
||||||
index:
|
index:
|
||||||
title: Managers
|
title: Managers
|
||||||
|
|||||||
@@ -106,6 +106,7 @@ es:
|
|||||||
subnav:
|
subnav:
|
||||||
info: Información
|
info: Información
|
||||||
draft_texts: Texto
|
draft_texts: Texto
|
||||||
|
questions: Debate
|
||||||
draft_versions:
|
draft_versions:
|
||||||
edit:
|
edit:
|
||||||
back: Volver
|
back: Volver
|
||||||
@@ -131,6 +132,30 @@ es:
|
|||||||
comments: Comentarios
|
comments: Comentarios
|
||||||
final_version: Versión final
|
final_version: Versión final
|
||||||
status: Estado
|
status: Estado
|
||||||
|
questions:
|
||||||
|
edit:
|
||||||
|
back: Volver
|
||||||
|
submit_button: Guardar cambios
|
||||||
|
errors:
|
||||||
|
form:
|
||||||
|
error: Error
|
||||||
|
form:
|
||||||
|
add_option: +Añadir respuesta cerrada
|
||||||
|
index:
|
||||||
|
back: Volver
|
||||||
|
title: Preguntas
|
||||||
|
create: Crear pregunta
|
||||||
|
new:
|
||||||
|
back: Volver
|
||||||
|
title: Crear nueva pregunta
|
||||||
|
submit_button: Crear pregunta
|
||||||
|
table:
|
||||||
|
title: Título
|
||||||
|
question_options: Opciones de respuesta
|
||||||
|
answers_count: Número de respuestas
|
||||||
|
comments_count: Número de comentarios
|
||||||
|
question_option_fields:
|
||||||
|
remove_option: Eliminar
|
||||||
managers:
|
managers:
|
||||||
index:
|
index:
|
||||||
title: Gestores
|
title: Gestores
|
||||||
|
|||||||
@@ -200,6 +200,7 @@ Rails.application.routes.draw do
|
|||||||
|
|
||||||
namespace :legislation do
|
namespace :legislation do
|
||||||
resources :processes do
|
resources :processes do
|
||||||
|
resources :questions
|
||||||
resources :draft_versions
|
resources :draft_versions
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
23
db/migrate/20161220120037_create_legislation_questions.rb
Normal file
23
db/migrate/20161220120037_create_legislation_questions.rb
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
class CreateLegislationQuestions < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
create_table :legislation_questions do |t|
|
||||||
|
t.references :legislation_process, index: true
|
||||||
|
t.text :title
|
||||||
|
t.integer :answers_count, default: 0
|
||||||
|
|
||||||
|
t.datetime :hidden_at, index: true
|
||||||
|
|
||||||
|
t.timestamps null: false
|
||||||
|
end
|
||||||
|
|
||||||
|
create_table :legislation_question_options do |t|
|
||||||
|
t.references :legislation_question, index: true
|
||||||
|
t.string :value
|
||||||
|
t.integer :answers_count, default: 0
|
||||||
|
|
||||||
|
t.datetime :hidden_at, index: true
|
||||||
|
|
||||||
|
t.timestamps null: false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
26
db/schema.rb
26
db/schema.rb
@@ -11,7 +11,7 @@
|
|||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 20161213144031) do
|
ActiveRecord::Schema.define(version: 20161220120037) do
|
||||||
|
|
||||||
# These are extensions that must be enabled in order to support this database
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "plpgsql"
|
enable_extension "plpgsql"
|
||||||
@@ -274,6 +274,30 @@ ActiveRecord::Schema.define(version: 20161213144031) do
|
|||||||
add_index "legislation_processes", ["hidden_at"], name: "index_legislation_processes_on_hidden_at", 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
|
add_index "legislation_processes", ["start_date"], name: "index_legislation_processes_on_start_date", using: :btree
|
||||||
|
|
||||||
|
create_table "legislation_question_options", force: :cascade do |t|
|
||||||
|
t.integer "legislation_question_id"
|
||||||
|
t.string "value"
|
||||||
|
t.integer "answers_count", default: 0
|
||||||
|
t.datetime "hidden_at"
|
||||||
|
t.datetime "created_at", null: false
|
||||||
|
t.datetime "updated_at", null: false
|
||||||
|
end
|
||||||
|
|
||||||
|
add_index "legislation_question_options", ["hidden_at"], name: "index_legislation_question_options_on_hidden_at", using: :btree
|
||||||
|
add_index "legislation_question_options", ["legislation_question_id"], name: "index_legislation_question_options_on_legislation_question_id", using: :btree
|
||||||
|
|
||||||
|
create_table "legislation_questions", force: :cascade do |t|
|
||||||
|
t.integer "legislation_process_id"
|
||||||
|
t.text "title"
|
||||||
|
t.integer "answers_count", default: 0
|
||||||
|
t.datetime "hidden_at"
|
||||||
|
t.datetime "created_at", null: false
|
||||||
|
t.datetime "updated_at", null: false
|
||||||
|
end
|
||||||
|
|
||||||
|
add_index "legislation_questions", ["hidden_at"], name: "index_legislation_questions_on_hidden_at", using: :btree
|
||||||
|
add_index "legislation_questions", ["legislation_process_id"], name: "index_legislation_questions_on_legislation_process_id", using: :btree
|
||||||
|
|
||||||
create_table "locks", force: :cascade do |t|
|
create_table "locks", force: :cascade do |t|
|
||||||
t.integer "user_id"
|
t.integer "user_id"
|
||||||
t.integer "tries", default: 0
|
t.integer "tries", default: 0
|
||||||
|
|||||||
@@ -389,4 +389,14 @@ FactoryGirl.define do
|
|||||||
final_version false
|
final_version false
|
||||||
body "Body of the legislation text"
|
body "Body of the legislation text"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
factory :legislation_question, class: 'Legislation::Question' do
|
||||||
|
process factory: :legislation_process
|
||||||
|
title "Question text"
|
||||||
|
end
|
||||||
|
|
||||||
|
factory :legislation_question_option, class: 'Legislation::QuestionOption' do
|
||||||
|
question factory: :legislation_question
|
||||||
|
sequence(:value) { |n| "Option #{n}" }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
89
spec/features/admin/legislation/questions_spec.rb
Normal file
89
spec/features/admin/legislation/questions_spec.rb
Normal file
@@ -0,0 +1,89 @@
|
|||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
feature 'Admin legislation questions' 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
|
||||||
|
process = create(:legislation_process)
|
||||||
|
expect{ visit admin_legislation_process_questions_path(process) }.to raise_exception(FeatureFlags::FeatureDisabled)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
context "Index" do
|
||||||
|
|
||||||
|
scenario 'Displaying legislation process questions' do
|
||||||
|
process = create(:legislation_process, title: 'An example legislation process')
|
||||||
|
question = create(:legislation_question, process: process, title: 'Question 1')
|
||||||
|
question = create(:legislation_question, process: process, title: 'Question 2')
|
||||||
|
|
||||||
|
visit admin_legislation_processes_path(filter: 'all')
|
||||||
|
|
||||||
|
click_link 'An example legislation process'
|
||||||
|
click_link 'Debate'
|
||||||
|
|
||||||
|
expect(page).to have_content('Question 1')
|
||||||
|
expect(page).to have_content('Question 2')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'Create' do
|
||||||
|
scenario 'Valid legislation question' do
|
||||||
|
process = create(:legislation_process, title: 'An example legislation process')
|
||||||
|
|
||||||
|
visit admin_root_path
|
||||||
|
|
||||||
|
within('#side_menu') do
|
||||||
|
click_link "Collaborative Legislation"
|
||||||
|
end
|
||||||
|
|
||||||
|
click_link "All"
|
||||||
|
|
||||||
|
expect(page).to have_content 'An example legislation process'
|
||||||
|
|
||||||
|
click_link 'An example legislation process'
|
||||||
|
click_link 'Debate'
|
||||||
|
|
||||||
|
click_link 'Create question'
|
||||||
|
|
||||||
|
fill_in 'legislation_question_title', with: 'Question 3'
|
||||||
|
click_button 'Create question'
|
||||||
|
|
||||||
|
expect(page).to have_content 'Question 3'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'Update' do
|
||||||
|
scenario 'Valid legislation question', :js do
|
||||||
|
process = create(:legislation_process, title: 'An example legislation process')
|
||||||
|
question = create(:legislation_question, title: 'Question 2', process: process)
|
||||||
|
|
||||||
|
visit admin_root_path
|
||||||
|
|
||||||
|
within('#side_menu') do
|
||||||
|
click_link "Collaborative Legislation"
|
||||||
|
end
|
||||||
|
|
||||||
|
click_link "All"
|
||||||
|
|
||||||
|
expect(page).to have_content 'An example legislation process'
|
||||||
|
|
||||||
|
click_link 'An example legislation process'
|
||||||
|
click_link 'Debate'
|
||||||
|
|
||||||
|
click_link 'Question 2'
|
||||||
|
|
||||||
|
fill_in 'legislation_question_title', with: 'Question 2b'
|
||||||
|
click_button 'Save changes'
|
||||||
|
|
||||||
|
expect(page).to have_content 'Question 2b'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
18
spec/models/legislation/question_option_spec.rb
Normal file
18
spec/models/legislation/question_option_spec.rb
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
RSpec.describe Legislation::QuestionOption, type: :model do
|
||||||
|
let(:legislation_question_option) { build(:legislation_question_option) }
|
||||||
|
|
||||||
|
it "should be valid" do
|
||||||
|
expect(legislation_question_option).to be_valid
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should be unique per question" do
|
||||||
|
question = create(:legislation_question)
|
||||||
|
valid_question_option = create(:legislation_question_option, question: question, value: "uno")
|
||||||
|
|
||||||
|
invalid_question_option = build(:legislation_question_option, question: question, value: "uno")
|
||||||
|
|
||||||
|
expect(invalid_question_option).to_not be_valid
|
||||||
|
end
|
||||||
|
end
|
||||||
9
spec/models/legislation/question_spec.rb
Normal file
9
spec/models/legislation/question_spec.rb
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
RSpec.describe Legislation::Question, type: :model do
|
||||||
|
let(:legislation_question) { build(:legislation_question) }
|
||||||
|
|
||||||
|
it "should be valid" do
|
||||||
|
expect(legislation_question).to be_valid
|
||||||
|
end
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user