RS, IZ; merged day's commits
This commit is contained in:
commit
ed26c82be4
20 changed files with 188 additions and 86 deletions
14
app/controllers/dashboard_controller.rb
Normal file
14
app/controllers/dashboard_controller.rb
Normal file
|
|
@ -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
|
||||||
|
|
@ -1,2 +1,9 @@
|
||||||
module ApplicationHelper
|
module ApplicationHelper
|
||||||
|
def object_path(object)
|
||||||
|
eval("#{object.class.to_s.underscore}_path(object)")
|
||||||
|
end
|
||||||
|
|
||||||
|
def object_fields(object)
|
||||||
|
object.attributes.keys
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
2
app/helpers/dashboard_helper.rb
Normal file
2
app/helpers/dashboard_helper.rb
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
module DashboardHelper
|
||||||
|
end
|
||||||
|
|
@ -3,7 +3,7 @@ module StatusMessagesHelper
|
||||||
def my_latest_message
|
def my_latest_message
|
||||||
message = StatusMessage.my_newest
|
message = StatusMessage.my_newest
|
||||||
unless message.nil?
|
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
|
else
|
||||||
return "No message to display."
|
return "No message to display."
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,21 +1,14 @@
|
||||||
class Blog
|
class Blog < Post
|
||||||
include Mongoid::Document
|
|
||||||
include Mongoid::Timestamps
|
|
||||||
include ROXML
|
|
||||||
|
|
||||||
xml_accessor :title
|
xml_accessor :title
|
||||||
xml_accessor :body
|
xml_accessor :body
|
||||||
xml_accessor :owner
|
|
||||||
|
|
||||||
|
|
||||||
field :title
|
field :title
|
||||||
field :body
|
field :body
|
||||||
field :owner
|
|
||||||
|
|
||||||
validates_presence_of :title, :body
|
validates_presence_of :title, :body
|
||||||
|
|
||||||
before_create :set_default_owner
|
|
||||||
|
|
||||||
def self.newest(owner_email)
|
def self.newest(owner_email)
|
||||||
Blog.last(:conditions => {:owner => owner_email})
|
Blog.last(:conditions => {:owner => owner_email})
|
||||||
end
|
end
|
||||||
|
|
@ -23,10 +16,4 @@ class Blog
|
||||||
def self.my_newest
|
def self.my_newest
|
||||||
Blog.newest(User.first.email)
|
Blog.newest(User.first.email)
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
|
||||||
|
|
||||||
def set_default_owner
|
|
||||||
self.owner ||= User.first.email
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,20 +1,12 @@
|
||||||
class Bookmark
|
class Bookmark < Post
|
||||||
include Mongoid::Document
|
|
||||||
include Mongoid::Timestamps
|
|
||||||
|
|
||||||
|
xml_accessor :link
|
||||||
|
xml_accessor :title
|
||||||
|
|
||||||
field :owner
|
|
||||||
field :link
|
field :link
|
||||||
field :title
|
field :title
|
||||||
|
|
||||||
|
|
||||||
validates_presence_of :link
|
validates_presence_of :link
|
||||||
|
|
||||||
before_create :set_default_owner
|
|
||||||
|
|
||||||
protected
|
|
||||||
|
|
||||||
def set_default_owner
|
|
||||||
self.owner ||= User.first.email
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
39
app/models/post.rb
Normal file
39
app/models/post.rb
Normal file
|
|
@ -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
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1,21 +1,14 @@
|
||||||
class StatusMessage
|
class StatusMessage < Post
|
||||||
include Mongoid::Document
|
|
||||||
include Mongoid::Timestamps
|
|
||||||
include ROXML
|
|
||||||
include StatusMessagesHelper
|
include StatusMessagesHelper
|
||||||
require 'lib/net/curl'
|
require 'lib/net/curl'
|
||||||
|
|
||||||
xml_accessor :message
|
xml_accessor :message
|
||||||
xml_accessor :owner
|
|
||||||
|
|
||||||
|
|
||||||
field :message
|
field :message
|
||||||
field :owner
|
|
||||||
|
|
||||||
validates_presence_of :message
|
validates_presence_of :message
|
||||||
|
|
||||||
before_create :set_default_owner
|
|
||||||
|
|
||||||
def self.newest(owner_email)
|
def self.newest(owner_email)
|
||||||
StatusMessage.last(:conditions => {:owner => owner_email})
|
StatusMessage.last(:conditions => {:owner => owner_email})
|
||||||
end
|
end
|
||||||
|
|
@ -32,11 +25,5 @@ class StatusMessage
|
||||||
(self.message == other.message) && (self.owner == other.owner)
|
(self.message == other.message) && (self.owner == other.owner)
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
|
||||||
|
|
||||||
def set_default_owner
|
|
||||||
self.owner ||= User.first.email
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
- form_for @blog do |f|
|
= form_for @blog do |f|
|
||||||
= f.error_messages
|
= f.error_messages
|
||||||
%p
|
%p
|
||||||
= f.label :title
|
= f.label :title
|
||||||
|
|
|
||||||
9
app/views/dashboard/index.html.haml
Normal file
9
app/views/dashboard/index.html.haml
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
- title "Dashboard"
|
||||||
|
|
||||||
|
%ul
|
||||||
|
- for post in @posts
|
||||||
|
%li
|
||||||
|
= render "shared/post", :post =>post
|
||||||
|
%br
|
||||||
|
%br
|
||||||
|
|
||||||
5
app/views/shared/_post.html.haml
Normal file
5
app/views/shared/_post.html.haml
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
%ul
|
||||||
|
%h3= link_to post.class, object_path(post)
|
||||||
|
- for field in object_fields(post)
|
||||||
|
%li= "#{field}: #{post.attributes[field]}"
|
||||||
|
|
||||||
|
|
@ -2,9 +2,10 @@
|
||||||
|
|
||||||
# Add new inflection rules using the following format
|
# Add new inflection rules using the following format
|
||||||
# (all these examples are active by default):
|
# (all these examples are active by default):
|
||||||
# ActiveSupport::Inflector.inflections do |inflect|
|
ActiveSupport::Inflector.inflections do |inflect|
|
||||||
# inflect.plural /^(ox)$/i, '\1en'
|
# inflect.plural /^(ox)$/i, '\1en'
|
||||||
# inflect.singular /^(ox)en/i, '\1'
|
# inflect.singular /^(ox)en/i, '\1'
|
||||||
# inflect.irregular 'person', 'people'
|
# inflect.irregular 'person', 'people'
|
||||||
# inflect.uncountable %w( fish sheep )
|
# inflect.uncountable %w( fish sheep )
|
||||||
# end
|
inflect.uncountable %w(dashboard)
|
||||||
|
end
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,6 @@ Diaspora::Application.routes.draw do |map|
|
||||||
|
|
||||||
resources :users
|
resources :users
|
||||||
resources :status_messages
|
resources :status_messages
|
||||||
match 'dashboard', :to => 'status_messages#index'
|
|
||||||
|
|
||||||
|
|
||||||
# The priority is based upon order of creation:
|
# 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.
|
# Note: This route will make all actions in every controller accessible via GET requests.
|
||||||
# match ':controller(/:action(/:id(.:format)))'
|
# match ':controller(/:action(/:id(.:format)))'
|
||||||
|
|
||||||
root :to => 'status_messages#index'
|
root :to => 'dashboard#index'
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
18
lib/common.rb
Normal file
18
lib/common.rb
Normal file
|
|
@ -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
|
||||||
11
spec/controllers/dashboard_controller_spec.rb
Normal file
11
spec/controllers/dashboard_controller_spec.rb
Normal file
|
|
@ -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
|
||||||
|
|
@ -8,7 +8,11 @@ end
|
||||||
|
|
||||||
Factory.define :status_message do |m|
|
Factory.define :status_message do |m|
|
||||||
m.sequence(:message) {|n| "jimmy's #{n} whales"}
|
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
|
end
|
||||||
|
|
||||||
Factory.define :user do |u|
|
Factory.define :user do |u|
|
||||||
|
|
@ -19,3 +23,8 @@ end
|
||||||
Factory.define :bookmark do |b|
|
Factory.define :bookmark do |b|
|
||||||
b.link "http://www.yahooligans.com/"
|
b.link "http://www.yahooligans.com/"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Factory.define :post do |p|
|
||||||
|
p.source "New York Times"
|
||||||
|
p.sequence(:snippet) {|n| "This is some information #{n}"}
|
||||||
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,10 @@
|
||||||
require File.dirname(__FILE__) + '/../spec_helper'
|
require File.dirname(__FILE__) + '/../spec_helper'
|
||||||
|
|
||||||
describe Blog do
|
describe Blog do
|
||||||
|
before do
|
||||||
|
Factory.create(:user, :email => "bob@aol.com", :password => "diggity")
|
||||||
|
end
|
||||||
|
|
||||||
it "should have a title and body" do
|
it "should have a title and body" do
|
||||||
n = Blog.new
|
n = Blog.new
|
||||||
n.valid?.should be false
|
n.valid?.should be false
|
||||||
|
|
@ -11,51 +15,41 @@ describe Blog do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should add an owner if none is present" do
|
it "should add an owner if none is present" do
|
||||||
User.create(:email => "bob@aol.com", :password => "big bux")
|
b = Factory.create(:blog)
|
||||||
n = Blog.create(:title => "kittens", :body => "puppies!")
|
b.owner.should == "bob@aol.com"
|
||||||
n.owner.should == "bob@aol.com"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
describe "newest" do
|
describe "newest" do
|
||||||
before do
|
before do
|
||||||
User.create(:email => "bob@aol.com", :password => "diggity")
|
(2..4).each { Factory.create(:blog, :owner => "some@dudes.com") }
|
||||||
Blog.create(:title => "bone dawg", :body => "wale for jimmy", :owner => "xzibit@dawgz.com")
|
(5..8).each { Factory.create(:blog) }
|
||||||
Blog.create(:title => "dawg bone", :body => "jimmy wales")
|
(9..11).each { Factory.create(:blog, :owner => "other@dudes.com") }
|
||||||
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")
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should give the most recent blog title and body from owner" do
|
it "should give the most recent blog title and body from owner" do
|
||||||
blog = Blog.my_newest
|
blog = Blog.my_newest
|
||||||
blog.title.should == "bone dawg"
|
blog.title.should == "bobby's 8 penguins"
|
||||||
blog.body.should == "roar"
|
blog.body.should == "jimmy's huge 8 whales"
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should give the most recent blog body for a given email" do
|
it "should give the most recent blog body for a given email" do
|
||||||
blog = Blog.newest("some@dudes.com")
|
blog = Blog.newest("some@dudes.com")
|
||||||
blog.title.should == "dawg bone"
|
blog.title.should == "bobby's 14 penguins"
|
||||||
blog.body.should == "sharks"
|
blog.body.should == "jimmy's huge 14 whales"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "XML" do
|
describe "XML" do
|
||||||
before do
|
|
||||||
@xml = "<blog>\n <title>yessir</title>\n <body>I hate WALRUSES!</body>\n <owner>Bob</owner>\n</blog>"
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'should serialize to XML' do
|
it 'should serialize to XML' do
|
||||||
body = Blog.create(:title => "yessir", :body => "I hate WALRUSES!", :owner => "Bob")
|
body = Factory.create(:blog, :title => "yessir", :body => "penguins")
|
||||||
body.to_xml.to_s.should == @xml
|
body.to_xml.to_s.should include "<title>yessir</title>"
|
||||||
|
body.to_xml.to_s.should include "<body>penguins</body>"
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should marshal serialized XML to object' do
|
it 'should marshal serialized XML to object' do
|
||||||
parsed = Blog.from_xml(@xml)
|
xml = "<blog>\n <title>yessir</title>\n <body>I hate WALRUSES!</body>\n</blog>"
|
||||||
|
parsed = Blog.from_xml(xml)
|
||||||
parsed.body.should == "I hate WALRUSES!"
|
parsed.body.should == "I hate WALRUSES!"
|
||||||
parsed.owner.should == "Bob"
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@ require File.dirname(__FILE__) + '/../spec_helper'
|
||||||
describe Friend do
|
describe Friend do
|
||||||
it 'should have a diaspora username and diaspora url' do
|
it 'should have a diaspora username and diaspora url' do
|
||||||
n = Factory.build(:friend, :url => nil)
|
n = Factory.build(:friend, :url => nil)
|
||||||
#n = Friend.new(:username => 'max')
|
|
||||||
n.valid?.should be false
|
n.valid?.should be false
|
||||||
n.url = "http://max.com/"
|
n.url = "http://max.com/"
|
||||||
n.valid?.should be true
|
n.valid?.should be true
|
||||||
|
|
|
||||||
32
spec/models/post_spec.rb
Normal file
32
spec/models/post_spec.rb
Normal file
|
|
@ -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
|
||||||
|
|
@ -3,8 +3,9 @@ include StatusMessagesHelper
|
||||||
|
|
||||||
describe StatusMessage do
|
describe StatusMessage do
|
||||||
before do
|
before do
|
||||||
@usr = Factory.create(:user,:email => "bob@aol.com", :password => "diggity")
|
Factory.create(:user, :email => "bob@aol.com", :password => "diggity")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should have a message" do
|
it "should have a message" do
|
||||||
n = Factory.build(:status_message, :message => nil)
|
n = Factory.build(:status_message, :message => nil)
|
||||||
n.valid?.should be false
|
n.valid?.should be false
|
||||||
|
|
@ -19,12 +20,11 @@ describe StatusMessage do
|
||||||
|
|
||||||
describe "newest" do
|
describe "newest" do
|
||||||
before do
|
before do
|
||||||
(1..5).each { Factory.create(:status_message, :owner => "some@dudes.com") }
|
(1..5).each { Factory.create(:status_message, :owner => "some@dudes.com") }
|
||||||
(6..10).each { Factory.create(:status_message) }
|
(6..10).each { Factory.create(:status_message) }
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should give the most recent message from owner" do
|
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"
|
StatusMessage.my_newest.message.should == "jimmy's 11 whales"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -34,19 +34,16 @@ describe StatusMessage do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "XML" do
|
describe "XML" do
|
||||||
before do
|
|
||||||
@xml = "<statusmessage>\n <message>I hate WALRUSES!</message>\n <owner>Bob</owner>\n</statusmessage>"
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'should serialize to XML' do
|
it 'should serialize to XML' do
|
||||||
message = Factory.create(:status_message, :message => "I hate WALRUSES!", :owner => "Bob")
|
message = Factory.create(:status_message, :message => "I hate WALRUSES!")
|
||||||
message.to_xml.to_s.should == @xml
|
message.to_xml.to_s.should include "<message>I hate WALRUSES!</message>"
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should marshal serialized XML to object' do
|
it 'should marshal serialized XML to object' do
|
||||||
parsed = StatusMessage.from_xml(@xml)
|
xml = "<statusmessage>\n <message>I hate WALRUSES!</message><owner>Bob@rob.ert</owner></statusmessage>"
|
||||||
|
parsed = StatusMessage.from_xml(xml)
|
||||||
parsed.message.should == "I hate WALRUSES!"
|
parsed.message.should == "I hate WALRUSES!"
|
||||||
parsed.owner.should == "Bob"
|
parsed.owner.should == "Bob@rob.ert"
|
||||||
parsed.valid?.should be_true
|
parsed.valid?.should be_true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue