From e27083e45cfc77f1274f46a9a8f6866e996378c1 Mon Sep 17 00:00:00 2001 From: Seth Call Date: Sat, 17 Nov 2012 21:41:26 -0600 Subject: [PATCH] * VRFS-100 completed --- .../api_music_sessions_controller.rb | 5 +++-- app/controllers/users_controller.rb | 3 ++- app/views/users/edit.html.erb | 7 +++++-- app/views/users/new.html.erb | 4 ++-- spec/factories.rb | 4 +++- spec/managers/user_manager_spec.rb | 10 ++-------- spec/requests/music_session_pages_spec.rb | 8 ++++---- spec/requests/search_api_spec.rb | 4 ++-- spec/requests/user_pages_spec.rb | 18 +++++++++++------- 9 files changed, 34 insertions(+), 29 deletions(-) diff --git a/app/controllers/api_music_sessions_controller.rb b/app/controllers/api_music_sessions_controller.rb index 88ad7047e..f150784b7 100644 --- a/app/controllers/api_music_sessions_controller.rb +++ b/app/controllers/api_music_sessions_controller.rb @@ -46,7 +46,7 @@ class ApiMusicSessionsController < ApiController unless @music_session.errors.any? # auto-join this user into the newly created session - connection_manager.join_music_session(current_user.id, client_id, @music_session.id) + connection_manager.join_music_session(current_user.id, client_id, @music_session.id, true) @connection = Connection.find_by_client_id(client_id) tracks = params[:tracks] @@ -110,7 +110,8 @@ class ApiMusicSessionsController < ApiController ConnectionManager.active_record_transaction do |connection_manager| @music_session = MusicSession.find(params[:id]) client_id = params[:client_id] - connection_manager.join_music_session(current_user.id, client_id, @music_session.id) + as_musician = params[:as_musician] + connection_manager.join_music_session(current_user.id, client_id, @music_session.id, as_musician) @connection = Connection.find_by_client_id(client_id) tracks = params[:tracks] associate_tracks(@connection, tracks) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 40ee063fb..6f5786ab7 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -27,7 +27,8 @@ class UsersController < ApplicationController end - @user = UserManager.new.signup(params[:jam_ruby_user][:name], + @user = UserManager.new.signup(params[:jam_ruby_user][:first_name], + params[:jam_ruby_user][:last_name], params[:jam_ruby_user][:email], params[:jam_ruby_user][:password], params[:jam_ruby_user][:password_confirmation], diff --git a/app/views/users/edit.html.erb b/app/views/users/edit.html.erb index a02ba9293..accea25d3 100644 --- a/app/views/users/edit.html.erb +++ b/app/views/users/edit.html.erb @@ -6,8 +6,11 @@ <%= form_for(@user) do |f| %> <%= render 'shared/error_messages', object: f.object %> - <%= f.label :name %> - <%= f.text_field :name %> + <%= f.label :first_name, "First Name" %> + <%= f.text_field :first_name %> + + <%= f.label :last_name, "Last Name" %> + <%= f.text_field :last_name %> <%= f.label :email %> <%= f.text_field :email %> diff --git a/app/views/users/new.html.erb b/app/views/users/new.html.erb index e57b20430..56d0e0e55 100644 --- a/app/views/users/new.html.erb +++ b/app/views/users/new.html.erb @@ -11,10 +11,10 @@
<%= form_for(@user) do |f| %> <%= render 'shared/error_messages', object: f.object %> - <%= f.label :first_name %> + <%= f.label :first_name, "First Name" %> <%= f.text_field :first_name %> - <%= f.label :last_name %> + <%= f.label :last_name, "Last Name" %> <%= f.text_field :last_name %> <%= f.label :email %> diff --git a/spec/factories.rb b/spec/factories.rb index 93fb0d62a..89138357f 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -1,10 +1,12 @@ FactoryGirl.define do factory :user, :class => "JamRuby::User" do - sequence(:name) { |n| "Person #{n}" } + sequence(:first_name) { |n| "Person" } + sequence(:last_name) { |n| "#{n}" } sequence(:email) { |n| "person_#{n}@example.com"} password "foobar" password_confirmation "foobar" email_confirmed true + musician true factory :admin do admin true diff --git a/spec/managers/user_manager_spec.rb b/spec/managers/user_manager_spec.rb index 777ce6f75..be880342c 100644 --- a/spec/managers/user_manager_spec.rb +++ b/spec/managers/user_manager_spec.rb @@ -48,12 +48,6 @@ describe UserManager do UserMailer.deliveries.length.should == 1 @user.errors.any?.should be_true @user.errors[:email][0].should == "has already been taken" - - # change email so that name appears dupped - @user = @user_manager.signup("bob", "smith", "bobbie@jamkazam.com", "foobar", "foobar", "Austin", "TX", "USA", nil, "http://localhost:3000/confirm" ) - UserMailer.deliveries.length.should == 1 - @user.errors.any?.should be_true - @user.errors[:name][0].should == "has already been taken" end it "fail on no username" do @@ -63,8 +57,8 @@ describe UserManager do @user.errors[:first_name][0].should == "can't be blank" end - it "fail on no username" do - @user = @user_manager.signup("murp", "", "foobar", "foobar", "Austin", "TX", "USA", nil, "http://localhost:3000/confirm" ) + it "fail on no email" do + @user = @user_manager.signup("murp", "blurp", "", "foobar", "foobar", "Austin", "TX", "USA", 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" diff --git a/spec/requests/music_session_pages_spec.rb b/spec/requests/music_session_pages_spec.rb index 41448a5a8..5b7691be4 100644 --- a/spec/requests/music_session_pages_spec.rb +++ b/spec/requests/music_session_pages_spec.rb @@ -118,7 +118,7 @@ describe "Music Session API ", :type => :api do end - it "should add a second member to the second" do + it "should add a second member to the session" do user2 = FactoryGirl.create(:user) client = FactoryGirl.create(:connection, :user => user, :ip_address => "1.1.1.1") @@ -143,7 +143,7 @@ describe "Music Session API ", :type => :api do musician["client_id"].should == client.client_id login(user2) - post "/api/sessions/#{music_session["id"]}/participants.json", { :client_id => client2.client_id, :tracks => [{"instrument_id" => "bass guitar", "sound" => "mono"}]}.to_json, "CONTENT_TYPE" => 'application/json' + post "/api/sessions/#{music_session["id"]}/participants.json", { :client_id => client2.client_id, :as_musician => true, :tracks => [{"instrument_id" => "bass guitar", "sound" => "mono"}]}.to_json, "CONTENT_TYPE" => 'application/json' last_response.status.should eql(201) @@ -321,7 +321,7 @@ describe "Music Session API ", :type => :api do # users are friends, but no invitation... so we shouldn't be able to join as user 2 login(user2) - post "/api/sessions/#{session["id"]}/participants.json", { :client_id => client2.client_id }.to_json + post "/api/sessions/#{session["id"]}/participants.json", { :client_id => client2.client_id, :as_musician => true }.to_json, "CONTENT_TYPE" => 'application/json' last_response.status.should eql(500) join_response = JSON.parse(last_response.body) join_response["type"].should == "PermissionError" @@ -332,7 +332,7 @@ describe "Music Session API ", :type => :api do last_response.status.should eql(201) login(user2) - post "/api/sessions/#{session["id"]}/participants.json", { :client_id => client2.client_id }.to_json, "CONTENT_TYPE" => 'application/json' + post "/api/sessions/#{session["id"]}/participants.json", { :client_id => client2.client_id, :as_musician => true }.to_json, "CONTENT_TYPE" => 'application/json' last_response.status.should eql(201) end end diff --git a/spec/requests/search_api_spec.rb b/spec/requests/search_api_spec.rb index f3ef15d76..32d57308e 100644 --- a/spec/requests/search_api_spec.rb +++ b/spec/requests/search_api_spec.rb @@ -28,8 +28,8 @@ describe "Search API ", :type => :api do it "simple search" do User.delete_search_index # so that the user created before the test and logged in doesn't show up User.create_search_index - @musician = FactoryGirl.create(:user, first_name: "Peach", last_name: "Nothing", name: "peach1", email: "user@example.com", musician: true) - @fan = FactoryGirl.create(:user, first_name: "Peach Peach", last_name: "Grovery", name: "peach2", email: "fan@example.com", musician: false) + @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(name: "Peach pit", website: "www.bands.com", biography: "zomg we rock") @band2 = Band.save(name: "Peach", website: "www.bands2.com", biography: "zomg we rock") User.search_index.refresh diff --git a/spec/requests/user_pages_spec.rb b/spec/requests/user_pages_spec.rb index c9d8d122b..25413e063 100644 --- a/spec/requests/user_pages_spec.rb +++ b/spec/requests/user_pages_spec.rb @@ -8,8 +8,8 @@ describe "User pages" do before do sign_in FactoryGirl.create(:user) - FactoryGirl.create(:user, name: "Bob", email: "bob@example.com") - FactoryGirl.create(:user, name: "Ben", email: "ben@example.com") + FactoryGirl.create(:user, first_name: "Bob", last_name: "User", email: "bob@example.com") + FactoryGirl.create(:user, first_name: "Ben", last_name: "User", email: "ben@example.com") visit users_path end @@ -112,6 +112,8 @@ describe "User pages" do describe "with valid information" do before do + fill_in "First Name", with: "Example" + fill_in "Last Name", with: "User" fill_in "Name", with: "Example User" fill_in "Email", with: "user@example.com" fill_in "City", with: "Austin" @@ -151,20 +153,22 @@ describe "User pages" do describe "with valid information" do - let(:new_name) { "New Name" } + let(:new_first_name) { "New" } + let(:new_last_name) { "Name" } let(:new_email) { "new@example.com" } before do - fill_in "Name", with: new_name + fill_in "First Name", with: new_first_name + fill_in "Last Name", with: new_last_name fill_in "Email", with: new_email fill_in "Password", with: user.password fill_in "Confirm Password", with: user.password click_button "Save changes" end - - it { should have_selector('title', text: new_name) } + it { should have_selector('div.alert.alert-success') } it { should have_link('Sign out', href: signout_path) } - specify { user.reload.name.should == new_name } + specify { user.reload.first_name.should == new_first_name } + specify { user.reload.last_name.should == new_last_name } specify { user.reload.email.should == new_email } end end