Skip to content

Commit

Permalink
Updated scopes to Rails 4 version
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael O'Keefe committed Jul 17, 2014
1 parent 5e666d0 commit 621a16f
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 30 deletions.
8 changes: 4 additions & 4 deletions app/models/ethnicity.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
class Ethnicity
include Mongoid::Document

field :name, type: String
field :order, type: Integer
field :codes, type: Array

scope :from_code, ->(code) {where("codes" => code)}
scope :ordered, order_by([:order, :asc])
scope :ordered, -> { order_by([:order, :asc]) }
scope :selected, ->(ethnicity_ids) { any_in(:_id => ethnicity_ids)}
scope :selected_or_all, ->(ethnicity_ids) { ethnicity_ids.nil? || ethnicity_ids.empty? ? Ethnicity.all : Ethnicity.selected(ethnicity_ids) }

validates_presence_of :name
validates_presence_of :order
validates_presence_of :codes
end
end
2 changes: 1 addition & 1 deletion app/models/product_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class ProductTest
validates_presence_of :effective_date
validates_presence_of :bundle_id

scope :order_by_type, order_by(_type: desc)
scope :order_by_type, -> { order_by(_type: desc) }

state_machine :state, :initial => :pending do

Expand Down
10 changes: 5 additions & 5 deletions app/models/race.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
class Race
include Mongoid::Document

field :name, type: String
field :order, type: Integer
field :codes, type: Array

scope :from_code, ->(code) {where("codes" => code)}
scope :ordered, order_by([:order, :asc])
scope :ordered, -> { order_by([:order, :asc]) }
scope :selected, ->(race_ids) { any_in(:_id => race_ids)}
scope :selected_or_all, ->(race_ids) { race_ids.nil? || race_ids.empty? ? Race.all : Race.selected(race_ids) }

validates_presence_of :name
validates_presence_of :order
validates_presence_of :codes
end
end
40 changes: 20 additions & 20 deletions app/models/test_execution.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,48 @@
class TestExecution
include Mongoid::Document
include Mongoid::Timestamps::Created

has_one :artifact, autosave: true

belongs_to :product_test

embeds_many :execution_errors
field :required_modules, type: Array
field :expected_results, type: Hash
field :reported_results, type: Hash
field :matched_results, type: Hash

field :status, type: Symbol
field :state, type: Symbol
field :file_ids, type: Array

scope :ordered_by_date, order_by(:created_at => :desc)
scope :order_by_state, order_by(:state => :asc)
scope :ordered_by_date, -> { order_by(created_at: :desc) }
scope :order_by_state, -> { order_by(state: :asc) }



state_machine :state , :initial=> :pending do

event :failed do
transition :pending => :failed
end

event :pass do
transition :pending => :passed
end

event :force_pass do
transition all => :passed
end

event :force_fail do
transition all => :failed
end

event :reset do
transition all => :pending
end

end

def execution_date
Expand All @@ -53,7 +53,7 @@ def execution_date
def count_errors
execution_errors.where({:msg_type=>:error}).count
end

def count_warnings
execution_errors.where({:msg_type=>:warning}).count
end
Expand All @@ -62,24 +62,24 @@ def count_warnings
def expected_result(measure)
(expected_results || product_test.expected_results || {})[measure.key] || {}
end

# Get the expected result for a particular measure
def reported_result(measure)
(reported_results || {})[measure.key] || {}
end

def passing?
state == :passed
end

def failing
state == :failed
end

def incomplete?
(!passing? && !failing)
end

def files
return [] if self.file_ids.nil? || self.file_ids.length == 0
Cypress::ArtifactManager.get_artifacts(self.file_ids)
Expand All @@ -104,7 +104,7 @@ def failing_measures
m_ids.flatten!
m_ids.compact!
m_ids.uniq!
mes = product_test.measures.collect{|m|
mes = product_test.measures.collect{|m|
m_ids.index("#{m.hqmf_id}-#{m.population_ids['stratification']}") || m_ids.index(m.key) ? m : nil } # look for m.key for older test executions
mes.compact!
mes.sort{|a,b| "#{a.cms_id}-#{a.nqf_id}" <=> "#{b.cms_id}-#{b.nqf_id}"}
Expand All @@ -113,7 +113,7 @@ def failing_measures
def measure_passed?(measure)
passing_measures.find{|m| m.id == measure.id}
end





end

0 comments on commit 621a16f

Please sign in to comment.