Skip to content

Commit

Permalink
More work done on testing.
Browse files Browse the repository at this point in the history
modified:   Gemfile.lock
modified:   app/controllers/analysis_items_controller.rb
modified:   app/controllers/analysis_jobs_controller.rb
modified:   app/controllers/analysis_scripts_controller.rb
modified:   app/controllers/application_controller.rb
modified:   app/controllers/audio_events_controller.rb
modified:   app/controllers/audio_recordings_controller.rb
modified:   app/controllers/bookmarks_controller.rb
modified:   app/controllers/permissions_controller.rb
modified:   app/controllers/photos_controller.rb
modified:   app/controllers/progresses_controller.rb
modified:   app/controllers/projects_controller.rb
modified:   app/controllers/saved_searches_controller.rb
modified:   app/controllers/sites_controller.rb
modified:   app/controllers/tags_controller.rb
modified:   app/controllers/users_controller.rb
modified:   app/models/audio_event.rb
modified:   app/models/tag.rb
modified:   app/models/user.rb
modified:   app/serializers/audio_event_serializer.rb
new file:   app/serializers/progress_serializer.rb
modified:   db/migrate/20121025001857_create_users.rb
modified:   db/migrate/20121102043637_add_deleted_at_fields.rb
modified:   db/migrate/20121211011323_create_analysis_jobs.rb
modified:   db/schema.rb
modified:   spec/controllers/audio_events_controller_spec.rb
modified:   spec/controllers/audio_recordings_controller_spec.rb
modified:   spec/controllers/permissions_controller_spec.rb
modified:   spec/controllers/photos_controller_spec.rb
modified:   spec/controllers/users_controller_spec.rb
modified:   spec/factories/analysis_job_factory.rb
modified:   spec/factories/analysis_script_factory.rb
modified:   spec/factories/audio_recording_factory.rb
modified:   spec/models/tag_spec.rb
modified:   spec/spec_helper.rb
modified:   spec/support/api_examples_delete.rb
modified:   spec/support/api_examples_update.rb
modified:   spec/support/helpers.rb
  • Loading branch information
Mark Cottman-Fields committed Feb 1, 2013
1 parent 0ac081e commit 6ecca30
Show file tree
Hide file tree
Showing 20 changed files with 100 additions and 93 deletions.
2 changes: 1 addition & 1 deletion app/controllers/analysis_items_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def destroy
@analysis_item.destroy

respond_to do |format|
format.json { head :no_content }
format.json { no_content_as_json }
end
end
end
4 changes: 3 additions & 1 deletion app/controllers/analysis_jobs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,10 @@ def destroy
@analysis_job = AnalysisJob.find(params[:id])
@analysis_job.destroy

add_archived_at_header @analysis_job

respond_to do |format|
format.json { head :no_content }
format.json { no_content_as_json }
end
end
end
4 changes: 3 additions & 1 deletion app/controllers/analysis_scripts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,10 @@ def destroy
@analysis_script = AnalysisScript.find(params[:id])
@analysis_script.destroy

add_archived_at_header(@analysis_script)

respond_to do |format|
format.json { head :no_content }
format.json { no_content_as_json }
end
end
end
10 changes: 10 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ def render_csv(filename = nil)
render :layout => false
end

def add_archived_at_header(model)
#if model.respond_to?(:deleted_at) && !model.deleted_at.blank?
response.headers["X-Archived-At"] = 'hi'#model.deleted_at
#end
end

def no_content_as_json
head :no_content, :content_type => "application/json"
end

private

#def set_stamper
Expand Down
85 changes: 37 additions & 48 deletions app/controllers/audio_events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,43 +14,10 @@ def index
end
end

def by_audio_id
# TODO: check if quid
id = params[:byAudioId]

@audio_events =
AudioEvent
.includes(:audio_recording)
.where(:audio_recordings => { :uuid => id })


#@audio_recording = (AudioRecording.find_by_uuid id)
#@audio_events = AudioEvent.find_all_by_audio_recording_id @audio_recording.id

#@audio_events =
# (AudioRecording)
# .select([:id, :uuid])
# .joins(:@audio_events)
# .where(:audio_recordings => {:uuid => id})

