Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
mjy committed Sep 14, 2018
2 parents c7eb723 + 99eea09 commit e7ac16c
Show file tree
Hide file tree
Showing 12 changed files with 94 additions and 42 deletions.
6 changes: 6 additions & 0 deletions Dockerfile
Expand Up @@ -64,9 +64,15 @@ RUN chmod +x /etc/my_init.d/init.sh && \
chmod +x /app/public/images/tmp && \
rm -f /etc/service/nginx/down



RUN chown 9999:9999 /app/public
RUN chown 9999:9999 /app/public/images/tmp
RUN chown 9999:9999 /app/public/packs
RUN chown 9999:9999 /app/log/

RUN touch /app/log/production.log
RUN chmod 0664 /app/log/production.log

CMD ["/sbin/my_init"]

Expand Down
6 changes: 5 additions & 1 deletion app/controllers/biological_associations_controller.rb
Expand Up @@ -12,7 +12,11 @@ def index
render '/shared/data/all/index'
}
format.json {
@biological_associations = Queries::BiologicalAssociation::Filter.new(filter_params).all.where(project_id: sessions_current_project_id).page(params[:page] || 1).per(100)
@biological_associations = Queries::BiologicalAssociation::Filter
.new(filter_params)
.all
.where(project_id: sessions_current_project_id)
.page(params[:page] || 1).per(500)
}
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/image.rb
Expand Up @@ -249,7 +249,7 @@ def self.scaled_to_box(params)
if ratio > 1 # wide into tall
c.resize(params[:box_width].to_i, (params[:box_height].to_f / ratio * box_ratio).to_i)
else # tall into tall
c.resize((params[:box_width ].to_f).to_i, (params[:box_height].to_f / ratio * box_ratio).to_i)
c.resize((params[:box_width ].to_f * ratio * box_ratio ).to_i, (params[:box_height].to_f ).to_i)
end
end
end
Expand Down
52 changes: 30 additions & 22 deletions app/models/person.rb
Expand Up @@ -169,8 +169,6 @@ def levenshtein_similar(cutoff = 4)
Person.where('levenshtein(last_name, ?) < ? and levenshtein(first_name, ?) < ?', last_name, cutoff, first_name, cutoff)
end

# rubocop:disable Metrics/BlockNesting
# rubocop:disable Metrics/MethodLength
# @param [Integer] person_id
# @return [Boolean]
# true if all records updated, false if any one failed (all or none)
Expand All @@ -184,12 +182,13 @@ def merge_with(person_id)
# rubocop:disable Rails/SaveBang
Role.where(person_id: r_person.id).update(person: self) # update merge person's roles to old
# rubocop:enable Rails/SaveBang
l_person_hash = self.annotations_hash
l_person_hash = annotations_hash

unless r_person.first_name.blank?
if self.first_name.blank?
self.update(first_name: r_person.first_name)
if first_name.blank?
update(first_name: r_person.first_name)
else
if self.first_name != r_person.first_name
if first_name != r_person.first_name
# create a first_name alternate_value of the r_person first name
skip_av = false
av_list = l_person_hash['alternate values']
Expand All @@ -205,13 +204,15 @@ def merge_with(person_id)
end
end

AlternateValue::AlternateSpelling.create!(alternate_value_object_type: 'Person',
value: r_person.first_name,
alternate_value_object_attribute: 'first_name',
alternate_value_object_id: id) unless skip_av
AlternateValue::AlternateSpelling.create!(
alternate_value_object_type: 'Person',
value: r_person.first_name,
alternate_value_object_attribute: 'first_name',
alternate_value_object_id: id) unless skip_av
end
end
end

unless r_person.last_name.blank?
if self.last_name.blank?
self.update(last_name: r_person.last_name)
Expand Down Expand Up @@ -240,6 +241,7 @@ def merge_with(person_id)
end
end
end

r_person.annotations_hash.each do |r_kee, r_objects|
r_objects.each do |r_o|
skip = false
Expand Down Expand Up @@ -288,59 +290,65 @@ def merge_with(person_id)
skip
end
unless skip
# r_err = r_o
r_o.annotated_object = self
r_o.save!
# r_o
end
end
end

