Skip to content

Commit

Permalink
Updating to Crystal 0.19.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Serdar Dogruyol committed Sep 11, 2016
1 parent 313eda6 commit 9cee5a3
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 53 deletions.
2 changes: 1 addition & 1 deletion shard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ dependencies:
development_dependencies:
mocks:
github: waterlink/mocks.cr
version: ~> 0.9
version: ~> 0.9.3
singleton:
github: waterlink/singleton.cr
version: ~> 0.1
20 changes: 10 additions & 10 deletions spec/active_record_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ module ActiveRecord
def call(params, fields)
return false unless fields.has_key?("number_of_dependents") &&
params.has_key?("1")
actual = fields["number_of_dependents"] as Int
expected = params["1"] as Int
actual = fields["number_of_dependents"].as(Int)
expected = params["1"].as(Int)
actual > expected
end
end
Expand All @@ -17,8 +17,8 @@ module ActiveRecord
def call(params, fields)
return false unless fields.has_key?("number_of_dependents") &&
params.has_key?("1")
actual = fields["number_of_dependents"] as Int
expected = params["1"] as Int
actual = fields["number_of_dependents"].as(Int)
expected = params["1"].as(Int)
actual < expected
end
end
Expand All @@ -29,9 +29,9 @@ module ActiveRecord
def call(params, fields)
return false unless fields.has_key?("number_of_dependents") &&
params.has_key?("1") && params.has_key?("2")
actual = fields["number_of_dependents"] as Int
low = params["1"] as Int
high = params["2"] as Int
actual = fields["number_of_dependents"].as(Int)
low = params["1"].as(Int)
high = params["2"].as(Int)
actual > low && actual < high
end
end
Expand All @@ -40,10 +40,10 @@ module ActiveRecord
def call(params, fields)
return false unless fields.has_key?("number_of_dependents") &&
params.has_key?("1") && params.has_key?("2")
actual = fields["number_of_dependents"] as Int
actual = fields["number_of_dependents"].as(Int)
array = [] of Int32
array << params["1"] as Int32
array << params["2"] as Int32
array << params["1"].as(Int32)
array << params["2"].as(Int32)
array.includes?(actual)
end
end
Expand Down
8 changes: 4 additions & 4 deletions spec/spec_helper.cr
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
ifdef !active_record_adapter
{% if !flag?(:active_record_adapter) %}
require "spec"
require "mocks"
require "../src/active_record"
require "../src/null_adapter"
require "../src/criteria_helper"
require "./fake_adapter"
end
{% end %}

def _specs_reset
ActiveRecord::NullAdapter.reset
FakeAdapter._reset

ifdef !active_record_adapter
{% if !flag?(:active_record_adapter) %}
Mocks.reset
end
{% end %}
end

Spec.before_each do
Expand Down
14 changes: 7 additions & 7 deletions spec/sql/query_generator_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ module ActiveRecord

example "or" do
query = (criteria("number") < 29) |
(criteria("other_number") == 2)
.or(criteria("kind") == "none")
(criteria("other_number") == 2)
.or(criteria("kind") == "none")

expected_query = Query.new(
"(number < :1) OR ((other_number = :2) OR (kind = :3))",
Expand All @@ -93,7 +93,7 @@ module ActiveRecord
generate(query).should eq(expected_query)

query = ((criteria("number") < 29) |
(criteria("other_number") == 2))
(criteria("other_number") == 2))
.or(criteria("kind") == "none")

