From 391e85122d1b355e6568b50ebce4b0e781cf7cb4 Mon Sep 17 00:00:00 2001 From: maiha Date: Tue, 27 Feb 2018 08:31:39 +0900 Subject: [PATCH] spec: don't clear database automatically --- spec/granite_orm/querying/all_spec.cr | 1 + spec/granite_orm/querying/count_spec.cr | 5 +++-- spec/granite_orm/querying/find_by_spec.cr | 4 ++++ spec/granite_orm/querying/find_each_spec.cr | 4 ++++ spec/granite_orm/querying/first_spec.cr | 3 +++ spec/granite_orm/transactions/save_spec.cr | 1 + spec/spec_models.cr | 14 -------------- 7 files changed, 16 insertions(+), 16 deletions(-) diff --git a/spec/granite_orm/querying/all_spec.cr b/spec/granite_orm/querying/all_spec.cr index 2fb5eaa1..2a14c3f4 100644 --- a/spec/granite_orm/querying/all_spec.cr +++ b/spec/granite_orm/querying/all_spec.cr @@ -4,6 +4,7 @@ require "../../spec_helper" module {{adapter.capitalize.id}} describe "{{ adapter.id }} #all" do it "finds all the records" do + Parent.clear model_ids = (0...100).map do |i| Parent.new(name: "model_#{i}").tap(&.save) end.map(&.id) diff --git a/spec/granite_orm/querying/count_spec.cr b/spec/granite_orm/querying/count_spec.cr index 92076cb1..3e3cac88 100644 --- a/spec/granite_orm/querying/count_spec.cr +++ b/spec/granite_orm/querying/count_spec.cr @@ -4,17 +4,18 @@ require "../../spec_helper" module {{adapter.capitalize.id}} describe "{{ adapter.id }} #count" do it "returns 0 if no result" do + Parent.clear count = Parent.count count.should eq 0 end it "returns a number of the all records for the model" do + count = Parent.count 2.times do |i| Parent.new(name: "model_#{i}").tap(&.save) end - count = Parent.count - count.should eq 2 + (Parent.count - count).should eq 2 end end end diff --git a/spec/granite_orm/querying/find_by_spec.cr b/spec/granite_orm/querying/find_by_spec.cr index c989f830..7f77100e 100644 --- a/spec/granite_orm/querying/find_by_spec.cr +++ b/spec/granite_orm/querying/find_by_spec.cr @@ -4,6 +4,7 @@ require "../../spec_helper" module {{adapter.capitalize.id}} describe "{{ adapter.id }} #find_by?, #find_by" do it "finds an object with a string field" do + Parent.clear name = "robinson" model = Parent.new @@ -18,6 +19,7 @@ module {{adapter.capitalize.id}} end it "finds an object with a symbol field" do + Parent.clear name = "robinson" model = Parent.new @@ -32,6 +34,7 @@ module {{adapter.capitalize.id}} end it "also works with reserved words" do + Parent.clear value = "robinson" model = ReservedWord.new @@ -46,6 +49,7 @@ module {{adapter.capitalize.id}} end it "returns nil or raises if no result" do + Parent.clear found = Parent.find_by?("name", "xxx") found.should be_nil diff --git a/spec/granite_orm/querying/find_each_spec.cr b/spec/granite_orm/querying/find_each_spec.cr index ac754e66..446090af 100644 --- a/spec/granite_orm/querying/find_each_spec.cr +++ b/spec/granite_orm/querying/find_each_spec.cr @@ -4,6 +4,7 @@ require "../../spec_helper" module {{adapter.capitalize.id}} describe "{{ adapter.id }} #find_each" do it "finds all the records" do + Parent.clear model_ids = (0...100).map do |i| Parent.new(name: "role_#{i}").tap {|r| r.save } end.map(&.id) @@ -17,12 +18,14 @@ module {{adapter.capitalize.id}} end it "doesnt yield when no records are found" do + Parent.clear Parent.find_each do |model| fail "did yield" end end it "can start from an offset" do + Parent.clear created_models = (0...10).map do |i| Parent.new(name: "model_#{i}").tap(&.save) end.map(&.id) @@ -41,6 +44,7 @@ module {{adapter.capitalize.id}} end it "doesnt obliterate a parameterized query" do + Parent.clear created_models = (0...10).map do |i| Parent.new(name: "model_#{i}").tap(&.save) end.map(&.id) diff --git a/spec/granite_orm/querying/first_spec.cr b/spec/granite_orm/querying/first_spec.cr index 36d11f13..48676d68 100644 --- a/spec/granite_orm/querying/first_spec.cr +++ b/spec/granite_orm/querying/first_spec.cr @@ -4,6 +4,7 @@ require "../../spec_helper" module {{adapter.capitalize.id}} describe "{{ adapter.id }} #first?, #first" do it "finds the first object" do + Parent.clear first = Parent.new.tap do |model| model.name = "Test 1" model.save @@ -22,6 +23,7 @@ module {{adapter.capitalize.id}} end it "supports a SQL clause" do + Parent.clear first = Parent.new.tap do |model| model.name = "Test 1" model.save @@ -40,6 +42,7 @@ module {{adapter.capitalize.id}} end it "returns nil or raises if no result" do + Parent.clear first = Parent.new.tap do |model| model.name = "Test 1" model.save diff --git a/spec/granite_orm/transactions/save_spec.cr b/spec/granite_orm/transactions/save_spec.cr index a6e741ea..36a51573 100644 --- a/spec/granite_orm/transactions/save_spec.cr +++ b/spec/granite_orm/transactions/save_spec.cr @@ -18,6 +18,7 @@ module {{adapter.capitalize.id}} end it "updates an existing object" do + Parent.clear parent = Parent.new parent.name = "Test Parent" parent.save diff --git a/spec/spec_models.cr b/spec/spec_models.cr index 14ccd89d..ae4c27d3 100644 --- a/spec/spec_models.cr +++ b/spec/spec_models.cr @@ -272,19 +272,5 @@ end Empty.drop_and_create ReservedWord.drop_and_create Callback.drop_and_create - - Spec.before_each do - Parent.clear - Teacher.clear - Student.clear - Klass.clear - Enrollment.clear - School.clear - Nation::County.clear - Review.clear - Empty.clear - ReservedWord.clear - Callback.clear - end end {% end %}