VRFS-3036 testing filter by key
This commit is contained in:
parent
caca4165fe
commit
9757712977
|
|
@ -8,7 +8,7 @@ module JamRuby
|
|||
|
||||
KEY_BAND_SEARCH_TYPE = 'band_search_type'
|
||||
KEY_BAND_TYPE = 'band_type'
|
||||
KEY_PLAY_COMMIT = 'play_commit'
|
||||
KEY_PLAY_COMMIT = 'play_commitment'
|
||||
KEY_TOUR_OPTION = 'tour_option'
|
||||
KEY_PERF_SAMPLES = 'perform_samples'
|
||||
KEY_HIRE_MAX_COST = 'max_cost'
|
||||
|
|
@ -50,22 +50,24 @@ module JamRuby
|
|||
'1',
|
||||
'2',
|
||||
'3',
|
||||
'4',
|
||||
]
|
||||
PLAY_COMMITS = {
|
||||
PLAY_COMMIT_VALS[0] => 'Any',
|
||||
PLAY_COMMIT_VALS[1] => 'Infrequent',
|
||||
PLAY_COMMIT_VALS[2] => 'Once a week',
|
||||
PLAY_COMMIT_VALS[3] => 'More than once a week',
|
||||
PLAY_COMMIT_VALS[2] => 'Once a Week',
|
||||
PLAY_COMMIT_VALS[3] => '2-3 Times Per Week',
|
||||
PLAY_COMMIT_VALS[4] => '4+ Times Per Week',
|
||||
}
|
||||
|
||||
TOUR_OPTION_VALS = [ANY_VAL_STR,
|
||||
'yes',
|
||||
'no',
|
||||
VAL_YES,
|
||||
VAL_NO,
|
||||
]
|
||||
TOUR_OPTIONS = {
|
||||
TOUR_OPTION_VALS[0] => 'Any',
|
||||
TOUR_OPTION_VALS[1] => 'Yes',
|
||||
TOUR_OPTION_VALS[2] => 'No',
|
||||
TOUR_OPTION_VALS[1] => VAL_YES,
|
||||
TOUR_OPTION_VALS[2] => VAL_NO,
|
||||
}
|
||||
|
||||
PERF_SAMPLES_VALS = TOUR_OPTION_VALS.clone
|
||||
|
|
@ -139,7 +141,7 @@ module JamRuby
|
|||
end
|
||||
end
|
||||
|
||||
def _play_commit(rel, filter)
|
||||
def _play_commitment(rel, filter)
|
||||
unless ANY_VAL_STR == filter[KEY_PLAY_COMMIT]
|
||||
rel = rel.where(play_commitment: filter[KEY_PLAY_COMMIT].to_i)
|
||||
end
|
||||
|
|
@ -148,9 +150,9 @@ module JamRuby
|
|||
|
||||
def _tour_option(rel, filter)
|
||||
case filter[KEY_TOUR_OPTION]
|
||||
when 'yes'
|
||||
when VAL_YES
|
||||
rel.where(touring_option: true)
|
||||
when 'no'
|
||||
when VAL_NO
|
||||
rel.where(touring_option: false)
|
||||
else
|
||||
rel
|
||||
|
|
@ -164,16 +166,16 @@ module JamRuby
|
|||
def _max_cost(rel, filter)
|
||||
if 0 < (max_cost = filter[KEY_HIRE_MAX_COST].to_i)
|
||||
col = Band.arel_table[:gig_minimum]
|
||||
rel = rel.where(col.lteq(max_cost))
|
||||
rel = rel.where(col.lteq(max_cost)).where(col.gt(0))
|
||||
end
|
||||
rel
|
||||
end
|
||||
|
||||
def _free_gigs(rel, filter)
|
||||
case filter[KEY_FREE_GIGS]
|
||||
when 'yes'
|
||||
case filter[KEY_HIRE_FREE]
|
||||
when VAL_YES
|
||||
rel.where(free_gigs: true)
|
||||
when 'no'
|
||||
when VAL_NO
|
||||
rel.where(free_gigs: false)
|
||||
else
|
||||
rel
|
||||
|
|
|
|||
|
|
@ -6,6 +6,9 @@ module JamRuby
|
|||
ANY_VAL_STR = 'any'
|
||||
ANY_VAL_INT = -1
|
||||
|
||||
VAL_YES = 'yes'
|
||||
VAL_NO = 'no'
|
||||
|
||||
PER_PAGE = 10
|
||||
PG_SMALLINT_MAX = 32767
|
||||
|
||||
|
|
|
|||
|
|
@ -51,16 +51,47 @@ describe 'Band Search Model' do
|
|||
end
|
||||
|
||||
describe "filtering by keys" do
|
||||
|
||||
let!(:band) { Band.first }
|
||||
|
||||
it "filters by genre" do
|
||||
filter = to_join
|
||||
band_id = Band.first.genres.first.id
|
||||
band_id = band.id
|
||||
filter[BandSearch::KEY_GENRES] = [band_id]
|
||||
search.search_results_page(BandSearch::TO_JOIN, filter)
|
||||
expect(search.results.count).to eq(Band.all.map(&:genres).flatten.select { |bb| bb.id == band_id }.count)
|
||||
end
|
||||
|
||||
it "" do
|
||||
it "filters by free gigs" do
|
||||
filter = to_join
|
||||
band.update_attribute(BandSearch::KEY_HIRE_FREE, true)
|
||||
filter[BandSearch::KEY_HIRE_FREE] = BandSearch::VAL_YES
|
||||
search.search_results_page(BandSearch::TO_JOIN, filter)
|
||||
expect(search.results.count).to eq(1)
|
||||
expect(search.results[0].id).to eq(band.id)
|
||||
end
|
||||
|
||||
it "filters by max cost" do
|
||||
filter = to_join
|
||||
band.update_attribute(:gig_minimum, 10)
|
||||
filter[BandSearch::KEY_HIRE_MAX_COST] = 5
|
||||
search.search_results_page(BandSearch::TO_JOIN, filter)
|
||||
expect(search.results.count).to eq(0)
|
||||
|
||||
filter[BandSearch::KEY_HIRE_MAX_COST] = 15
|
||||
search.search_results_page(BandSearch::TO_JOIN, filter)
|
||||
expect(search.results.count).to eq(1)
|
||||
end
|
||||
|
||||
it "filters by play commitment" do
|
||||
filter = to_join
|
||||
band.update_attribute(BandSearch::KEY_PLAY_COMMIT, BandSearch::PLAY_COMMIT_VALS[1].to_i)
|
||||
filter[BandSearch::KEY_PLAY_COMMIT] = BandSearch::PLAY_COMMIT_VALS[1]
|
||||
search.search_results_page(BandSearch::TO_JOIN, filter)
|
||||
expect(search.results.count).to eq(1)
|
||||
expect(search.results[0].id).to eq(band.id)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in New Issue