Skip to content

Commit

Permalink
Merge pull request openSNP#20 from tsujigiri/known_phenotypes
Browse files Browse the repository at this point in the history
Known phenotypes
  • Loading branch information
gedankenstuecke committed Mar 31, 2012
2 parents ce41ad1 + fa00177 commit 1f5bca4
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 44 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -20,3 +20,4 @@ vendor/bundle
public/data
coverage*
hiredis/
log/
1 change: 1 addition & 0 deletions .travis.yml
Expand Up @@ -4,6 +4,7 @@ env: DB=postgres
before_install:
- git clone https://github.com/antirez/hiredis.git && cd hiredis && make && sudo make install && sudo ldconfig && cd ..
before_script:
- bash -c "find /home/vagrant/.rvm/gems -name sunspot_test.rb -exec sed -i 's/at_exit/#at_exit/' {} \;"
- cp config/database.yml.ci config/database.yml
- echo "foo" > mail_username.txt
- echo "bar" > mail_password.txt
Expand Down
1 change: 1 addition & 0 deletions Gemfile
Expand Up @@ -47,6 +47,7 @@ group :test do
gem 'factory_girl'
gem 'mocha'
gem 'ruby-debug19'
gem 'sunspot_test'
end

# gem 'email_veracity' # to check whether user-mails are OK
Expand Down
40 changes: 5 additions & 35 deletions Gemfile.ci
Expand Up @@ -32,38 +32,8 @@ gem 'paperclip', '~> 2.4'
gem 'friendly_id', :git => 'https://github.com/norman/friendly_id.git'
gem 'recommendify', :git => 'https://github.com/paulasmuth/recommendify.git'

#group :production do
# gem 'rpm_contrib'
# gem 'newrelic_rpm'
#end

group :test do
gem 'shoulda-context'
gem 'shoulda-matchers'
gem 'factory_girl'
gem 'mocha'
gem 'ruby-debug19'
end


# gem 'email_veracity' # to check whether user-mails are OK
# authlogic does that anyway

# Use unicorn as the web server
# gem 'unicorn'

# Deploy with Capistrano
# gem 'capistrano'

# Bundle the extra gems:
# gem 'bj'
# gem 'nokogiri'
# gem 'sqlite3-ruby', :require => 'sqlite3'
# gem 'aws-s3', :require => 'aws/s3'

# Bundle gems for the local environment. Make sure to
# put test-only gems in this group so their generators
# and rake tasks are available in development mode:
# group :development, :test do
# gem 'webrat'
# end
gem 'shoulda-context'
gem 'shoulda-matchers'
gem 'factory_girl'
gem 'mocha'
gem 'sunspot_test'
3 changes: 3 additions & 0 deletions Gemfile.lock
Expand Up @@ -157,6 +157,8 @@ GEM
sunspot_rails (1.2.1)
nokogiri
sunspot (= 1.2.1)
sunspot_test (0.4.0)
sunspot_rails (>= 1.2.1)
thor (0.14.6)
tilt (1.3.3)
treetop (1.4.10)
Expand Down Expand Up @@ -194,4 +196,5 @@ DEPENDENCIES
shoulda-context
shoulda-matchers
sunspot_rails (~> 1.2.1)
sunspot_test
will_paginate (= 3.0.pre2)
7 changes: 5 additions & 2 deletions app/jobs/zipgenotypingfiles.rb
Expand Up @@ -3,8 +3,11 @@
class Zipgenotypingfiles
@queue = :zipgenotyping

def self.perform(phenotype_id,variation,target_address)
@user_phenotypes = UserPhenotype.find_all_by_phenotype_id_and_variation(phenotype_id,variation)
def self.perform(phenotype_id, variation, target_address)
@user_phenotypes = UserPhenotype.search do
with :phenotype_id, phenotype_id
fulltext variation
end.results
@genotyping_files = []
@user_phenotypes.each do |up|
@user = User.find_by_id(up.user_id)
Expand Down
15 changes: 8 additions & 7 deletions app/models/user_phenotype.rb
@@ -1,11 +1,12 @@
class UserPhenotype < ActiveRecord::Base
belongs_to :phenotype, dependent: :destroy
belongs_to :user
validates_presence_of :variation
belongs_to :phenotype, dependent: :destroy
belongs_to :user
validates_presence_of :variation

attr_accessible :variation,:phenotype_id,:js_modal
attr_accessible :variation,:phenotype_id,:js_modal

searchable do
text :variation
end
searchable do
text :variation
integer :phenotype_id
end
end
2 changes: 2 additions & 0 deletions test/test_helper.rb
Expand Up @@ -2,6 +2,8 @@
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'
require "authlogic/test_case"
SunspotTest.solr_startup_timeout = 30
require 'sunspot_test/test_unit'

class ActiveSupport::TestCase
FactoryGirl.find_definitions
Expand Down
25 changes: 25 additions & 0 deletions test/unit/user_phenotype_test.rb
@@ -0,0 +1,25 @@
require_relative '../test_helper'

class UserPhenotypeTest < ActiveSupport::TestCase
context "UserPhenotype" do
setup do
@phenotype = Factory :phenotype
@user_phenotype_0 = Factory :user_phenotype,
phenotype_id: @phenotype.id, variation: 'male'
@user_phenotype_1 = Factory :user_phenotype,
phenotype_id: @phenotype.id, variation: 'female'
@user_phenotype_2 = Factory :user_phenotype,
phenotype_id: @phenotype.id + 1, variation: 'male'
Sunspot.commit
end

should "find similar user phenotypes" do
phenotype = @phenotype
results = UserPhenotype.search do
with(:phenotype_id, phenotype.id)
fulltext 'male'
end.results
assert_equal [@user_phenotype_0], results.sort_by(&:id)
end
end
end

0 comments on commit 1f5bca4

Please sign in to comment.