diff --git a/ruby/lib/jam_ruby/models/band.rb b/ruby/lib/jam_ruby/models/band.rb index 131883ade..e29c8295e 100644 --- a/ruby/lib/jam_ruby/models/band.rb +++ b/ruby/lib/jam_ruby/models/band.rb @@ -130,11 +130,10 @@ module JamRuby # helper method for creating / updating a Band def self.save(id, name, website, biography, city, state, country, genres, user_id, photo_url, logo_url) - user = User.find(user_id) # new band - if id.nil? + if id.blank? # ensure person creating this Band is a Musician unless user.musician? @@ -173,35 +172,28 @@ module JamRuby # country band.country = country unless country.nil? - # genres - unless genres.nil? - ActiveRecord::Base.transaction do - # delete all genres for this band first - unless band.id.nil? || band.id.length == 0 - band.genres.delete_all - end - - # loop through each genre in the array and save to the db - genres.each do |genre_id| - g = Genre.find(genre_id) - band.genres << g - end - end - end - # photo url band.photo_url = photo_url unless photo_url.nil? # logo url band.logo_url = logo_url unless logo_url.nil? - band.updated_at = Time.now.getutc - band.save + # band.updated_at = Time.now.getutc + band.save! + band.reload + + # genres + unless genres.nil? + ActiveRecord::Base.transaction do + # delete all genres for this band first + band.genres.delete_all if id.present? + # loop through each genre in the array and save to the db + genres.each { |genre_id| band.genres << Genre.find(genre_id) } + end + end # add the creator as the admin - if id.nil? - BandMusician.create(:band_id => band.id, :user_id => user_id, :admin => true) - end + BandMusician.create(:band_id => band.id, :user_id => user_id, :admin => true) if id.blank? return band end @@ -243,6 +235,7 @@ module JamRuby if (city_changed? || state_changed? || country_changed?) update_lat_lng end + true end def update_lat_lng diff --git a/ruby/lib/jam_ruby/models/search.rb b/ruby/lib/jam_ruby/models/search.rb index e3f200677..930bb109c 100644 --- a/ruby/lib/jam_ruby/models/search.rb +++ b/ruby/lib/jam_ruby/models/search.rb @@ -41,8 +41,7 @@ module JamRuby search_results.take(LIMIT).each do |result| if result.class == User if result.musician - @musicians_filter.push(result) - @search_type = PARAM_MUSICIAN + @musicians.push(result) else @fans.push(result) end diff --git a/ruby/spec/jam_ruby/models/band_search_spec.rb b/ruby/spec/jam_ruby/models/band_search_spec.rb index ce9ca8767..40e26d50f 100644 --- a/ruby/spec/jam_ruby/models/band_search_spec.rb +++ b/ruby/spec/jam_ruby/models/band_search_spec.rb @@ -5,6 +5,8 @@ describe User do let(:user) { FactoryGirl.create(:user) } before(:each) do + @geocode1 = FactoryGirl.create(:geocoder) + @geocode2 = FactoryGirl.create(:geocoder) @user = FactoryGirl.create(:user) @band = Band.save(nil, "Example Band", "www.bands.com", "zomg we rock", "Apex", "NC", "US", ["hip hop"], user.id, nil, nil) diff --git a/web/spec/features/musician_search_spec.rb b/web/spec/features/musician_search_spec.rb index b2ce07802..e7c29d7aa 100644 --- a/web/spec/features/musician_search_spec.rb +++ b/web/spec/features/musician_search_spec.rb @@ -24,14 +24,12 @@ describe "Musician Search", :js => true, :type => :feature, :capybara_feature => 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 have_selector('#musician_instrument') + find('#musician_instrument').find(:xpath, 'option[2]').select_option expect(page).to_not have_selector('#musician-filter-results .musician-list-result') end diff --git a/web/spec/requests/musician_search_api_spec.rb b/web/spec/requests/musician_search_api_spec.rb index 11680a2a5..a48a1c6b1 100644 --- a/web/spec/requests/musician_search_api_spec.rb +++ b/web/spec/requests/musician_search_api_spec.rb @@ -29,7 +29,7 @@ describe "Musician Search API", :type => :api do it "default search" do get_query good_response - expect(json['musicians'].count).to be [Search::M_PER_PAGE, User.musicians_geocoded.count].min + expect(json['musicians'].count).to be [Search::M_PER_PAGE, User.musicians.count].min end context 'location filtering' do