diff options
| author | cedricnjanga | 2017-09-27 16:08:19 +0200 |
|---|---|---|
| committer | cedricnjanga | 2017-09-27 16:23:22 +0200 |
| commit | 5911206bbadb2c3c9609f8be0ce1affd6584015e (patch) | |
| tree | d0b70454259fd985f1f6b6d0bbcd5616055fac83 | |
| parent | eb761e221efc3ce0b09bfea96415907afac33d4a (diff) | |
| download | chouette-core-5911206bbadb2c3c9609f8be0ce1affd6584015e.tar.bz2 | |
Refs #4615 Change spec and controller regarding to the ComplianceControl models changes
| -rw-r--r-- | app/controllers/compliance_controls_controller.rb | 2 | ||||
| -rw-r--r-- | app/models/compliance_control.rb | 8 | ||||
| -rw-r--r-- | spec/factories/compliance_controls.rb | 1 | ||||
| -rw-r--r-- | spec/models/compliance_control_spec.rb | 24 |
4 files changed, 27 insertions, 8 deletions
diff --git a/app/controllers/compliance_controls_controller.rb b/app/controllers/compliance_controls_controller.rb index 7deeab01d..b4fb2f1de 100644 --- a/app/controllers/compliance_controls_controller.rb +++ b/app/controllers/compliance_controls_controller.rb @@ -19,7 +19,7 @@ class ComplianceControlsController < BreadcrumbController end def compliance_control_params - base = [:name, :code, :criticity, :comment, :control_attributes, :type, compliance_control_block_attributes: [:name, :transport_mode]] + base = [:name, :code, :origin_code, :criticity, :comment, :control_attributes, :type, compliance_control_block_attributes: [:name, :transport_mode]] permited = base + dynamic_attributes_params params.require(:compliance_control).permit(permited) end diff --git a/app/models/compliance_control.rb b/app/models/compliance_control.rb index 9c3083695..c5389e832 100644 --- a/app/models/compliance_control.rb +++ b/app/models/compliance_control.rb @@ -29,10 +29,10 @@ class ComplianceControl < ActiveRecord::Base end before_validation(on: :create) do - self.name = self.class.name - self.code = @@default_code - self.origin_code = @@default_code - self.criticity = @@default_criticity + self.name ||= self.class.name + self.code ||= @@default_code + self.origin_code ||= @@default_code + self.criticity ||= @@default_criticity end end diff --git a/spec/factories/compliance_controls.rb b/spec/factories/compliance_controls.rb index 01cdeb6d3..b1b6bd837 100644 --- a/spec/factories/compliance_controls.rb +++ b/spec/factories/compliance_controls.rb @@ -4,6 +4,7 @@ FactoryGirl.define do type "GenericAttributeMinMax" criticity :warning code "code" + origin_code "code" comment "Text" association :compliance_control_set end diff --git a/spec/models/compliance_control_spec.rb b/spec/models/compliance_control_spec.rb index e11873144..226e7ae74 100644 --- a/spec/models/compliance_control_spec.rb +++ b/spec/models/compliance_control_spec.rb @@ -1,14 +1,32 @@ require 'rails_helper' RSpec.describe ComplianceControl, type: :model do + + let(:compliance_control) { create :compliance_control } + it 'should have a valid factory' do - expect(FactoryGirl.build(:compliance_control)).to be_valid + expect(compliance_control).to be_valid end it { should belong_to :compliance_control_set } it { should have_one(:compliance_control_block).dependent(:destroy) } - it { should validate_presence_of :criticity } - it { should validate_presence_of :name } it { should validate_presence_of :code } + it { should validate_presence_of :origin_code } + + it 'should validate_presence_of criticity' do + compliance_control.criticity = nil + expect(compliance_control).not_to be_valid + end + + it 'should validate_presence_of name' do + compliance_control.name = nil + expect(compliance_control).not_to be_valid + end + + #TODO dont know why the 'shortcuts' below to validates presence dont work + # That's why we dont it 'manually' + # it { should validate_presence_of :criticity } + # it { should validate_presence_of :name } + end |