#@formatted_events = @audio_events.collect{ |audio_event|
# {
# :high_freq => audio_event.high_frequency_hertz,
# :id => audio_event.audio_recording.id,
# :site => audio_event.audio_recording.site.name,
#} }

# :include => [{ :sites => { :only => [ :id, :name ] } }
respond_to do |format|
format.json { render json: @audio_events }
format.xml { render xml: @audio_events }
end
end

# GET /audio_events/1
# GET /audio_events/1.json
def show
@audio_event = AudioEvent.includes(:audio_event_tags).find(params[:id])
@audio_event = AudioEvent.find(params[:id])

respond_to do |format|
format.json { render json: @audio_event }
Expand All @@ -67,25 +34,13 @@ def new
end
end

# GET /audio_events/1/edit
#def edit
# @audio_event =
# AudioEvent.find(params[:id]).include(:audio_event_tags)
#end

# POST /audio_events
# POST /audio_events.json
def create


@audio_event = AudioEvent.new(params[:audio_event])
#@audio_event.audio_event_tags.each{ |aet| aet.build() }

#@audio_event.audio_event_tags.count.times { @audio_event.audio_event_tags.build }

respond_to do |format|
if @audio_event.save
#@audio_event.audio_event_tags.reload
format.json { render json: @audio_event, status: :created, location: @audio_event }
else
format.json { render json: @audio_event.errors, status: :unprocessable_entity }
Expand Down Expand Up @@ -113,13 +68,47 @@ def destroy
@audio_event = AudioEvent.find(params[:id])
@audio_event.destroy

add_archived_at_header(@audio_event)

respond_to do |format|
format.json { head :no_content }
format.json { no_content_as_json }
end
end

def download
def by_audio_id
# TODO: check if quid
id = params[:byAudioId]

@audio_events =
AudioEvent
.includes(:audio_recording)
.where(:audio_recordings => { :uuid => id })


#@audio_recording = (AudioRecording.find_by_uuid id)
#@audio_events = AudioEvent.find_all_by_audio_recording_id @audio_recording.id

#@audio_events =
# (AudioRecording)
# .select([:id, :uuid])
# .joins(:@audio_events)
# .where(:audio_recordings => {:uuid => id})

#@formatted_events = @audio_events.collect{ |audio_event|
# {
# :high_freq => audio_event.high_frequency_hertz,
# :id => audio_event.audio_recording.id,
# :site => audio_event.audio_recording.site.name,
#} }

# :include => [{ :sites => { :only => [ :id, :name ] } }
respond_to do |format|
format.json { render json: @audio_events }
format.xml { render xml: @audio_events }
end
end

def download
@formatted_annotations =
custom_format AudioEvent.includes(:tags).order(:audio_event => :recorded_date).all

Expand Down
4 changes: 3 additions & 1 deletion app/controllers/audio_recordings_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,10 @@ def destroy
@audio_recording = AudioRecording.find(params[:id])
@audio_recording.destroy

add_archived_at_header(@audio_recording)

respond_to do |format|
format.json { head :no_content }
format.json { no_content_as_json }
end
end

Expand Down
6 changes: 1 addition & 5 deletions app/controllers/bookmarks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,14 @@ def update
end
end

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

# DELETE /bookmarks/1
# DELETE /bookmarks/1.json
def destroy
@bookmark = Bookmark.find(params[:id])
@bookmark.destroy

respond_to do |format|
format.json { head :no_content }
format.json { no_content_as_json }
end
end
end
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 { no_content_as_json }
end
end
end
2 changes: 1 addition & 1 deletion app/controllers/photos_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def destroy
@photo.destroy

respond_to do |format|
format.json { head :no_content }
format.json { no_content_as_json }
end
end
end
4 changes: 3 additions & 1 deletion app/controllers/progresses_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,10 @@ def destroy
@progress = Progress.find(params[:id])
@progress.destroy

add_archived_at_header @progress

respond_to do |format|
format.json { head :no_content }
format.json { no_content_as_json }
end
end
end
17 changes: 4 additions & 13 deletions app/controllers/projects_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,12 @@ def show
# GET /projects/new.json
def new
@project = Project.new
#@project.sites.build
#@project.photos.build
#@all_sites = Site.all

