diff --git a/app/models/status_message.rb b/app/models/status_message.rb index fd200e445..79b1be205 100644 --- a/app/models/status_message.rb +++ b/app/models/status_message.rb @@ -4,10 +4,20 @@ class StatusMessage include ROXML xml_accessor :message + xml_accessor :owner field :message + field :owner validates_presence_of :message + + before_create :add_owner + + protected + + def add_owner + self.owner ||= User.first.email + end end diff --git a/app/views/status_messages/index.html.haml b/app/views/status_messages/index.html.haml index 222df2dee..c54056f30 100644 --- a/app/views/status_messages/index.html.haml +++ b/app/views/status_messages/index.html.haml @@ -1,13 +1,14 @@ - title "Status Messages" -%table - %tr - %th Message + +%h3 Messages +%ul - for status_message in @status_messages - %tr - %td= status_message.message - %td= link_to 'Show', status_message - %td= link_to 'Destroy', status_message, :confirm => 'Are you sure?', :method => :delete + %li + = "#{status_message.message} by #{status_message.owner}" + = link_to 'Show', status_message + | + =link_to 'Destroy', status_message, :confirm => 'Are you sure?', :method => :delete %h2 Friends diff --git a/app/views/status_messages/show.html.haml b/app/views/status_messages/show.html.haml index d06bf2f55..4be35c793 100644 --- a/app/views/status_messages/show.html.haml +++ b/app/views/status_messages/show.html.haml @@ -3,6 +3,10 @@ %p %strong Message: = @status_message.message + +%p + %strong Owner: + = @status_message.owner %p = link_to "Destroy", @status_message, :confirm => 'Are you sure?', :method => :delete diff --git a/config/mongoid.yml b/config/mongoid.yml index 6a6e6be61..2a97fd67c 100644 --- a/config/mongoid.yml +++ b/config/mongoid.yml @@ -1,10 +1,5 @@ defaults: &defaults host: localhost - # slaves: - # - host: slave1.local - # port: 27018 - # - host: slave2.local - # port: 27019 allow_dynamic_fields: false parameterize_keys: true persist_in_safe_mode: true diff --git a/spec/controllers/status_messages_controller_spec.rb b/spec/controllers/status_messages_controller_spec.rb index b8ea56b37..e0fe528d6 100644 --- a/spec/controllers/status_messages_controller_spec.rb +++ b/spec/controllers/status_messages_controller_spec.rb @@ -4,6 +4,7 @@ describe StatusMessagesController do before do #TODO(dan) Mocking Warden; this is a temp fix request.env['warden'] = mock_model(Warden, :authenticate => @user, :authenticate! => @user) + User.create(:email => "bob@aol.com", :password => "secret") StatusMessage.create(:message => "yodels.") end diff --git a/spec/models/status_message_spec.rb b/spec/models/status_message_spec.rb index 7cf7e308a..81a041742 100644 --- a/spec/models/status_message_spec.rb +++ b/spec/models/status_message_spec.rb @@ -8,18 +8,26 @@ describe StatusMessage do n.valid?.should be true end + it "should add an owner if none is present" do + User.create(:email => "bob@aol.com", :password => "big bux") + n = StatusMessage.create(:message => "puppies!") + n.owner.should == "bob@aol.com" + end + describe "XML" do before do - @xml = "\n I hate WALRUSES!\n" + @xml = "\n I hate WALRUSES!\n Bob\n" end it 'should serialize to XML' do - message = StatusMessage.new(:message => "I hate WALRUSES!") + message = StatusMessage.create(:message => "I hate WALRUSES!", :owner => "Bob") message.to_xml.to_s.should == @xml end it 'should marshal serialized XML to object' do - StatusMessage.from_xml(@xml).message.should == "I hate WALRUSES!" + parsed = StatusMessage.from_xml(@xml) + parsed.message.should == "I hate WALRUSES!" + parsed.owner.should == "Bob" end end end