From 1b92bcd17c86874bbc940c957a053b47309c04a7 Mon Sep 17 00:00:00 2001 From: Daniel Vincent Grippi Date: Mon, 13 Sep 2010 17:26:24 -0700 Subject: [PATCH] Add albums_by_aspect method to user --- app/views/albums/_album.html.haml | 1 - app/views/aspects/index.html.haml | 3 ++- app/views/aspects/show.html.haml | 2 +- app/views/shared/_aspect_nav.haml | 2 +- lib/diaspora/user/querying.rb | 4 ++++ spec/models/user/posting_spec.rb | 7 +++++++ spec/models/user/visible_posts_spec.rb | 24 ++++++++++++++++++++++++ 7 files changed, 39 insertions(+), 4 deletions(-) diff --git a/app/views/albums/_album.html.haml b/app/views/albums/_album.html.haml index bd777e0dd..3ff1a507d 100644 --- a/app/views/albums/_album.html.haml +++ b/app/views/albums/_album.html.haml @@ -16,7 +16,6 @@ -# along with Diaspora. If not, see . -# - .album{:id => post.id, :class => ("mine" if current_user.owns?(post))} %div.name diff --git a/app/views/aspects/index.html.haml b/app/views/aspects/index.html.haml index 919c8110d..c1f1b461f 100644 --- a/app/views/aspects/index.html.haml +++ b/app/views/aspects/index.html.haml @@ -18,7 +18,8 @@ - content_for :page_title do - Home + = link_to "photos", albums_path(:aspect => @aspect) + - content_for :left_pane do = render "shared/aspect_friends" diff --git a/app/views/aspects/show.html.haml b/app/views/aspects/show.html.haml index 919c8110d..1ec0b64ee 100644 --- a/app/views/aspects/show.html.haml +++ b/app/views/aspects/show.html.haml @@ -18,7 +18,7 @@ - content_for :page_title do - Home + = link_to "photos", albums_path - content_for :left_pane do = render "shared/aspect_friends" diff --git a/app/views/shared/_aspect_nav.haml b/app/views/shared/_aspect_nav.haml index 13016044d..503c66988 100644 --- a/app/views/shared/_aspect_nav.haml +++ b/app/views/shared/_aspect_nav.haml @@ -23,7 +23,7 @@ %li{:id => aspect.id, :class => ("selected" if current_aspect?(aspect))} = link_for_aspect aspect - %li.new_aspect= link_to("+", "#add_aspect_pane", :id => "add_aspect_button", :title => "Add a new relation") + %li.new_aspect= link_to("+", "#add_aspect_pane", :id => "add_aspect_button", :title => "Add a new aspect") #aspect_manage_button diff --git a/lib/diaspora/user/querying.rb b/lib/diaspora/user/querying.rb index 1d66e70be..b185dadcf 100644 --- a/lib/diaspora/user/querying.rb +++ b/lib/diaspora/user/querying.rb @@ -77,6 +77,10 @@ module Diaspora def all_aspect_ids self.aspects.all.collect{|x| x.id} end + + def albums_by_aspect aspect + aspect.posts.find_all_by__type("Album") + end end end end diff --git a/spec/models/user/posting_spec.rb b/spec/models/user/posting_spec.rb index 43ef6e368..17f4cdbc7 100644 --- a/spec/models/user/posting_spec.rb +++ b/spec/models/user/posting_spec.rb @@ -50,6 +50,13 @@ describe User do @aspect.post_ids.include?(post.id).should be true end + it 'should put an album in the aspect post array' do + album = @user.post :album, :name => "Georges", :to => @aspect.id + @aspect.reload + @aspect.post_ids.include?(album.id).should be true + @aspect.posts.include?(album).should be true + end + describe 'dispatching' do before do @post = @user.build_post :status_message, :message => "hey" diff --git a/spec/models/user/visible_posts_spec.rb b/spec/models/user/visible_posts_spec.rb index 7edd9b2eb..f45b06e99 100644 --- a/spec/models/user/visible_posts_spec.rb +++ b/spec/models/user/visible_posts_spec.rb @@ -58,5 +58,29 @@ describe User do @user.visible_posts(:by_members_of => @aspect2).include?(status_message2).should be true @user.visible_posts(:by_members_of => @aspect2).include?(status_message3).should be true end + + describe 'albums' do + before do + @album = @user.post :album, :name => "Georges", :to => @aspect.id + @aspect.reload + @aspect2.reload + @user.reload + + @album2 = @user.post :album, :name => "Borges", :to => @aspect.id + @aspect.reload + @aspect2.reload + @user.reload + + @user.post :album, :name => "Luises", :to => @aspect2.id + @aspect.reload + @aspect2.reload + @user.reload + end + + it 'should return the right number of albums' do + @user.albums_by_aspect(@aspect).size.should == 2 + @user.albums_by_aspect(@aspect2).size.should == 1 + end + end end