diff options
Diffstat (limited to 'spec/models/workbench_spec.rb')
| -rw-r--r-- | spec/models/workbench_spec.rb | 24 |
1 files changed, 24 insertions, 0 deletions
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 |