# TODO: handle prefix and suffix
if self.prefix.blank?
self.prefix = r_person.prefix
if prefix.blank?
write_attribute(:prefix, r_person.prefix)
else
unless r_person.prefix.blank?
# What to do when both have some content?
end
end
if self.suffix.blank?

if suffix.blank?
self.suffix = r_person.suffix
else
unless r_person.suffix.blank?
# What to do when both have some content?
end
end

# TODO: handle years attributes
if self.year_born.nil?
if year_born.nil?
self.year_born = r_person.year_born
else
unless r_person.year_born.nil?
# What to do when both have some (different) numbers?
end
end
if self.year_died.nil?

if year_died.nil?
self.year_died = r_person.year_died
else
unless r_person.year_died.nil?
# What to do when both have some (different) numbers?
end
end

if r_person.year_active_start # if not, r_person has nothing to contribute
if self.year_active_start.nil? || (self.year_active_start > r_person.year_active_start)
self.year_active_start = r_person.year_active_start
end
end

if r_person.year_active_end # if not, r_person has nothing to contribute
if self.year_active_end.nil? || (self.year_active_end < r_person.year_active_end)
self.year_active_end = r_person.year_active_end
end
end

# update type, if necesssary
if self.type.include?('Unv')
unless unvetted
self.update(type: 'Person::Vetted')
end
end

# last thing to do in the transaction...
self.save! unless self.persisted?
end
Expand All @@ -351,9 +359,6 @@ def merge_with(person_id)
true
end

# rubocop:enable Metrics/BlockNesting
# rubocop:enable Metrics/MethodLength

# @return [Boolean]
def is_determiner?
determiner_roles.to_a.length > 0
Expand Down Expand Up @@ -404,8 +409,11 @@ def activity_ended_after_started

# @return [Ignored]
def not_active_after_death
errors.add(:year_active_start, 'is older than year of death') if year_active_start && year_died && year_active_start > year_died
errors.add(:year_active_end, 'is older than year of death') if year_active_end && year_died && year_active_end > year_died
unless is_editor? || is_author?
errors.add(:year_active_start, 'is older than year of death') if year_active_start && year_died && year_active_start > year_died
errors.add(:year_active_end, 'is older than year of death') if year_active_end && year_died && year_active_end > year_died
end
true
end

# @return [Ignored]
Expand Down
2 changes: 1 addition & 1 deletion app/models/role/project_role.rb
Expand Up @@ -2,7 +2,6 @@
# @todo Refactor after Housekeeping / FactoryBot issues resolved (nested set!!)
#
class Role::ProjectRole < Role

# self.abstract_class = true

include Housekeeping
Expand All @@ -13,6 +12,7 @@ class Role::ProjectRole < Role

protected

# TODO: this doesn't do what we think it does
def set_project_if_possible
self.project = self.role_object.project if self.role_object && self.project.nil?
end
Expand Down
1 change: 0 additions & 1 deletion app/models/taxon_name_author.rb
@@ -1,5 +1,4 @@
class TaxonNameAuthor < Role::ProjectRole
include Housekeeping

def self.human_name
'Taxon name author'
Expand Down
1 change: 0 additions & 1 deletion app/models/type_designator.rb
@@ -1,5 +1,4 @@
class TypeDesignator < Role::ProjectRole
include Housekeeping

def self.human_name
'Type designator'
Expand Down
12 changes: 12 additions & 0 deletions config/routes.rb
Expand Up @@ -1035,6 +1035,18 @@
get '/character_states/:id/annotations',
to: 'character_states#annotations'

# TODO: DRY
# Generate shallow routes for annotations based on model properties, like
# otu_citations GET /otus/:otu_id/citations(.:format) citations#index
ApplicationEnumeration.data_models.each do |m|
Shared::IsData::Annotation::ANNOTATION_TYPES.each do |t|
if m.send("has_#{t}?")
n = m.model_name
match "/#{n.route_key}/:#{n.param_key}_id/#{t}", to: "#{t}#index", via: :get, constraints: {format: :json}, defaults: {format: :json}
end
end
end

