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 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions spec/adapter/adapters_spec.cr
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
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: 0 additions & 4 deletions spec/granite/columns/primary_key_spec.cr
Expand Up @@ -11,10 +11,6 @@ describe "#new" do
end

describe "#new(primary_key: value)" do
it "ignores the value in default" do
Parent.new(id: 1_i64).id.should eq(nil)
end
Comment on lines -14 to -16
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This wouldn't compile anymore assuming the user doesn't include id within the initializer (which wouldn't make sense since its auto increment anyway).


it "sets the value when the primary is defined as `auto: false`" do
Kvs.new(k: "foo").k.should eq("foo")
Kvs.new(k: "foo", v: "v").k.should eq("foo")
Expand Down
4 changes: 2 additions & 2 deletions spec/granite/columns/uuid_spec.cr
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
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
17 changes: 0 additions & 17 deletions spec/granite/transactions/save_spec.cr
Expand Up @@ -15,12 +15,6 @@ describe "#save" do
parent.persisted?.should be_false
end

it "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
end

it "updates an existing object" do
Parent.clear
parent = Parent.new
Expand All @@ -46,17 +40,6 @@ 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
parent1 = Parent.new
parent1.name = "Test Parent"
parent1.save.should be_true

parent2 = Parent.new
parent2.id = parent1.id
parent2.name = "Test Parent2"
parent2.save.should be_false
end

describe "with a custom primary key" do
it "creates a new object" do
school = School.new
Expand Down
2 changes: 1 addition & 1 deletion spec/granite/transactions/touch_spec.cr
Expand Up @@ -6,7 +6,7 @@ describe "#touch" do
end

it "should raise on non existent field" do
expect_raises Exception, "Field 'foo' does not exist on type 'TimeTest'." do
expect_raises Exception, "Column 'foo' does not exist on type 'TimeTest'." do
model = TimeTest.create(name: "foo")
model.touch(:foo)
end
Expand Down
67 changes: 0 additions & 67 deletions spec/granite/transactions/update_spec.cr

This file was deleted.

6 changes: 3 additions & 3 deletions spec/granite/validations/validator_spec.cr
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