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

Updated tests and typo fixed. #42

Merged
merged 2 commits into from
Mar 16, 2016
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
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ class Person < ActiveRecord::Model
# table_name people

# Database fields
primary id :: Int
field last_name :: String
field first_name :: String
field number_of_dependents :: Int
primary id : Int
field last_name : String
field first_name : String
field number_of_dependents : Int

# Domain logic
def get_tax_exemption
Expand Down
30 changes: 15 additions & 15 deletions spec/active_record_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ class Person < ActiveRecord::Model
adapter null
table_name people

primary id :: Int
field last_name :: String
field first_name :: String
field number_of_dependents :: Int
field special_tax_group :: Bool
primary id : Int
field last_name : String
field first_name : String
field number_of_dependents : Int
field special_tax_group : Bool

def get_tax_exemption
return 0.0 if number_of_dependents < 2
Expand All @@ -68,18 +68,18 @@ class Another::Model < ActiveRecord::Model
adapter null
table_name something_else

primary id :: Int
field name :: String
primary id : Int
field name : String
end

class Post < ActiveRecord::Model
adapter null
table_name posts

primary id :: Int
field title :: String
field content :: String
field created_at :: Time
primary id : Int
field title : String
field content : String
field created_at : Time

field_level :protected

Expand All @@ -99,16 +99,16 @@ end
class ExampleModel < ActiveRecord::Model
adapter fake

primary id :: Int
field name :: String
primary id : Int
field name : String
end

class AnotherExampleModel < ActiveRecord::Model
adapter fake
table_name some_models

primary id :: Int
field name :: String
primary id : Int
field name : String
end

def new_person
Expand Down
6 changes: 3 additions & 3 deletions spec/criteria_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ class AModel < ActiveRecord::Model
adapter null
table_name a_models

primary id :: Int
field name :: String
field other_model_id :: Int
primary id : Int
field name : String
field other_model_id : Int

def self.with_name(name)
where(criteria("name") == name)
Expand Down
15 changes: 9 additions & 6 deletions spec/query_spec.cr
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
require "./spec_helper"
require "mocks"
require "mocks/spec"
require "../src/criteria"

module ActiveRecord
create_double "Condition" do
Mocks::Macro.create_double "Condition" do
mock (instance == other), Bool
end

describe Query do
describe "#same_query?" do
it "is not the same query if other is not a Query" do
condition_a = double("Condition")
condition_a = Mocks::Macro.double("Condition")

Query.new(condition_a).same_query?(nil).should be_false
Query.new(condition_a).same_query?({} of Symbol => String).should be_false
Expand All @@ -20,20 +22,21 @@ module ActiveRecord
end

it "is the same query if other is a Query with the same condition" do
condition_a = double("Condition")
condition_b = double("Condition")
condition_a = Mocks::Macro.double("Condition")
condition_b = Mocks::Macro.double("Condition")

allow(condition_a).to receive(instance.==(condition_b)).and_return(true)
Query.new(condition_a).same_query?(Query.new(condition_b)).should be_true
end

it "is not the same query if other is a Query with different condition" do
condition_a = double("Condition")
condition_b = double("Condition")
condition_a = Mocks::Macro.double("Condition")
condition_b = Mocks::Macro.double("Condition")

allow(condition_a).to receive(instance.==(condition_b)).and_return(false)
Query.new(condition_a).same_query?(Query.new(condition_b)).should be_false
end
end
end

end
2 changes: 1 addition & 1 deletion src/sql/query_generator.cr
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module ActiveRecord
getter query
getter params

@params :: Hash(String, ::ActiveRecord::SupportedType)
@params : Hash(String, ::ActiveRecord::SupportedType)

def self.[](*args)
new(*args)
Expand Down