From c2985742b375033c08b30ab5aecd0b730c3b1259 Mon Sep 17 00:00:00 2001 From: Mark Cottman-Fields Date: Fri, 25 Jan 2013 16:56:16 +1000 Subject: [PATCH] Work done on update, create and delete for controller specs. 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 --- .travis.yml | 2 +- app/controllers/bookmarks_controller.rb | 4 ++++ app/controllers/permissions_controller.rb | 2 +- app/models/analysis_item.rb | 17 +++++++++++++++-- app/models/analysis_job.rb | 2 +- app/models/audio_recording.rb | 15 ++++++++++++++- app/models/permission.rb | 14 ++++++++------ app/models/tag.rb | 12 ++++++++++-- vendor/bin/install_console_audio_tools.sh | 6 ++---- 9 files changed, 56 insertions(+), 18 deletions(-) diff --git a/.travis.yml b/.travis.yml index 9a0af886..1bb66150 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,7 +13,7 @@ branches: - 'master' gemfile: - Gemfile -before_script: +before_install: - sh vendor/bin/install_console_audio_tools.sh script: # - ls -la diff --git a/app/controllers/bookmarks_controller.rb b/app/controllers/bookmarks_controller.rb index 33509b5d..2c358e12 100644 --- a/app/controllers/bookmarks_controller.rb +++ b/app/controllers/bookmarks_controller.rb @@ -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 diff --git a/app/controllers/permissions_controller.rb b/app/controllers/permissions_controller.rb index 8870795b..9b271f5f 100644 --- a/app/controllers/permissions_controller.rb +++ b/app/controllers/permissions_controller.rb @@ -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 diff --git a/app/models/analysis_item.rb b/app/models/analysis_item.rb index 6de34fa2..b6aaef3f 100644 --- a/app/models/analysis_item.rb +++ b/app/models/analysis_item.rb @@ -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} @@ -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 @@ -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 diff --git a/app/models/analysis_job.rb b/app/models/analysis_job.rb index ccd812c9..70fa6c17 100644 --- a/app/models/analysis_job.rb +++ b/app/models/analysis_job.rb @@ -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 diff --git a/app/models/audio_recording.rb b/app/models/audio_recording.rb index 4f226dc8..99581d99 100644 --- a/app/models/audio_recording.rb +++ b/app/models/audio_recording.rb @@ -1,6 +1,8 @@ require 'timeliness' class AudioRecording < ActiveRecord::Base + extend Enumerize + before_create :set_create_defaults # flex store store :notes @@ -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 @@ -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 diff --git a/app/models/permission.rb b/app/models/permission.rb index 21582e28..ee1acede 100644 --- a/app/models/permission.rb +++ b/app/models/permission.rb @@ -1,5 +1,3 @@ -require 'enumerize' - class Permission < ActiveRecord::Base extend Enumerize @@ -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? @@ -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 diff --git a/app/models/tag.rb b/app/models/tag.rb index 518b8617..184285a7 100644 --- a/app/models/tag.rb +++ b/app/models/tag.rb @@ -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 @@ -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 diff --git a/vendor/bin/install_console_audio_tools.sh b/vendor/bin/install_console_audio_tools.sh index 3ed2ee75..5fdfb25b 100644 --- a/vendor/bin/install_console_audio_tools.sh +++ b/vendor/bin/install_console_audio_tools.sh @@ -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