rename type_champs into type_champ and change links/routes for procedure : use show instead of edit

This commit is contained in:
Tanguy PATTE 2015-11-17 10:23:05 +01:00
parent 9942525984
commit 5a422c75ac
21 changed files with 84 additions and 48 deletions

View file

@ -88,8 +88,8 @@ function add_new_type_de_champ_params() {
$("#new_type_de_champ .description").attr('id', 'procedure_new_type_de_champ_'+types_de_champ_index+'__description');
$("#new_type_de_champ .description").val('');
$("#new_type_de_champ .type_champs").attr('name', 'procedure[new_type_de_champ[' + types_de_champ_index + ']][type_champs]');
$("#new_type_de_champ .type_champs").attr('id', 'procedure_new_type_de_champ_'+types_de_champ_index+'__type_champs');
$("#new_type_de_champ .type_champ").attr('name', 'procedure[new_type_de_champ[' + types_de_champ_index + ']][type_champ]');
$("#new_type_de_champ .type_champ").attr('id', 'procedure_new_type_de_champ_'+types_de_champ_index+'__type_champ');
$("#new_type_de_champ .order_place").attr('name', 'procedure[new_type_de_champ[' + types_de_champ_index + ']][order_place]');
$("#new_type_de_champ .order_place").attr('id', 'procedure_new_type_de_champ_'+types_de_champ_index+'__order_place');

View file

@ -7,7 +7,7 @@
}
}
.type_champs-text {
.type_champ-text {
@extend .col-md-6;
@extend .col-lg-6;
@ -16,7 +16,7 @@
}
}
.type_champs-textarea {
.type_champ-textarea {
@extend .col-md-8;
@extend .col-lg-8;
@ -26,7 +26,7 @@
}
}
.type_champs-number {
.type_champ-number {
@extend .col-md-3;
@extend .col-lg-3;
@ -35,7 +35,7 @@
}
}
.type_champs-datetime {
.type_champ-datetime {
@extend .col-md-2;
@extend .col-lg-2;

View file

@ -9,7 +9,7 @@ class Admin::TypesDeChampController < AdminController
render json: { message: 'Champ not found' }, status: 404
end
def edit
def show
end
def update
@ -20,7 +20,7 @@ class Admin::TypesDeChampController < AdminController
end
def update_params
params.require(:procedure).permit(types_de_champ_attributes: [:libelle, :description, :order_place, :type_champs, :id])
params.require(:procedure).permit(types_de_champ_attributes: [:libelle, :description, :order_place, :type_champ, :id])
end
private

View file

@ -1,5 +1,5 @@
class Champ < ActiveRecord::Base
belongs_to :dossier
belongs_to :type_de_champ
delegate :libelle, :type_champs, :order_place, to: :type_de_champ
delegate :libelle, :type_champ, :order_place, to: :type_de_champ
end

View file

@ -9,6 +9,6 @@ class TypeDeChamp < ActiveRecord::Base
has_many :champ
validates :libelle, presence: true, allow_blank: false, allow_nil: false
validates :type_champs, presence: true, allow_blank: false, allow_nil: false
validates :type_champ, presence: true, allow_blank: false, allow_nil: false
# validates :order_place, presence: true, allow_blank: false, allow_nil: false
end

View file

@ -2,7 +2,7 @@
%li
= link_to('Description', admin_procedure_path(@procedure))
%li
= link_to('Champs', edit_admin_procedure_types_de_champ_path(@procedure))
= link_to('Champs', admin_procedure_types_de_champ_path(@procedure))
%li.active
= link_to('Pièces justificatives', edit_admin_procedure_pieces_justificatives_path(@procedure))

View file

@ -2,7 +2,7 @@
%li.active
= link_to('Description', admin_procedure_path(@procedure))
%li
= link_to('Champs', edit_admin_procedure_types_de_champ_path(@procedure))
= link_to('Champs', admin_procedure_types_de_champ_path(@procedure))
%li
= link_to('Pièces justificatives', edit_admin_procedure_pieces_justificatives_path(@procedure))

View file

@ -6,7 +6,7 @@
= ff.text_field :libelle, class: 'form-control libelle', placeholder: 'Libellé'
.form-group
%h4 Type
= ff.select :type_champs, TypeDeChamp.type_champs, {}, {class: 'form-control type_champs'}
= ff.select :type_champ, TypeDeChamp.type_champ, {}, {class: 'form-control type_champ'}
.form-group
%h4 Description
= ff.text_area :description, class: 'form-control description', placeholder: 'Description'
@ -48,7 +48,7 @@
/ .form-group{ style: 'padding-right: 2%' }
/ %h4 Type
/ =ff.select :type_champs, TypeDeChamp.type_champs, {}, {class: 'form-control type_champs'}
/ =ff.select :type_champ, TypeDeChamp.type_champ, {}, {class: 'form-control type_champ'}
/ .form-group{ style: 'padding-right: 2%' }
/ %h4 Description

View file

@ -5,7 +5,7 @@
= ff.text_field :libelle, class: 'form-control libelle', placeholder: 'Libellé'
.form-group
%h4 Type
= ff.select :type_champs, TypeDeChamp.type_champs, {}, {class: 'form-control type_champs'}
= ff.select :type_champ, TypeDeChamp.type_champs, {}, {class: 'form-control type_champ'}
.form-group
%h4 Description
= ff.text_area :description, class: 'form-control description', placeholder: 'Description'

View file

@ -2,4 +2,4 @@
= render partial: 'fields', locals: { types_de_champ: @procedure.types_de_champ, f: f }
#new_type_de_champ
= render partial: 'fields', locals: { types_de_champ: TypeDeChamp.new, f: f }
= f.submit "Ajouter un champ", class: 'btn btn-success'
= f.submit "Ajouter un champ", class: 'btn btn-success', id: :add_type_de_champ

View file

@ -2,7 +2,7 @@
%li
= link_to('Description', admin_procedure_path(@procedure))
%li.active
= link_to('Champs', edit_admin_procedure_types_de_champ_path(@procedure))
= link_to('Champs', admin_procedure_types_de_champ_path(@procedure))
%li
= link_to('Pièces justificatives', edit_admin_procedure_pieces_justificatives_path(@procedure))

View file

@ -19,11 +19,11 @@
-unless @champs.nil?
-@champs.each do |champ|
.row
%div{class: "type_champs-#{champ.type_champs}"}
%div{class: "type_champ-#{champ.type_champ}"}
%h4
= champ.libelle
-if champ.type_champs == 'textarea'
-if champ.type_champ == 'textarea'
%textarea.form-control{name:"champs['#{champ.id}']",
placeholder: champ.libelle,
id: "champs_#{champ.id}"}
@ -33,9 +33,9 @@
placeholder: champ.libelle,
id: "champs_#{champ.id}",
value: champ.value,
type:"#{champ.type_champs}",
'data-provide' => ('datepicker' if champ.type_champs == 'datetime'),
'data-date-format' => ('dd/mm/yyyy' if champ.type_champs == 'datetime')}
type:"#{champ.type_champ}",
'data-provide' => ('datepicker' if champ.type_champ == 'datetime'),
'data-date-format' => ('dd/mm/yyyy' if champ.type_champ == 'datetime')}
%br
%h3 Documents administratifs

