diff --git a/spec/controllers/aspects_controller_spec.rb b/spec/controllers/aspects_controller_spec.rb index 028e8402d..5346d31c7 100644 --- a/spec/controllers/aspects_controller_spec.rb +++ b/spec/controllers/aspects_controller_spec.rb @@ -84,7 +84,7 @@ describe AspectsController do end describe "#create" do - describe "with valid params" do + context "with valid params" do it "creates an aspect" do @user.aspects.count.should == 2 post :create, "aspect" => {"name" => "new aspect"} @@ -95,7 +95,7 @@ describe AspectsController do response.should redirect_to(aspect_path(Aspect.find_by_name("new aspect"))) end end - describe "with invalid params" do + context "with invalid params" do it "does not create an aspect" do @user.aspects.count.should == 2 post :create, "aspect" => {"name" => ""} diff --git a/spec/controllers/comments_controller_spec.rb b/spec/controllers/comments_controller_spec.rb index 993a08577..24f5ee4cd 100644 --- a/spec/controllers/comments_controller_spec.rb +++ b/spec/controllers/comments_controller_spec.rb @@ -7,24 +7,24 @@ require 'spec_helper' describe CommentsController do render_views - let!(:user) { make_user } - let!(:aspect) { user.aspects.create(:name => "AWESOME!!") } + let!(:user1) { make_user } + let!(:aspect1) { user1.aspects.create(:name => "AWESOME!!") } - let!(:user2) { make_user } + let!(:user2) { make_user } let!(:aspect2) { user2.aspects.create(:name => "WIN!!") } before do - sign_in :user, user + sign_in :user, user1 end describe '#create' do let(:comment_hash) { - {:text =>"facebook, is that you?", + {:text =>"facebook, is that you?", :post_id =>"#{@post.id}"} } context "on my own post" do before do - @post = user.post :status_message, :message => 'GIANTS', :to => aspect.id + @post = user1.post :status_message, :message => 'GIANTS', :to => aspect1.id end it 'responds to format js' do post :create, comment_hash.merge(:format => 'js') @@ -35,7 +35,7 @@ describe CommentsController do context "on a post from a contact" do before do - connect_users(user, aspect, user2, aspect2) + connect_users(user1, aspect1, user2, aspect2) @post = user2.post :status_message, :message => 'GIANTS', :to => aspect2.id end it 'comments' do @@ -46,10 +46,10 @@ describe CommentsController do new_user = make_user comment_hash[:person_id] = new_user.person.id.to_s post :create, comment_hash - Comment.find_by_text(comment_hash[:text]).person_id.should == user.person.id + Comment.find_by_text(comment_hash[:text]).person_id.should == user1.person.id end it "doesn't overwrite id" do - old_comment = user.comment("hello", :on => @post) + old_comment = user1.comment("hello", :on => @post) comment_hash[:id] = old_comment.id post :create, comment_hash old_comment.reload.text.should == 'hello' @@ -60,7 +60,7 @@ describe CommentsController do @post = user2.post :status_message, :message => 'GIANTS', :to => aspect2.id end it 'posts no comment' do - user.should_receive(:comment).exactly(0).times + user1.should_not_receive(:comment) post :create, comment_hash response.code.should == '406' end diff --git a/spec/controllers/home_controller_spec.rb b/spec/controllers/home_controller_spec.rb index b30ab4165..802d6f7c1 100644 --- a/spec/controllers/home_controller_spec.rb +++ b/spec/controllers/home_controller_spec.rb @@ -14,14 +14,14 @@ describe HomeController do end describe '#show' do - it 'should show a login link if no user is not logged in' do - get :show + it 'shows a login link if no user is not logged in' do + get :show response.body.should include("login") end - it 'should redirect to aspects index if user is logged in' do + it 'redirects to aspects index if user is logged in' do sign_in @user - get :show + get :show response.should redirect_to aspects_path end end @@ -40,15 +40,15 @@ describe HomeController do end it 'logs a unified id in a request' do id = @lines.first.match(/r_id=(\w+)\s/).captures.first - @lines.each do |line| + @lines.each do |line| line.match(/r_id=(\w+)\s/).captures.first.should == @id end end it 'logs different ids in different requests' do get :show - old_lines = Rails.logger.infos.select do |line| + old_lines = Rails.logger.infos.select do |line| line.match(/r_id=(\w+)\s/).captures.first == @id - end + end old_lines.length.should == Rails.logger.infos.length/2 end end @@ -72,7 +72,7 @@ describe HomeController do end it 'logs layouts' do pending 'where is the template=home/show line?' - home_line = @lines.detect{|t| + home_line = @lines.detect{|t| t.include?("template=home/show.html.haml")} home_line.should match /layout=layouts\/application/ end diff --git a/spec/controllers/invitations_controller_spec.rb b/spec/controllers/invitations_controller_spec.rb index 6c4486d53..ed3427e28 100644 --- a/spec/controllers/invitations_controller_spec.rb +++ b/spec/controllers/invitations_controller_spec.rb @@ -9,8 +9,8 @@ describe InvitationsController do render_views - let!(:user) {make_user} - let!(:aspect){user.aspects.create(:name => "WIN!!")} + let!(:user) { make_user } + let!(:aspect) { user.aspects.create(:name => "WIN!!") } before do request.env["devise.mapping"] = Devise.mappings[:user] @@ -26,23 +26,26 @@ describe InvitationsController do request.env["HTTP_REFERER"]= 'http://test.host/cats/foo' end - it 'should call the resque job Jobs::InviteUser' do + it 'calls the resque job Jobs::InviteUser' do Resque.should_receive(:enqueue) post :create, :user => @invite end - it 'can handle a comma seperated list of emails' do + it 'handles a comma seperated list of emails' do Resque.should_receive(:enqueue).twice() - post :create, :user => @invite.merge(:email => "foofoofoofoo@example.com, mbs@gmail.com") + post :create, :user => @invite.merge( + :email => "foofoofoofoo@example.com, mbs@gmail.com") end - it 'can handle a comma seperated list of emails with whitespace' do + it 'handles a comma seperated list of emails with whitespace' do Resque.should_receive(:enqueue).twice() - post :create, :user => @invite.merge(:email => "foofoofoofoo@example.com , mbs@gmail.com") + post :create, :user => @invite.merge( + :email => "foofoofoofoo@example.com , mbs@gmail.com") end - it 'displays a message that tells you how many invites were sent, and which REJECTED' do - post :create, :user => @invite.merge(:email => "mbs@gmail.com, foo@bar.com, foo.com, lala@foo, cool@bar.com") + it 'displays a message that tells the user how many invites were sent, and which REJECTED' do + post :create, :user => @invite.merge( + :email => "mbs@gmail.com, foo@bar.com, foo.com, lala@foo, cool@bar.com") flash[:error].should_not be_empty flash[:error].should =~ /foo\.com/ flash[:error].should =~ /lala@foo/ @@ -75,7 +78,7 @@ describe InvitationsController do end context 'success' do let(:invited) {User.find_by_username(@accept_params[:user][:username])} - it 'creates user' do + it 'creates a user' do put :update, @accept_params invited.should_not be_nil end diff --git a/spec/controllers/people_controller_spec.rb b/spec/controllers/people_controller_spec.rb index 24cafb5c7..2a6ae0653 100644 --- a/spec/controllers/people_controller_spec.rb +++ b/spec/controllers/people_controller_spec.rb @@ -7,7 +7,7 @@ require 'spec_helper' describe PeopleController do render_views - let(:user) { Factory(:user) } + let(:user) { make_user } let!(:aspect) { user.aspects.create(:name => "lame-os") } before do @@ -119,19 +119,27 @@ describe PeopleController do end describe '#index' do before do - @eugene = Factory.create(:person, :profile => {:first_name => "Eugene", :last_name => "w"}) - @korth = Factory.create(:person, :profile => {:first_name => "Evan", :last_name => "Korth"}) + @eugene = Factory.create(:person, + :profile => {:first_name => "Eugene", + :last_name => "w"}) + @korth = Factory.create(:person, + :profile => {:first_name => "Evan", + :last_name => "Korth"}) end it "assigns hashes" do - eugene2 = Factory.create(:person, :profile => {:first_name => "Eugene", :last_name => "w"}) + eugene2 = Factory.create(:person, + :profile => {:first_name => "Eugene", + :last_name => "w"}) get :index, :q => "Eu" people = assigns[:hashes].map{|h| h[:person]} people.should include @eugene people.should include eugene2 end it "assigns people" do - eugene2 = Factory.create(:person, :profile => {:first_name => "Eugene", :last_name => "w"}) + eugene2 = Factory.create(:person, + :profile => {:first_name => "Eugene", + :last_name => "w"}) get :index, :q => "Eu" assigns[:people].should =~ [@eugene, eugene2] end @@ -162,7 +170,7 @@ describe PeopleController do end describe '#show' do - it 'should go to the current_user show page' do + it 'goes to the current_user show page' do get :show, :id => user.person.id response.should be_success end @@ -180,12 +188,12 @@ describe PeopleController do response.should be_success end - it "redirects on an invalid id" do + it "redirects to #index if the id is invalid" do get :show, :id => 'delicious' response.should redirect_to people_path end - it "redirects on a nonexistent person" do + it "redirects to #index if no person is found" do get :show, :id => user.id response.should redirect_to people_path end @@ -256,7 +264,8 @@ describe PeopleController do end it 'does not overwrite the profile diaspora handle' do - handle_params = {:id => user.person.id, :profile => {:diaspora_handle => 'abc@a.com'}} + handle_params = {:id => user.person.id, + :profile => {:diaspora_handle => 'abc@a.com'} } put :update, handle_params user.person.reload.profile[:diaspora_handle].should_not == 'abc@a.com' end diff --git a/spec/controllers/photos_controller_spec.rb b/spec/controllers/photos_controller_spec.rb index d805ef052..65810347e 100644 --- a/spec/controllers/photos_controller_spec.rb +++ b/spec/controllers/photos_controller_spec.rb @@ -7,17 +7,17 @@ require 'spec_helper' describe PhotosController do render_views - let(:user) {make_user} + let(:user) {make_user} let(:user2) {make_user} - let!(:aspect) {user.aspects.create(:name => 'winners')} - let(:aspect2) {user2.aspects.create(:name => 'winners')} + let!(:aspect) { user.aspects.create(:name => 'winners') } + let(:aspect2) { user2.aspects.create(:name => 'winners') } - let(:filename) {'button.png'} - let(:fixture_name) {File.join(File.dirname(__FILE__), '..', 'fixtures', filename)} - let(:image) {File.open(fixture_name)} - let!(:photo){ user.post(:photo, :user_file => image, :to => aspect.id)} - let!(:photo2){ user2.post(:photo, :user_file => image, :to => aspect2.id)} + let(:filename) { 'button.png' } + let(:fixture_name) { File.join(File.dirname(__FILE__), '..', 'fixtures', filename) } + let(:image) { File.open(fixture_name) } + let!(:photo) { user.post(:photo, :user_file => image, :to => aspect.id) } + let!(:photo2) { user2.post(:photo, :user_file => image, :to => aspect2.id) } before do connect_users(user, aspect, user2, aspect2) @@ -27,11 +27,11 @@ describe PhotosController do describe '#create' do before do @controller.stub!(:file_handler).and_return(image) - @params = {:photo => {:user_file => image, :aspect_ids => "all"}} + @params = {:photo => {:user_file => image, :aspect_ids => "all"} } end it 'can make a photo' do - proc{ + lambda { post :create, @params }.should change(Photo, :count).by(1) end @@ -54,28 +54,28 @@ describe PhotosController do get :index, :person_id => user2.person.id.to_s assigns[:person].should == user2.person - assigns[:posts].should == [] + assigns[:posts].should be_empty end end describe '#show' do it 'assigns the photo based on the photo id' do get :show, :id => photo.id - response.code.should == "200" + response.status.should == 200 assigns[:photo].should == photo - assigns[:ownership].should == true + assigns[:ownership].should be_true end end describe '#edit' do - it 'should let you edit a photo' do + it 'lets the user edit a photo' do get :edit, :id => photo.id - response.code.should == "200" + response.status.should == 200 end - it 'should not let you edit a photo that is not yours' do + it 'does not let the user edit a photo that is not his' do get :edit, :id => photo2.id response.should redirect_to(:action => :index, :person_id => user.person.id.to_s) end @@ -83,35 +83,34 @@ describe PhotosController do describe '#destroy' do - it 'should let me delete my photos' do + it 'allows the user to delete his photos' do delete :destroy, :id => photo.id - Photo.find_by_id(photo.id).should be nil + Photo.find_by_id(photo.id).should be_nil end it 'will not let you destory posts you do not own' do delete :destroy, :id => photo2.id - Photo.find_by_id(photo2.id).should_not be nil + Photo.find_by_id(photo2.id).should be_true end end describe "#update" do - it "should update the caption of a photo" do - put :update, :id => photo.id, :photo => { :caption => "now with lasers!"} + it "updates the caption of a photo" do + put :update, :id => photo.id, :photo => { :caption => "now with lasers!" } photo.reload.caption.should == "now with lasers!" end it "doesn't overwrite random attributes" do new_user = Factory.create :user - params = { :caption => "now with lasers!", :person_id => new_user.id} + params = { :caption => "now with lasers!", :person_id => new_user.id } put :update, :id => photo.id, :photo => params photo.reload.person_id.should == user.person.id end - it 'should redirect if you do not have access to the post' do - params = { :caption => "now with lasers!"} + it 'redirects if you do not have access to the post' do + params = { :caption => "now with lasers!" } put :update, :id => photo2.id, :photo => params response.should redirect_to(:action => :index, :person_id => user.person.id.to_s) - end end diff --git a/spec/controllers/publics_controller_spec.rb b/spec/controllers/publics_controller_spec.rb index 1689ab613..ac78c148e 100644 --- a/spec/controllers/publics_controller_spec.rb +++ b/spec/controllers/publics_controller_spec.rb @@ -7,7 +7,7 @@ require 'spec_helper' describe PublicsController do render_views - let(:user) { make_user } + let(:user) { make_user } let(:person) { Factory(:person) } describe '#receive' do diff --git a/spec/controllers/registrations_controller_spec.rb b/spec/controllers/registrations_controller_spec.rb index 9f8e5299a..f8b4c0ecb 100644 --- a/spec/controllers/registrations_controller_spec.rb +++ b/spec/controllers/registrations_controller_spec.rb @@ -2,7 +2,7 @@ # licensed under the Affero General Public License version 3 or later. See # the COPYRIGHT file. -require File.join(File.dirname(__FILE__), "..", "spec_helper") +require 'spec_helper' describe RegistrationsController do include Devise::TestHelpers @@ -11,10 +11,13 @@ describe RegistrationsController do before do request.env["devise.mapping"] = Devise.mappings[:user] - @valid_params = {"user" => {"username" => "jdoe", - "email" => "jdoe@example.com", - "password" => "password", - "password_confirmation" => "password"}} + @valid_params = {:user => { + :username => "jdoe", + :email => "jdoe@example.com", + :password => "password", + :password_confirmation => "password" + } + } end describe '#check_registrations_open!' do @@ -24,12 +27,12 @@ describe RegistrationsController do after do APP_CONFIG[:registrations_closed] = false end - it 'stops a #new request' do + it 'redirects #new to the login page' do get :new flash[:error].should == I18n.t('registrations.closed') response.should redirect_to new_user_session_path end - it 'stops a #create request' do + it 'redirects #create to the login page' do post :create, @valid_params flash[:error].should == I18n.t('registrations.closed') response.should redirect_to new_user_session_path @@ -43,11 +46,13 @@ describe RegistrationsController do User.stub!(:build).and_return(user) end it "creates a user" do - lambda { get :create, @valid_params }.should change(User, :count).by(1) + lambda { + get :create, @valid_params + }.should change(User, :count).by(1) end it "assigns @user" do get :create, @valid_params - assigns(:user).should_not be_nil + assigns(:user).should be_true end it "sets the flash" do get :create, @valid_params @@ -61,7 +66,7 @@ describe RegistrationsController do context "with invalid parameters" do before do @invalid_params = @valid_params - @invalid_params["user"]["password_confirmation"] = "baddword" + @invalid_params[:user][:password_confirmation] = "baddword" end it "does not create a user" do lambda { get :create, @invalid_params }.should_not change(User, :count) diff --git a/spec/controllers/requests_controller_spec.rb b/spec/controllers/requests_controller_spec.rb index a1823cb42..d909f4b7f 100644 --- a/spec/controllers/requests_controller_spec.rb +++ b/spec/controllers/requests_controller_spec.rb @@ -23,24 +23,28 @@ describe RequestsController do describe '#destroy' do before do @other_user.send_contact_request_to(@user.person, @other_user.aspects.first) - @user.reload # so it can find its pending requests. @friend_request = Request.to(@user.person).first end describe 'when accepting a contact request' do it "succeeds" do - xhr :delete, :destroy, "accept" => "true", "aspect_id" => @user.aspects.first.id.to_s, "id" => @friend_request.id.to_s + xhr :delete, :destroy, + :accept => "true", + :aspect_id => @user.aspects.first.id.to_s, + :id => @friend_request.id.to_s response.should redirect_to(aspect_path(@user.aspects.first)) end end describe 'when ignoring a contact request' do it "succeeds" do - xhr :delete, :destroy, "id" => @friend_request.id.to_s + xhr :delete, :destroy, + :id => @friend_request.id.to_s response.should be_success end it "removes the request object" do lambda { - xhr :delete, :destroy, "id" => @friend_request.id.to_s - }.should change(Request, 'count').by(-1) + xhr :delete, :destroy, + :id => @friend_request.id.to_s + }.should change(Request, :count).by(-1) end end end @@ -48,8 +52,10 @@ describe RequestsController do describe '#create' do context 'valid new request' do before do - @params = {:request => {:to => @other_user.diaspora_handle, - :into => @user.aspects[0].id}} + @params = {:request => { + :to => @other_user.diaspora_handle, + :into => @user.aspects[0].id + }} end it 'creates a contact' do @user.contact_for(@other_user).should be_nil @@ -63,21 +69,19 @@ describe RequestsController do it 'does not persist a Request' do lambda { post :create, @params - }.should_not change(Request,:count) + }.should_not change(Request, :count) end end it 'autoaccepts and when sending a request to someone who sent me a request' do @other_user.send_contact_request_to(@user.person, @other_user.aspects[0]) - Request.to(@user).count.should == 1 - @user.contact_for(@other_user.person).should be_nil post(:create, :request => { :to => @other_user.diaspora_handle, :into => @user.aspects[0].id} ) - Request.to(@user).count.should == 0 - @user.contact_for(@other_user.person).should_not be_nil - @user.aspects[0].contacts.all(:person_id => @other_user.person.id).should_not be_nil + Request.to(@user).first.should be_nil + @user.contact_for(@other_user.person).should be_true + @user.aspects[0].contacts.all(:person_id => @other_user.person.id).should be_true end it "redirects when requesting to be contacts with yourself" do diff --git a/spec/controllers/services_controller_spec.rb b/spec/controllers/services_controller_spec.rb index 57e60ebf6..e34f3ffb0 100644 --- a/spec/controllers/services_controller_spec.rb +++ b/spec/controllers/services_controller_spec.rb @@ -6,22 +6,24 @@ require 'spec_helper' describe ServicesController do render_views - let(:user) { make_user } + let(:user) { make_user } let!(:aspect) { user.aspects.create(:name => "lame-os") } let(:mock_access_token) { Object.new } - let(:omniauth_auth) {{ 'provider' => 'twitter', 'uid' => '2', - 'user_info' => { 'nickname' => 'grimmin' }, - 'credentials' => { 'token' => 'tokin', 'secret' =>"not_so_much" } - }} + let(:omniauth_auth) { + { 'provider' => 'twitter', + 'uid' => '2', + 'user_info' => { 'nickname' => 'grimmin' }, + 'credentials' => { 'token' => 'tokin', 'secret' =>"not_so_much" } + } + } before do sign_in :user, user @controller.stub!(:current_user).and_return(user) - mock_access_token.stub!(:token).and_return("12345") - mock_access_token.stub!(:secret).and_return("56789") + mock_access_token.stub!(:token => "12345", :secret => "56789") end describe '#index' do @@ -39,17 +41,19 @@ describe ServicesController do describe '#create' do it 'creates a new OmniauthService' do request.env['omniauth.auth'] = omniauth_auth - lambda{post :create}.should change(user.services, :count).by(1) + lambda{ + post :create + }.should change(user.services, :count).by(1) end - it 'should redirect to getting started if the user still getting started' do + it 'redirects to getting started if the user is getting started' do user.getting_started = true request.env['omniauth.auth'] = omniauth_auth post :create response.should redirect_to getting_started_path(:step => 3) end - it 'should redirect to services url' do + it 'redirects to services url' do user.getting_started = false request.env['omniauth.auth'] = omniauth_auth post :create @@ -66,9 +70,14 @@ describe ServicesController do end describe '#destroy' do - let!(:service1) {a = Factory(:service); user.services << a; a} - it 'should destroy a service of a users with the id' do - lambda{delete :destroy, :id => service1.id.to_s}.should change(user.services, :count).by(-1) + before do + @service1 = Factory.create(:service) + user.services << @service1 + end + it 'destroys a service selected by id' do + lambda{ + delete :destroy, :id => @service1.id + }.should change(user.services, :count).by(-1) end end end diff --git a/spec/controllers/sockets_controller_spec.rb b/spec/controllers/sockets_controller_spec.rb index bc991d60e..8f7cc3379 100644 --- a/spec/controllers/sockets_controller_spec.rb +++ b/spec/controllers/sockets_controller_spec.rb @@ -17,11 +17,6 @@ describe SocketsController do @controller = SocketsController.new end - it 'should unstub the websockets' do - Diaspora::WebSocket.initialize_channels - @controller.class.should == SocketsController - end - describe 'actionhash' do before do @aspect = @user.aspects.create(:name => "losers") @@ -29,13 +24,13 @@ describe SocketsController do @fixture_name = File.dirname(__FILE__) + '/../fixtures/button.png' end - it 'should actionhash posts' do + it 'actionhashes posts' do json = @controller.action_hash(@user.id, @message) json.include?(@message.message).should be_true json.include?('status_message').should be_true end - it 'should actionhash retractions' do + it 'actionhashes retractions' do retraction = Retraction.for @message json = @controller.action_hash(@user.id, retraction) json.include?('retraction').should be_true diff --git a/spec/controllers/status_message_controller_spec.rb b/spec/controllers/status_message_controller_spec.rb index 83ad36017..2bd304914 100644 --- a/spec/controllers/status_message_controller_spec.rb +++ b/spec/controllers/status_message_controller_spec.rb @@ -7,17 +7,17 @@ require 'spec_helper' describe StatusMessagesController do render_views - let!(:user) { make_user } - let!(:aspect) { user.aspects.create(:name => "AWESOME!!") } + let!(:user1) { make_user } + let!(:aspect1) { user1.aspects.create(:name => "AWESOME!!") } - let!(:user2) { make_user } + let!(:user2) { make_user } let!(:aspect2) { user2.aspects.create(:name => "WIN!!") } before do - connect_users(user, aspect, user2, aspect2) + connect_users(user1, aspect1, user2, aspect2) request.env["HTTP_REFERER"] = "" - sign_in :user, user - @controller.stub!(:current_user).and_return(user) + sign_in :user, user1 + @controller.stub!(:current_user).and_return(user1) end describe '#show' do @@ -26,30 +26,33 @@ describe StatusMessagesController do @url="http://www.youtube.com/watch?v=#{@video_id}&a=GxdCwVVULXdvEBKmx_f5ywvZ0zZHHHDU&list=ML&playnext=1" end it 'renders posts with youtube urls' do - message = user.build_post :status_message, :message => @url, :to => aspect.id + message = user1.build_post :status_message, :message => @url, :to => aspect1.id message[:youtube_titles]= {@video_id => "title"} message.save! - user.add_to_streams(message, aspect.id) - user.dispatch_post message, :to => aspect.id + user1.add_to_streams(message, aspect1.id) + user1.dispatch_post message, :to => aspect1.id + get :show, :id => message.id response.body.should match /Youtube: title/ end it 'renders posts with comments with youtube urls' do - message = user.post :status_message, :message => "Respond to this with a video!", :to => aspect.id - @comment = user.comment "none", :on => message + message = user1.post :status_message, :message => "Respond to this with a video!", :to => aspect1.id + @comment = user1.comment "none", :on => message @comment.text = @url @comment[:youtube_titles][@video_id] = "title" @comment.save! + get :show, :id => message.id response.body.should match /Youtube: title/ end end describe '#create' do let(:status_message_hash) { - {:status_message =>{ - :public =>"true", - :message =>"facebook, is that you?", - :aspect_ids =>"#{aspect.id}"}} + { :status_message => { + :public =>"true", + :message =>"facebook, is that you?", + :aspect_ids =>"#{aspect1.id}" } + } } it 'responds to js requests' do post :create, status_message_hash.merge(:format => 'js') @@ -57,16 +60,18 @@ describe StatusMessagesController do end it "doesn't overwrite person_id" do - new_user = make_user - status_message_hash[:status_message][:person_id] = new_user.person.id + status_message_hash[:status_message][:person_id] = user2.person.id post :create, status_message_hash - StatusMessage.find_by_message(status_message_hash[:status_message][:message]).person_id.should == user.person.id + new_message = StatusMessage.find_by_message(status_message_hash[:status_message][:message]) + new_message.person_id.should == user1.person.id end it "doesn't overwrite id" do - old_status_message = user.post(:status_message, :message => "hello", :to => aspect.id) + old_status_message = user1.post(:status_message, :message => "hello", :to => aspect1.id) status_message_hash[:status_message][:id] = old_status_message.id - lambda {post :create, status_message_hash}.should raise_error /failed save/ + lambda { + post :create, status_message_hash + }.should raise_error /failed save/ old_status_message.reload.message.should == 'hello' end @@ -74,8 +79,8 @@ describe StatusMessagesController do fixture_filename = 'button.png' fixture_name = File.join(File.dirname(__FILE__), '..', 'fixtures', fixture_filename) - photo1 = user.build_post(:photo, :user_file=> File.open(fixture_name), :to => aspect.id) - photo2 = user.build_post(:photo, :user_file=> File.open(fixture_name), :to => aspect.id) + photo1 = user1.build_post(:photo, :user_file=> File.open(fixture_name), :to => aspect1.id) + photo2 = user1.build_post(:photo, :user_file=> File.open(fixture_name), :to => aspect1.id) photo1.save! photo2.save! @@ -83,28 +88,27 @@ describe StatusMessagesController do hash = status_message_hash hash[:photos] = [photo1.id.to_s, photo2.id.to_s] - user.should_receive(:dispatch_post).exactly(3).times + user1.should_receive(:dispatch_post).exactly(3).times post :create, hash end end describe '#destroy' do - let!(:message) {user.post(:status_message, :message => "hey", :to => aspect.id)} + let!(:message) {user1.post(:status_message, :message => "hey", :to => aspect1.id)} let!(:message2) {user2.post(:status_message, :message => "hey", :to => aspect2.id)} - it 'should let me delete my photos' do + it 'let a user delete his photos' do delete :destroy, :id => message.id StatusMessage.find_by_id(message.id).should be_nil end it 'will not let you destroy posts visible to you' do delete :destroy, :id => message2.id - StatusMessage.find_by_id(message2.id).should_not be_nil + StatusMessage.find_by_id(message2.id).should be_true end it 'will not let you destory posts you do not own' do delete :destroy, :id => message2.id - StatusMessage.find_by_id(message2.id).should_not be_nil + StatusMessage.find_by_id(message2.id).should be_true end - end end diff --git a/spec/controllers/users_controller_spec.rb b/spec/controllers/users_controller_spec.rb index 6e0bd5f60..63a099bf2 100644 --- a/spec/controllers/users_controller_spec.rb +++ b/spec/controllers/users_controller_spec.rb @@ -7,18 +7,18 @@ require 'spec_helper' describe UsersController do render_views - let(:user) { make_user } + let(:user) { make_user } let!(:aspect) { user.aspects.create(:name => "lame-os") } let!(:old_password) { user.encrypted_password } let!(:old_language) { user.language } - + before do sign_in :user, user end describe '#export' do - it 'should return an xml file' do + it 'returns an xml file' do get :export response.header["Content-Type"].should include "application/xml" end @@ -26,36 +26,50 @@ describe UsersController do describe '#update' do it "doesn't overwrite random attributes" do - params = {:diaspora_handle => "notreal@stuff.com"} - proc{ put 'update', :id => user.id, "user" => params }.should_not change(user, :diaspora_handle) + params = { :id => user.id, + :user => { :diaspora_handle => "notreal@stuff.com" } } + lambda { + put :update, params + }.should_not change(user, :diaspora_handle) end - context 'should allow the user to update their password' do - it 'should change a users password ' do - put("update", :id => user.id, "user"=> {"password" => "foobaz", 'password_confirmation' => "foobaz"}) + context 'password updates' do + it 'allows a user to change his password' do + put(:update, :id => user.id, :user => + { :password => "foobaz", + :password_confirmation => "foobaz" } + ) user.reload user.encrypted_password.should_not == old_password end - it 'should not change a password if they do not match' do - put("update", :id => user.id, "user"=> {"password" => "foobarz", 'password_confirmation' => "not_the_same"}) + it 'requires a matching password confirmation' do + put(:update, :id => user.id, :user => + { :password => "foobarz", + :password_confirmation => "not_the_same"} + ) user.reload user.encrypted_password.should == old_password end - it 'should not update if the password fields are left blank' do - put("update", :id => user.id, "user"=> {"password" => "", 'password_confirmation' => ""}) + it 'does not update if the password fields are left blank' do + put(:update, :id => user.id, :user => + { :password => "", + :password_confirmation => ""} + ) user.reload user.encrypted_password.should == old_password end end describe 'language' do - it 'should allow user to change his language' do - user.language = 'en' + it 'allow the user to change his language' do + old_language = 'en' + user.language = old_language user.save - old_language = user.language - put("update", :id => user.id, "user" => {"language" => "fr"}) + put(:update, :id => user.id, :user => + { :language => "fr"} + ) user.reload user.language.should_not == old_language end @@ -64,8 +78,8 @@ describe UsersController do describe '#edit' do it "returns a 200" do - get 'edit', :id => user.id - response.code.should == "200" + get 'edit', :id => user.id + response.status.should == 200 end end end diff --git a/spec/factories.rb b/spec/factories.rb index 58933eade..048c0dfc3 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -12,29 +12,30 @@ def r_str end Factory.define :profile do |p| - p.sequence(:first_name){|n| "Robert#{n}#{r_str}"} - p.sequence(:last_name){|n| "Grimm#{n}#{r_str}"} + p.sequence(:first_name) { |n| "Robert#{n}#{r_str}" } + p.sequence(:last_name) { |n| "Grimm#{n}#{r_str}" } end Factory.define :person do |p| - p.sequence(:diaspora_handle) {|n| "bob-person-#{n}#{r_str}@aol.com"} - p.sequence(:url) {|n| "http://google-#{n}#{r_str}.com/"} + p.sequence(:diaspora_handle) { |n| "bob-person-#{n}#{r_str}@aol.com" } + p.sequence(:url) { |n| "http://google-#{n}#{r_str}.com/" } p.profile Factory.create(:profile, :first_name => "eugene", :last_name => "weinstien") p.serialized_public_key OpenSSL::PKey::RSA.generate(1024).public_key.export end Factory.define :user do |u| - u.sequence(:username) {|n| "bob#{n}#{r_str}"} - u.sequence(:email) {|n| "bob#{n}#{r_str}@pivotallabs.com"} + u.sequence(:username) { |n| "bob#{n}#{r_str}" } + u.sequence(:email) { |n| "bob#{n}#{r_str}@pivotallabs.com" } u.password "bluepin7" - u.password_confirmation "bluepin7" + u.password_confirmation { |u| u.password } u.serialized_private_key OpenSSL::PKey::RSA.generate(1024).export u.after_build do |user| - user.person = Factory.build(:person, :profile => Factory.create(:profile), :owner_id => user._id, - :serialized_public_key => user.encryption_key.public_key.export, - :diaspora_handle => "#{user.username}@#{APP_CONFIG[:pod_url].gsub(/(https?:|www\.)\/\//, '').chop!}") + user.person = Factory.build(:person, :profile => Factory.create(:profile), + :owner_id => user._id, + :serialized_public_key => user.encryption_key.public_key.export, + :diaspora_handle => "#{user.username}@#{APP_CONFIG[:pod_url].gsub(/(https?:|www\.)\/\//, '').chop!}") end end @@ -47,7 +48,7 @@ Factory.define :aspect do |aspect| end Factory.define :status_message do |m| - m.sequence(:message) {|n| "jimmy's #{n} whales"} + m.sequence(:message) { |n| "jimmy's #{n} whales" } m.person end diff --git a/spec/misc_spec.rb b/spec/misc_spec.rb index 1db1d671f..729da9410 100644 --- a/spec/misc_spec.rb +++ b/spec/misc_spec.rb @@ -5,7 +5,7 @@ require 'spec_helper' describe 'making sure the spec runner works' do - it 'should factory create a user with a person saved' do + it 'factoy creates a user with a person saved' do user = make_user loaded_user = User.first(:id => user.id) loaded_user.person.owner_id.should == user.id @@ -16,30 +16,31 @@ describe 'making sure the spec runner works' do User.count.should == 0 end - it 'returns a user on fixed_user' do - new_user = make_user - new_user.is_a?(User).should be_true - User.count.should == 1 + describe '#make_user' do + it 'returns a user on' do + new_user = make_user + new_user.is_a?(User).should be_true + User.count.should == 1 + end + + it 'returns a different user the second time' do + new_user = make_user + second_user = make_user + + User.count.should == 2 + new_user.id.should_not == second_user.id + end end - - it 'returns a different user on the second fixed_user' do - new_user = make_user - second_user = make_user - - User.count.should == 2 - new_user.id.should_not == second_user.id - end - end describe 'factories' do describe 'build' do it 'does not save a built user' do - Factory.build(:user).persisted?.should be_false + Factory.build(:user).should_not be_persisted end it 'does not save a built person' do - Factory.build(:person).persisted?.should be_false + Factory.build(:person).should_not be_persisted end end end @@ -58,7 +59,7 @@ describe 'making sure the spec runner works' do contact.should_not be_nil @user1.contacts.include?(contact).should be_true @aspect1.contacts.include?(contact).should be_true - contact.aspects.include?( @aspect1 ).should be true + contact.aspects.include?(@aspect1).should be_true end it 'connects the second user to the first' do @@ -66,7 +67,7 @@ describe 'making sure the spec runner works' do contact.should_not be_nil @user2.contacts.include?(contact).should be_true @aspect2.contacts.include?(contact).should be_true - contact.aspects.include?( @aspect2 ).should be true + contact.aspects.include?(@aspect2).should be_true end it 'allows posting after running' do