From 70a57dd2aa166c9072ca98b6a49720f849151035 Mon Sep 17 00:00:00 2001 From: Yacine Petitprez Date: Fri, 29 Jun 2018 08:06:40 +0200 Subject: [PATCH] Add polymorphism specs on load --- spec/model/model_spec.cr | 2 +- spec/model/polymorphism_spec.cr | 41 ++++++++++++++++++++++----------- 2 files changed, 28 insertions(+), 15 deletions(-) diff --git a/spec/model/model_spec.cr b/spec/model/model_spec.cr index 3aa4a9dbd..7e6e46a3a 100644 --- a/spec/model/model_spec.cr +++ b/spec/model/model_spec.cr @@ -83,7 +83,7 @@ module ModelSpec describe "Clear::Model" do context "fields management" do - it "can load from array" do + it "can load from tuple" do temporary do reinit u = User.new({id: 123}) diff --git a/spec/model/polymorphism_spec.cr b/spec/model/polymorphism_spec.cr index c3985d489..d29b1dab2 100644 --- a/spec/model/polymorphism_spec.cr +++ b/spec/model/polymorphism_spec.cr @@ -6,9 +6,9 @@ module PolymorphismSpec self.table = "polymorphs" - polymorphic ConcreteClass1, - ConcreteClass2, - through: "type" + polymorphic ConcreteClass1, + ConcreteClass2, + through: "type" abstract def print_value : String end @@ -73,25 +73,38 @@ module PolymorphismSpec end end - it "filter the subclass using the type column" do + it "filters the subclass using the type column" do temporary do reinit - 5.times do - ConcreteClass1.create({integer_value: 1}) - end - - 10.times do - ConcreteClass2.create({string_value: "Yey"}) - end + 5.times { ConcreteClass1.create({integer_value: 1}) } + 10.times { ConcreteClass2.create({string_value: "Yey"}) } ConcreteClass1.query.count.should eq 5 ConcreteClass2.query.count.should eq 10 AbstractClass.query.count.should eq 15 - end end - end + it "loads the model correctly" do + temporary do + reinit -end \ No newline at end of file + 5.times { ConcreteClass1.create({integer_value: 1}) } + 10.times { ConcreteClass2.create({string_value: "Yey"}) } + + c1, c2 = 0, 0 + AbstractClass.query.each do |mdl| + if mdl.is_a? ConcreteClass1 + c1 += 1 + elsif mdl.is_a? ConcreteClass2 + c2 += 1 + end + end + + c1.should eq 5 + c2.should eq 10 + end + end + end +end