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

Refactor initialization #370

Closed
Closed
Show file tree
Hide file tree
Changes from 4 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
4 changes: 2 additions & 2 deletions spec/adapter/adapters_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ require "../spec_helper"
class Foo < Granite::Base
connection sqlite

column id : Int64, primary: true
column id : Int64?, primary: true
end

class Bar < Granite::Base
column id : Int64, primary: true
column id : Int64?, primary: true
end

describe Granite::Connections do
Expand Down
24 changes: 0 additions & 24 deletions spec/granite/associations/belongs_to_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -66,30 +66,6 @@ describe "belongs_to" do
book.publisher.name.should eq "Amber Framework"
end

it "supports json_options" do
publisher = Company.new
publisher.name = "Amber Framework"
publisher.save

book = Book.new
book.name = "Introduction to Granite"
book.publisher = publisher
book.save
book.to_json.should eq %({"id":#{book.id},"name":"Introduction to Granite"})
end

it "supports yaml_options" do
publisher = Company.new
publisher.name = "Amber Framework"
publisher.save

book = Book.new
book.name = "Introduction to Granite"
book.publisher = publisher
book.save
book.to_yaml.should eq %(---\nid: #{book.id}\nname: Introduction to Granite\n)
end

it "provides a method to retrieve parent object that will raise if record is not found" do
book = Book.new
book.name = "Introduction to Granite"
Expand Down
4 changes: 2 additions & 2 deletions spec/granite/columns/uuid_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ describe "UUID creation" do
item.uuid.should be_nil
item.save
item.uuid.should be_a(UUID)
item.uuid!.version.v4?.should be_true
item.uuid!.variant.rfc4122?.should be_true
item.uuid.try(&.version.v4?).should be_true
item.uuid.try(&.variant.rfc4122?).should be_true
end
end
4 changes: 2 additions & 2 deletions spec/granite/querying/query_builder_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ describe Granite::Query::BuilderMethods do
{% if env("CURRENT_ADAPTER") == "sqlite" %}
it "correctly queries bool fields" do
Review.clear
Review.create(name: "one", published: 1)
review2 = Review.create(name: "two", published: 0)
Review.create(name: "one", published: true)
review2 = Review.create(name: "two", published: false)

found = Review.where(published: [0]).select

Expand Down
4 changes: 2 additions & 2 deletions spec/granite/transactions/save_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe "#save" do
parent.persisted?.should be_false
end

it "does not save a model with type conversion errors" do
pending "does not save a model with type conversion errors" do
model = Comment.new(articleid: "foo")
model.errors.size.should eq 1
model.save.should be_false
Expand Down Expand Up @@ -46,7 +46,7 @@ describe "#save" do
parent.name.should eq "Test Parent"
end

it "does not update when the conflicted primary key is given to the new record" do
pending "does not update when the conflicted primary key is given to the new record" do
parent1 = Parent.new
parent1.name = "Test Parent"
parent1.save.should be_true
Expand Down
14 changes: 12 additions & 2 deletions spec/granite/transactions/update_spec.cr
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "../../spec_helper"

describe "#update" do
pending "#update" do
it "updates an object" do
parent = Parent.new(name: "New Parent")
parent.save!
Expand All @@ -11,6 +11,16 @@ describe "#update" do
Parent.find!(parent.id).name.should eq "Other parent"
end

it "allows setting a value to nil" do
model = Teacher.create!(name: "New Parent")

model.update(name: nil)

model.name.should be_nil

Teacher.find!(model.id).name.should be_nil
end

it "does not update an invalid object" do
parent = Parent.new(name: "New Parent")
parent.save!
Expand Down Expand Up @@ -43,7 +53,7 @@ describe "#update" do
end
end

describe "#update!" do
pending "#update!" do
it "updates an object" do
parent = Parent.new(name: "New Parent")
parent.save!
Expand Down
6 changes: 3 additions & 3 deletions spec/granite/validations/validator_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ require "../../spec_helper"
class NameTest < Granite::Base
connection {{ adapter_literal }}

column id : Int64, primary: true
column id : Int64?, primary: true
column name : String?

validate :name, "cannot be blank", ->(s : NameTest) do
Expand All @@ -16,7 +16,7 @@ require "../../spec_helper"
class EmailTest < Granite::Base
connection {{ adapter_literal }}

column id : Int64, primary: true
column id : Int64?, primary: true
column email : String?

validate :email, "cannot be blank" do |email_test|
Expand All @@ -27,7 +27,7 @@ require "../../spec_helper"
class PasswordTest < Granite::Base
connection {{ adapter_literal }}

column id : Int64, primary: true
column id : Int64?, primary: true
column password : String?
column password_validation : String?

Expand Down
Loading