forked from openSNP/snpr
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request openSNP#19 from tsujigiri/known_phenotypes
Nice work, lots of unnecessary stuff is gone
- Loading branch information
Showing
8 changed files
with
67 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,19 @@ | ||
class Phenotype < ActiveRecord::Base | ||
has_many :user_phenotypes | ||
has_many :phenotype_comments | ||
serialize :known_phenotypes | ||
has_many :user_phenotypes, dependent: :destroy | ||
has_many :phenotype_comments, dependent: :destroy | ||
|
||
validates_presence_of :characteristic | ||
validates_presence_of :characteristic | ||
|
||
searchable do | ||
text :characteristic | ||
end | ||
|
||
after_create :default_array | ||
|
||
def default_array | ||
self.known_phenotypes ||= [] | ||
end | ||
|
||
searchable do | ||
text :characteristic | ||
end | ||
|
||
def known_phenotypes | ||
@known_phenotypes ||= | ||
user_phenotypes.map(&:variation). | ||
map(&:downcase). | ||
uniq. | ||
map(&:camelize) | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
require_relative '../test_helper' | ||
|
||
class PhenotypeTest < ActiveSupport::TestCase | ||
context "Phenotype" do | ||
setup do | ||
Sunspot.stubs(:index) | ||
@phenotype = Factory(:phenotype) | ||
@phenotype.instance_variable_set(:@known_phenotypes, nil) | ||
end | ||
|
||
should "know some phenotypes" do | ||
@phenotype.user_phenotypes.create(variation: "Ping pong") | ||
@phenotype.user_phenotypes.create(variation: "ping pong") | ||
assert_equal ["Ping pong"], @phenotype.known_phenotypes | ||
end | ||
end | ||
end |