Skip to content

Commit

Permalink
Fix nested name space error
Browse files Browse the repository at this point in the history
  • Loading branch information
cyangle committed Aug 8, 2024
1 parent b958e62 commit 5f76bfa
Show file tree
Hide file tree
Showing 45 changed files with 86 additions and 74 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@
**Model**

* Add `EnumConverter` converter for Postgre `ENUM` field convert
* (pg only) field presenting `ENUM` field should explicitly specify `converter: Jennifer::Model::EnumConverter`
* (pg only) field presenting `ENUM` field should explicitly specify `converter: ::Jennifer::Model::EnumConverter`

**Adapter**

Expand Down
6 changes: 3 additions & 3 deletions docs/model_mapping.md
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ end
class Note < Jennifer::Model::Base
mapping(
category: {type: Category?, converter: Jennifer::Model::EnumConverter(Category)}
category: {type: Category?, converter: ::Jennifer::Model::EnumConverter(Category)}
)
end
```
Expand All @@ -259,7 +259,7 @@ It expects next options to be specified in a field mapping:
class Order < Jennifer::Model::Base
mapping(
# ...
total: { type: BigDecimal?, converter: Jennifer::Model::BigDecimalConverter(PG::Numeric), scale: 2 }
total: { type: BigDecimal?, converter: ::Jennifer::Model::BigDecimalConverter(PG::Numeric), scale: 2 }
# for MySQL use Float64
)
end
Expand All @@ -280,7 +280,7 @@ end
class User < Jennifer::Model::Base
mapping(
# ...
location: { type: Location, converter: Jennifer::Model::JSONSerializableConverter(Location) }
location: { type: Location, converter: ::Jennifer::Model::JSONSerializableConverter(Location) }
)
end
```
Expand Down
2 changes: 1 addition & 1 deletion docs/relations.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class Post < Jennifer::Model::Base
user_id: Int64?
)
belongs_to :user, User, required: ->(object : Jennifer::Model::Translation, _field : String) do
belongs_to :user, User, required: ->(object : ::Jennifer::Model::Translation, _field : String) do
record = object.as(Post)
"Post #{record.title} isn't attached to any user"
end
Expand Down
2 changes: 1 addition & 1 deletion docs/validation.md
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ class Person < Jennifer::Model::Base
# Proc
validates_uniqueness :username,
message: ->(object : Jennifer::Model::Translation, field : String) do
message: ->(object : ::Jennifer::Model::Translation, field : String) do
record = object.as(Person)
"Hey #{record.name}, #{record.attribute(field)} is already taken."
end
Expand Down
2 changes: 1 addition & 1 deletion spec/adapter/base_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ private def config
end

private def adapter
Jennifer::Adapter.default_adapter_class.not_nil!.new(Jennifer::Config.instance)
Jennifer::Adapter.default_adapter_class.not_nil!.new(::Jennifer::Config.instance)
end

default_adapter = Jennifer::Adapter.default_adapter
Expand Down
2 changes: 1 addition & 1 deletion spec/adapter/command_shell/docker_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ def prepare_docker_config
Jennifer::Config.configure do |conf|
conf.docker_container = "some_container"
end
Jennifer::Adapter::Docker.new(Jennifer::Config.instance)
Jennifer::Adapter::Docker.new(::Jennifer::Config.instance)
end

describe Jennifer::Adapter::Docker do
Expand Down
6 changes: 3 additions & 3 deletions spec/adapter/db_command_interface_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ describe Jennifer::Adapter::DBCommandInterface do
describe ".build_shell" do
it do
Jennifer::Config.config.command_shell = "bash"
described_class.build_shell(Jennifer::Config.config).is_a?(Jennifer::Adapter::Bash).should be_true
described_class.build_shell(::Jennifer::Config.config).is_a?(Jennifer::Adapter::Bash).should be_true
end

it do
Jennifer::Config.config.command_shell = "docker"
described_class.build_shell(Jennifer::Config.config).is_a?(Jennifer::Adapter::Docker).should be_true
described_class.build_shell(::Jennifer::Config.config).is_a?(Jennifer::Adapter::Docker).should be_true
end

it do
Jennifer::Config.config.command_shell = "unknown"
expect_raises(Jennifer::BaseException) { described_class.build_shell(Jennifer::Config.config) }
expect_raises(Jennifer::BaseException) { described_class.build_shell(::Jennifer::Config.config) }
end
end
end
2 changes: 1 addition & 1 deletion spec/adapter/postgres/command_interface_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ postgres_only do
described_class = Jennifer::Postgres::CommandInterface

describe "#database_exists?" do
it { described_class.new(Jennifer::Config.config).database_exists?.should be_true }
it { described_class.new(::Jennifer::Config.config).database_exists?.should be_true }

