aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/compliance_controls_controller_spec.rb25
-rw-r--r--spec/factories/compliance_checks.rb1
-rw-r--r--spec/factories/compliance_control_blocks.rb1
-rw-r--r--spec/factories/compliance_controls.rb4
-rw-r--r--spec/factories/referential_suites.rb3
-rw-r--r--spec/factories/workbenches.rb1
-rw-r--r--spec/models/compliance_check_spec.rb1
-rw-r--r--spec/models/compliance_control_block_spec.rb3
-rw-r--r--spec/models/compliance_control_set_spec.rb2
-rw-r--r--spec/models/compliance_control_spec.rb37
-rw-r--r--spec/models/workbench_spec.rb24
-rw-r--r--spec/support/referential.rb17
12 files changed, 94 insertions, 25 deletions
diff --git a/spec/controllers/compliance_controls_controller_spec.rb b/spec/controllers/compliance_controls_controller_spec.rb
index 165c00329..a39408ccb 100644
--- a/spec/controllers/compliance_controls_controller_spec.rb
+++ b/spec/controllers/compliance_controls_controller_spec.rb
@@ -3,8 +3,10 @@ require 'rails_helper'
RSpec.describe ComplianceControlsController, type: :controller do
login_user
- let(:compliance_control) { create :compliance_control }
- let(:compliance_control_set) { compliance_control.compliance_control_set }
+
+ let(:compliance_control) { create(:compliance_control) }
+ let!(:compliance_control_set) { compliance_control.compliance_control_set }
+ let(:compliance_control_params) { compliance_control.as_json.merge(type: 'GenericAttributeControl::MinMax') }
describe "GET show" do
it 'should be successful' do
@@ -13,13 +15,6 @@ RSpec.describe ComplianceControlsController, type: :controller do
end
end
- describe "GET index" do
- it 'should be successful' do
- get :index, compliance_control_set_id: compliance_control_set.id
- expect(response).to be_success
- end
- end
-
describe 'GET #edit' do
it 'should be successful' do
get :edit, compliance_control_set_id: compliance_control_set.id, id: compliance_control.id
@@ -36,24 +31,24 @@ RSpec.describe ComplianceControlsController, type: :controller do
describe 'POST #create' do
it 'should be successful' do
- post :create, compliance_control_set_id: compliance_control_set.id, compliance_control: build(:compliance_control).as_json
+ post :create, compliance_control_set_id: compliance_control_set.id, compliance_control: compliance_control_params
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, compliance_control_set_id: compliance_control_set.id, id: compliance_control.id, compliance_control: compliance_control.as_json
+ post :update, compliance_control_set_id: compliance_control_set.id, id: compliance_control.id, compliance_control: compliance_control_params
expect(response).to redirect_to compliance_control_set_compliance_control_path(compliance_control_set, compliance_control)
- expect(flash[:notice]).to eq(I18n.t('notice.compliance_control.updated'))
end
end
describe 'DELETE #destroy' do
it 'should be successful' do
- delete :destroy, compliance_control_set_id: compliance_control_set.id, id: compliance_control.id
- expect(flash[:notice]).to eq I18n.t('notice.compliance_control.destroyed')
+ expect {
+ delete :destroy, compliance_control_set_id: compliance_control_set.id, id: compliance_control.id
+ }.to change(GenericAttributeControl::MinMax, :count).by(-1)
+ expect(response).to have_http_status(302)
end
end
end
diff --git a/spec/factories/compliance_checks.rb b/spec/factories/compliance_checks.rb
index 4009653da..f9af62c73 100644
--- a/spec/factories/compliance_checks.rb
+++ b/spec/factories/compliance_checks.rb
@@ -4,6 +4,7 @@ FactoryGirl.define do
type "Type"
criticity :info
code "code"
+ origin_code "code"
comment "Text"
association :compliance_check_set
association :compliance_check_block
diff --git a/spec/factories/compliance_control_blocks.rb b/spec/factories/compliance_control_blocks.rb
index 5bc45cc75..1b043324e 100644
--- a/spec/factories/compliance_control_blocks.rb
+++ b/spec/factories/compliance_control_blocks.rb
@@ -2,5 +2,6 @@ FactoryGirl.define do
factory :compliance_control_block do
sequence(:name) { |n| "Compliance control block #{n}" }
association :compliance_control_set
+ association :compliance_control
end
end
diff --git a/spec/factories/compliance_controls.rb b/spec/factories/compliance_controls.rb
index 8aa16b674..ced505565 100644
--- a/spec/factories/compliance_controls.rb
+++ b/spec/factories/compliance_controls.rb
@@ -1,11 +1,11 @@
FactoryGirl.define do
factory :compliance_control do
sequence(:name) { |n| "Compliance control #{n}" }
- type "ComplianceControl"
+ type "GenericAttributeControl::MinMax"
criticity :warning
code "code"
+ origin_code "code"
comment "Text"
association :compliance_control_set
- association :compliance_control_block
end
end
diff --git a/spec/factories/referential_suites.rb b/spec/factories/referential_suites.rb
new file mode 100644
index 000000000..bb17b085c
--- /dev/null
+++ b/spec/factories/referential_suites.rb
@@ -0,0 +1,3 @@
+FactoryGirl.define do
+ factory :referential_suite
+end
diff --git a/spec/factories/workbenches.rb b/spec/factories/workbenches.rb
index d55141513..57bef2203 100644
--- a/spec/factories/workbenches.rb
+++ b/spec/factories/workbenches.rb
@@ -5,5 +5,6 @@ FactoryGirl.define do
association :organisation
association :line_referential
association :stop_area_referential
+ association :output, factory: :referential_suite
end
end
diff --git a/spec/models/compliance_check_spec.rb b/spec/models/compliance_check_spec.rb
index 4fbc23d42..acdcc3ebf 100644
--- a/spec/models/compliance_check_spec.rb
+++ b/spec/models/compliance_check_spec.rb
@@ -11,4 +11,5 @@ RSpec.describe ComplianceCheck, type: :model do
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 }
end
diff --git a/spec/models/compliance_control_block_spec.rb b/spec/models/compliance_control_block_spec.rb
index 248049b0c..f45ec3d42 100644
--- a/spec/models/compliance_control_block_spec.rb
+++ b/spec/models/compliance_control_block_spec.rb
@@ -1,9 +1,12 @@
require 'rails_helper'
RSpec.describe ComplianceControlBlock, type: :model do
+ subject { create(:compliance_control_block) }
+
it 'should have a valid factory' do
expect(FactoryGirl.build(:compliance_control_block)).to be_valid
end
it { should belong_to :compliance_control_set }
+ it { should belong_to :compliance_control }
end
diff --git a/spec/models/compliance_control_set_spec.rb b/spec/models/compliance_control_set_spec.rb
index ededec5e0..edc684bbc 100644
--- a/spec/models/compliance_control_set_spec.rb
+++ b/spec/models/compliance_control_set_spec.rb
@@ -6,7 +6,7 @@ RSpec.describe ComplianceControlSet, type: :model do
end
it { should belong_to :organisation }
- it { should have_many :compliance_controls }
+ it { should have_many(:compliance_controls).dependent(:destroy) }
it { should validate_presence_of :name }
end
diff --git a/spec/models/compliance_control_spec.rb b/spec/models/compliance_control_spec.rb
index b00ff4c5a..d7bffb0b2 100644
--- a/spec/models/compliance_control_spec.rb
+++ b/spec/models/compliance_control_spec.rb
@@ -1,14 +1,41 @@
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 belong_to :compliance_control_block }
+ it { should have_one(:compliance_control_block).dependent(:destroy) }
+
+ 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
+
+ it 'should validate_presence_of code' do
+ compliance_control.code = nil
+ expect(compliance_control).not_to be_valid
+ end
+
+ it 'should validate_presence_of origin_code' do
+ compliance_control.origin_code = nil
+ expect(compliance_control).not_to be_valid
+ end
- it { should validate_presence_of :criticity }
- it { should validate_presence_of :name }
- it { should validate_presence_of :code }
+ #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 }
+ # it { should validate_presence_of :code }
+ # it { should validate_presence_of :origin_code }
+
end
diff --git a/spec/models/workbench_spec.rb b/spec/models/workbench_spec.rb
index 84149ddb0..037537b60 100644
--- a/spec/models/workbench_spec.rb
+++ b/spec/models/workbench_spec.rb
@@ -11,6 +11,7 @@ RSpec.describe Workbench, :type => :model do
it { should belong_to(:organisation) }
it { should belong_to(:line_referential) }
it { should belong_to(:stop_area_referential) }
+ it { should belong_to(:output).class_name('ReferentialSuite') }
it { should have_many(:lines).through(:line_referential) }
it { should have_many(:networks).through(:line_referential) }
@@ -19,6 +20,15 @@ RSpec.describe Workbench, :type => :model do
it { should have_many(:stop_areas).through(:stop_area_referential) }
+ it do
+ # This callback interferes with the validation test
+ Workbench.skip_callback(:validation, :before, :initialize_output)
+
+ should validate_presence_of(:output)
+
+ Workbench.set_callback(:validation, :before, :initialize_output)
+ end
+
context '.lines' do
let!(:ids) { ['STIF:CODIFLIGNE:Line:C00840', 'STIF:CODIFLIGNE:Line:C00086'] }
let!(:organisation) { create :organisation, sso_attributes: { functional_scope: ids.to_json } }
@@ -33,4 +43,18 @@ RSpec.describe Workbench, :type => :model do
expect(lines.map(&:objectid)).to include(*ids)
end
end
+
+ describe ".create" do
+ it "must automatically create a ReferentialSuite when being created" do
+ workbench = Workbench.create
+ expect(workbench.output).to be_an_instance_of(ReferentialSuite)
+ end
+
+ it "must not overwrite a given ReferentialSuite" do
+ referential_suite = create(:referential_suite)
+ workbench = create(:workbench, output: referential_suite)
+
+ expect(workbench.output).to eq(referential_suite)
+ end
+ end
end
diff --git a/spec/support/referential.rb b/spec/support/referential.rb
index 3b74cb639..6f60bd86b 100644
--- a/spec/support/referential.rb
+++ b/spec/support/referential.rb
@@ -52,8 +52,21 @@ RSpec.configure do |config|
referential.add_member organisation, owner: true
end
- workbench = Workbench.create!(:name => "Gestion de l'offre", organisation: organisation, line_referential: line_referential, stop_area_referential: stop_area_referential)
- referential = Referential.create! prefix: "first", name: "first", slug: "first", organisation: organisation, workbench: workbench
+ workbench = FactoryGirl.create(
+ :workbench,
+ name: "Gestion de l'offre",
+ organisation: organisation,
+ line_referential: line_referential,
+ stop_area_referential: stop_area_referential
+ )
+ referential = FactoryGirl.create(
+ :referential,
+ prefix: "first",
+ name: "first",
+ slug: "first",
+ organisation: organisation,
+ workbench: workbench
+ )
end
config.before(:each) do