Skip to content

Commit

Permalink
removed unused code and added test using all filters
Browse files Browse the repository at this point in the history
  • Loading branch information
cofiem committed Apr 24, 2016
1 parent ef7628a commit 0541179
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 59 deletions.
59 changes: 0 additions & 59 deletions app/controllers/audio_events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -210,65 +210,6 @@ def download

private

# @param [AudioEvent] audio_event
def json_format(audio_event)

user = audio_event.creator
user_name = user.blank? ? '' : user.user_name
user_id = user.blank? ? '' : user.id

audio_event_hash = {
audio_event_id: audio_event.id,
id: audio_event.id,
audio_event_start_date: audio_event.audio_recording.recorded_date.advance(seconds: audio_event.start_time_seconds),
audio_recording_id: audio_event.audio_recording_id,
audio_recording_duration_seconds: audio_event.audio_recording.duration_seconds,
audio_recording_recorded_date: audio_event.audio_recording.recorded_date,
site_name: audio_event.audio_recording.site.name,
site_id: audio_event.audio_recording.site.id,
owner_name: user_name,
owner_id: user_id,
is_reference: audio_event.is_reference,
start_time_seconds: audio_event.start_time_seconds,
end_time_seconds: audio_event.end_time_seconds,
high_frequency_hertz: audio_event.high_frequency_hertz,
low_frequency_hertz: audio_event.low_frequency_hertz,
updated_at: audio_event.updated_at,
updater_id: audio_event.updater_id,
created_at: audio_event.created_at,
creator_id: audio_event.creator_id,
}

audio_event_hash[:tags] = audio_event.tags.map do |tag|
{
id: tag.id,
text: tag.text,
is_taxanomic: tag.is_taxanomic,
retired: tag.retired,
type_of_tag: tag.type_of_tag
}
end

audio_event_hash[:projects] = audio_event.audio_recording.site.projects.map do |project|
{
id: project.id,
name: project.name
}
end

# next and prev are just in order of ids (essentially the order the audio events were created)
next_event = AudioEvent.where('id > ?', audio_event.id).order('id ASC').first
prev_event = AudioEvent.where('id < ?', audio_event.id).order('id DESC').first
audio_event_hash[:paging] = {next_event: {}, prev_event: {}}

audio_event_hash[:paging][:next_event][:audio_event_id] = next_event.id unless next_event.blank?
audio_event_hash[:paging][:next_event][:audio_recording_id] = next_event.audio_recording_id unless next_event.blank?
audio_event_hash[:paging][:prev_event][:audio_event_id] = prev_event.id unless prev_event.blank?
audio_event_hash[:paging][:prev_event][:audio_recording_id] = prev_event.audio_recording_id unless prev_event.blank?

audio_event_hash
end

def audio_event_params
params.require(:audio_event).permit(
:audio_recording_id,
Expand Down
77 changes: 77 additions & 0 deletions spec/lib/filter/query_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1316,4 +1316,81 @@ def create_filter(params)

end

context 'available filter items' do

it 'every item is available' do
filter_hash = {
filter: {
and: {
media_type: {
# comparison
eq: 'm',
equal: 'm',
not_eq: 'm',
not_equal: 'm',
lt: 'm',
less_than: 'm',
not_lt: 'm',
not_less_than: 'm',
gt: 'm',
greater_than: 'm',
not_gt: 'm',
not_greater_than: 'm',
lteq: 'm',
less_than_or_equal: 'm',
not_lteq: 'm',
not_less_than_or_equal: 'm',
gteq: 'm',
greater_than_or_equal: 'm',
not_gteq: 'm',
not_greater_than_or_equal: 'm',

# subset
range: {from: 'm', to: 'm'},
in_range: {from: 'm', to: 'm'},
not_range: {from: 'm', to: 'm'},
not_in_range: {from: 'm', to: 'm'},
in: ['m'],
not_in: ['m'],
contains: 'm',
contain: 'm',
not_contains: 'm',
not_contain: 'm',
does_not_contain: 'm',
starts_with: 'm',
start_with: 'm',
not_starts_with: 'm',
not_start_with: 'm',
does_not_start_with: 'm',
ends_with: 'm',
end_with: 'm',
not_ends_with: 'm',
not_end_with: 'm',
does_not_end_with: 'm',
regex: 'm',
regex_match: 'm',
matches: 'm',
not_regex: 'm',
not_regex_match: 'm',
does_not_match: 'm',
not_match: 'm'
}
}
}
}

filter = Filter::Query.new(
filter_hash,
Access::Query.audio_recordings(admin_user),
AudioRecording,
AudioRecording.filter_settings
)

expect(filter.filter).to eq(filter_hash[:filter])

query = filter.query_full
expect(query.pluck(:id)).to match_array([])
end
end

end

0 comments on commit 0541179

Please sign in to comment.