it do
config = Jennifer::Config.config
Expand Down
2 changes: 1 addition & 1 deletion spec/model/enum_converter_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class NoteWithEnumText < Jennifer::Model::Base

mapping({
id: Primary64,
text: {type: Category?, converter: Jennifer::Model::EnumConverter(Category)},
text: {type: Category?, converter: ::Jennifer::Model::EnumConverter(Category)},
created_at: Time?,
updated_at: Time?,
}, false)
Expand Down
2 changes: 1 addition & 1 deletion spec/model/json_serializable_converter_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class AddressWithSerializable < Jennifer::Model::Base

mapping({
id: Primary64,
details: {type: Location?, converter: Jennifer::Model::JSONSerializableConverter(Location)},
details: {type: Location?, converter: ::Jennifer::Model::JSONSerializableConverter(Location)},
created_at: Time?,
updated_at: Time?,
}, false)
Expand Down
6 changes: 3 additions & 3 deletions spec/model/mapping_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ postgres_only do
mapping({
id: Primary64,
name: String,
ballance: {type: BigDecimal, converter: Jennifer::Model::BigDecimalConverter(PG::Numeric), scale: 2},
ballance: {type: BigDecimal, converter: ::Jennifer::Model::BigDecimalConverter(PG::Numeric), scale: 2},
}, false)
end
end
Expand All @@ -26,7 +26,7 @@ mysql_only do
mapping({
id: Primary64,
name: String,
ballance: {type: BigDecimal, converter: Jennifer::Model::BigDecimalConverter(Float64), scale: 2},
ballance: {type: BigDecimal, converter: ::Jennifer::Model::BigDecimalConverter(Float64), scale: 2},
}, false)
end
end
Expand Down Expand Up @@ -77,7 +77,7 @@ class UserWithConverter < Jennifer::Model::Base

mapping(
id: Primary64,
name: {type: JSON::Any, converter: Jennifer::Model::JSONConverter}
name: {type: JSON::Any, converter: ::Jennifer::Model::JSONConverter}
)
end

Expand Down
2 changes: 1 addition & 1 deletion spec/model/relation_definition_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ module Jennifer::Model
Union(User | FacebookProfile),
dependent: :destroy,
polymorphic: true,
required: ->(_record : Jennifer::Model::Translation, _field : String) { "notable is missing" }
required: ->(_record : ::Jennifer::Model::Translation, _field : String) { "notable is missing" }
actual_table_field_count
end

Expand Down
2 changes: 1 addition & 1 deletion spec/model/sti_mapping_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ end

class ProfileWithConverter < SimplifiedProfile
mapping(
details: {type: JSON::Any, convert: Jennifer::Model::JSONConverter}
details: {type: JSON::Any, convert: ::Jennifer::Model::JSONConverter}
)
end

Expand Down
18 changes: 9 additions & 9 deletions spec/model/time_zone_converter_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -5,44 +5,44 @@ describe Jennifer::Model::TimeZoneConverter do

it "converts column value to local time zone when is read from result set" do
record = Factory.create_note.reload
record.created_at!.zone.should eq(Jennifer::Config.local_time_zone.lookup(Time.utc))
record.created_at!.zone.should eq(::Jennifer::Config.local_time_zone.lookup(Time.utc))
record.created_at!.should be_close(Time.local(location: Jennifer::Config.local_time_zone), 1.second)
end

it "converts column value to local time zone when is read from hash" do
record = Note.new({"created_at" => Time.utc})
record.created_at!.should be_close(Time.local(location: Jennifer::Config.local_time_zone), 1.second)
record.created_at!.zone.should eq(Jennifer::Config.local_time_zone.lookup(Time.utc))
record.created_at!.zone.should eq(::Jennifer::Config.local_time_zone.lookup(Time.utc))
end

describe ".from_hash" do
it "accepts time in current time zone" do
time = Time.local(location: Jennifer::Config.local_time_zone)
value = described_class.from_hash({"value" => time}, "value", {name: "value"})
value.should eq(time)
value.zone.should eq(Jennifer::Config.local_time_zone.lookup(Time.utc))
value.zone.should eq(::Jennifer::Config.local_time_zone.lookup(Time.utc))
end

it "converts time to application time zone" do
time = Time.utc
value = described_class.from_hash({"value" => time}, "value", {name: "value"})
value.should eq(time.in(Jennifer::Config.local_time_zone))
value.zone.should eq(Jennifer::Config.local_time_zone.lookup(Time.utc))
value.should eq(time.in(::Jennifer::Config.local_time_zone))
value.zone.should eq(::Jennifer::Config.local_time_zone.lookup(Time.utc))
end