expected_query = Query.new(
Expand All @@ -106,8 +106,8 @@ module ActiveRecord

example "and" do
query = (criteria("number") < 29) &
(criteria("other_number") == 2)
.and(criteria("kind") == "none")
(criteria("other_number") == 2)
.and(criteria("kind") == "none")

expected_query = Query.new(
"(number < :1) AND ((other_number = :2) AND (kind = :3))",
Expand All @@ -119,8 +119,8 @@ module ActiveRecord

example "mixing and, or" do
query = (criteria("number") < 29) &
(criteria("other_number") == 2)
.or(criteria("kind") == "none")
(criteria("other_number") == 2)
.or(criteria("kind") == "none")

expected_query = Query.new(
"(number < :1) AND ((other_number = :2) OR (kind = :3))",
Expand Down
28 changes: 14 additions & 14 deletions spec/types_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,25 @@ require "./spec_helper"

module StuffGenerator
def self.an_int
37 as ActiveRecord::SupportedType
37.as(ActiveRecord::SupportedType)
end

def self.an_int_null
Int::Null.new as ActiveRecord::SupportedType
Int::Null.new.as(ActiveRecord::SupportedType)
end

def self.a_string
"hello world" as ActiveRecord::SupportedType
"hello world".as(ActiveRecord::SupportedType)
end

def self.a_string_null
String::Null.new as ActiveRecord::SupportedType
String::Null.new.as(ActiveRecord::SupportedType)
end
end

macro test_non_null(ty, value, other_value, name="_", check_op="")
macro test_non_null(ty, value, other_value, name = "_", check_op = "")
context "when {{ty}} is not null" do
subject = {{value}} as SupportedType
subject = {{value}}.as SupportedType

it "has correct type" do
typeof(subject).should_not eq {{ty}}
Expand All @@ -42,7 +42,7 @@ context "when {{ty}} is not null" do
end

it "forwards calls to original value" do
{{name.id}} = subject as {{ty}}
{{name.id}} = subject.as({{ty}})
({{check_op.id}}).should eq(true)
end

Expand All @@ -54,9 +54,9 @@ context "when {{ty}} is not null" do
end
end

macro test_null(ty, zero, other_value, name="_", check_op="true")
macro test_null(ty, zero, other_value, name = "_", check_op = "true")
context "when {{ty}} is null" do
subject = {{ty}}::Null.new as SupportedType
subject = {{ty}}::Null.new.as(SupportedType)

it "has correct type" do
typeof(subject).should_not eq {{ty}}
Expand All @@ -79,7 +79,7 @@ context "when {{ty}} is null" do
end

it "forwards calls to zero-like value" do
{{name.id}} = subject as {{ty}}::Null
{{name.id}} = subject.as({{ty}}::Null)
({{check_op.id}}).should eq(true)
end

Expand All @@ -93,11 +93,11 @@ end

macro test_comparable(ty, spec_ty, value, zero)
it "implements correct Comparable" do
subject = {{value}} as SupportedType
null = {{ty}}::Null.new as SupportedType
subject = {{value}}.as(SupportedType)
null = {{ty}}::Null.new.as(SupportedType)

((subject as {{spec_ty}}) <=> {{zero}}).should eq({{value}} <=> {{zero}})
((null as {{ty}}::Null) <=> {{value}}).should eq({{zero}} <=> {{value}})
(subject.as({{spec_ty}}) <=> {{zero}}).should eq({{value}} <=> {{zero}})
(null.as({{ty}}::Null) <=> {{value}}).should eq({{zero}} <=> {{value}})
end
end

Expand Down
12 changes: 6 additions & 6 deletions src/model.cr
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ module ActiveRecord

MACRO_CURRENT = [] of String

DEFAULT_CONNECTION_POOL_CAPACITY = 1
DEFAULT_CONNECTION_POOL_TIMEOUT = 2.0
DEFAULT_CONNECTION_POOL_CAPACITY = 1
DEFAULT_CONNECTION_POOL_TIMEOUT = 2.0

macro null_object(name_and_super, &block)
class {{name_and_super.receiver}} < {{name_and_super.args[0]}}
Expand Down Expand Up @@ -53,12 +53,12 @@ module ActiveRecord
\{% MACRO_FIELDS_{{MACRO_CURRENT.last.id}} << name %}

{{level.id}} def \{{name.id}}=(value : \{{field_declaration.type}})
typed_fields = fields[\{{field_declaration.type.stringify}}] as ::ActiveRecord::Model::Fields::\{{field_declaration.type.id}}
typed_fields = fields[\{{field_declaration.type.stringify}}].as ::ActiveRecord::Model::Fields::\{{field_declaration.type.id}}
typed_fields.fields[\{{field_declaration.var.stringify}}] = value
end

{{level.id}} def \{{name.id}}
typed_fields = fields[\{{field_declaration.type.stringify}}] as ::ActiveRecord::Model::Fields::\{{field_declaration.type.id}}
typed_fields = fields[\{{field_declaration.type.stringify}}].as ::ActiveRecord::Model::Fields::\{{field_declaration.type.id}}
typed_fields.fields.fetch(\{{field_declaration.var.stringify}}, \{{field_declaration.type}}::Null.new)
end

Expand Down Expand Up @@ -157,7 +157,7 @@ module ActiveRecord
def self.get(primary_key)
pool.connection do |adapter|
if adapter.get(primary_key)
build(adapter.get(primary_key)) as self
build(adapter.get(primary_key)).as(self)
else
raise RecordNotFoundException.new("Record not found with given id.")
end
Expand Down Expand Up @@ -228,7 +228,7 @@ module ActiveRecord
private def set_field(field, value)
return unless self.class.fields.includes?(field)
fields[self.class.field_types[field]]
.set_field(field, value)
.set_field(field, value)
end

def self.null_value
Expand Down
10 changes: 5 additions & 5 deletions src/null_adapter.cr
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ module ActiveRecord
end

def get(primary_key)
return nil if deleted.includes?((primary_key as Int32) - 1)
records[(primary_key as Int32) - 1]
return nil if deleted.includes?((primary_key.as(Int32)) - 1)
records[(primary_key.as(Int32)) - 1]
end

def create(fields)
Expand All @@ -63,7 +63,7 @@ module ActiveRecord
records
end

def where(query : Query::Query)
def where(query : ::Query::Query)
query = self.class.generate_query(query).not_nil!
_where(query.query, query.params)
end
Expand Down Expand Up @@ -104,11 +104,11 @@ module ActiveRecord
end

def update(primary_key, fields)
records[(primary_key as Int32) - 1] = fields.dup
records[(primary_key.as(Int32)) - 1] = fields.dup
end

def delete(primary_key)
deleted << (primary_key as Int32) - 1
deleted << (primary_key.as(Int32)) - 1
end

def _reset
Expand Down
12 changes: 6 additions & 6 deletions src/types.cr
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
module ActiveRecord
AS = {} of String => Int32
SPEC_TYPES = [] of Int32
AS = {} of String => Int32
SPEC_TYPES = [] of Int32
TYPE_GROUPS = [] of Int32

macro alias_types(group, special=false, _as=nil)
macro alias_types(group, special = false, _as = nil)
{% AS[""] = _as %}
{% AS[""] = "#{group.id}Types".id unless AS.[""] %}
{% TYPE_GROUPS << group unless special %}
Expand All @@ -25,12 +25,12 @@ module ActiveRecord
{% end %}
end

macro register_type(type, group, name, register=true)
macro register_type(type, group, name, register = true)
{% ActiveRecord::SPEC_TYPES << {group, name} if register == true %}

{{type.id}} {{name.id}}
def not_null! : {{name}}
self as {{name}}
self.as({{name}})
end

def null?
Expand All @@ -53,7 +53,7 @@ module ActiveRecord
{{:end.id}}
end

macro register_type_group(kind, ty, default=nil, comparable=false, to_s="")
macro register_type_group(kind, ty, default = nil, comparable = false, to_s = "")
{{kind.id}} {{ty.id}}
def self.null_class
Null
Expand Down

0 comments on commit 9cee5a3

Please sign in to comment.