diff options
| author | Guillaume | 2017-09-18 18:06:59 +0200 | 
|---|---|---|
| committer | Guillaume | 2017-09-18 18:06:59 +0200 | 
| commit | 47bc1f0ef1b4c1ba0db0a9e6e75f765dd2c5d88d (patch) | |
| tree | e9715d2ab0f4c420d43a230eb66410b36eaab64d | |
| parent | 06ad1bb051cabb4575306f7397287ea77d70e109 (diff) | |
| download | chouette-core-47bc1f0ef1b4c1ba0db0a9e6e75f765dd2c5d88d.tar.bz2 | |
add create/edit for compliance_control_set, add specs
| -rw-r--r-- | app/controllers/compliance_control_sets_controller.rb | 20 | ||||
| -rw-r--r-- | app/models/compliance_control_set.rb | 3 | ||||
| -rw-r--r-- | app/models/organisation.rb | 1 | ||||
| -rw-r--r-- | app/views/compliance_control_sets/_form.html.slim | 49 | ||||
| -rw-r--r-- | app/views/compliance_control_sets/edit.html.slim | 2 | ||||
| -rw-r--r-- | app/views/compliance_control_sets/new.html.slim | 2 | ||||
| -rw-r--r-- | app/views/compliance_control_sets/show.html.slim | 79 | ||||
| -rw-r--r-- | db/schema.rb | 47 | ||||
| -rw-r--r-- | spec/controllers/compliance_control_sets_controller_spec.rb | 55 | ||||
| -rw-r--r-- | spec/models/compliance_control_set_spec.rb | 2 | 
10 files changed, 103 insertions, 157 deletions
| diff --git a/app/controllers/compliance_control_sets_controller.rb b/app/controllers/compliance_control_sets_controller.rb index b0a719cdc..1b23becaa 100644 --- a/app/controllers/compliance_control_sets_controller.rb +++ b/app/controllers/compliance_control_sets_controller.rb @@ -1,15 +1,20 @@  class ComplianceControlSetsController < BreadcrumbController -    defaults resource_class: ComplianceControlSet    respond_to :html    def index -    index! do -      @compliance_control_sets = decorate_compliance_control_sets(@compliance_control_sets) -      build_breadcrumb :show +    index! do |format| +      format.html { +        @compliance_control_sets = decorate_compliance_control_sets(@compliance_control_sets) +      }      end    end +  def show +    show! do +      @compliance_control_set = @compliance_control_set.decorate +    end +  end    def decorate_compliance_control_sets(compliance_control_sets)      ModelDecorator.decorate( @@ -18,4 +23,11 @@ class ComplianceControlSetsController < BreadcrumbController      )    end +  protected + +  private + +  def compliance_control_set_params +    params.require(:compliance_control_set).permit(:name) +  end  end diff --git a/app/models/compliance_control_set.rb b/app/models/compliance_control_set.rb index ca112531d..cefdfbf1f 100644 --- a/app/models/compliance_control_set.rb +++ b/app/models/compliance_control_set.rb @@ -1,4 +1,7 @@  class ComplianceControlSet < ActiveRecord::Base    belongs_to :organisation    has_many :compliance_controls + +  validates :name, presence: true +  end diff --git a/app/models/organisation.rb b/app/models/organisation.rb index 895ca03d9..ba65ad375 100644 --- a/app/models/organisation.rb +++ b/app/models/organisation.rb @@ -4,6 +4,7 @@ class Organisation < ActiveRecord::Base    has_many :users, :dependent => :destroy    has_many :referentials, :dependent => :destroy    has_many :rule_parameter_sets, :dependent => :destroy +  has_many :compliance_control_sets, :dependent => :destroy    has_many :stop_area_referential_memberships    has_many :stop_area_referentials, through: :stop_area_referential_memberships diff --git a/app/views/compliance_control_sets/_form.html.slim b/app/views/compliance_control_sets/_form.html.slim index ba14edf41..cf144bbd9 100644 --- a/app/views/compliance_control_sets/_form.html.slim +++ b/app/views/compliance_control_sets/_form.html.slim @@ -1,53 +1,8 @@ -= simple_form_for @compliance_control_sets, html: { class: 'form-horizontal', id: 'calendar_form' }, wrapper: :horizontal_form do |f| += simple_form_for @compliance_control_set, html: { class: 'form-horizontal', id: 'compliance_control_set_form' }, wrapper: :horizontal_form do |f|    .row      .col-lg-12        = f.input :name -      = f.input :short_name - -      - if policy(@compliance_control_sets).share? -        .form-group.has_switch -          = f.label :shared, class: 'col-sm-4 col-xs-5 control-label' -          = f.input :shared, as: :boolean, checked_value: true, unchecked_value: false, label: content_tag(:span, t("#{@calendar.shared}"), class: 'switch-label', data: {checkedValue: t('true'), uncheckedValue: t('false')}), wrapper_html: { class: 'col-sm-8 col-xs-7'}    .separator -   -  .row -    .col-lg-12 -      .subform -        .nested-head -          .wrapper -            div -              .form-group -                label.control-label -                  = Calendar.human_attribute_name(:date) -            div - -        = f.simple_fields_for :date_values do |date_value| -          = render 'date_value_fields', f: date_value - -        .links.nested-linker -          = link_to_add_association t('simple_form.labels.calendar.add_a_date'), f, :date_values, class: 'btn btn-outline-primary' -   -  .separator -   -  .row -    .col-lg-12 -      .subform -        .nested-head -          .wrapper -            div -              .form-group -                label.control-label -                  = t('simple_form.labels.calendar.ranges.begin') -            div -              .form-group -                label.control-label -                  = t('simple_form.labels.calendar.ranges.end') -            div - -        = f.simple_fields_for :periods do |period| -          = render 'period_fields', f: period -        .links.nested-linker -          = link_to_add_association t('simple_form.labels.calendar.add_a_date_range'), f, :periods, class: 'btn btn-outline-primary' -  = f.button :submit, t('actions.submit'), class: 'btn btn-default formSubmitr', form: 'calendar_form' +  = f.button :submit, t('actions.submit'), class: 'btn btn-default formSubmitr', form: 'compliance_control_set_form' diff --git a/app/views/compliance_control_sets/edit.html.slim b/app/views/compliance_control_sets/edit.html.slim index 73381be34..a9b8d7253 100644 --- a/app/views/compliance_control_sets/edit.html.slim +++ b/app/views/compliance_control_sets/edit.html.slim @@ -7,4 +7,4 @@    .container-fluid      .row        .col-lg-8.col-lg-offset-2.col-md-8.col-md-offset-2.col-sm-10.col-sm-offset-1 -        /= render 'form' +        = render 'form' diff --git a/app/views/compliance_control_sets/new.html.slim b/app/views/compliance_control_sets/new.html.slim index 93475974a..d6be41ee8 100644 --- a/app/views/compliance_control_sets/new.html.slim +++ b/app/views/compliance_control_sets/new.html.slim @@ -8,4 +8,4 @@    .container-fluid      .row        .col-lg-8.col-lg-offset-2.col-md-8.col-md-offset-2.col-sm-10.col-sm-offset-1 -        /= render 'form' +        = render 'form' diff --git a/app/views/compliance_control_sets/show.html.slim b/app/views/compliance_control_sets/show.html.slim index 12ecc1894..b4a5b2260 100644 --- a/app/views/compliance_control_sets/show.html.slim +++ b/app/views/compliance_control_sets/show.html.slim @@ -6,77 +6,20 @@    / Below is secondary actions & optional contents (filters, ...)    .row.mb-sm      .col-lg-12.text-right -      /- @compliance_control_set.action_links.each do |link| -      /  - if link.is_a?(HTMLElement) -      /    = link.to_html(class: 'btn btn-primary') -      /  - else -      /    = link_to link.href, -      /        method: link.method, -      /        data: link.data, -      /        class: 'btn btn-primary' do -      /          = link.content +      - @compliance_control_set.action_links.each do |link| +        - if link.is_a?(HTMLElement) +          = link.to_html(class: 'btn btn-primary') +        - else +          = link_to link.href, +              method: link.method, +              data: link.data, +              class: 'btn btn-primary' do +                = link.content  / PageContent  .page_content    .container-fluid      .row        .col-lg-6.col-md-6.col-sm-12.col-xs-12 -        /= definition_list t('metadatas'), -        /  { t('activerecord.attributes.referential.status') => @referential.archived? ? "<div class='td-block'><span class='fa fa-archive'></span><span>#{t('activerecord.attributes.referential.archived_at')}</span></div>".html_safe : "<div class='td-block'><span class='sb sb-lg sb-preparing'></span><span>#{t('activerecord.attributes.referential.archived_at_null')}</span></div>".html_safe, -        /    @referential.human_attribute_name(:validity_period) => (@referential.validity_period.present? ? t('validity_range', debut: l(@referential.try(:validity_period).try(:begin), format: :short), end: l(@referential.try(:validity_period).try(:end), format: :short)) : '-'), -        /    @referential.human_attribute_name(:organisation) => @referential.organisation.name, -        /    @referential.human_attribute_name(:published_at) => '-' } - -    /- if params[:q].present? or @reflines.any? -      .row -        .col-lg-12 -          /= render 'filters' - -    /- if @reflines.any? -      .row -        .col-lg-12 -          / ID Codif, nom court, nom de la ligne, réseau, mode, transporteur principal, actions = [show, edit_notes] -          = table_builder_2 @reflines, -            [ \ -              TableBuilderHelper::Column.new( \ -                name: t('id_codif'), \ -                attribute: Proc.new { |n| n.objectid.local_id }, \ -                sortable: false \ -              ), \ -              TableBuilderHelper::Column.new( \ -                key: :number, \ -                attribute: 'number' \ -              ), \ -              TableBuilderHelper::Column.new( \ -                key: :name, \ -                attribute: 'name', \ -                link_to: lambda do |line| \ -                  referential_line_path(@referential, line) \ -                end \ -              ), \ -              TableBuilderHelper::Column.new( \ -                key: :deactivated, \ -                attribute: Proc.new { |n| n.deactivated? ? t('false') : t('true') } \ -              ), \ -              TableBuilderHelper::Column.new( \ -                key: :transport_mode, \ -                attribute: Proc.new { |n| n.transport_mode ? t("enumerize.line.transport_mode.#{n.transport_mode}") : '' }, \ -              ), \ -              TableBuilderHelper::Column.new( \ -                key: 'networks.name', \ -                attribute: Proc.new { |n| n.try(:network).try(:name) } \ -              ), \ -              TableBuilderHelper::Column.new( \ -                key: 'companies.name', \ -                attribute: Proc.new { |n| n.try(:company).try(:name) } \ -              ) \ -            ], -            links: [:show], -            cls: 'table has-filter has-search' - -          = new_pagination @reflines, 'pull-right' - -    /- unless @reflines.any? -      .row.mt-xs -        .col-lg-12 -          = replacement_msg t('referential_lines.search_no_results')
\ No newline at end of file +        = definition_list t('metadatas'), +            ComplianceControlSet.human_attribute_name(:name) => @compliance_control_set.name
\ No newline at end of file diff --git a/db/schema.rb b/db/schema.rb index 5e2edf33d..39162b447 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -270,22 +270,6 @@ ActiveRecord::Schema.define(version: 20170913074922) do    add_index "connection_links", ["objectid"], name: "connection_links_objectid_key", unique: true, using: :btree -  create_table "delayed_jobs", id: :bigserial, force: :cascade do |t| -    t.integer  "priority",               default: 0 -    t.integer  "attempts",               default: 0 -    t.text     "handler" -    t.text     "last_error" -    t.datetime "run_at" -    t.datetime "locked_at" -    t.datetime "failed_at" -    t.string   "locked_by",  limit: 255 -    t.string   "queue",      limit: 255 -    t.datetime "created_at" -    t.datetime "updated_at" -  end - -  add_index "delayed_jobs", ["priority", "run_at"], name: "delayed_jobs_priority", using: :btree -    create_table "exports", id: :bigserial, force: :cascade do |t|      t.integer  "referential_id",  limit: 8      t.string   "status" @@ -407,12 +391,12 @@ ActiveRecord::Schema.define(version: 20170913074922) do      t.datetime "started_at"      t.datetime "ended_at"      t.string   "token_download" -    t.string   "type",                  limit: 255 +    t.string   "type"      t.integer  "parent_id",             limit: 8      t.string   "parent_type" -    t.integer  "current_step",                      default: 0 -    t.integer  "total_steps",                       default: 0      t.datetime "notified_parent_at" +    t.integer  "current_step",                    default: 0 +    t.integer  "total_steps",                     default: 0      t.string   "creator"    end @@ -564,11 +548,6 @@ ActiveRecord::Schema.define(version: 20170913074922) do    add_index "networks", ["objectid"], name: "networks_objectid_key", unique: true, using: :btree    add_index "networks", ["registration_number"], name: "networks_registration_number_key", using: :btree -  create_table "object_id_factories", id: :bigserial, force: :cascade do |t| -    t.datetime "created_at", null: false -    t.datetime "updated_at", null: false -  end -    create_table "organisations", id: :bigserial, force: :cascade do |t|      t.string   "name"      t.datetime "created_at" @@ -745,7 +724,7 @@ ActiveRecord::Schema.define(version: 20170913074922) do    create_table "stop_areas", id: :bigserial, force: :cascade do |t|      t.integer  "parent_id",                       limit: 8 -    t.string   "objectid",                                                              null: false +    t.string   "objectid",                                                            null: false      t.integer  "object_version",                  limit: 8      t.string   "creator_id"      t.string   "name" @@ -754,8 +733,8 @@ ActiveRecord::Schema.define(version: 20170913074922) do      t.string   "registration_number"      t.string   "nearest_topic_name"      t.integer  "fare_code" -    t.decimal  "longitude",                                   precision: 19, scale: 16 -    t.decimal  "latitude",                                    precision: 19, scale: 16 +    t.decimal  "longitude",                                 precision: 19, scale: 16 +    t.decimal  "latitude",                                  precision: 19, scale: 16      t.string   "long_lat_type"      t.string   "country_code"      t.string   "street_name" @@ -773,7 +752,7 @@ ActiveRecord::Schema.define(version: 20170913074922) do      t.datetime "deleted_at"      t.datetime "created_at"      t.datetime "updated_at" -    t.string   "stif_type",                       limit: 255 +    t.string   "stif_type"    end    add_index "stop_areas", ["name"], name: "index_stop_areas_on_name", using: :btree @@ -844,18 +823,18 @@ ActiveRecord::Schema.define(version: 20170913074922) do    add_index "time_table_periods", ["time_table_id"], name: "index_time_table_periods_on_time_table_id", using: :btree    create_table "time_tables", id: :bigserial, force: :cascade do |t| -    t.string   "objectid",                                null: false -    t.integer  "object_version",  limit: 8,   default: 1 +    t.string   "objectid",                              null: false +    t.integer  "object_version",  limit: 8, default: 1      t.string   "creator_id"      t.string   "version"      t.string   "comment" -    t.integer  "int_day_types",               default: 0 +    t.integer  "int_day_types",             default: 0      t.date     "start_date"      t.date     "end_date"      t.integer  "calendar_id",     limit: 8      t.datetime "created_at"      t.datetime "updated_at" -    t.string   "color",           limit: 255 +    t.string   "color"      t.integer  "created_from_id"      t.string   "checksum"      t.text     "checksum_source" @@ -999,13 +978,9 @@ ActiveRecord::Schema.define(version: 20170913074922) do    add_foreign_key "compliance_controls", "compliance_control_blocks"    add_foreign_key "compliance_controls", "compliance_control_sets"    add_foreign_key "group_of_lines_lines", "group_of_lines", name: "groupofline_group_fkey", on_delete: :cascade -  add_foreign_key "journey_frequencies", "timebands", name: "journey_frequencies_timeband_id_fk", on_delete: :nullify    add_foreign_key "journey_frequencies", "timebands", on_delete: :nullify -  add_foreign_key "journey_frequencies", "vehicle_journeys", name: "journey_frequencies_vehicle_journey_id_fk", on_delete: :nullify    add_foreign_key "journey_frequencies", "vehicle_journeys", on_delete: :nullify -  add_foreign_key "journey_pattern_sections", "journey_patterns", name: "journey_pattern_sections_journey_pattern_id_fk", on_delete: :cascade    add_foreign_key "journey_pattern_sections", "journey_patterns", on_delete: :cascade -  add_foreign_key "journey_pattern_sections", "route_sections", name: "journey_pattern_sections_route_section_id_fk", on_delete: :cascade    add_foreign_key "journey_pattern_sections", "route_sections", on_delete: :cascade    add_foreign_key "journey_patterns", "routes", name: "jp_route_fkey", on_delete: :cascade    add_foreign_key "journey_patterns", "stop_points", column: "arrival_stop_point_id", name: "arrival_point_fkey", on_delete: :nullify diff --git a/spec/controllers/compliance_control_sets_controller_spec.rb b/spec/controllers/compliance_control_sets_controller_spec.rb index 12500174b..25d0becfe 100644 --- a/spec/controllers/compliance_control_sets_controller_spec.rb +++ b/spec/controllers/compliance_control_sets_controller_spec.rb @@ -1,5 +1,60 @@  require 'rails_helper'  RSpec.describe ComplianceControlSetsController, type: :controller do +  login_user + +  let(:compliance_control_set) { create :compliance_control_set } + +  describe "GET show" do +    it 'should be successful' do +      get :show, id: compliance_control_set.id +      expect(response).to be_success +    end +  end + +  describe "GET index" do +    it 'should be successful' do +      get :index, id: compliance_control_set.id +      expect(response).to be_success +    end +  end + +  describe "GET #edit" do +    it 'should be successful' do +      get :edit, id: compliance_control_set.id +      expect(response).to be_success +    end +  end + +  describe 'GET #new' do +    it 'should be successful' do +      get :new, id: compliance_control_set.id +      expect(response).to be_success +    end +  end + +  describe 'POST #create' do +    it 'should be successful' do +      post :create, compliance_control_set: build(:compliance_control_set).as_json +      expect(response).to have_http_status(302) +      # expect(flash[:notice]).to eq(I18n.t('notice.compliance_control.created')) +    end +  end + +  describe 'POST #update' do +    it 'should be successful' do +      post :update, id: compliance_control_set.id, compliance_control_set: compliance_control_set.as_json +      expect(response).to redirect_to compliance_control_set_path(compliance_control_set) +      # expect(flash[:notice]).to eq(I18n.t('notice.compliance_control.updated')) +    end +  end + +  describe 'DELETE #destroy' do +    it 'should be successful' do +      delete :destroy, id: compliance_control_set.id +      # expect(flash[:notice]).to eq I18n.t('notice.compliance_control.destroyed') +    end +  end +  end diff --git a/spec/models/compliance_control_set_spec.rb b/spec/models/compliance_control_set_spec.rb index 8ec57fdc0..ededec5e0 100644 --- a/spec/models/compliance_control_set_spec.rb +++ b/spec/models/compliance_control_set_spec.rb @@ -7,4 +7,6 @@ RSpec.describe ComplianceControlSet, type: :model do    it { should belong_to :organisation }    it { should have_many :compliance_controls } + +  it { should validate_presence_of :name }  end | 
