From 3eef53892cf26a18f71d79cc453404d2d73e4d00 Mon Sep 17 00:00:00 2001 From: maxwell Date: Mon, 14 Jun 2010 17:48:21 -0700 Subject: [PATCH] DG MS; Dashboard shows the user's most recent update --- app/models/status_message.rb | 10 +++++++++- app/views/layouts/application.html.haml | 3 ++- app/views/status_messages/index.html.haml | 10 ++++++++-- public/stylesheets/application.css | 2 ++ public/stylesheets/sass/application.sass | 4 ++++ spec/models/status_message_spec.rb | 22 ++++++++++++++++++++++ 6 files changed, 47 insertions(+), 4 deletions(-) diff --git a/app/models/status_message.rb b/app/models/status_message.rb index 79b1be205..c0b27d87c 100644 --- a/app/models/status_message.rb +++ b/app/models/status_message.rb @@ -14,10 +14,18 @@ class StatusMessage before_create :add_owner + def self.newest(owner_email) + StatusMessage.last(:conditions => {:owner => owner_email}) + end + + def self.my_newest + StatusMessage.newest(User.first.email) + end + protected def add_owner - self.owner ||= User.first.email + self.owner ||= User.first.email end end diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index 26089e42d..9a26b6810 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -16,7 +16,8 @@ %body #header .container - %img#diaspora_text{:src => '/images/diaspora.png'} + %a#diaspora_text{:href => root_url} + %img{:src => '/images/diaspora.png'} #session_action - if user_signed_in? diff --git a/app/views/status_messages/index.html.haml b/app/views/status_messages/index.html.haml index c54056f30..c1c10fe68 100644 --- a/app/views/status_messages/index.html.haml +++ b/app/views/status_messages/index.html.haml @@ -1,11 +1,17 @@ -- title "Status Messages" +- title "Home" +%h3 Your latest message +%h2= "#{StatusMessage.my_newest.message} #{time_ago_in_words(StatusMessage.my_newest.created_at)} ago" + +%br +%br +%br %h3 Messages %ul - for status_message in @status_messages %li - = "#{status_message.message} by #{status_message.owner}" + = "#{status_message.message} by #{status_message.owner} #{time_ago_in_words(status_message.created_at)} ago" = link_to 'Show', status_message | =link_to 'Destroy', status_message, :confirm => 'Are you sure?', :method => :delete diff --git a/public/stylesheets/application.css b/public/stylesheets/application.css index 143c558b8..a704c4be8 100644 --- a/public/stylesheets/application.css +++ b/public/stylesheets/application.css @@ -52,6 +52,8 @@ h4 { padding-top: 1em; padding-bottom: 1em; margin-bottom: 1em; } + #header #diaspora_text { + border: none; } #header #session_action { float: right; } #header ul.nav { diff --git a/public/stylesheets/sass/application.sass b/public/stylesheets/sass/application.sass index 17d67a425..0ebd465f8 100644 --- a/public/stylesheets/sass/application.sass +++ b/public/stylesheets/sass/application.sass @@ -60,6 +60,10 @@ h4 :margin :bottom 1em + #diaspora_text + :border none + + #session_action :float right diff --git a/spec/models/status_message_spec.rb b/spec/models/status_message_spec.rb index 81a041742..d20cb6188 100644 --- a/spec/models/status_message_spec.rb +++ b/spec/models/status_message_spec.rb @@ -14,6 +14,28 @@ describe StatusMessage do n.owner.should == "bob@aol.com" end + + describe "newest" do + before do + User.create(:email => "bob@aol.com", :password => "diggity") + StatusMessage.create(:message => "wale for jimmy", :owner => "xzibit@dawgz.com") + StatusMessage.create(:message => "jimmy wales") + StatusMessage.create(:message => "jimmy your wales", :owner => "some@dudes.com") + StatusMessage.create(:message => "lions", :owner => "xzibit@dawgz.com") + StatusMessage.create(:message => "bears") + StatusMessage.create(:message => "sharks", :owner => "some@dudes.com") + StatusMessage.create(:message => "roar") + end + + it "should give the most recent message from owner" do + StatusMessage.my_newest.message.should == "roar" + end + + it "should give the most recent message for a given email" do + StatusMessage.newest("some@dudes.com").message.should == "sharks" + end + end + describe "XML" do before do @xml = "\n I hate WALRUSES!\n Bob\n"