From 2748588caad532960d2592f937147b2bec48afdc Mon Sep 17 00:00:00 2001 From: Jonathan Kolyer Date: Mon, 25 Nov 2013 15:56:54 -0600 Subject: [PATCH] testing updates --- ruby/lib/jam_ruby/models/search.rb | 8 +++-- web/spec/features/musician_search_spec.rb | 38 +++++++++++++++++++++++ web/spec/spec_helper.rb | 1 + web/spec/support/request_helpers.rb | 11 +++++++ 4 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 web/spec/features/musician_search_spec.rb diff --git a/ruby/lib/jam_ruby/models/search.rb b/ruby/lib/jam_ruby/models/search.rb index e520c4753..cdfcb8d53 100644 --- a/ruby/lib/jam_ruby/models/search.rb +++ b/ruby/lib/jam_ruby/models/search.rb @@ -100,7 +100,7 @@ module JamRuby end def self.musician_search(params={}, current_user=nil) - rel = User.where(:musician => true) + rel = User.musicians unless (instrument = params[:instrument]).blank? rel = rel.joins("RIGHT JOIN musicians_instruments AS minst ON minst.user_id = users.id") .where(['minst.instrument_id = ? AND users.id IS NOT NULL', instrument]) @@ -130,7 +130,7 @@ module JamRuby end sel_str = 'users.*' case ordering = self.musician_order_param(params) - when :plays + when :plays # FIXME: double counting? sel_str = "COUNT(records)+COUNT(sessions) AS play_count, #{sel_str}" rel = rel.joins("LEFT JOIN music_sessions AS sessions ON sessions.user_id = users.id") rel = rel.joins("LEFT JOIN recordings AS records ON records.owner_id = users.id") @@ -204,6 +204,8 @@ module JamRuby self end + private + def _count(musician, key) if mm = @user_counters[musician.id] return mm.detect { |ii| ii.is_a?(Hash) }[key] @@ -211,6 +213,8 @@ module JamRuby 0 end + public + def follow_count(musician) _count(musician, COUNT_FOLLOW) end diff --git a/web/spec/features/musician_search_spec.rb b/web/spec/features/musician_search_spec.rb new file mode 100644 index 000000000..b2ce07802 --- /dev/null +++ b/web/spec/features/musician_search_spec.rb @@ -0,0 +1,38 @@ +require 'spec_helper' + +describe "Musician Search", :js => true, :type => :feature, :capybara_feature => true do + + subject { page } + + let(:user) { FactoryGirl.create(:user) } + + before(:all) do + poltergeist_setup + end + + before(:each) do + sign_in_poltergeist user + visit "/client#/musicians" + end + + it "shows the musician search page" do + expect(page).to have_selector('#find-musician-form') + end + + it "shows search results" do + expect(page).to have_selector('#musician-filter-results .musician-list-result') + end + + it "shows submits query" do + find("a#btn-refresh-musicians").trigger(:click) + expect(page).to have_selector('#musician-filter-results .musician-list-result') + end + + it "shows blank result set" do + expect(page).to have_selector('#instrument') + find('#instrument').find(:xpath, 'option[2]').select_option + find("a#btn-refresh-musicians").trigger(:click) + expect(page).to_not have_selector('#musician-filter-results .musician-list-result') + end + +end diff --git a/web/spec/spec_helper.rb b/web/spec/spec_helper.rb index 9a46ea0cc..17c386611 100644 --- a/web/spec/spec_helper.rb +++ b/web/spec/spec_helper.rb @@ -94,6 +94,7 @@ Spork.prefork do config.infer_base_class_for_anonymous_controllers = false config.include Requests::JsonHelpers, type: :request + config.include Requests::FeatureHelpers, type: :feature config.before(:suite) do end diff --git a/web/spec/support/request_helpers.rb b/web/spec/support/request_helpers.rb index 85dfba23c..3a871b415 100644 --- a/web/spec/support/request_helpers.rb +++ b/web/spec/support/request_helpers.rb @@ -1,4 +1,15 @@ module Requests + + module FeatureHelpers + + def poltergeist_setup + Capybara.javascript_driver = :poltergeist + Capybara.current_driver = Capybara.javascript_driver + Capybara.default_wait_time = 30 # these tests are SLOOOOOW + end + + end + module JsonHelpers def json