diff --git a/app/controllers/dashboard_controller.rb b/app/controllers/dashboard_controller.rb new file mode 100644 index 000000000..e534252b6 --- /dev/null +++ b/app/controllers/dashboard_controller.rb @@ -0,0 +1,14 @@ +class DashboardController < ApplicationController + before_filter :authenticate_user! + + def index + @posts = Post.all + + @bookmarks = Bookmark.all + @status_messages = StatusMessage.all + @blogs = Blog.all + #@status_messages = @posts.select{ |x| x._type == "StatusMessage"} + #@blogs = @posts.select{ |x| x._type == "Blog"} + #@bookmarks = @posts.select{ |x| x._type == "Bookmarks"} + end +end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index de6be7945..f58313c9b 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,2 +1,9 @@ module ApplicationHelper + def object_path(object) + eval("#{object.class.to_s.underscore}_path(object)") + end + + def object_fields(object) + object.attributes.keys + end end diff --git a/app/helpers/dashboard_helper.rb b/app/helpers/dashboard_helper.rb new file mode 100644 index 000000000..a94ddfc2e --- /dev/null +++ b/app/helpers/dashboard_helper.rb @@ -0,0 +1,2 @@ +module DashboardHelper +end diff --git a/app/helpers/status_messages_helper.rb b/app/helpers/status_messages_helper.rb index 71a0b26ea..5d1bcdc93 100644 --- a/app/helpers/status_messages_helper.rb +++ b/app/helpers/status_messages_helper.rb @@ -3,7 +3,7 @@ module StatusMessagesHelper def my_latest_message message = StatusMessage.my_newest unless message.nil? - return message.message + " " + time_ago_in_words(message.created_at) + "ago." + return message.message + " " + time_ago_in_words(message.created_at) + " ago." else return "No message to display." end diff --git a/app/models/blog.rb b/app/models/blog.rb index fd49ac248..3da382754 100644 --- a/app/models/blog.rb +++ b/app/models/blog.rb @@ -1,21 +1,14 @@ -class Blog - include Mongoid::Document - include Mongoid::Timestamps - include ROXML +class Blog < Post xml_accessor :title xml_accessor :body - xml_accessor :owner field :title field :body - field :owner validates_presence_of :title, :body - before_create :set_default_owner - def self.newest(owner_email) Blog.last(:conditions => {:owner => owner_email}) end @@ -23,10 +16,4 @@ class Blog def self.my_newest Blog.newest(User.first.email) end - - protected - - def set_default_owner - self.owner ||= User.first.email - end end diff --git a/app/models/bookmark.rb b/app/models/bookmark.rb index fc62d7225..c6241931f 100644 --- a/app/models/bookmark.rb +++ b/app/models/bookmark.rb @@ -1,20 +1,12 @@ -class Bookmark - include Mongoid::Document - include Mongoid::Timestamps +class Bookmark < Post + xml_accessor :link + xml_accessor :title - field :owner field :link field :title validates_presence_of :link - before_create :set_default_owner - - protected - - def set_default_owner - self.owner ||= User.first.email - end end diff --git a/app/models/post.rb b/app/models/post.rb new file mode 100644 index 000000000..34af94757 --- /dev/null +++ b/app/models/post.rb @@ -0,0 +1,39 @@ +class Post + + # XML accessors must always preceed mongo field tags + + include Mongoid::Document + include Mongoid::Timestamps + include ROXML + + xml_accessor :owner + xml_accessor :snippet + xml_accessor :source + + field :owner + field :source + field :snippet + + + before_create :set_defaults + #after_update :notify_friends + + protected + + def set_defaults + user_email = User.first.email + self.owner ||= user_email + self.source ||= user_email + self.snippet ||= user_email + end + + + #def notify_friends + #friends = Permissions.get_list_for(self) + #xml = self.to_xml_to_s + #friends.each{|friend| ping friend :with => xml } + #end + +end + + diff --git a/app/models/status_message.rb b/app/models/status_message.rb index 6c0c7cbb5..4aec011e6 100644 --- a/app/models/status_message.rb +++ b/app/models/status_message.rb @@ -1,21 +1,14 @@ -class StatusMessage - include Mongoid::Document - include Mongoid::Timestamps - include ROXML +class StatusMessage < Post include StatusMessagesHelper require 'lib/net/curl' - + xml_accessor :message - xml_accessor :owner - - field :message - field :owner - + + validates_presence_of :message - before_create :set_default_owner - + def self.newest(owner_email) StatusMessage.last(:conditions => {:owner => owner_email}) end @@ -32,11 +25,5 @@ class StatusMessage (self.message == other.message) && (self.owner == other.owner) end - protected - - def set_default_owner - self.owner ||= User.first.email - end - end diff --git a/app/views/blogs/_form.html.haml b/app/views/blogs/_form.html.haml index 5651e1eb0..5628b602e 100644 --- a/app/views/blogs/_form.html.haml +++ b/app/views/blogs/_form.html.haml @@ -1,4 +1,4 @@ -- form_for @blog do |f| += form_for @blog do |f| = f.error_messages %p = f.label :title diff --git a/app/views/dashboard/index.html.haml b/app/views/dashboard/index.html.haml new file mode 100644 index 000000000..0b4a5224d --- /dev/null +++ b/app/views/dashboard/index.html.haml @@ -0,0 +1,9 @@ +- title "Dashboard" + +%ul + - for post in @posts + %li + = render "shared/post", :post =>post + %br + %br + diff --git a/app/views/shared/_post.html.haml b/app/views/shared/_post.html.haml new file mode 100644 index 000000000..0ec4bc41e --- /dev/null +++ b/app/views/shared/_post.html.haml @@ -0,0 +1,5 @@ +%ul + %h3= link_to post.class, object_path(post) + - for field in object_fields(post) + %li= "#{field}: #{post.attributes[field]}" + diff --git a/config/initializers/inflections.rb b/config/initializers/inflections.rb index d531b8bb8..dded445cc 100644 --- a/config/initializers/inflections.rb +++ b/config/initializers/inflections.rb @@ -2,9 +2,10 @@ # Add new inflection rules using the following format # (all these examples are active by default): -# ActiveSupport::Inflector.inflections do |inflect| + ActiveSupport::Inflector.inflections do |inflect| # inflect.plural /^(ox)$/i, '\1en' # inflect.singular /^(ox)en/i, '\1' # inflect.irregular 'person', 'people' # inflect.uncountable %w( fish sheep ) -# end + inflect.uncountable %w(dashboard) + end diff --git a/config/routes.rb b/config/routes.rb index 9f7998572..81cd16e47 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -17,7 +17,6 @@ Diaspora::Application.routes.draw do |map| resources :users resources :status_messages - match 'dashboard', :to => 'status_messages#index' # The priority is based upon order of creation: @@ -77,6 +76,6 @@ Diaspora::Application.routes.draw do |map| # Note: This route will make all actions in every controller accessible via GET requests. # match ':controller(/:action(/:id(.:format)))' - root :to => 'status_messages#index' + root :to => 'dashboard#index' end diff --git a/lib/common.rb b/lib/common.rb new file mode 100644 index 000000000..a89072fc5 --- /dev/null +++ b/lib/common.rb @@ -0,0 +1,18 @@ +module CommonField + + def self.included(klass) + klass.class_eval do + include Mongoid::Document + include ROXML + include Mongoid::Timestamps + + xml_accessor :owner + xml_accessor :snippet + xml_accessor :source + + field :owner + field :source + field :snippet + end + end +end diff --git a/spec/controllers/dashboard_controller_spec.rb b/spec/controllers/dashboard_controller_spec.rb new file mode 100644 index 000000000..0b20b21ab --- /dev/null +++ b/spec/controllers/dashboard_controller_spec.rb @@ -0,0 +1,11 @@ +require File.dirname(__FILE__) + '/../spec_helper' + +describe DashboardController do + render_views + + it "index action should render index template" do + request.env['warden'] = mock_model(Warden, :authenticate? => @user, :authenticate! => @user) + get :index + response.should render_template(:index) + end +end diff --git a/spec/factories.rb b/spec/factories.rb index 0ebbb93e2..a63f32c31 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -8,7 +8,11 @@ end Factory.define :status_message do |m| m.sequence(:message) {|n| "jimmy's #{n} whales"} +end +Factory.define :blog do |b| + b.sequence(:title) {|n| "bobby's #{n} penguins"} + b.sequence(:body) {|n| "jimmy's huge #{n} whales"} end Factory.define :user do |u| @@ -19,3 +23,8 @@ end Factory.define :bookmark do |b| b.link "http://www.yahooligans.com/" end + +Factory.define :post do |p| + p.source "New York Times" + p.sequence(:snippet) {|n| "This is some information #{n}"} +end diff --git a/spec/models/blogs_spec.rb b/spec/models/blogs_spec.rb index ce3e5f9a5..32c9557a4 100644 --- a/spec/models/blogs_spec.rb +++ b/spec/models/blogs_spec.rb @@ -1,6 +1,10 @@ require File.dirname(__FILE__) + '/../spec_helper' describe Blog do + before do + Factory.create(:user, :email => "bob@aol.com", :password => "diggity") + end + it "should have a title and body" do n = Blog.new n.valid?.should be false @@ -11,51 +15,41 @@ describe Blog do end it "should add an owner if none is present" do - User.create(:email => "bob@aol.com", :password => "big bux") - n = Blog.create(:title => "kittens", :body => "puppies!") - n.owner.should == "bob@aol.com" + b = Factory.create(:blog) + b.owner.should == "bob@aol.com" end - describe "newest" do before do - User.create(:email => "bob@aol.com", :password => "diggity") - Blog.create(:title => "bone dawg", :body => "wale for jimmy", :owner => "xzibit@dawgz.com") - Blog.create(:title => "dawg bone", :body => "jimmy wales") - Blog.create(:title => "bone dawg", :body => "jimmy your wales", :owner => "some@dudes.com") - Blog.create(:title => "dawg bone", :body => "lions", :owner => "xzibit@dawgz.com") - Blog.create(:title => "bone dawg", :body => "bears") - Blog.create(:title => "dawg bone", :body => "sharks", :owner => "some@dudes.com") - Blog.create(:title => "bone dawg", :body => "roar") + (2..4).each { Factory.create(:blog, :owner => "some@dudes.com") } + (5..8).each { Factory.create(:blog) } + (9..11).each { Factory.create(:blog, :owner => "other@dudes.com") } end it "should give the most recent blog title and body from owner" do blog = Blog.my_newest - blog.title.should == "bone dawg" - blog.body.should == "roar" + blog.title.should == "bobby's 8 penguins" + blog.body.should == "jimmy's huge 8 whales" end it "should give the most recent blog body for a given email" do blog = Blog.newest("some@dudes.com") - blog.title.should == "dawg bone" - blog.body.should == "sharks" + blog.title.should == "bobby's 14 penguins" + blog.body.should == "jimmy's huge 14 whales" end end describe "XML" do - before do - @xml = "\n yessir\n I hate WALRUSES!\n Bob\n" - end - it 'should serialize to XML' do - body = Blog.create(:title => "yessir", :body => "I hate WALRUSES!", :owner => "Bob") - body.to_xml.to_s.should == @xml + body = Factory.create(:blog, :title => "yessir", :body => "penguins") + body.to_xml.to_s.should include "yessir" + body.to_xml.to_s.should include "penguins" end it 'should marshal serialized XML to object' do - parsed = Blog.from_xml(@xml) + xml = "\n yessir\n I hate WALRUSES!\n" + parsed = Blog.from_xml(xml) parsed.body.should == "I hate WALRUSES!" - parsed.owner.should == "Bob" end end end diff --git a/spec/models/friend_spec.rb b/spec/models/friend_spec.rb index 57417e9b0..7106e16ee 100644 --- a/spec/models/friend_spec.rb +++ b/spec/models/friend_spec.rb @@ -3,7 +3,6 @@ require File.dirname(__FILE__) + '/../spec_helper' describe Friend do it 'should have a diaspora username and diaspora url' do n = Factory.build(:friend, :url => nil) - #n = Friend.new(:username => 'max') n.valid?.should be false n.url = "http://max.com/" n.valid?.should be true diff --git a/spec/models/post_spec.rb b/spec/models/post_spec.rb new file mode 100644 index 000000000..313956825 --- /dev/null +++ b/spec/models/post_spec.rb @@ -0,0 +1,32 @@ +require File.dirname(__FILE__) + '/../spec_helper' + +describe Post do + before do + Factory.create(:user, :email => "bob@aol.com") + @post = Factory.create(:post, :owner => nil, :source => nil, :snippet => nil) + end + + describe 'requirements' do + end + + describe 'defaults' do + + it "should add an owner if none is present" do + @post.owner.should == "bob@aol.com" + end + + it "should add a source if none is present" do + @post.source.should == "bob@aol.com" + end + + it "should add a snippet if none is present" do + @post.snippet.should == "bob@aol.com" + end + end +end + +#question! +#STI ? do i need to call mongoid doc on child? +# validations inherit? +# type param. +# inheriting snippet builder method diff --git a/spec/models/status_message_spec.rb b/spec/models/status_message_spec.rb index 11978b8d3..899a43484 100644 --- a/spec/models/status_message_spec.rb +++ b/spec/models/status_message_spec.rb @@ -3,8 +3,9 @@ include StatusMessagesHelper describe StatusMessage do before do - @usr = Factory.create(:user,:email => "bob@aol.com", :password => "diggity") + Factory.create(:user, :email => "bob@aol.com", :password => "diggity") end + it "should have a message" do n = Factory.build(:status_message, :message => nil) n.valid?.should be false @@ -19,12 +20,11 @@ describe StatusMessage do describe "newest" do before do - (1..5).each { Factory.create(:status_message, :owner => "some@dudes.com") } - (6..10).each { Factory.create(:status_message) } + (1..5).each { Factory.create(:status_message, :owner => "some@dudes.com") } + (6..10).each { Factory.create(:status_message) } end it "should give the most recent message from owner" do - #puts StatusMessage.newest("sam@cool.com") StatusMessage.my_newest.message.should == "jimmy's 11 whales" end @@ -34,19 +34,16 @@ describe StatusMessage do end describe "XML" do - before do - @xml = "\n I hate WALRUSES!\n Bob\n" - end - it 'should serialize to XML' do - message = Factory.create(:status_message, :message => "I hate WALRUSES!", :owner => "Bob") - message.to_xml.to_s.should == @xml + message = Factory.create(:status_message, :message => "I hate WALRUSES!") + message.to_xml.to_s.should include "I hate WALRUSES!" end it 'should marshal serialized XML to object' do - parsed = StatusMessage.from_xml(@xml) + xml = "\n I hate WALRUSES!Bob@rob.ert" + parsed = StatusMessage.from_xml(xml) parsed.message.should == "I hate WALRUSES!" - parsed.owner.should == "Bob" + parsed.owner.should == "Bob@rob.ert" parsed.valid?.should be_true end end