Skip to content

Commit

Permalink
Work done on update, create and delete for controller specs.
Browse files Browse the repository at this point in the history
modified:   .travis.yml
modified:   Gemfile
modified:   Gemfile.lock
modified:   app/controllers/bookmarks_controller.rb
modified:   app/controllers/permissions_controller.rb
modified:   app/models/analysis_item.rb
modified:   app/models/analysis_job.rb
modified:   app/models/audio_recording.rb
modified:   app/models/permission.rb
modified:   app/models/tag.rb
modified:   spec/controllers/analysis_items_controller_spec.rb
modified:   spec/controllers/analysis_jobs_controller_spec.rb
modified:   spec/controllers/analysis_scripts_controller_spec.rb
modified:   spec/controllers/audio_events_controller_spec.rb
modified:   spec/controllers/audio_recordings_controller_spec.rb
modified:   spec/controllers/bookmarks_controller_spec.rb
modified:   spec/controllers/permissions_controller_spec.rb
modified:   spec/controllers/photos_controller_spec.rb
modified:   spec/controllers/progresses_controller_spec.rb
modified:   spec/controllers/projects_controller_spec.rb
modified:   spec/controllers/saved_searches_controller_spec.rb
modified:   spec/controllers/sites_controller_spec.rb
modified:   spec/controllers/tags_controller_spec.rb
modified:   spec/controllers/users_controller_spec.rb
modified:   spec/factories/analysis_item_factory.rb
modified:   spec/factories/audio_recording_factory.rb
modified:   spec/factories/permission_factory.rb
modified:   spec/factories/progress_factory.rb
modified:   spec/factories/user_factory.rb
modified:   spec/models/tag_spec.rb
modified:   spec/spec_helper.rb
modified:   spec/support/api_examples_create.rb
modified:   spec/support/api_examples_delete.rb
modified:   spec/support/api_examples_idempotent.rb
modified:   spec/support/api_examples_update.rb
modified:   spec/support/helpers.rb
modified:   vendor/bin/install_console_audio_tools.sh
  • Loading branch information
Mark Cottman-Fields committed Jan 25, 2013
1 parent d970959 commit c298574
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ branches:
- 'master'
gemfile:
- Gemfile
before_script:
before_install:
- sh vendor/bin/install_console_audio_tools.sh
script:
# - ls -la
Expand Down
4 changes: 4 additions & 0 deletions app/controllers/bookmarks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ def update
end
end

# Bookmarks can be deleted but not Archived
DELETEABLE = true
ARCHIVEABLE = false

# DELETE /bookmarks/1
# DELETE /bookmarks/1.json
def destroy
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/permissions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def destroy
@permission.destroy

respond_to do |format|
format.json { head :no_content }
format.json { head :no_content }
end
end
end
17 changes: 15 additions & 2 deletions app/models/analysis_item.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
class AnalysisItem < ActiveRecord::Base
extend Enumerize

# relations
belongs_to :audio_recording
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
:status, :worker_info, :worker_run_details, :worker_started_utc, :analysis_job_id

accepts_nested_attributes_for :analysis_job, :audio_recording

# enums
AVAILABLE_STATUSES = [:ready, :running, :complete, :error].map{ |item| item.to_s }
enumerize :status, in: AVAILABLE_STATUSES, :default => :ready, predicates: true
validates :status, inclusion: {in: AVAILABLE_STATUSES}, presence: true

# validations
validates :offset_start_seconds, presence: true, numericality: {greater_than_or_equal_to: 0}
validates :offset_end_seconds, presence: true, numericality: {greater_than_or_equal_to: 0}
Expand All @@ -18,7 +25,7 @@ class AnalysisItem < ActiveRecord::Base

# documentation for timeliness: https://github.com/adzap/validates_timeliness
validates :worker_started_utc, allow_nil: true, allow_blank: true, timeliness: {type: :datetime, on_or_before: :now}
validates :status, inclusion: {in: [:ready, :running, :complete, :error]}, presence: true


# custom validation methods
def start_must_be_lte_end
Expand All @@ -28,4 +35,10 @@ def start_must_be_lte_end
errors.add(:offset_start_seconds, "must be lower than end time")
end
end

# http://stackoverflow.com/questions/11569940/inclusion-validation-fails-when-provided-a-symbol-instead-of-a-string
# this lets a symbol be set, and it all still works
def status=(new_status)
super new_status.to_s
end
end
2 changes: 1 addition & 1 deletion app/models/analysis_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class AnalysisJob < ActiveRecord::Base
# this is a copy of the information from the analysis_scripts table
# duplicated to create a instance snap-shot of the data that will not change
:script_description, :script_display_name, :script_extra_data, :script_name,
:script_settings, :script_version
:script_settings, :script_version, :saved_search_id


