Skip to content

Commit

Permalink
Misc formatting.
Browse files Browse the repository at this point in the history
  • Loading branch information
TuckerJD committed Aug 13, 2014
1 parent af97710 commit 6fbb093
Show file tree
Hide file tree
Showing 13 changed files with 140 additions and 145 deletions.
4 changes: 2 additions & 2 deletions Gemfile
Expand Up @@ -39,8 +39,8 @@ gem 'jquery-turbolinks'
gem 'jbuilder', '~> 2.0'
gem 'chronic', '~> 0.10'

gem 'awesome_nested_set',
git: 'https://github.com/collectiveidea/awesome_nested_set.git'
gem 'awesome_nested_set',
git: 'https://github.com/collectiveidea/awesome_nested_set.git'
# tag: 'v3.0.0.rc.5',

# BibTex handling
Expand Down
14 changes: 7 additions & 7 deletions app/models/asserted_distribution.rb
Expand Up @@ -12,14 +12,14 @@ class AssertedDistribution < ActiveRecord::Base
validates_presence_of :source_id, message: 'Source is not selected'
validates_uniqueness_of :geographic_area_id, scope: [:otu_id, :source_id], message: 'Duplicate record'

scope :with_otu_id, -> (otu_id) {where(otu_id: otu_id)}
scope :with_geographic_area_id, -> (geographic_area_id) {where(geographic_area_id: geographic_area_id)}
scope :with_geographic_area_array, -> (geographic_area_array) {where('geographic_area_id IN (?)', geographic_area_array ) }
scope :with_is_absent, -> {where('is_absent = true')}
scope :without_is_absent, -> {where('is_absent = false OR is_absent is Null')}
scope :with_otu_id, -> (otu_id) { where(otu_id: otu_id) }
scope :with_geographic_area_id, -> (geographic_area_id) { where(geographic_area_id: geographic_area_id) }
scope :with_geographic_area_array, -> (geographic_area_array) { where('geographic_area_id IN (?)', geographic_area_array) }
scope :with_is_absent, -> { where('is_absent = true') }
scope :without_is_absent, -> { where('is_absent = false OR is_absent is Null') }

# TODO: this should be a housekeeping scope
scope :not_self, -> (id) {where('asserted_distribution.id <> ?', id )}
scope :not_self, -> (id) { where('asserted_distribution.id <> ?', id) }

soft_validate(:sv_conflicting_geographic_area, set: :conflicting_geographic_area)

Expand All @@ -32,7 +32,7 @@ def sv_conflicting_geographic_area
presence = AssertedDistribution.without_is_absent.with_geographic_area_id(self.geographic_area_id) # this returns an array, not a single GA so test below is not right
soft_validations.add(:geographic_area_id, "Taxon is reported as present in #{presence.first.geographic_area.name}") unless presence.empty?
else
areas = [ga.level0_id, ga.level1_id, ga.level2_id].compact
areas = [ga.level0_id, ga.level1_id, ga.level2_id].compact
presence = AssertedDistribution.with_is_absent.with_geographic_area_array(areas)
soft_validations.add(:geographic_area_id, "Taxon is reported as missing in #{presence.first.geographic_area.name}") unless presence.empty?
end
Expand Down
13 changes: 5 additions & 8 deletions app/models/project.rb
Expand Up @@ -4,7 +4,7 @@ class Project < ActiveRecord::Base
store_accessor :workbench_settings, :worker_tasks, :workbench_starting_path

