Skip to content
This repository has been archived by the owner on Aug 12, 2018. It is now read-only.

Commit

Permalink
i can't even remember but all tests pass
Browse files Browse the repository at this point in the history
  • Loading branch information
slmyers committed Mar 1, 2016
1 parent 43a92ad commit b410801
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 20 deletions.
9 changes: 7 additions & 2 deletions backend/app/lib/auto_complete.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
require 'set'
class AutoComplete
def self.find(name)
@name = "%#{name}%".downcase
@response = Person.where("name LIKE ?", @name)
@institutions = Search.get_institutions(@response)
@response = Person.where("name LIKE ?", @name).includes(:institution)
@institutions = Set.new
@response.each do |p|
@institutions.add(p.institution)
end

return {'people' => @response, 'institutions' => @institutions}
end
end
6 changes: 1 addition & 5 deletions backend/app/lib/search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def Search.relations_by_id(person_id)
'target' => Array.new,
'mentors' => Array.new, 'mentored' => Array.new,
'supervisors' => Array.new, 'supervised' => Array.new,
'institutions' => Array.new, 'people' => Array.new
'institutions' => Array.new
}
end

Expand All @@ -52,10 +52,6 @@ def Search.relations_by_id(person_id)
.includes(:institution)
unless @supervised.blank? then @persons.add(@supervised) end

# there is a possible optimization to make, but doing so makes the returned values unwieldy
# check here for more info
# https://github.com/401ChemistryGenealogy/ChemistryGenealogy/wiki/interesting-trace-from-search

@persons.each do |p|
p.each do |person|
@institutions.add(person.institution)
Expand Down
7 changes: 7 additions & 0 deletions backend/lib/tasks/test_data.rake
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ namespace :app do
Supervision.delete_all
Mentorship.delete_all

User.create!([
{
password: 'testPassword', email: '[email protected]', password_digest: 'pword',
first_name: 'first', last_name: 'last', approved: true
}
])

# Other test data should be added here...
Institution.create!([
{name: 'university of alberta', approved: true},
Expand Down
5 changes: 3 additions & 2 deletions backend/reloadDB.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#!/bin/bash
# i'm sure not all these are required, but my god i've been given so many
# headaches i'm just using the hammer here
# uses migrations to construct database then seeds database with test data
# use migrations to construct database
rake db:drop
rake db:migrate
rake db:schema:load
# seed development database with sample data etc
RAILS_ENV=development rake db:seed
# change to development or test depending on context
# load test data into test db
RAILS_ENV=test rake app:load_demo_data
2 changes: 0 additions & 2 deletions backend/spec/controllers/auto_complete_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
=begin
require 'rails_helper'

RSpec.configure do |config|
Expand All @@ -25,4 +24,3 @@
end
end
end
=end
3 changes: 1 addition & 2 deletions backend/spec/controllers/people_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
=begin

require 'rails_helper'

RSpec.configure do |config|
Expand All @@ -19,4 +19,3 @@
end
end
end
=end
1 change: 0 additions & 1 deletion backend/spec/controllers/search_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
get :index, :format => :json, :name => 'set all_relations_focal'
expect(response.status).to eq 200
expect(assigns(:response)).not_to be_nil
puts assigns(:response).to_json
expect(response.body == assigns(:response).to_json).to be(true)
end

Expand Down
7 changes: 3 additions & 4 deletions backend/spec/lib/auto_complete_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
=begin

describe AutoComplete do
it "is instantiable" do
@auto = AutoComplete.new
Expand All @@ -21,14 +21,13 @@
end

it "tod will return todd lowary and university of alberta" do
@res = AutoComplete.find('tod')
@res = AutoComplete.find('no')
@people = @res["people"]
expect(@people.length == 1).to be(true)
expect(@people.first.name == 'todd lowary').to be(true)
expect(@people.first.name == 'no relations').to be(true)
@institutions = @res["institutions"]
expect(@institutions.length == 1).to be(true)
expect(@institutions.first.name == 'university of alberta').to be(true)
expect(@institutions.find(@people.first.institution_id)).not_to eql(nil)
end
end
=end
3 changes: 1 addition & 2 deletions backend/spec/lib/search_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
expect(@search).not_to eql(nil)
end

it "returns 6 required fields in hash" do
it "returns 5 required fields in hash" do
@result = Search.relations_by_id(1)
expect(@result["target"]).not_to eql(nil)
expect(@result["mentors"]).not_to eql(nil)
Expand All @@ -24,7 +24,6 @@
expect(@result["supervisors"].length).to eql(0)
expect(@result["supervised"].length).to eql(0)
expect(@result["institutions"].length).to eql(0)
expect(@result["people"].length).to eql(0)
end

it "for every mentor there is a person obj" do
Expand Down

0 comments on commit b410801

Please sign in to comment.