accepts_nested_attributes_for :saved_search
Expand Down
15 changes: 14 additions & 1 deletion app/models/audio_recording.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
require 'timeliness'

class AudioRecording < ActiveRecord::Base
extend Enumerize

before_create :set_create_defaults
# flex store
store :notes
Expand All @@ -26,6 +28,11 @@ class AudioRecording < ActiveRecord::Base
acts_as_paranoid
validates_as_paranoid

#enums
AVAILABLE_STATUSES = [:new, :to_check, :ready, :corrupt, :ignore].map{ |item| item.to_s }
enumerize :status, in: AVAILABLE_STATUSES, predicates: true
validates :status, :inclusion => {in: AVAILABLE_STATUSES}, :presence => true

# validation
validates :uuid, :presence => true, :length => {:is => 36}, :uniqueness => { :case_sensitive => false }
validates :uploader_id, :presence => true
Expand All @@ -46,12 +53,18 @@ class AudioRecording < ActiveRecord::Base

validates :file_hash, :presence => true

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


# uuid stuff
attr_protected :uuid
include UUIDHelper

# http://stackoverflow.com/questions/11569940/inclusion-validation-fails-when-provided-a-symbol-instead-of-a-string
# this lets a symbol be set, and it all still works
def status=(new_status)
super new_status.to_s
end

# scoped, re-usable queries
# when chaining a lambda scope you must also wrap it with a
# lambda or else you will end up with the wrong result
Expand Down
14 changes: 8 additions & 6 deletions app/models/permission.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require 'enumerize'

class Permission < ActiveRecord::Base
extend Enumerize

Expand All @@ -15,13 +13,13 @@ class Permission < ActiveRecord::Base
belongs_to :user, class_name: 'User', foreign_key: :creator_id

# enumerations
enumerize :level, :in => [:owner, :writer, :reader, :none], :default => :none, predicates: true
AVAILABLE_LEVELS = [:owner, :writer, :reader, :none].map{ |item| item.to_s }
enumerize :level, :in => AVAILABLE_LEVELS, :default => :none, predicates: true
validates :level, :inclusion => {in: AVAILABLE_LEVELS}, :presence => true

# validation
validates :level, :presence => true
validate :anonymous_permission_can_only_be_read_or_none


# custom validation methods
def anonymous_permission_can_only_be_read_or_none
return unless self.user.nil?
Expand All @@ -36,6 +34,10 @@ def anonymous?
self.user.nil?
end

# scopes
# http://stackoverflow.com/questions/11569940/inclusion-validation-fails-when-provided-a-symbol-instead-of-a-string
# this lets a symbol be set, and it all still works
def level=(new_level)
super new_level.to_s
end

end
12 changes: 10 additions & 2 deletions app/models/tag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ class Tag < ActiveRecord::Base
validates_as_paranoid

# enums
enumerize :type_of_tag, in: [:common_name, :species_name, :looks_like, :sounds_like], predicates: true
AVAILABLE_TYPE_OF_TAGS = [:common_name, :species_name, :looks_like, :sounds_like].map{ |item| item.to_s }
enumerize :type_of_tag, in: AVAILABLE_TYPE_OF_TAGS, predicates: true
validates :type_of_tag, :inclusion => {in: AVAILABLE_TYPE_OF_TAGS}, :presence => true

# validation
validates :is_taxanomic, inclusion: { in: [true, false] }
validates :text, uniqueness: { case_sensitive: false }
validates :type_of_tag, :presence => true


validate :no_nils

Expand All @@ -42,6 +44,12 @@ def no_nils
# errors.add(:type_of_tag, "class and type_of_tag cannot both be set")
#end

# http://stackoverflow.com/questions/11569940/inclusion-validation-fails-when-provided-a-symbol-instead-of-a-string
# this lets a symbol be set, and it all still works
def type_of_tag=(new_type_of_tag)
super new_type_of_tag.to_s
end

private
# default values
after_initialize :init
Expand Down
6 changes: 2 additions & 4 deletions vendor/bin/install_console_audio_tools.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#!/usr/bin/env bash

echo "Installing audio tools"
sudo apt-get update
sudo apt-get upgrade
sudo apt-get update -qq
# sudo apt-get upgrade
# sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-key 16126D3A3E5C1192
sudo apt-get install ffmpeg mp3splt sox wavpack --fix-missing

Expand Down

0 comments on commit c298574

Please sign in to comment.