respond_to do |format|
format.json { render json: @project }
end
end

# GET /projects/1/edit
#def edit
# @project = Project.find(params[:id])
#@all_sites = Site.all
#end

# POST /projects
# POST /projects.json
def create
Expand All @@ -61,9 +52,7 @@ def create
# http://iqbalfarabi.net/2011/01/20/rails-nested-form-with-has-many-through-association/
def update
@project = Project.find(params[:id])

#ProjectSite.find(2).destroy


respond_to do |format|
if @project.update_attributes(params[:project])
format.json { head :no_content }
Expand All @@ -79,8 +68,10 @@ def destroy
@project = Project.find(params[:id])
@project.destroy

add_archived_at_header(@project)

respond_to do |format|
format.json { head :no_content }
format.json { no_content_as_json }
end
end
end
4 changes: 3 additions & 1 deletion app/controllers/saved_searches_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,10 @@ def destroy
@saved_search = SavedSearch.find(params[:id])
@saved_search.destroy

add_archived_at_header @saved_search

respond_to do |format|
format.json { head :no_content }
format.json { no_content_as_json }
end
end
end
4 changes: 3 additions & 1 deletion app/controllers/sites_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,10 @@ def destroy
@site = Site.find(params[:id])
@site.destroy

add_archived_at_header(@site)

respond_to do |format|
format.json { head :no_content }
format.json { no_content_as_json }
end
end
end
7 changes: 1 addition & 6 deletions app/controllers/tags_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,6 @@ def new
end
end

# GET /tags/1/edit
#def edit
# @tag = Tag.find(params[:id])
#end

# POST /tags
# POST /tags.json
def create
Expand Down Expand Up @@ -69,7 +64,7 @@ def destroy
@tag.destroy

respond_to do |format|
format.json { head :no_content }
format.json { no_content_as_json }
end
end
end
6 changes: 4 additions & 2 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,11 @@ def destroy
@user = User.find(params[:id])
@user.destroy

add_archived_at_header @user

respond_to do |format|
format.html { redirect_to users_url }
format.json { head :no_content }
#format.html { redirect_to users_url }
format.json { no_content_as_json }
end
end
end
7 changes: 3 additions & 4 deletions app/models/audio_event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@ class AudioEvent < ActiveRecord::Base
# relations
belongs_to :audio_recording

has_many :audio_event_tags

has_many :tags, :through => :audio_event_tags, :uniq => true
accepts_nested_attributes_for :tags

has_many :audio_event_tags
#accepts_nested_attributes_for :audio_event_tags

# attr
attr_accessible :audio_recording_id, :end_time_seconds, :high_frequency_hertz, :is_reference,
:low_frequency_hertz, :start_time_seconds,
:tags_attributes, :audio_event_tags_attributes
:tags_attributes

# userstamp
stampable
Expand Down
7 changes: 3 additions & 4 deletions app/models/tag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,16 @@ class Tag < ActiveRecord::Base
# relations
has_many :audio_event_tags
has_many :audio_events, :through => :audio_event_tags

accepts_nested_attributes_for :audio_events, :audio_event_tags
accepts_nested_attributes_for :audio_events

# attr
attr_accessible :is_taxanomic, :text, :type_of_tag

# userstamp
stampable
belongs_to :user, class_name: 'User', foreign_key: :creator_id
acts_as_paranoid
validates_as_paranoid
#acts_as_paranoid # deletable, not archiveable
#validates_as_paranoid

# enums
AVAILABLE_TYPE_OF_TAGS = [:common_name, :species_name, :looks_like, :sounds_like].map{ |item| item.to_s }
Expand Down
7 changes: 7 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
class User < ActiveRecord::Base
before_validation :ensure_password

# NB: this intentionally left simple
# The bulk of the emails populated into this model will come from external authentication providers
Expand Down Expand Up @@ -62,4 +63,10 @@ def skip_user_name_exclusion_list
@skip_user_name_exclusion_list
end

private

def ensure_password
self.password = Devise.friendly_token[0,20] if self.password.blank?
end

end
Loading

0 comments on commit 6ecca30

Please sign in to comment.