View file

@ -42,7 +42,7 @@ Rails.application.routes.draw do
namespace :admin do
get 'sign_in' => '/administrateurs/sessions#new'
resources :procedures do
resource :types_de_champ, only: [:edit, :update]
resource :types_de_champ, only: [:show, :update]
resources :types_de_champ, only: [:destroy]
resource :pieces_justificatives, only: [:edit, :update]
end

View file

@ -0,0 +1,5 @@
class RenameTypeChampsIntoTypeChamp < ActiveRecord::Migration
def change
rename_column :types_de_champ, :type_champs, :type_champ
end
end

View file

@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20151110091451) do
ActiveRecord::Schema.define(version: 20151116175817) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -146,7 +146,7 @@ ActiveRecord::Schema.define(version: 20151110091451) do
create_table "types_de_champ", force: :cascade do |t|
t.string "libelle"
t.string "type_champs"
t.string "type_champ"
t.integer "order_place"
t.integer "procedure_id"
t.text "description"

View file

@ -9,7 +9,7 @@ describe Admin::TypesDeChampController, type: :controller do
describe '#update' do
let(:procedure) { create(:procedure) }
let(:libelle) { 'mon libelle' }
let(:type_champs) { 'text' }
let(:type_champ) { 'text' }
let(:description) { 'titi' }
let(:order_place) { '' }
let(:types_de_champ_id) { '' }
@ -19,7 +19,7 @@ describe Admin::TypesDeChampController, type: :controller do
{ '0' =>
{
libelle: libelle,
type_champs: type_champs,
type_champ: type_champ,
description: description,
order_place: order_place,
id: types_de_champ_id
@ -41,7 +41,7 @@ describe Admin::TypesDeChampController, type: :controller do
subject { procedure.types_de_champ.first }
it { expect(subject.libelle).to eq('mon libelle') }
it { expect(subject.type_champs).to eq('text') }
it { expect(subject.type_champ).to eq('text') }
it { expect(subject.description).to eq('titi') }
# it { expect(subject.order_place).to eq('0') }
end
@ -51,7 +51,7 @@ describe Admin::TypesDeChampController, type: :controller do
let(:type_de_champ) { procedure.types_de_champ.first }
let(:types_de_champ_id) { type_de_champ.id }
let(:libelle) { 'toto' }
let(:type_champs) { 'text' }
let(:type_champ) { 'text' }
let(:description) { 'citrouille' }
let(:order_place) { '0' }
before do
@ -60,7 +60,7 @@ describe Admin::TypesDeChampController, type: :controller do
end
subject { procedure.types_de_champ.first }
it { expect(subject.libelle).to eq('toto') }
it { expect(subject.type_champs).to eq('text') }
it { expect(subject.type_champ).to eq('text') }
it { expect(subject.description).to eq('citrouille') }
# it { expect(subject.order_place).to eq(0) }
end

View file

@ -2,7 +2,7 @@ FactoryGirl.define do
factory :type_de_champ do
libelle 'Libellé'
description 'description de votre projet'
type_champs 'textarea'
type_champ 'textarea'
order_place 1
end
end

View file

@ -1,12 +1,43 @@
require 'spec_helper'
# feature 'add a new type de champs', js: true do
# let(:administrateur) { create(:administrateur) }
feature 'add a new type de champs', js: true do
# before do
# login_as administrateur, scope: :administrateur
# end
let(:administrateur) { create(:administrateur) }
let(:procedure) { create(:procedure) }
before do
login_as administrateur, scope: :administrateur
visit admin_procedure_types_de_champ_path(procedure)
end
scenario 'displays a form for type de champs' do
expect(page).to have_css('#procedure_types_de_champ_attributes_0_libelle')
expect(page).to have_css('#procedure_types_de_champ_attributes_0_type_champ')
expect(page).to have_css('#procedure_types_de_champ_attributes_0_description')
expect(page).to have_css('#add_type_de_champ')
end
context 'user fill a new type de champ', js: true do
let(:libelle) { 'mon libelle' }
let(:type_champ) { 'text' }
let(:description) { 'ma super histoire' }
before do
page.find_by_id('procedure_types_de_champ_attributes_0_libelle').set libelle
page.find_by_id('procedure_types_de_champ_attributes_0_type_champ').set type_champ
page.find_by_id('procedure_types_de_champ_attributes_0_description').set description
click_button 'Ajouter un champ'
procedure.reload
end
subject { procedure.types_de_champ.first }
scenario 'creates the type de champ', js: true do
expect(page).to have_css('#procedure_types_de_champ_attributes_1_libelle')
expect(subject.libelle).to eq(libelle)
expect(subject.type_champ).to eq(type_champ)
expect(subject.description).to eq(description)
end
end
end
# context 'when create a new procedure' do
# before do
# visit new_admin_procedure_path
@ -15,7 +46,7 @@ require 'spec_helper'
# scenario 'page have form to created new type de champs' do
# expect(page).to have_css('#type_de_champ_0')
# expect(page).to have_css('input[name="procedure[new_type_de_champ[0]][libelle]"]')
# expect(page).to have_css('select[name="procedure[new_type_de_champ[0]][type_champs]"]')
# expect(page).to have_css('select[name="procedure[new_type_de_champ[0]][type_champ]"]')
# expect(page).to have_css('textarea[name="procedure[new_type_de_champ[0]][description]"]')
# expect(page).to have_css('input[name="procedure[new_type_de_champ[0]][order_place]"]', visible: false)
# expect(page).to have_css('input[name="procedure[new_type_de_champ[0]][_destroy]"]', visible: false)
@ -37,7 +68,7 @@ require 'spec_helper'
# scenario 'a new champs type line is appeared with increment index id' do
# expect(page).to have_css('#type_de_champ_1')
# expect(page).to have_css('input[name="procedure[new_type_de_champ[1]][libelle]"]')
# expect(page).to have_css('select[name="procedure[new_type_de_champ[1]][type_champs]"]')
# expect(page).to have_css('select[name="procedure[new_type_de_champ[1]][type_champ]"]')
# expect(page).to have_css('textarea[name="procedure[new_type_de_champ[1]][description]"]')
# expect(page).to have_css('input[name="procedure[new_type_de_champ[1]][order_place]"]', visible: false)
# expect(page).to have_css('input[name="procedure[new_type_de_champ[1]][_destroy]"]', visible: false)

View file

@ -12,7 +12,7 @@ describe Champ do
describe 'delegation' do
it { is_expected.to delegate_method(:libelle).to(:type_de_champ) }
it { is_expected.to delegate_method(:type_champs).to(:type_de_champ) }
it { is_expected.to delegate_method(:type_champ).to(:type_de_champ) }
it { is_expected.to delegate_method(:order_place).to(:type_de_champ) }
end
end

View file

@ -3,7 +3,7 @@ require 'spec_helper'
describe TypeDeChamp do
describe 'database columns' do
it { is_expected.to have_db_column(:libelle) }
it { is_expected.to have_db_column(:type_champs) }
it { is_expected.to have_db_column(:type_champ) }
it { is_expected.to have_db_column(:order_place) }
it { is_expected.to have_db_column(:description) }
end
@ -21,13 +21,13 @@ describe TypeDeChamp do
end
context 'type' do
it { is_expected.not_to allow_value(nil).for(:type_champs) }
it { is_expected.not_to allow_value('').for(:type_champs) }
it { is_expected.not_to allow_value(nil).for(:type_champ) }
it { is_expected.not_to allow_value('').for(:type_champ) }
it { is_expected.to allow_value('text').for(:type_champs) }
it { is_expected.to allow_value('textarea').for(:type_champs) }
it { is_expected.to allow_value('datetime').for(:type_champs) }
it { is_expected.to allow_value('number').for(:type_champs) }
it { is_expected.to allow_value('text').for(:type_champ) }
it { is_expected.to allow_value('textarea').for(:type_champ) }
it { is_expected.to allow_value('datetime').for(:type_champ) }
it { is_expected.to allow_value('number').for(:type_champ) }
end
context 'order_place' do

View file

@ -95,13 +95,13 @@ describe 'users/description/show.html.haml', type: :view do
describe 'first champs' do
subject { dossier.champs.first }
it { expect(rendered).to have_css(".type_champs-#{subject.type_champs}") }
it { expect(rendered).to have_css(".type_champ-#{subject.type_champ}") }
it { expect(rendered).to have_css("#champs_#{subject.id}") }
end
describe 'last champs' do
subject { dossier.champs.last }
it { expect(rendered).to have_css(".type_champs-#{subject.type_champs}") }
it { expect(rendered).to have_css(".type_champ-#{subject.type_champ}") }
it { expect(rendered).to have_css("#champs_#{subject.id}") }
end
end