end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/queries/biological_association/filter.rb
Expand Up @@ -90,7 +90,7 @@ def all
if a = and_clauses
::BiologicalAssociation.where(and_clauses)
else
::BiologicalAssociation.none
::BiologicalAssociation.all
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/tasks/tw.rake
Expand Up @@ -72,7 +72,7 @@ namespace :tw do
end
@args.merge!(data_directory: (ENV['data_directory'] || default))
# TODO: Use Dir.exists? and fix tasks that are treating data_directory as a file parameter
raise "path (#{default}) not found" if !File.exists?(@args[:data_directory])
raise Rainbow("Path to data directory (#{default}) not found").red if !File.exists?(@args[:data_directory])
@args
end

Expand Down
48 changes: 36 additions & 12 deletions spec/models/person_spec.rb
Expand Up @@ -55,6 +55,7 @@

context 'years' do
before { person.year_died = 1920 }

specify 'died after birth' do
person.year_born = 1930
person.valid?
Expand All @@ -67,21 +68,44 @@
expect(person.errors.include?(:year_active_start)).to be_truthy
end

context 'as author/editor' do
before do
person.last_name = 'Smith'
person.save!
end

specify 'active after death as editor - active start' do
source_bibtex.editors << person
person.reload
person.year_active_start = 1930
person.valid?
expect(person.errors.include?(:year_active_start)).to be_falsey
end

specify 'active after death as author - active start' do
source_bibtex.authors << person
person.reload
person.year_active_start = 1930
person.valid?
expect(person.errors.include?(:year_active_start)).to be_falsey
end
end

specify 'not active after death - active end' do
person.year_active_end = 1930
person.valid?
expect(person.errors.include?(:year_active_end)).to be_truthy
end

specify 'not active before birth - active start' do
person.year_born = 1920
person.year_born = 1920
person.year_active_start = 1890
person.valid?
expect(person.errors.include?(:year_active_start)).to be_truthy
end

specify 'not active before birth - active end' do
person.year_born = 1920
person.year_born = 1920
person.year_active_end = 1890
person.valid?
expect(person.errors.include?(:year_active_end)).to be_truthy
Expand Down Expand Up @@ -178,9 +202,9 @@
p = FactoryBot.create(:person,
first_name: 'January', last_name: 'Smith',
prefix: 'Dr.', suffix: 'III')
gr2.georeferencers << p
p.data_attributes << da1
p
gr2.georeferencers << p
p.data_attributes << da1
p
}
let!(:person1a) {
p = person1.dup
Expand All @@ -194,11 +218,11 @@
# type: 'Person::Unvetted',
year_born: 2000, year_died: 2015,
year_active_start: 2012, year_active_end: 2015)
tn2.taxon_name_authors << p
tn1.taxon_name_authors << p
gr1.georeferencers << p
p.data_attributes << da2
p
tn2.taxon_name_authors << p
tn1.taxon_name_authors << p
gr1.georeferencers << p
p.data_attributes << da2
p
}
let(:person1c) {
p = FactoryBot.create(:person,
Expand All @@ -207,8 +231,8 @@
# type: 'Person::Unvetted',
year_born: 2000, year_died: 2015,
year_active_start: 2012, year_active_end: 2015)
# additional attributes not replicated yet
p
# additional attributes not replicated yet
p
}
let(:person2) { FactoryBot.create(:person, first_name: 'J.', last_name: 'McDonald') }
let(:person3) { FactoryBot.create(:person, first_name: 'D. Keith McE.', last_name: 'Kevan') }
Expand Down
2 changes: 1 addition & 1 deletion spec/support/features/authentication_helpers.rb
Expand Up @@ -4,7 +4,7 @@ module AuthenticationHelpers

def sign_in_with(email, password)
visit signin_path
fill_in 'session_email', with: email, wait: 8, id: 'session_email'
fill_in 'session_email', with: email, wait: 9, id: 'session_email'
fill_in 'session_password', with: password, wait: 8, id: 'session_password'
click_button 'sign_in'
find_link('sign_out') # TODO: check for Capybara bug fix down the road?
Expand Down

0 comments on commit e7ac16c

Please sign in to comment.