Skip to content

Commit

Permalink
More model tests written. Additionally added some missing relations t…
Browse files Browse the repository at this point in the history
…o the models.

modified:   app/models/analysis_item.rb
modified:   app/models/analysis_job.rb
modified:   app/models/analysis_script.rb
modified:   app/models/audio_recording.rb
modified:   app/models/saved_search.rb
modified:   app/models/user.rb
new file:   spec/factories/analysis_item_factory.rb
new file:   spec/factories/analysis_job_factory.rb
new file:   spec/factories/analysis_script_factory.rb
modified:   spec/models/analysis_item_spec.rb
modified:   spec/models/analysis_job_spec.rb
modified:   spec/models/audio_event_spec.rb
modified:   spec/models/audio_recording_spec.rb
  • Loading branch information
atruskie committed Jan 14, 2013
1 parent 4f7a62e commit 39c0e2f
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 17 deletions.
13 changes: 7 additions & 6 deletions app/models/analysis_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ class AnalysisItem < ActiveRecord::Base
belongs_to :analysis_job

# attr
attr_accessible :audio_recording_id, :offset_end_seconds, :offset_start_seconds, :status, :worker_info, :worker_run_details, :worker_started_utc
attr_accessible :audio_recording_id, :offset_end_seconds, :offset_start_seconds,
:status, :worker_info, :worker_run_details, :worker_started_utc

accepts_nested_attributes_for :analysis_job, :audio_recording

# validations
validates :offset_start_seconds, :presence => true, :numericality => true
validates :offset_end_seconds, :presence => true, :numericality => true
validates :audio_recording_id, :presence => true
validates :offset_start_seconds, presence: true, numericality: true
validates :offset_end_seconds, presence: true, numericality: true
validates :audio_recording_id, presence: true
# documentation for timeliness: https://github.com/adzap/validates_timeliness
validates :worker_started_utc, :timeliness => { :type => :datetime, :allow_blank => true }
validates :status, :inclusion => { :in => %w(ready running complete error) }
validates :worker_started_utc, timeliness: {type: :datetime, allow_blank: true}
validates :status, inclusion: {in: %w(ready running complete error)}
end
14 changes: 10 additions & 4 deletions app/models/analysis_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,18 @@ class AnalysisJob < ActiveRecord::Base

# relations
belongs_to :saved_search
has_many :analysis_items

# attr
attr_accessible :data_set_identifier, :description, :name, :notes,
attr_accessible :description, :name, :notes, :process_new,
# a generated identifier from an ?executed? saved search
:data_set_identifier,

# this is a copy of the information from the analysis_scripts table
# duplicated create and instance snap-shot of the data that will not change
:script_description, :script_display_name, :script_extra_data, :script_name,
:script_settings, :script_version,
:process_new
:script_settings, :script_version


accepts_nested_attributes_for :saved_search

Expand All @@ -28,6 +34,6 @@ class AnalysisJob < ActiveRecord::Base

# custom validation methods
def data_set_cannot_process_new
errors.add(:level, "An analysis job that references a data set cannot process new recordings.") if self.data_set_identifier && self.process_new
errors.add(:level, 'An analysis job that references a data set cannot process new recordings.') if self.data_set_identifier && self.process_new
end
end
21 changes: 14 additions & 7 deletions app/models/analysis_script.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@ class AnalysisScript < ActiveRecord::Base
store :notes

# attr
attr_accessible :description, :display_name, :extra_data, :name, :settings, :version, :notes, :verified
attr_accessible :description,
:display_name, # the original name
:extra_data,
:name, # a filesystem safe version of display_name
:settings,
:version,
:notes,
:verified

# userstamp
stampable
Expand All @@ -12,11 +19,11 @@ class AnalysisScript < ActiveRecord::Base
validates_as_paranoid

# validations
validates :name, :presence => true, :length => { :minimum => 2, :maximum => 100 }, :uniqueness => { :case_sensitive => false }
validates :display_name, :presence => true
validates :settings, :presence => true
validates :version, :presence => true
validates :display_name, :presence => true
validates :verified, :inclusion => { :in => [true, false] }
validates :name, presence: true, length: {minimum: 2, maximum: 100}, uniqueness: {case_sensitive: false}
validates :display_name, presence: true
validates :settings, presence: true
validates :version, presence: true
validates :display_name, presence: true
validates :verified, inclusion: {in: [true, false]}

end
2 changes: 2 additions & 0 deletions app/models/audio_recording.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ class AudioRecording < ActiveRecord::Base
belongs_to :site
has_many :audio_events
belongs_to :user, :class_name => 'User', :foreign_key => "uploader_id"
has_many :analysis_items
has_many :bookmarks

# attr
attr_accessible :bit_rate_bps, :channels, :data_length_bytes,
Expand Down
1 change: 1 addition & 0 deletions app/models/saved_search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ class SavedSearch < ActiveRecord::Base
# relations
# note currently no support for nullable user (because the user field is the creator_id field
# automatically generated by userstamps)
has_many :progresses

# attr
attr_accessible :name, :search_object
Expand Down
6 changes: 6 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ class User < ActiveRecord::Base
has_many :tags
has_many :audio_event_tags
has_many :permissions
has_many :analysis_scripts
has_many :analysis_jobs
has_many :progresses
has_many :bookmarks
has_many :saved_searches


# validation
#validates_presence_of :display_name
Expand Down

0 comments on commit 39c0e2f

Please sign in to comment.