it "assumes time in application time zone if time_zone_aware_attributes is off" do
Jennifer::Config.time_zone_aware_attributes = false
time = Time.utc
value = described_class.from_hash({"value" => time}, "value", {name: "value"})
value.should eq(time.to_local_in(Jennifer::Config.local_time_zone))
value.zone.should eq(Jennifer::Config.local_time_zone.lookup(Time.utc))
value.should eq(time.to_local_in(::Jennifer::Config.local_time_zone))
value.zone.should eq(::Jennifer::Config.local_time_zone.lookup(Time.utc))
end

it "assumes time in application time zone if time_zone_aware is specified" do
time = Time.utc
value = described_class.from_hash({"value" => time}, "value", {name: "value", time_zone_aware: false})
value.should eq(time.to_local_in(Jennifer::Config.local_time_zone))
value.zone.should eq(Jennifer::Config.local_time_zone.lookup(Time.utc))
value.should eq(time.to_local_in(::Jennifer::Config.local_time_zone))
value.zone.should eq(::Jennifer::Config.local_time_zone.lookup(Time.utc))
end

it "accepts string value" do
Expand Down
4 changes: 2 additions & 2 deletions spec/model/validation_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ postgres_only do

mapping({
id: Primary64,
ballance: {type: BigDecimal, converter: Jennifer::Model::BigDecimalConverter(PG::Numeric), scale: 2},
ballance: {type: BigDecimal, converter: ::Jennifer::Model::BigDecimalConverter(PG::Numeric), scale: 2},
}, false)

validates_numericality :ballance, greater_than: 20
Expand Down Expand Up @@ -128,7 +128,7 @@ class ProcMessageValidationModel < ApplicationRecord
name: String,
})

validates_length :name, is: 3, message: ->(record : Jennifer::Model::Translation, _field : String) do
validates_length :name, is: 3, message: ->(record : ::Jennifer::Model::Translation, _field : String) do
record.as(ProcMessageValidationModel).name
end
end
Expand Down
6 changes: 3 additions & 3 deletions spec/spec_helper.cr
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ require "./support/*"
require "../scripts/migrations/20170119011451314_create_contacts"
require "../scripts/migrations/20180909200027509_create_notes"

class Jennifer::Adapter::ICommandShell
class ::Jennifer::Adapter::ICommandShell
class_property? stub = false
end

class Jennifer::Adapter::Bash < Jennifer::Adapter::ICommandShell
class ::Jennifer::Adapter::Bash < Jennifer::Adapter::ICommandShell
private def invoke(string, options)
if Jennifer::Adapter::ICommandShell.stub?
{result: 0, output: [string, options]}
Expand All @@ -37,7 +37,7 @@ class Jennifer::Adapter::Bash < Jennifer::Adapter::ICommandShell
end
end

class Jennifer::Adapter::Docker < Jennifer::Adapter::ICommandShell
class ::Jennifer::Adapter::Docker < Jennifer::Adapter::ICommandShell
private def invoke(string, options)
if Jennifer::Adapter::ICommandShell.stub?
{result: 0, output: [string, options]}
Expand Down
4 changes: 2 additions & 2 deletions spec/support/config.cr
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ require "../../src/jennifer/generators/*"
require "../../src/jennifer/adapter/db_colorized_formatter"
require "sam"

class Jennifer::Generators::Base
class ::Jennifer::Generators::Base
def puts(_value); end
end

Expand Down Expand Up @@ -77,7 +77,7 @@ def set_default_configuration
conf.user = ENV["DB_USER"] if ENV["DB_USER"]?
conf.password = ENV["DB_PASSWORD"] if ENV["DB_PASSWORD"]?
conf.verbose_migrations = false
conf.local_time_zone_name = "Europe/Kiev"
conf.local_time_zone_name = "Europe/Kyiv"
conf.pool_size = (ENV["DB_CONNECTION_POOL"]? || 1).to_i
end

Expand Down
4 changes: 2 additions & 2 deletions spec/support/factories.cr
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class JoinFactory < Factory::Base
end

class ExpressionFactory < Factory::Base
describe_class Jennifer::QueryBuilder::ExpressionBuilder
describe_class ::Jennifer::QueryBuilder::ExpressionBuilder
skip_all_constructors

attr :table, "tests"
Expand All @@ -46,7 +46,7 @@ class ExpressionFactory < Factory::Base
end

class QueryFactory < Factory::Base
describe_class Jennifer::QueryBuilder::Query
describe_class ::Jennifer::QueryBuilder::Query
skip_all_constructors

