From 2255e80b69ec2c9cb818e7c3fd283bcff1f20202 Mon Sep 17 00:00:00 2001 From: Sarah Mei <sarahmei@gmail.com> Date: Mon, 29 Aug 2011 22:03:05 -0700 Subject: [PATCH] So. It turns out that postgresql has a less-consistent idea of what .first means in an association with no default ordering. All the places we were doing bob.aspects.first (& etc.) needed to be more specific. & o ya, POSTGRES IS GREEN. --- spec/controllers/aspects_controller_spec.rb | 3 ++- spec/controllers/comments_controller_spec.rb | 10 ++++---- spec/controllers/likes_controller_spec.rb | 25 +++++++++----------- spec/controllers/people_controller_spec.rb | 6 +++-- spec/models/aspect_membership_spec.rb | 2 +- spec/models/contact_spec.rb | 13 ++++++---- spec/support/fixture_builder.rb | 9 +++++-- 7 files changed, 39 insertions(+), 29 deletions(-) diff --git a/spec/controllers/aspects_controller_spec.rb b/spec/controllers/aspects_controller_spec.rb index 0569498a9d..6234419a52 100644 --- a/spec/controllers/aspects_controller_spec.rb +++ b/spec/controllers/aspects_controller_spec.rb @@ -163,7 +163,8 @@ describe AspectsController do describe "post visibilities" do before do - @status = bob.post(:status_message, :text=> "hello", :to => bob.aspects.first) + aspect_to_post = bob.aspects.where(:name => "generic").first + @status = bob.post(:status_message, :text=> "hello", :to => aspect_to_post) @vis = @status.post_visibilities.first end diff --git a/spec/controllers/comments_controller_spec.rb b/spec/controllers/comments_controller_spec.rb index 5a706d75ec..126aaf963f 100644 --- a/spec/controllers/comments_controller_spec.rb +++ b/spec/controllers/comments_controller_spec.rb @@ -6,8 +6,8 @@ require 'spec_helper' describe CommentsController do before do - @aspect1 = alice.aspects.first - @aspect2 = bob.aspects.first + @aspect1 = alice.aspects.where(:name => "generic").first + @aspect2 = bob.aspects.where(:name => "generic").first @controller.stub(:current_user).and_return(alice) sign_in :user, alice @@ -124,7 +124,8 @@ describe CommentsController do describe '#index' do before do - @message = bob.post(:status_message, :text => "hey", :to => bob.aspects.first.id) + aspect_to_post = bob.aspects.where(:name => "generic").first + @message = bob.post(:status_message, :text => "hey", :to => aspect_to_post.id) @comments = [alice, bob, eve].map{ |u| u.comment("hey", :post => @message) } end it 'works for mobile' do @@ -141,7 +142,8 @@ describe CommentsController do response.status.should == 404 end it 'returns a 404 on a post that is not visible to the signed in user' do - message = eve.post(:status_message, :text => "hey", :to => eve.aspects.first.id) + aspect_to_post = eve.aspects.where(:name => "generic").first + message = eve.post(:status_message, :text => "hey", :to => aspect_to_post.id) bob.comment("hey", :post => @message) get :index, :post_id => message.id, :format => 'js' response.status.should == 404 diff --git a/spec/controllers/likes_controller_spec.rb b/spec/controllers/likes_controller_spec.rb index 71a2e097d6..156b646922 100644 --- a/spec/controllers/likes_controller_spec.rb +++ b/spec/controllers/likes_controller_spec.rb @@ -6,13 +6,10 @@ require 'spec_helper' describe LikesController do before do - @user1 = alice - @user2 = bob + @alices_aspect = alice.aspects.where(:name => "generic").first + @bobs_aspect = bob.aspects.where(:name => "generic").first - @aspect1 = @user1.aspects.first - @aspect2 = @user2.aspects.first - - sign_in :user, @user1 + sign_in :user, alice end [Comment, Post].each do |class_const| @@ -33,9 +30,9 @@ describe LikesController do context "on my own post" do before do - @target = @user1.post :status_message, :text => "AWESOME", :to => @aspect1.id + @target = alice.post :status_message, :text => "AWESOME", :to => @alices_aspect.id - @target = @user1.comment "hey", :post => @target if class_const == Comment + @target = alice.comment "hey", :post => @target if class_const == Comment end it 'responds to format js' do @@ -46,8 +43,8 @@ describe LikesController do context "on a post from a contact" do before do - @target = @user2.post :status_message, :text => "AWESOME", :to => @aspect2.id - @target = @user2.comment "hey", :post => @target if class_const == Comment + @target = bob.post :status_message, :text => "AWESOME", :to => @bobs_aspect.id + @target = bob.comment "hey", :post => @target if class_const == Comment end it 'likes' do @@ -61,7 +58,7 @@ describe LikesController do end it "doesn't post multiple times" do - @user1.like(1, :target => @target) + alice.like(1, :target => @target) post :create, dislike_hash response.code.should == '422' end @@ -74,7 +71,7 @@ describe LikesController do end it "doesn't post" do - @user1.should_not_receive(:like) + alice.should_not_receive(:like) post :create, like_hash response.code.should == '422' end @@ -83,7 +80,7 @@ describe LikesController do describe '#index' do before do - @message = alice.post(:status_message, :text => "hey", :to => @aspect1.id) + @message = alice.post(:status_message, :text => "hey", :to => @alices_aspect.id) @message = alice.comment( "hey", :post => @message) if class_const == Comment end it 'returns a 404 for a post not visible to the user' do @@ -107,7 +104,7 @@ describe LikesController do describe '#destroy' do before do - @message = bob.post(:status_message, :text => "hey", :to => @aspect1.id) + @message = bob.post(:status_message, :text => "hey", :to => @alices_aspect.id) @message = bob.comment( "hey", :post => @message) if class_const == Comment @like = alice.build_like(:positive => true, :target => @message) @like.save diff --git a/spec/controllers/people_controller_spec.rb b/spec/controllers/people_controller_spec.rb index 408935e40b..09a6707123 100644 --- a/spec/controllers/people_controller_spec.rb +++ b/spec/controllers/people_controller_spec.rb @@ -253,8 +253,10 @@ describe PeopleController do it "assigns only the posts the current user can see" do bob.posts.should be_empty posts_user_can_see = [] - posts_user_can_see << bob.post(:status_message, :text => "to an aspect @user is in", :to => bob.aspects[0].id) - bob.post(:status_message, :text => "to an aspect @user is not in", :to => bob.aspects[1].id) + aspect_user_is_in = bob.aspects.where(:name => "generic").first + aspect_user_is_not_in = bob.aspects.where(:name => "empty").first + posts_user_can_see << bob.post(:status_message, :text => "to an aspect @user is in", :to => aspect_user_is_in.id) + bob.post(:status_message, :text => "to an aspect @user is not in", :to => aspect_user_is_not_in.id) posts_user_can_see << bob.post(:status_message, :text => "to all aspects", :to => 'all') posts_user_can_see << bob.post(:status_message, :text => "public", :to => 'all', :public => true) bob.reload.posts.length.should == 4 diff --git a/spec/models/aspect_membership_spec.rb b/spec/models/aspect_membership_spec.rb index fb09ccabc5..3301f5bf35 100644 --- a/spec/models/aspect_membership_spec.rb +++ b/spec/models/aspect_membership_spec.rb @@ -11,7 +11,7 @@ describe AspectMembership do @aspect = alice.aspects.create(:name => "two") @contact = alice.contact_for(bob.person) - @am = alice.aspects.first.aspect_memberships.first + @am = alice.aspects.where(:name => "generic").first.aspect_memberships.first @am.stub!(:user).and_return(alice) end diff --git a/spec/models/contact_spec.rb b/spec/models/contact_spec.rb index 5de1306f0b..a8d3dc1661 100644 --- a/spec/models/contact_spec.rb +++ b/spec/models/contact_spec.rb @@ -90,17 +90,21 @@ describe Contact do @eve = eve @bob.aspects.create(:name => 'next') @bob.aspects(true) + + @original_aspect = @bob.aspects.where(:name => "generic").first + @new_aspect = @bob.aspects.where(:name => "next").first + @people1 = [] @people2 = [] 1.upto(5) do person = Factory(:person) - @bob.contacts.create(:person => person, :aspects => [@bob.aspects.first]) + @bob.contacts.create(:person => person, :aspects => [@original_aspect]) @people1 << person end 1.upto(5) do person = Factory(:person) - @bob.contacts.create(:person => person, :aspects => [@bob.aspects.last]) + @bob.contacts.create(:person => person, :aspects => [@new_aspect]) @people2 << person end #eve <-> bob <-> alice @@ -118,9 +122,8 @@ describe Contact do end it 'returns nothing if contacts_visible is false in that aspect' do - asp = @bob.aspects.first - asp.contacts_visible = false - asp.save + @original_aspect.contacts_visible = false + @original_aspect.save @contact.contacts.should == [] end diff --git a/spec/support/fixture_builder.rb b/spec/support/fixture_builder.rb index 9345c66f30..2bb201594d 100644 --- a/spec/support/fixture_builder.rb +++ b/spec/support/fixture_builder.rb @@ -8,12 +8,17 @@ FixtureBuilder.configure do |fbuilder| fbuilder.factory do # Users alice = Factory(:user_with_aspect, :username => "alice") + alices_aspect = alice.aspects.where(:name => "generic").first + eve = Factory(:user_with_aspect, :username => "eve") + eves_aspect = eve.aspects.where(:name => "generic").first + bob = Factory(:user_with_aspect, :username => "bob") + bobs_aspect = bob.aspects.where(:name => "generic").first Factory(:aspect, :name => "empty", :user => bob) - connect_users(bob, bob.aspects.first, alice, alice.aspects.first) - connect_users(bob, bob.aspects.first, eve, eve.aspects.first) + connect_users(bob, bobs_aspect, alice, alices_aspect) + connect_users(bob, bobs_aspect, eve, eves_aspect) # Set up friends -- GitLab