diff options
| author | Teddy Wing | 2017-11-29 15:56:42 +0100 | 
|---|---|---|
| committer | Teddy Wing | 2017-11-29 15:56:42 +0100 | 
| commit | 7ebc710729081119da4a69472c7fd1dd3dfd58d8 (patch) | |
| tree | 753b20468505fda369e2708e514bb2ba5fdc7578 | |
| parent | 77c7751694feae5c4b7d119d1d5e6134307909cc (diff) | |
| download | chouette-core-7ebc710729081119da4a69472c7fd1dd3dfd58d8.tar.bz2 | |
referential_spec(duplicate referential): Validate existing behaviour
Change bits of the test to validate that when saving duplicate
`Referential`s synchronously, the second one fails to be saved.
A few things needed to be changed since the last commit in order to get
this test working:
* Most crucially: The `metadata_1.save` lines needed to be removed. The
  metadata is indended to be saved at the same time as the
  `Referential`s. Otherwise, the validation doesn't work the way it
  should.
* `create` the workbench in order to be able to associate it
  with the new referentials.
* Explicitly set the referential organisation to the workbench
  organisation to pass validation that they both refer to the same
  organisation.
* Explicitly make the `has_many` association of the metadata objects to
  referentials.
* Since the second referential doesn't get saved when the spec passes,
  no schema is created for it. Thus our previous `Apartment` `drop` call
  failed for the second schema. To cover our bases for when the test
  both fails and passes, check if the referentials were persisted as a
  way of knowing whether the schema exists before trying to remove it.
Refs #5024
| -rw-r--r-- | spec/models/referential_spec.rb | 14 | 
1 files changed, 8 insertions, 6 deletions
| diff --git a/spec/models/referential_spec.rb b/spec/models/referential_spec.rb index 8fc9f359e..3a0532c05 100644 --- a/spec/models/referential_spec.rb +++ b/spec/models/referential_spec.rb @@ -132,10 +132,11 @@ describe Referential, :type => :model do      # TODO: Rename js: true to no transaction something      it "only creates one Referential", js: true do        begin -        workbench = build(:workbench) +        workbench = create(:workbench)          referential_1 = build(            :referential, -          workbench: workbench +          workbench: workbench, +          organisation: workbench.organisation          )          referential_2 = referential_1.dup          referential_2.slug = "#{referential_1.slug}_different" @@ -148,11 +149,12 @@ describe Referential, :type => :model do          # referential_2.metadatas << metadata          metadata_2 = metadata_1.dup          metadata_2.referential = referential_2 -        metadata_1.save -        metadata_2.save          # puts Referential.all.inspect          # puts referential_1.inspect +        referential_1.metadatas << metadata_1 +        referential_2.metadatas << metadata_2 +          # thread_1 = Thread.new do          #   ActiveRecord::Base.transaction do              referential_1.save @@ -174,8 +176,8 @@ describe Referential, :type => :model do          expect(referential_2).not_to be_persisted        ensure -        Apartment::Tenant.drop(referential_1.slug) -        Apartment::Tenant.drop(referential_2.slug) +        Apartment::Tenant.drop(referential_1.slug) if referential_1.persisted? +        Apartment::Tenant.drop(referential_2.slug) if referential_2.persisted?        end      end    end | 