attr :table, "tests"
Expand Down
6 changes: 3 additions & 3 deletions spec/support/models.cr
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ class Publication < Jennifer::Model::Base
name: {type: String, column: :title},
version: Int32,
publisher: String,
type: {type: String, converter: Jennifer::Model::PgEnumConverter}
type: {type: String, converter: ::Jennifer::Model::PgEnumConverter}
)
{% else %}
mapping(
Expand Down Expand Up @@ -475,7 +475,7 @@ class ContactWithDependencies < Jennifer::Model::Base
name: String?,
description: String?,
age: {type: Int32, default: 10},
gender: {type: String?, default: "male", converter: Jennifer::Model::PgEnumConverter},
gender: {type: String?, default: "male", converter: ::Jennifer::Model::PgEnumConverter},
}, false)
{% else %}
mapping({
Expand Down Expand Up @@ -539,7 +539,7 @@ end

mapping({
id: Primary64,
ballance: {type: Float64?, converter: Jennifer::Model::NumericToFloat64Converter},
ballance: {type: Float64?, converter: ::Jennifer::Model::NumericToFloat64Converter},
}, false)
end
{% end %}
Expand Down
2 changes: 1 addition & 1 deletion spec/support/models/contact.cr
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Contact < ApplicationRecord
name: String,
ballance: PG::Numeric?,
age: {type: Int32, default: 10},
gender: {type: String?, default: "male", converter: Jennifer::Model::PgEnumConverter},
gender: {type: String?, default: "male", converter: ::Jennifer::Model::PgEnumConverter},
description: String?,
created_at: Time?,
updated_at: Time?,
Expand Down
6 changes: 3 additions & 3 deletions spec/support/views.cr
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class MaleContact < Jennifer::View::Base
mapping({
id: Primary64,
name: String,
gender: {type: String, converter: Jennifer::Model::PgEnumConverter},
gender: {type: String, converter: ::Jennifer::Model::PgEnumConverter},
age: Int32,
created_at: Time?,
}, false)
Expand Down Expand Up @@ -49,7 +49,7 @@ class FakeFemaleContact < Jennifer::View::Base
mapping({
id: Primary64,
name: String,
gender: {type: String, converter: Jennifer::Model::PgEnumConverter},
gender: {type: String, converter: ::Jennifer::Model::PgEnumConverter},
age: Int32,
created_at: Time?,
}, false)
Expand Down Expand Up @@ -106,7 +106,7 @@ class PrintPublication < Jennifer::View::Base
publisher: String,
pages: Int32?,
url: String?,
type: {type: String, converter: Jennifer::Model::PgEnumConverter}
type: {type: String, converter: ::Jennifer::Model::PgEnumConverter}
)
{% else %}
mapping(
Expand Down
2 changes: 1 addition & 1 deletion spec/validations/absence_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe Jennifer::Validations::Absence do

describe "message" do
it do
proc = ->(record : Jennifer::Model::Translation, field : String) { "#{record.as(Address).attribute(field).inspect} #{field} invalid" }
proc = ->(record : ::Jennifer::Model::Translation, field : String) { "#{record.as(Address).attribute(field).inspect} #{field} invalid" }
validated_by_record(:contact_id, 1, {message: proc, record: Factory.build_address})
.should has_error_message(:contact_id, "nil contact_id invalid")
end
Expand Down
2 changes: 1 addition & 1 deletion spec/validations/acceptance_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe Jennifer::Validations::Acceptance do

describe "message" do
it do
proc = ->(record : Jennifer::Model::Translation, field : String) do
proc = ->(record : ::Jennifer::Model::Translation, field : String) do
"#{record.as(Contact).attribute(field)} #{field} invalid"
end
validated_by_record(:name, "no", {message: proc, accept: %w[yes]})
Expand Down
2 changes: 1 addition & 1 deletion spec/validations/confirmation_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe Jennifer::Validations::Confirmation do

describe "message" do
it do
proc = ->(record : Jennifer::Model::Translation, field : String) do
proc = ->(record : ::Jennifer::Model::Translation, field : String) do
"#{record.as(Contact).attribute(field)} #{field} invalid"
end
validated_by_record(:name, "John", {message: proc, confirmation: "Joh", case_sensitive: true})
Expand Down
2 changes: 1 addition & 1 deletion spec/validations/exclusion_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe Jennifer::Validations::Exclusion do

describe "message" do
it do
proc = ->(record : Jennifer::Model::Translation, field : String) do
proc = ->(record : ::Jennifer::Model::Translation, field : String) do
"#{record.as(Contact).attribute(field)} #{field} invalid"
end
validated_by_record(:name, 1, {message: proc, collection: [1]})
Expand Down
Loading

0 comments on commit 5f76bfa

Please sign in to comment.