Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

spec: don't clear database automatically #165

Merged
merged 1 commit into from
Mar 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions spec/granite_orm/querying/all_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions spec/granite_orm/querying/count_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions spec/granite_orm/querying/find_by_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -32,6 +34,7 @@ module {{adapter.capitalize.id}}
end

it "also works with reserved words" do
Parent.clear
value = "robinson"

model = ReservedWord.new
Expand All @@ -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

Expand Down
4 changes: 4 additions & 0 deletions spec/granite_orm/querying/find_each_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions spec/granite_orm/querying/first_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions spec/granite_orm/transactions/save_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 0 additions & 14 deletions spec/spec_models.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}