From 7bb6d6b71e2e3c551d2b31279f3fb9ba5ccbe28a Mon Sep 17 00:00:00 2001 From: Brian Smith Date: Wed, 28 Nov 2012 00:26:43 -0500 Subject: [PATCH] VRFS 79 add image URL fields to users and bands tables --- Gemfile | 1 + app/controllers/api_bands_controller.rb | 12 ++++++++---- app/controllers/api_users_controller.rb | 6 ++++-- app/controllers/sessions_controller.rb | 5 +++-- app/controllers/users_controller.rb | 1 + lib/managers/user_manager.rb | 4 ++-- spec/managers/user_manager_spec.rb | 14 +++++++------- spec/requests/bands_api_spec.rb | 20 ++++++++++++-------- spec/requests/search_api_spec.rb | 4 ++-- 9 files changed, 40 insertions(+), 27 deletions(-) diff --git a/Gemfile b/Gemfile index 6f7972ad9..3622f1bc1 100644 --- a/Gemfile +++ b/Gemfile @@ -40,6 +40,7 @@ gem 'omniauth-facebook' gem 'fb_graph' gem 'sendgrid' gem 'recaptcha' +gem 'filepicker-rails' group :development, :test do gem 'rspec-rails', '2.11.0' diff --git a/app/controllers/api_bands_controller.rb b/app/controllers/api_bands_controller.rb index 0a778e5b1..69a8af249 100644 --- a/app/controllers/api_bands_controller.rb +++ b/app/controllers/api_bands_controller.rb @@ -21,7 +21,9 @@ class ApiBandsController < ApiController params[:state], params[:country], params[:genres], - current_user.id) + current_user.id, + params[:photo_url], + params[:logo_url]) respond_with @band, responder: ApiResponder, :status => 201, :location => api_band_detail_url(@band) end @@ -38,7 +40,9 @@ class ApiBandsController < ApiController params[:state], params[:country], params[:genres], - current_user.id,) + current_user.id, + params[:photo_url], + params[:logo_url]) respond_with @band, responder: ApiResponder, :status => :ok end @@ -120,7 +124,7 @@ class ApiBandsController < ApiController end def recording_destroy - @band = Band.find(params[:id]) + @band = Band.find_by_id(params[:id]) auth_band_member(@band, current_user) @recording = Recording.find(params[:recording_id]) @@ -138,7 +142,7 @@ class ApiBandsController < ApiController def invitation_index @band = Band.find(params[:id]) auth_band_member(@band, current_user) - @invitations = @band.invitations + @invitations = @band.invitations #BandInvitation.find_by_band_id(params[:id]) respond_with @invitations, responder: ApiResponder, :status => 200 end diff --git a/app/controllers/api_users_controller.rb b/app/controllers/api_users_controller.rb index c224adf4f..9b7a92bc0 100644 --- a/app/controllers/api_users_controller.rb +++ b/app/controllers/api_users_controller.rb @@ -30,6 +30,7 @@ class ApiUsersController < ApiController params[:state], params[:country], params[:instruments], + params[:photo_url], ApplicationHelper.base_uri(request) + "/confirm") # check for errors @@ -68,7 +69,8 @@ class ApiUsersController < ApiController params[:city], params[:state], params[:country], - params[:instruments]) + params[:instruments], + params[:photo_url]) respond_with @user, responder: ApiResponder, :status => 200 end @@ -271,7 +273,7 @@ class ApiUsersController < ApiController def band_invitation_index auth_user(params[:id]) @user = current_user - @invitations = @user.received_band_invitations #.merge(@user.sent_band_invitations) + @invitations = @user.received_band_invitations#.merge(@user.sent_band_invitations) respond_with @invitations, responder: ApiResponder, :status => 200 end diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index f9341f8a4..3802055f6 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -46,8 +46,9 @@ class SessionsController < ApplicationController nil, auth_hash[:info][:location], nil, # state - nil, # @country - nil, + nil, # country + nil, # instruments + nil, # photo_url nil) # Users who sign up using oauth are presumed to have valid email adddresses. diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 481c8431f..0447ba6fe 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -36,6 +36,7 @@ class UsersController < ApplicationController params[:jam_ruby_user][:state], params[:jam_ruby_user][:country], params[:jam_ruby_user][:instruments], + params[:jam_ruby_user][:photo_url], ApplicationHelper.base_uri(request) + "/confirm") # check for errors diff --git a/lib/managers/user_manager.rb b/lib/managers/user_manager.rb index 052181181..9e996d26b 100644 --- a/lib/managers/user_manager.rb +++ b/lib/managers/user_manager.rb @@ -9,7 +9,7 @@ class UserManager < BaseManager end def signup(first_name, last_name, email, password, password_confirmation, - city, state, country, instruments, signup_confirm_url) + city, state, country, instruments, photo_url, signup_confirm_url) @user = User.new @@ -22,7 +22,7 @@ class UserManager < BaseManager #else # sends email to email account for confirmation @user = User.signup(first_name, last_name, email, password, password_confirmation, - city, state, country, instruments, signup_confirm_url) + city, state, country, instruments, photo_url, signup_confirm_url) return @user #end diff --git a/spec/managers/user_manager_spec.rb b/spec/managers/user_manager_spec.rb index 599690e8b..d6da1f846 100644 --- a/spec/managers/user_manager_spec.rb +++ b/spec/managers/user_manager_spec.rb @@ -11,7 +11,7 @@ describe UserManager do describe "signup" do it "signup successfully" do - @user = @user_manager.signup("bob", "smith", "bob@jamkazam.com", "foobar", "foobar", "Austin", "TX", "USA", nil, "http://localhost:3000/confirm" ) + @user = @user_manager.signup("bob", "smith", "bob@jamkazam.com", "foobar", "foobar", "Austin", "TX", "USA", nil, nil, "http://localhost:3000/confirm" ) @user.errors.any?.should be_false @user.first_name.should == "bob" @@ -29,7 +29,7 @@ describe UserManager do it "signup successfully with instruments" do @user = @user_manager.signup("bob", "smith", "bob@jamkazam.com", "foobar", "foobar", "Austin", "TX", "USA", - [{ :instrument_id => "electric guitar", :proficiency_level => 3, :priority => 0}], "http://localhost:3000/confirm") + [{ :instrument_id => "electric guitar", :proficiency_level => 3, :priority => 0}], nil, "http://localhost:3000/confirm") @user.errors.any?.should be_false @user.instruments.length.should == 1 @@ -39,26 +39,26 @@ describe UserManager do end it "duplicate signup failure" do - @user = @user_manager.signup("bob", "smith", "bob@jamkazam.com", "foobar", "foobar", "Austin", "TX", "USA", nil, "http://localhost:3000/confirm") + @user = @user_manager.signup("bob", "smith", "bob@jamkazam.com", "foobar", "foobar", "Austin", "TX", "USA", nil, nil, "http://localhost:3000/confirm") UserMailer.deliveries.length.should == 1 @user.errors.any?.should be_false # exactly the same parameters; should dup on email, and send no email - @user = @user_manager.signup("bob", "smith", "bob@jamkazam.com", "foobar", "foobar", "Austin", "TX", "USA", nil, "http://localhost:3000/confirm") + @user = @user_manager.signup("bob", "smith", "bob@jamkazam.com", "foobar", "foobar", "Austin", "TX", "USA", nil, nil, "http://localhost:3000/confirm") UserMailer.deliveries.length.should == 1 @user.errors.any?.should be_true @user.errors[:email][0].should == "has already been taken" end it "fail on no username" do - @user = @user_manager.signup("", "", "bob@jamkazam.com", "foobar", "foobar", "Austin", "TX", "USA", nil, "http://localhost:3000/confirm") + @user = @user_manager.signup("", "", "bob@jamkazam.com", "foobar", "foobar", "Austin", "TX", "USA", nil, nil, "http://localhost:3000/confirm") UserMailer.deliveries.length.should == 0 @user.errors.any?.should be_true @user.errors[:first_name][0].should == "can't be blank" end it "fail on no email" do - @user = @user_manager.signup("murp", "blurp", "", "foobar", "foobar", "Austin", "TX", "USA", nil, "http://localhost:3000/confirm" ) + @user = @user_manager.signup("murp", "blurp", "", "foobar", "foobar", "Austin", "TX", "USA", nil, nil, "http://localhost:3000/confirm" ) UserMailer.deliveries.length.should == 0 @user.errors.any?.should be_true @user.errors[:email][0].should == "can't be blank" @@ -67,7 +67,7 @@ describe UserManager do describe "signup_confirm" do it "fail on no username" do - @user = @user_manager.signup("bob", "smith", "bob@jamkazam.com", "foobar", "foobar", "Austin", "TX", "USA", nil, "http://localhost:3000/confirm" ) + @user = @user_manager.signup("bob", "smith", "bob@jamkazam.com", "foobar", "foobar", "Austin", "TX", "USA", nil, nil, "http://localhost:3000/confirm" ) @user = @user_manager.signup_confirm(@user.signup_token) @user.email_confirmed.should be_true end diff --git a/spec/requests/bands_api_spec.rb b/spec/requests/bands_api_spec.rb index 3f3516cec..ea25f914e 100644 --- a/spec/requests/bands_api_spec.rb +++ b/spec/requests/bands_api_spec.rb @@ -19,27 +19,31 @@ describe "Band API", :type => :api do end ################################## BANDS ################################## - def create_band(authenticated_user, name, website, biography, city, state, country, genres) + def create_band(authenticated_user, name, website, biography, city, state, country, genres, photo_url, logo_url) post "/api/bands.json", { :name => name, :website => website, :biography => biography, :city => city, :state => state, :country => country, - :genres => genres + :genres => genres, + :photo_url => photo_url, + :logo_url => logo_url }.to_json, "CONTENT_TYPE" => 'application/json' return last_response end - def update_band(authenticated_user, band_id, name, website, biography, city, state, country, genres) + def update_band(authenticated_user, band_id, name, website, biography, city, state, country, genres, photo_url, logo_url) post "/api/bands/#{band_id}.json", { :name => name, :website => website, :biography => biography, :city => city, :state => state, :country => country, - :genres => genres + :genres => genres, + :photo_url => photo_url, + :logo_url => logo_url }.to_json, "CONTENT_TYPE" => 'application/json' return last_response @@ -96,7 +100,7 @@ describe "Band API", :type => :api do it "should allow band creation" do - last_response = create_band(user, "My Band", "http://www.myband.com", "Bio", "Apex", "NC", "USA", ["african", "hip hop", "country"]) + last_response = create_band(user, "My Band", "http://www.myband.com", "Bio", "Apex", "NC", "USA", ["african", "hip hop", "country"], "www.photos.com", "www.logos.com") last_response.status.should == 201 new_band = JSON.parse(last_response.body) @@ -113,14 +117,14 @@ describe "Band API", :type => :api do end it "should prevent bands with less than 1 genre" do - last_response = create_band(user, "My Band", "http://www.myband.com", "Bio", "Apex", "NC", "USA", nil) + last_response = create_band(user, "My Band", "http://www.myband.com", "Bio", "Apex", "NC", "USA", nil, "www.photos.com", "www.logos.com") last_response.status.should == 400 error_msg = JSON.parse(last_response.body) error_msg["message"].should == ValidationMessages::GENRE_MINIMUM_NOT_MET end it "should prevent bands with more than 3 genres" do - last_response = create_band(user, "My Band", "http://www.myband.com", "Bio", "Apex", "NC", "USA", ["african", "hip hop", "country", "reggae"]) + last_response = create_band(user, "My Band", "http://www.myband.com", "Bio", "Apex", "NC", "USA", ["african", "hip hop", "country", "reggae"], "www.photos.com", "www.logos.com") last_response.status.should == 400 error_msg = JSON.parse(last_response.body) error_msg["message"].should == ValidationMessages::GENRE_LIMIT_EXCEEDED @@ -141,7 +145,7 @@ describe "Band API", :type => :api do band.genres.size.should == 3 - last_response = update_band(user, band.id, "Brian's Band", "http://www.briansband.com", "Bio", "Apex", "NC", "USA", ["african", "blues"]) + last_response = update_band(user, band.id, "Brian's Band", "http://www.briansband.com", "Bio", "Apex", "NC", "USA", ["african", "blues"], "www.photos.com", "www.logos.com") last_response.status.should == 200 updated_band = JSON.parse(last_response.body) diff --git a/spec/requests/search_api_spec.rb b/spec/requests/search_api_spec.rb index 10028f01a..690fa75fb 100644 --- a/spec/requests/search_api_spec.rb +++ b/spec/requests/search_api_spec.rb @@ -29,8 +29,8 @@ describe "Search API", :type => :api do User.create_search_index @musician = FactoryGirl.create(:user, first_name: "Peach", last_name: "Nothing", email: "user@example.com", musician: true) @fan = FactoryGirl.create(:user, first_name: "Peach Peach", last_name: "Grovery", email: "fan@example.com", musician: false) - @band = Band.save(nil, "Peach pit", "www.bands.com", "zomg we rock", "Apex", "NC", "USA", ["hip hop"], user.id) - @band2 = Band.save(nil, "Peach", "www.bands2.com", "zomg we rock", "Apex", "NC", "USA", ["hip hop"], user.id) + @band = Band.save(nil, "Peach pit", "www.bands.com", "zomg we rock", "Apex", "NC", "USA", ["hip hop"], user.id, nil, nil) + @band2 = Band.save(nil, "Peach", "www.bands2.com", "zomg we rock", "Apex", "NC", "USA", ["hip hop"], user.id, nil, nil) User.search_index.refresh Band.search_index.refresh