From 205380d91eb15b73b9dc5d90475437858ab8e012 Mon Sep 17 00:00:00 2001 From: Brian Smith Date: Sat, 17 Nov 2012 22:56:23 -0500 Subject: [PATCH] more test cleanup --- app/controllers/users_controller.rb | 3 ++- spec/factories.rb | 1 - spec/managers/user_manager_spec.rb | 12 ++++++------ spec/requests/search_api_spec.rb | 4 ++-- spec/requests/user_pages_spec.rb | 19 ++++++++++++------- 5 files changed, 22 insertions(+), 17 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 40ee063fb..481c8431f 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/spec/factories.rb b/spec/factories.rb index 93fb0d62a..2a8c04b8f 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -1,6 +1,5 @@ FactoryGirl.define do factory :user, :class => "JamRuby::User" do - sequence(:name) { |n| "Person #{n}" } sequence(:email) { |n| "person_#{n}@example.com"} password "foobar" password_confirmation "foobar" diff --git a/spec/managers/user_manager_spec.rb b/spec/managers/user_manager_spec.rb index 777ce6f75..f934f69ab 100644 --- a/spec/managers/user_manager_spec.rb +++ b/spec/managers/user_manager_spec.rb @@ -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}], "http://localhost:3000/confirm") @user.errors.any?.should be_false @user.instruments.length.should == 1 @@ -39,32 +39,32 @@ 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, "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, "http://localhost:3000/confirm") 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" ) + @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 - @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, "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 username" do - @user = @user_manager.signup("murp", "", "foobar", "foobar", "Austin", "TX", "USA", nil, "http://localhost:3000/confirm" ) + @user = @user_manager.signup("murp", "last", "", "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/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..20b8cef5b 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: "Smith", email: "bob@example.com") + FactoryGirl.create(:user, first_name: "Ben", last_name: "Smith", email: "ben@example.com") visit users_path end @@ -112,7 +112,8 @@ describe "User pages" do describe "with valid information" do before do - fill_in "Name", with: "Example User" + fill_in "First Name", with: "Example" + fill_in "Last Name", with: "User" fill_in "Email", with: "user@example.com" fill_in "City", with: "Austin" fill_in "State", with: "TX" @@ -151,20 +152,24 @@ describe "User pages" do describe "with valid information" do - let(:new_name) { "New Name" } + let(:new_first_name) { "New First Name" } + let(:new_last_name) { "New Last 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('title', text: new_first_name) } + it { should have_selector('title', text: new_last_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