diff options
| author | Teddy Wing | 2017-11-29 16:18:46 +0100 |
|---|---|---|
| committer | Teddy Wing | 2017-11-29 16:18:46 +0100 |
| commit | dba5ded7b591126c3ee690669afb23eec7e04522 (patch) | |
| tree | 97f31d3ce5cb33e2b9c163f5a6a0e1f623ad8c86 | |
| parent | 03bc0004ade09b27b31c3f6d14c725a7ab99a303 (diff) | |
| download | chouette-core-dba5ded7b591126c3ee690669afb23eec7e04522.tar.bz2 | |
referential_spec: Add threaded version of duplicate referential spec
This replicates the synchronous test and adds threads and sleeps to save
the two referentials asynchronously. This version fails, which is
consistent with the current behaviour of the application.
Refs #5024
| -rw-r--r-- | spec/models/referential_spec.rb | 49 |
1 files changed, 48 insertions, 1 deletions
diff --git a/spec/models/referential_spec.rb b/spec/models/referential_spec.rb index 867ee4658..e65f8f457 100644 --- a/spec/models/referential_spec.rb +++ b/spec/models/referential_spec.rb @@ -128,7 +128,6 @@ describe Referential, :type => :model do end context "when two identical Referentials are created, only one is saved" do - # TODO: Rename js: true to no transaction something it "works synchronously" do begin workbench = create(:workbench) @@ -160,5 +159,53 @@ describe Referential, :type => :model do Apartment::Tenant.drop(referential_2.slug) if referential_2.persisted? end end + + # TODO: Rename js: true to no transaction something + it "works asynchronously", js: true do + begin + workbench = create(:workbench) + referential_1 = build( + :referential, + workbench: workbench, + organisation: workbench.organisation + ) + referential_2 = referential_1.dup + referential_2.slug = "#{referential_1.slug}_different" + + metadata_1 = build( + :referential_metadata, + referential: referential_1 + ) + metadata_2 = metadata_1.dup + metadata_2.referential = referential_2 + + referential_1.metadatas << metadata_1 + referential_2.metadatas << metadata_2 + + thread_1 = Thread.new do + ActiveRecord::Base.transaction do + referential_1.save + sleep 10 + end + end + + thread_2 = Thread.new do + sleep 5 + ActiveRecord::Base.transaction do + referential_2.save + end + end + + thread_1.join + thread_2.join + + expect(referential_1).to be_persisted + expect(referential_2).not_to be_persisted + + ensure + Apartment::Tenant.drop(referential_1.slug) if referential_1.persisted? + Apartment::Tenant.drop(referential_2.slug) if referential_2.persisted? + end + end end end |
