Skip to content

Commit

Permalink
Did a whole bunch of testing work
Browse files Browse the repository at this point in the history
modified:   Gemfile
modified:   Gemfile.lock
	-- temporary roleback to rails 3.2.8 because of this issue rails/rails#8718
	-- added FactoryGirl, Faker, Shoulda gems for testing

modified:   app/models/audio_recording.rb
modified:   app/models/audio_event.rb
	-- fixed bugs found while testing, and minor refactoring

modified:   app/models/project.rb
	-- added validation regex for urn

modified:   app/models/site.rb
	-- removed outdated to_json definition

modified:   spec/controllers/projects_controller_spec.rb
	-- removed unused framework

new file:   spec/factories/audio_event_factory.rb
new file:   spec/factories/audio_recording_factory.rb
new file:   spec/factories/project_factory.rb
new file:   spec/factories/site_factory.rb
new file:   spec/factories/user_factory.rb
	-- created factories for testing using FactoryGirl and Faker

renamed:    test/unit/analysis_item_test.rb -> spec/models/analysis_item_spec.rb
renamed:    test/unit/analysis_job_test.rb -> spec/models/analysis_job_spec.rb
renamed:    test/unit/analysis_script_test.rb -> spec/models/analysis_script_spec.rb
new file:   spec/models/audio_event_spec.rb
new file:   spec/models/audio_recording_spec.rb
renamed:    test/unit/authorization_test.rb -> spec/models/authorization_spec.rb
renamed:    test/unit/bookmark_test.rb -> spec/models/bookmark_spec.rb
renamed:    test/unit/class_search_test.rb -> spec/models/class_search_spec.rb
renamed:    test/unit/module_audio_test.rb -> spec/models/module_audio_spec.rb
renamed:    test/unit/module_cache_test.rb -> spec/models/module_cache_spec.rb
renamed:    test/unit/module_harvester_test.rb -> spec/models/module_harvester_spec.rb
renamed:    test/unit/module_spectrogram_test.rb -> spec/models/module_spectrogram_spec.rb
renamed:    test/unit/permission_test.rb -> spec/models/permission_spec.rb
renamed:    test/unit/photo_test.rb -> spec/models/photo_spec.rb
renamed:    test/unit/progress_test.rb -> spec/models/progress_spec.rb
new file:   spec/models/project_spec.rb
renamed:    test/unit/saved_search_test.rb -> spec/models/saved_search_spec.rb
new file:   spec/models/site_spec.rb
renamed:    test/unit/tag_test.rb -> spec/models/tag_spec.rb
renamed:    test/unit/user_test.rb -> spec/models/user_spec.rb
	-- moved all the test-unit stubs to the rspec directory. N.B. Most of these still contain invalid rspec code (it's all the test::unit stubs)
	-- also wrote and completed model tests for AudioEvents, Projects, Sites, AudioRecordings

modified:   spec/spec_helper.rb
	-- added factorygirl shortcut methods to rspec config

deleted:    test/unit/audio_event_test.rb
deleted:    test/unit/audio_recording_test.rb
deleted:    test/unit/project_test.rb
deleted:    test/unit/site_test.rb
	-- duplicate files not needed
  • Loading branch information
atruskie committed Jan 13, 2013
1 parent db4d86a commit 4f7a62e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 51 deletions.
50 changes: 13 additions & 37 deletions app/models/audio_event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,61 +15,37 @@ class AudioEvent < ActiveRecord::Base

# userstamp
stampable
belongs_to :user, :class_name => 'User', :foreign_key => :creator_id
belongs_to :user, class_name: 'User', foreign_key: :creator_id
acts_as_paranoid
validates_as_paranoid

# validation
validates :audio_recording, :presence => true
validates :audio_recording, presence: true
validates :is_reference, inclusion: {in: [true, false]}

validates :start_time_seconds, :presence => true, :numericality => { :greater_than_or_equal_to => 0 }
validates :end_time_seconds, :numericality => { :greater_than_or_equal_to => 0 }
validate :start_time_must_be_lte_end_time
validates :start_time_seconds, presence: true, numericality: {greater_than_or_equal_to: 0}
validates :end_time_seconds, numericality: {greater_than_or_equal_to: 0}, allow_nil: true
validate :start_must_be_lte_end

validates :low_frequency_hertz, :presence => true, :numericality => { :greater_than_or_equal_to => 0 }
validates :high_frequency_hertz, :numericality => { :greater_than_or_equal_to => 0 }
validate :low_frequency_must_be_lte_high_frequency
validates :low_frequency_hertz, presence: true, numericality: {greater_than_or_equal_to: 0}
validates :high_frequency_hertz, numericality: {greater_than_or_equal_to: 0}, allow_nil: true
validate :low_must_be_lte_high

# custom validation methods
def start_time_must_be_lte_end_time
return unless end_time_seconds
def start_must_be_lte_end
return unless end_time_seconds && start_time_seconds

if start_time_seconds > end_time_seconds then
errors.add(:start_time_seconds, "must be lower than end time")
end
end

def low_frequency_must_be_lte_high_frequency
return unless high_frequency_hertz
def low_must_be_lte_high
return unless high_frequency_hertz && low_frequency_hertz

if low_frequency_hertz > high_frequency_hertz then
errors.add(:start_time_seconds, "must be lower than high frequency")
end
end



# json formatting
#def as_json(options={})
# super(
# :include =>
# [
# :audio_event_tags,
# :audio_recording => {:only => [:id, :uuid]}
# ],
# :except => :audio_recording_id
# )
#end

#def active_model_serializer
# AudioEventSerializer
#end



# other stuff
#def download_format(options)
# #as_json(:only => )
#end

end
6 changes: 3 additions & 3 deletions app/models/audio_recording.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ class AudioRecording < ActiveRecord::Base

validates :recorded_date, :presence => true, :timeliness => {:on_or_before => lambda { Date.current }, :type => :date }
validates :site, :presence => true
validates :duration_seconds, :presence => true, :numericality => { :greater_than_or_equal_to => 0 }
validates :duration_seconds, :presence => true, :numericality => {greater_than_or_equal_to: 0}

validates :sample_rate_hertz, :numericality => { :only_integer => true, :greater_than_or_equal_to => 0 }
validates :sample_rate_hertz, :numericality => {only_integer: true, greater_than_or_equal_to: 0}

# the channels field encodes our special version of a bit flag. 0 (no bits flipped) represents
# a mix down option - we don't store mix downs (if we did they would be stored as single channel / mono (value = 1))
Expand All @@ -44,7 +44,7 @@ class AudioRecording < ActiveRecord::Base

validates :file_hash, :presence => true

validates :status, :inclusion => { :in => %w(new to_check ready corrupt ignore) }
validates :status, :inclusion => {in: %w(new to_check ready corrupt ignore)}

# uuid stuff
attr_protected :uuid
Expand Down
1 change: 1 addition & 0 deletions app/models/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class Project < ActiveRecord::Base
# validation
validates :name, :presence => true, :uniqueness => { :case_sensitive => false }
validates :urn, :presence => true, :uniqueness => { :case_sensitive => false }
validates_format_of :urn, :with => /^urn:[a-z0-9][a-z0-9-]{0,31}:[a-z0-9()+,\-.:=@;$_!*'%\/?#]+$/

# commonly used queries (these return
# ActiveRecord::Relation object which will allow for
Expand Down
11 changes: 0 additions & 11 deletions app/models/site.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,4 @@ class Site < ActiveRecord::Base
#scope :sites_in_project, lambda { |project_ids| where(Project.specified_projects, { :ids => project_ids } ) }
scope :site_projects, lambda{ |project_ids| includes(:projects).where(:projects => {:id => project_ids} ) }

# json formatting
def as_json(options={})
super(
:include =>
[
:photos,
:projects => {:only => [:id, :name]},
]
)
end

end

0 comments on commit 4f7a62e

Please sign in to comment.