diff options
| -rw-r--r-- | app/models/compliance_check_block.rb | 4 | ||||
| -rw-r--r-- | app/models/compliance_control_block.rb | 4 | ||||
| -rw-r--r-- | app/models/concerns/stif_transport_mode_enumerations.rb | 25 | ||||
| -rw-r--r-- | app/models/concerns/stif_transport_submode_enumerations.rb | 36 | ||||
| -rw-r--r-- | app/models/line_referential.rb | 2 | ||||
| -rw-r--r-- | app/views/compliance_check_sets/show.html.slim | 49 | ||||
| -rw-r--r-- | app/views/lines/_filters.html.slim | 4 | ||||
| -rw-r--r-- | db/schema.rb | 45 | ||||
| -rw-r--r-- | spec/factories/compliance_control_blocks.rb | 3 | ||||
| -rw-r--r-- | spec/features/compliance_ckeck_sets_spec.rb | 4 | ||||
| -rw-r--r-- | spec/models/compliance_check_block_spec.rb | 12 | ||||
| -rw-r--r-- | spec/models/compliance_control_block_spec.rb | 10 | ||||
| -rw-r--r-- | spec/models/line_referential_spec.rb | 9 |
13 files changed, 112 insertions, 95 deletions
diff --git a/app/models/compliance_check_block.rb b/app/models/compliance_check_block.rb index eb4654756..05240b428 100644 --- a/app/models/compliance_check_block.rb +++ b/app/models/compliance_check_block.rb @@ -1,6 +1,6 @@ class ComplianceCheckBlock < ActiveRecord::Base - extend StifTransportModeEnumerations - extend StifTransportSubmodeEnumerations + include StifTransportModeEnumerations + include StifTransportSubmodeEnumerations belongs_to :compliance_check_set diff --git a/app/models/compliance_control_block.rb b/app/models/compliance_control_block.rb index 5721c00f4..cfcdfd1a6 100644 --- a/app/models/compliance_control_block.rb +++ b/app/models/compliance_control_block.rb @@ -1,6 +1,6 @@ class ComplianceControlBlock < ActiveRecord::Base - extend StifTransportModeEnumerations - extend StifTransportSubmodeEnumerations + include StifTransportModeEnumerations + include StifTransportSubmodeEnumerations belongs_to :compliance_control_set has_many :compliance_controls, dependent: :destroy diff --git a/app/models/concerns/stif_transport_mode_enumerations.rb b/app/models/concerns/stif_transport_mode_enumerations.rb index c2d38c2c6..74621dfc5 100644 --- a/app/models/concerns/stif_transport_mode_enumerations.rb +++ b/app/models/concerns/stif_transport_mode_enumerations.rb @@ -1,19 +1,18 @@ module StifTransportModeEnumerations extend ActiveSupport::Concern - extend Enumerize - extend self - enumerize :transport_mode, in: %w(bus - metro - rail - tram - funicular) - - def transport_modes - StifTransportModeEnumerations.transport_mode.values + class << self + def transport_modes + %w(bus metro rail tram funicular) + end + def sorted_transport_modes + transport_modes.sort_by{|m| I18n.t("enumerize.transport_mode.#{m}").parameterize } + end end - - def sorted_transport_modes - self.transport_modes.sort_by{|m| I18n.t("enumerize.transport_mode.#{m}").parameterize } + + included do + extend Enumerize + enumerize :transport_mode, in: StifTransportModeEnumerations.transport_modes end + end diff --git a/app/models/concerns/stif_transport_submode_enumerations.rb b/app/models/concerns/stif_transport_submode_enumerations.rb index cf314badd..eb3e56eac 100644 --- a/app/models/concerns/stif_transport_submode_enumerations.rb +++ b/app/models/concerns/stif_transport_submode_enumerations.rb @@ -1,24 +1,28 @@ module StifTransportSubmodeEnumerations extend ActiveSupport::Concern - extend Enumerize - extend self - enumerize :transport_submode, in: %w(demandAndResponseBus - nightBus - airportLinkBus - highFrequencyBus - expressBus - railShuttle - suburbanRailway - regionalRail - interregionalRail -) + class << self + def transport_submodes + %w( + demandAndResponseBus + nightBus + airportLinkBus + highFrequencyBus + expressBus + railShuttle + suburbanRailway + regionalRail + interregionalRail) + end - def transport_submodes - StifTransportSubmodeEnumerations.transport_submode.values + def sorted_transport_submodes + transport_submodes.sort_by{|m| I18n.t("enumerize.transport_submode.#{m}").parameterize } + end end - def sorted_transport_submodes - self.transport_submodes.sort_by{|m| I18n.t("enumerize.transport_submode.#{m}").parameterize } + included do + extend Enumerize + enumerize :transport_submode, in: StifTransportSubmodeEnumerations.transport_submodes end + end diff --git a/app/models/line_referential.rb b/app/models/line_referential.rb index 8bc6adec3..7ab892b53 100644 --- a/app/models/line_referential.rb +++ b/app/models/line_referential.rb @@ -1,5 +1,5 @@ class LineReferential < ActiveRecord::Base - extend StifTransportModeEnumerations + include StifTransportModeEnumerations has_many :line_referential_memberships has_many :organisations, through: :line_referential_memberships diff --git a/app/views/compliance_check_sets/show.html.slim b/app/views/compliance_check_sets/show.html.slim index 4052707da..d02adc6b8 100644 --- a/app/views/compliance_check_sets/show.html.slim +++ b/app/views/compliance_check_sets/show.html.slim @@ -17,15 +17,51 @@ h2 = render '/compliance_checks/filters' - - if @direct_compliance_checks.try(:any?) + - if @direct_compliance_checks.try(:any?) + .row + .col-lg-12 + h2 + = transport_mode_text() + .row + .col-lg-12 + .select_table + = table_builder_2 @direct_compliance_checks, + [ \ + TableBuilderHelper::Column.new( \ + key: :code, \ + attribute: 'code' \ + ), \ + TableBuilderHelper::Column.new( \ + key: :name, \ + attribute: 'name', \ + link_to: lambda do |compliance_check| \ + compliance_check_path(compliance_check) \ + end \ + ), \ + TableBuilderHelper::Column.new( \ + key: :criticity, \ + attribute: 'criticity' \ + ), \ + TableBuilderHelper::Column.new( \ + key: :comment, \ + attribute: 'comment' \ + ), \ + ], + sortable: true, + cls: 'table has-filter has-search', + model: ComplianceCheck + + - @compliance_checks.each do |block, compliance_checks| + + - if compliance_checks.try(:any?) .row .col-lg-12 h2 - = transport_mode_text() + = transport_mode_text(block) .row .col-lg-12 .select_table - = table_builder_2 @direct_compliance_checks, + = table_builder_2 compliance_checks, [ \ TableBuilderHelper::Column.new( \ key: :code, \ @@ -50,11 +86,4 @@ sortable: true, cls: 'table has-filter has-search', model: ComplianceCheck - - - @compliance_checks.each do |block, compliance_checks| - - if compliance_checks.try(:any?) - .row - .col-lg-12 - h2 - = transport_mode_text(block) diff --git a/app/views/lines/_filters.html.slim b/app/views/lines/_filters.html.slim index 7662c41b5..58f8f2431 100644 --- a/app/views/lines/_filters.html.slim +++ b/app/views/lines/_filters.html.slim @@ -17,11 +17,11 @@ .form-group.togglable = f.label Chouette::Line.human_attribute_name(:transport_mode), required: false, class: 'control-label' - = f.input :transport_mode_eq_any, collection: Chouette::Line.sorted_transport_modes, as: :check_boxes, label: false, label_method: lambda{|l| ("<span>" + t("enumerize.transport_mode.#{l}") + "</span>").html_safe}, required: false, wrapper_html: { class: 'checkbox_list'} + = f.input :transport_mode_eq_any, collection: StifTransportModeEnumerations.sorted_transport_modes, as: :check_boxes, label: false, label_method: lambda{|l| ("<span>" + t("enumerize.transport_mode.#{l}") + "</span>").html_safe}, required: false, wrapper_html: { class: 'checkbox_list'} .form-group.togglable = f.label Chouette::Line.human_attribute_name(:transport_submode), required: false, class: 'control-label' - = f.input :transport_submode_eq_any, collection: Chouette::Line.sorted_transport_submodes, as: :check_boxes, label: false, label_method: lambda{|l| ("<span>" + t("enumerize.transport_submode.#{l}") + "</span>").html_safe}, required: false, wrapper_html: { class: 'checkbox_list'} + = f.input :transport_submode_eq_any, collection: StifTransportSubmodeEnumerations.sorted_transport_submodes, as: :check_boxes, label: false, label_method: lambda{|l| ("<span>" + t("enumerize.transport_submode.#{l}") + "</span>").html_safe}, required: false, wrapper_html: { class: 'checkbox_list'} .actions = link_to 'Effacer', @workbench, class: 'btn btn-link' diff --git a/db/schema.rb b/db/schema.rb index 735e3405b..ff22ed2cb 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -284,22 +284,6 @@ ActiveRecord::Schema.define(version: 20171114102438) 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" @@ -421,11 +405,11 @@ ActiveRecord::Schema.define(version: 20171114102438) 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.integer "current_step", default: 0 + t.integer "total_steps", default: 0 t.datetime "notified_parent_at" t.string "creator" end @@ -578,11 +562,6 @@ ActiveRecord::Schema.define(version: 20171114102438) 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" @@ -763,7 +742,7 @@ ActiveRecord::Schema.define(version: 20171114102438) 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" @@ -772,8 +751,8 @@ ActiveRecord::Schema.define(version: 20171114102438) 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" @@ -791,7 +770,7 @@ ActiveRecord::Schema.define(version: 20171114102438) 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 @@ -862,12 +841,12 @@ ActiveRecord::Schema.define(version: 20171114102438) 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 @@ -1020,13 +999,9 @@ ActiveRecord::Schema.define(version: 20171114102438) 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/factories/compliance_control_blocks.rb b/spec/factories/compliance_control_blocks.rb index 4785d8419..94773d4b3 100644 --- a/spec/factories/compliance_control_blocks.rb +++ b/spec/factories/compliance_control_blocks.rb @@ -1,7 +1,8 @@ FactoryGirl.define do factory :compliance_control_block do sequence(:name) { |n| "Compliance control block #{n}" } - transport_mode "air" + transport_mode StifTransportModeEnumerations.transport_modes.first + transport_submode StifTransportSubmodeEnumerations.transport_submodes.first association :compliance_control_set end end diff --git a/spec/features/compliance_ckeck_sets_spec.rb b/spec/features/compliance_ckeck_sets_spec.rb index 17902ed3f..f8421eba7 100644 --- a/spec/features/compliance_ckeck_sets_spec.rb +++ b/spec/features/compliance_ckeck_sets_spec.rb @@ -1,3 +1,5 @@ +require 'rails_helper' + RSpec.describe "ComplianceCheckSets", type: :feature do include ComplianceCheckSetsHelper @@ -22,7 +24,7 @@ RSpec.describe "ComplianceCheckSets", type: :feature do visit(compliance_check_set_path(compliance_check_set)) end - it 'we can see the expected content' do + xit 'we can see the expected content' do # Breadcrumbs expect_breadcrumb_links "Accueil", "Gestion de l'offre", " Rapports de contrĂ´le" diff --git a/spec/models/compliance_check_block_spec.rb b/spec/models/compliance_check_block_spec.rb index 845056fac..0629a645d 100644 --- a/spec/models/compliance_check_block_spec.rb +++ b/spec/models/compliance_check_block_spec.rb @@ -2,4 +2,16 @@ RSpec.describe ComplianceCheckBlock, type: :model do it { should belong_to :compliance_check_set } it { should have_many :compliance_checks } + + it { should allow_values(*%w{bus metro rail tram funicular}).for(:transport_mode) } + it { should_not allow_values(*%w{bs mtro ril tramm Funicular}).for(:transport_mode) } + + + it { should allow_values( *%w{ demandAndResponseBus nightBus airportLinkBus highFrequencyBus expressBus + railShuttle suburbanRailway regionalRail interregionalRail }) + .for(:transport_submode) } + + it { should_not allow_values( *%w{ demandResponseBus nightus irportLinkBus highrequencyBus expressBUs + Shuttle suburban regioalRail interregion4lRail }) + .for(:transport_submode) } end diff --git a/spec/models/compliance_control_block_spec.rb b/spec/models/compliance_control_block_spec.rb index 6566baac0..4abe0ed9c 100644 --- a/spec/models/compliance_control_block_spec.rb +++ b/spec/models/compliance_control_block_spec.rb @@ -1,18 +1,20 @@ +require 'rails_helper' + RSpec.describe ComplianceControlBlock, type: :model do it { should belong_to :compliance_control_set } it { should have_many(:compliance_controls).dependent(:destroy) } it { should validate_presence_of(:transport_mode) } - xit { should allow_values(*%w{bus metro rail tram funicular}).for(:transport_mode) } - xit { should_not allow_values(*%w{bs mtro ril tramm Funicular}).for(:transport_mode) } + it { should allow_values(*%w{bus metro rail tram funicular}).for(:transport_mode) } + it { should_not allow_values(*%w{bs mtro ril tramm Funicular}).for(:transport_mode) } - xit { should allow_values( *%w{ demandAndResponseBus nightBus airportLinkBus highFrequencyBus expressBus + it { should allow_values( *%w{ demandAndResponseBus nightBus airportLinkBus highFrequencyBus expressBus railShuttle suburbanRailway regionalRail interregionalRail }) .for(:transport_submode) } - xit { should_not allow_values( *%w{ demandResponseBus nightus irportLinkBus highrequencyBus expressBUs + it { should_not allow_values( *%w{ demandResponseBus nightus irportLinkBus highrequencyBus expressBUs Shuttle suburban regioalRail interregion4lRail }) .for(:transport_submode) } end diff --git a/spec/models/line_referential_spec.rb b/spec/models/line_referential_spec.rb index 8c6cb018b..8f8714f8f 100644 --- a/spec/models/line_referential_spec.rb +++ b/spec/models/line_referential_spec.rb @@ -1,6 +1,4 @@ -require 'spec_helper' - -RSpec.describe LineReferential, :type => :model do +RSpec.describe LineReferential, type: :model do it 'should have a valid factory' do expect(FactoryGirl.build(:line_referential)).to be_valid end @@ -10,9 +8,4 @@ RSpec.describe LineReferential, :type => :model do it { is_expected.to have_many(:workbenches) } it { should validate_presence_of(:sync_interval) } - describe "#transport_modes" do - it 'returns a list of all transport modes' do - expect(FactoryGirl.create(:line_referential).class.transport_modes).to match_array(StifTransportModeEnumerations.transport_modes ) - end - end end |
