Skip to content

Commit

Permalink
Testing issue #1011
Browse files Browse the repository at this point in the history
  • Loading branch information
jwoertink committed Mar 17, 2024
1 parent d8909ef commit 97758ab
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 0 deletions.
14 changes: 14 additions & 0 deletions db/migrations/20240317161918_create_interviews.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class CreateInterviews::V20240317161918 < Avram::Migrator::Migration::V1
def migrate
create table_for(Interview) do
primary_key id : Int64
add_timestamps
add_belongs_to interviewer : User, on_delete: :cascade
add_belongs_to interviewee : User, on_delete: :cascade
end
end

def rollback
drop table_for(Interview)
end
end
12 changes: 12 additions & 0 deletions spec/avram/query_associations_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -176,4 +176,16 @@ describe "Query associations" do

result.should eq(product)
end

it "handles aliases", focus: true do
interviewer = UserFactory.create(&.available_for_hire(false).name("Interviewer"))
interviewee = UserFactory.create(&.available_for_hire(true).name("Interviewee"))
UserFactory.create(&.available_for_hire(false).name("Employed"))
InterviewFactory.create(&.interviewee(interviewee).interviewer(interviewer))

InterviewQuery.new

Check failure on line 186 in spec/avram/query_associations_spec.cr

View workflow job for this annotation

GitHub Actions / specs (shard.yml, 12, 1.6.2, false)

got: "SELECT interviews.id, interviews.created_at, interviews.updated_at, interviews.interviewer_id, interviews.interviewee_id FROM interviews INNER JOIN users ON interviews.interviewer_id = users.id WHERE users.available_for_hire = 'false' AND users.available_for_hire = 'true'"

Check failure on line 186 in spec/avram/query_associations_spec.cr

View workflow job for this annotation

GitHub Actions / specs (shard.yml, 12, latest, false)

got: "SELECT interviews.id, interviews.created_at, interviews.updated_at, interviews.interviewer_id, interviews.interviewee_id FROM interviews INNER JOIN users ON interviews.interviewer_id = users.id WHERE users.available_for_hire = 'false' AND users.available_for_hire = 'true'"

Check failure on line 186 in spec/avram/query_associations_spec.cr

View workflow job for this annotation

GitHub Actions / specs (shard.yml, 13, 1.6.2, false)

got: "SELECT interviews.id, interviews.created_at, interviews.updated_at, interviews.interviewer_id, interviews.interviewee_id FROM interviews INNER JOIN users ON interviews.interviewer_id = users.id WHERE users.available_for_hire = 'false' AND users.available_for_hire = 'true'"

Check failure on line 186 in spec/avram/query_associations_spec.cr

View workflow job for this annotation

GitHub Actions / specs (shard.yml, 13, latest, false)

got: "SELECT interviews.id, interviews.created_at, interviews.updated_at, interviews.interviewer_id, interviews.interviewee_id FROM interviews INNER JOIN users ON interviews.interviewer_id = users.id WHERE users.available_for_hire = 'false' AND users.available_for_hire = 'true'"

Check failure on line 186 in spec/avram/query_associations_spec.cr

View workflow job for this annotation

GitHub Actions / specs (shard.yml, 14, 1.6.2, false)

got: "SELECT interviews.id, interviews.created_at, interviews.updated_at, interviews.interviewer_id, interviews.interviewee_id FROM interviews INNER JOIN users ON interviews.interviewer_id = users.id WHERE users.available_for_hire = 'false' AND users.available_for_hire = 'true'"

Check failure on line 186 in spec/avram/query_associations_spec.cr

View workflow job for this annotation

GitHub Actions / specs (shard.yml, 14, latest, false)

got: "SELECT interviews.id, interviews.created_at, interviews.updated_at, interviews.interviewer_id, interviews.interviewee_id FROM interviews INNER JOIN users ON interviews.interviewer_id = users.id WHERE users.available_for_hire = 'false' AND users.available_for_hire = 'true'"

Check failure on line 186 in spec/avram/query_associations_spec.cr

View workflow job for this annotation

GitHub Actions / specs (shard.edge.yml, latest, 14, true)

got: "SELECT interviews.id, interviews.created_at, interviews.updated_at, interviews.interviewer_id, interviews.interviewee_id FROM interviews INNER JOIN users ON interviews.interviewer_id = users.id WHERE users.available_for_hire = 'false' AND users.available_for_hire = 'true'"

Check failure on line 186 in spec/avram/query_associations_spec.cr

View workflow job for this annotation

GitHub Actions / specs (shard.yml, nightly, 14, true)

got: "SELECT interviews.id, interviews.created_at, interviews.updated_at, interviews.interviewer_id, interviews.interviewee_id FROM interviews INNER JOIN users ON interviews.interviewer_id = users.id WHERE users.available_for_hire = 'false' AND users.available_for_hire = 'true'"
.where_interviewer(UserQuery.new.available_for_hire(false))
.where_interviewee(UserQuery.new.available_for_hire(true))
.to_prepared_sql.should eq("nothing")
end
end
20 changes: 20 additions & 0 deletions spec/support/factories/interview_factory.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
class InterviewFactory < BaseFactory
def initialize
before_save do
if operation.interviewer_id.value.nil?
interviewer(UserFactory.create)
end
if operation.interviewee_id.value.nil?
interviewee(UserFactory.create)
end
end
end

def interviewer(u : User)
interviewer_id(u.id)
end

def interviewee(u : User)
interviewee_id(u.id)
end
end
9 changes: 9 additions & 0 deletions spec/support/models/interview.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class Interview < BaseModel
table do
belongs_to interviewer : User
belongs_to interviewee : User
end
end

class InterviewQuery < Interview::BaseQuery
end

0 comments on commit 97758ab

Please sign in to comment.