Add albums_by_aspect method to user

This commit is contained in:
Daniel Vincent Grippi 2010-09-13 17:26:24 -07:00
parent 84b29770fe
commit 1b92bcd17c
7 changed files with 39 additions and 4 deletions

View file

@ -16,7 +16,6 @@
-# along with Diaspora. If not, see <http://www.gnu.org/licenses/>. -# along with Diaspora. If not, see <http://www.gnu.org/licenses/>.
-# -#
.album{:id => post.id, :class => ("mine" if current_user.owns?(post))} .album{:id => post.id, :class => ("mine" if current_user.owns?(post))}
%div.name %div.name

View file

@ -18,7 +18,8 @@
- content_for :page_title do - content_for :page_title do
Home = link_to "photos", albums_path(:aspect => @aspect)
- content_for :left_pane do - content_for :left_pane do
= render "shared/aspect_friends" = render "shared/aspect_friends"

View file

@ -18,7 +18,7 @@
- content_for :page_title do - content_for :page_title do
Home = link_to "photos", albums_path
- content_for :left_pane do - content_for :left_pane do
= render "shared/aspect_friends" = render "shared/aspect_friends"

View file

@ -23,7 +23,7 @@
%li{:id => aspect.id, :class => ("selected" if current_aspect?(aspect))} %li{:id => aspect.id, :class => ("selected" if current_aspect?(aspect))}
= link_for_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 #aspect_manage_button

View file

@ -77,6 +77,10 @@ module Diaspora
def all_aspect_ids def all_aspect_ids
self.aspects.all.collect{|x| x.id} self.aspects.all.collect{|x| x.id}
end end
def albums_by_aspect aspect
aspect.posts.find_all_by__type("Album")
end
end end
end end
end end

View file

@ -50,6 +50,13 @@ describe User do
@aspect.post_ids.include?(post.id).should be true @aspect.post_ids.include?(post.id).should be true
end 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 describe 'dispatching' do
before do before do
@post = @user.build_post :status_message, :message => "hey" @post = @user.build_post :status_message, :message => "hey"

View file

@ -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_message2).should be true
@user.visible_posts(:by_members_of => @aspect2).include?(status_message3).should be true @user.visible_posts(:by_members_of => @aspect2).include?(status_message3).should be true
end 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 end