DEFAULT_WORKBENCH_STARTING_PATH = '/hub'
DEFAULT_WORKBENCH_SETTINGS = {
DEFAULT_WORKBENCH_SETTINGS = {
'workbench_starting_path' => DEFAULT_WORKBENCH_STARTING_PATH
}

Expand All @@ -21,9 +21,8 @@ def clear_workbench_settings
self.update('workbench_settings' => DEFAULT_WORKBENCH_SETTINGS)
end


# TODO: wrap this in an authentication layer, and protect it?

def nuke
begin
ActiveRecord::Base.descendants.each do |d|
Expand All @@ -33,19 +32,17 @@ def nuke
end
rescue
raise
end
end
end



protected

def set_default_workbench_settings
self.workbench_settings = DEFAULT_WORKBENCH_SETTINGS.merge(self.workbench_settings ||= {})
end

def self.find_for_autocomplete(params)
where('name LIKE ?', "#{params[:term]}%")
end
end

end
12 changes: 5 additions & 7 deletions app/models/tag.rb
@@ -1,6 +1,6 @@
class Tag < ActiveRecord::Base
include Housekeeping

acts_as_list scope: [:keyword_id]

belongs_to :keyword
Expand All @@ -10,32 +10,30 @@ class Tag < ActiveRecord::Base
validates :keyword, presence: true
validate :keyword_is_allowed_on_object, :object_can_be_tagged_with_keyword

validates_uniqueness_of :keyword_id, scope: [ :tag_object_id, :tag_object_type]
validates_uniqueness_of :keyword_id, scope: [:tag_object_id, :tag_object_type]

def tag_object_class
tag_object.class
end

def self.find_for_autocomplete(params)
# todo: @mjy figure out how to reach through the table for a list of controlled_vocabulary_terms.names
# where('name LIKE ?', "#{params[:term]}%")

# todo: @mjy below code is running but not giving results we want
terms = params[:term].split.collect{ |t| "'#{t}%'"}.join(' or ')
terms = params[:term].split.collect { |t| "'#{t}%'" }.join(' or ')
joins(:keyword).where('controlled_vocabulary_terms.name like ?', terms) # "#{params[:term]}%" )
end

protected

def keyword_is_allowed_on_object
return true if keyword.nil? || tag_object.nil? || !keyword.respond_to?(:can_tag)
return true if keyword.nil? || tag_object.nil? || !keyword.respond_to?(:can_tag)
if !keyword.can_tag.include?(tag_object.class.name)
errors.add(:keyword, "this keyword class (#{tag_object.class}) can not be attached to a #{tag_object_type}")
end
end

def object_can_be_tagged_with_keyword
return true if keyword.nil? || tag_object.nil? || !tag_object.respond_to?(:taggable_with)
return true if keyword.nil? || tag_object.nil? || !tag_object.respond_to?(:taggable_with)
if !tag_object.taggable_with.include?(keyword.class.name)
errors.add(:tag_object, "this tag_object_type (#{tag_object.class}) can not be tagged with this keyword class (#{keyword.class})")
end
Expand Down
12 changes: 6 additions & 6 deletions app/models/taxon_name.rb
Expand Up @@ -679,9 +679,9 @@ def validate_parent_rank_is_higher
end

if (self.rank_class != self.rank_class_was) && # @proceps this catches nothing, as self.rank_class_was is never defined!
self.children &&
!self.children.empty? &&
RANKS.index(self.rank_string) >= self.children.collect { |r| RANKS.index(r.rank_string) }.max
self.children &&
!self.children.empty? &&
RANKS.index(self.rank_string) >= self.children.collect { |r| RANKS.index(r.rank_string) }.max
errors.add(:rank_class, "The taxon rank (#{self.rank_class.rank_name}) is not higher than child ranks")
end
end
Expand All @@ -697,7 +697,7 @@ def validate_rank_class_class

# @proceps self.rank_class_was is not a class method anywhere, so this comparison is vs. nil
def check_new_rank_class
if (self.rank_class != self.rank_class_was) &&
if (self.rank_class != self.rank_class_was) &&
!self.rank_class_was.nil?
old_rank_group = self.rank_class_was.safe_constantize.parent
if self.rank_class.parent != old_rank_group
Expand All @@ -716,11 +716,11 @@ def check_new_parent_class
end

def validate_source_type
errors.add(:source_id, 'Source must be a Bibtex') if self.source && self.source.type != 'Source::Bibtex'
errors.add(:source_id, 'Source must be a Bibtex') if self.source && self.source.type != 'Source::Bibtex'
end

def validate_one_root_per_project
errors.add(:parent_id, 'Only one root allowed per project') if TaxonName.where(parent_id: nil, project_id: self.project_id ).count > 1
errors.add(:parent_id, 'Only one root allowed per project') if TaxonName.where(parent_id: nil, project_id: self.project_id).count > 1
end

#TODO: validate, that all the ranks in the table could be linked to ranks in classes (if those had changed)
Expand Down
18 changes: 9 additions & 9 deletions config/environments/test.rb
Expand Up @@ -5,34 +5,34 @@
# test suite. You never need to work with it otherwise. Remember that
# your test database is "scratch space" for the test suite and is wiped
# and recreated between test runs. Don't rely on the data there!
config.cache_classes = false # true
config.cache_classes = false # true

# Do not eager load code on boot. This avoids loading your whole application
# just for the purpose of running a single test. If you are using a tool that
# preloads Rails for running tests, you may have to set it to true.
config.eager_load = false
config.eager_load = false

# Configure static asset server for tests with Cache-Control for performance.
config.serve_static_assets = true
config.static_cache_control = "public, max-age=3600"
config.serve_static_assets = true
config.static_cache_control = "public, max-age=3600"

# Show full error reports and disable caching.
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
config.consider_all_requests_local = true
config.action_controller.perform_caching = false

# Raise exceptions instead of rendering exception templates.
config.action_dispatch.show_exceptions = false
config.action_dispatch.show_exceptions = false

# Disable request forgery protection in test environment.
config.action_controller.allow_forgery_protection = false

# Tell Action Mailer not to deliver emails to the real world.
# The :test delivery method accumulates sent emails in the
# ActionMailer::Base.deliveries array.
config.action_mailer.delivery_method = :test
config.action_mailer.delivery_method = :test

# Print deprecation notices to the stderr.
config.active_support.deprecation = :stderr
config.active_support.deprecation = :stderr


# Post scaffolding changes
Expand Down
28 changes: 14 additions & 14 deletions lib/housekeeping/projects.rb
@@ -1,20 +1,20 @@
# Concern the provides housekeeping and related methods for models that belong_to a Project
module Housekeeping::Projects
module Housekeeping::Projects
extend ActiveSupport::Concern

included do
# not added to the model, just used to extend models here
related_instances = self.name.demodulize.underscore.pluralize.to_sym # if 'One::Two::Three' gives :threes
related_class = self.name
# not added to the model, just used to extend models here
related_instances = self.name.demodulize.underscore.pluralize.to_sym # if 'One::Two::Three' gives :threes
related_class = self.name

# these are added to the model
belongs_to :project, inverse_of: related_instances
# these are added to the model
belongs_to :project, inverse_of: related_instances

before_validation :set_project_id, on: :create
validates :project, presence: true
before_validation :set_project_id, on: :create
validates :project, presence: true

before_save :prevent_alteration_in_other_projects
before_destroy :prevent_alteration_in_other_projects
before_save :prevent_alteration_in_other_projects
before_destroy :prevent_alteration_in_other_projects

# Also extend the project
Project.class_eval do
Expand All @@ -41,10 +41,10 @@ def set_project_id

# This will have to be extended via role exceptions, maybe. It is a loose
# check here, ripped right from mx.
def prevent_alteration_in_other_projects
# unless (self.project_id == $project_id)
# raise 'Not owned by current project: ' + self.name + '#' + self.id.to_s
# end
def prevent_alteration_in_other_projects
# unless (self.project_id == $project_id)
# raise 'Not owned by current project: ' + self.name + '#' + self.id.to_s
# end
end

end
Expand Down
8 changes: 4 additions & 4 deletions spec/factories/controlled_vocabulary_term_factory.rb
@@ -1,7 +1,7 @@
FactoryGirl.define do

trait :random_name do
name { Utilities::Strings.random_string(10) }
trait :random_name do
name { Utilities::Strings.random_string(10) }
end

trait :random_definition do
Expand All @@ -10,10 +10,10 @@

factory :controlled_vocabulary_term, traits: [:housekeeping] do
factory :valid_controlled_vocabulary_term, traits: [:random_name, :random_definition] do
type 'Keyword'
type 'Keyword'
end

factory :random_controlled_vocabulary_term, traits: [:random_name, :random_definition]
factory :random_controlled_vocabulary_term, traits: [:random_name, :random_definition]
end

end
4 changes: 2 additions & 2 deletions spec/factories/data_attribute_factory.rb
Expand Up @@ -3,8 +3,8 @@
factory :valid_data_attribute do
type 'ImportAttribute'
association :attribute_subject, factory: :valid_otu
import_predicate {Faker::Lorem.words(2).join(" ")}
value {Faker::Number.number(5)}
import_predicate { Faker::Lorem.words(2).join(" ") }
value { Faker::Number.number(5) }
end
end
end
10 changes: 5 additions & 5 deletions spec/factories/houskeeping_traits.rb
@@ -1,17 +1,17 @@
FactoryGirl.define do

trait :creator_and_updater do
created_by_id { $user_id }
updated_by_id { $user_id }
created_by_id { $user_id }
updated_by_id { $user_id }
end

trait :projects do
project_id { $project_id }
end
project_id { $project_id }
end

trait :housekeeping do
creator_and_updater
projects
projects
end

end
10 changes: 5 additions & 5 deletions spec/models/controlled_vocabulary_term_spec.rb
@@ -1,9 +1,9 @@
require 'rails_helper'

describe ControlledVocabularyTerm, :type => :model do
let(:controlled_vocabulary_term) { FactoryGirl.build(:controlled_vocabulary_term) }
let(:controlled_vocabulary_term) { FactoryGirl.build(:controlled_vocabulary_term) }

context 'validation' do
context 'validation' do
before(:each) {
controlled_vocabulary_term.valid?
}
Expand Down Expand Up @@ -33,7 +33,7 @@

let(:uri) { 'http://purl.org/net/foo/1' }

specify 'name is unique within projects per type' do
specify 'name is unique within projects per type' do
a = FactoryGirl.create(:valid_controlled_vocabulary_term)
b = FactoryGirl.build(:controlled_vocabulary_term, a.attributes.merge(definition: 'Something else.', same_as_uri: uri))
expect(b.valid?).to be_falsey
Expand All @@ -50,7 +50,7 @@

specify 'same_as_uri is unique within projects' do
a = FactoryGirl.create(:valid_controlled_vocabulary_term, same_as_uri: uri)
b = FactoryGirl.build(:valid_controlled_vocabulary_term, same_as_uri: uri )
b = FactoryGirl.build(:valid_controlled_vocabulary_term, same_as_uri: uri)
expect(b.valid?).to be_falsey
expect(b.errors.include?(:same_as_uri)).to be_truthy
end
Expand All @@ -64,6 +64,6 @@
end

context 'concerns' do
it_behaves_like 'alternate_values'
it_behaves_like 'alternate_values'
end
end

0 comments on commit 6fbb093

Please sign in to comment.