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
|
||||
def object_path(object)
|
||||
eval("#{object.class.to_s.underscore}_path(object)")
|
||||
end
|
||||
|
||||
def object_fields(object)
|
||||
object.attributes.keys
|
||||
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
|
||||
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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
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,20 +1,13 @@
|
|||
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})
|
||||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
- form_for @blog do |f|
|
||||
= form_for @blog do |f|
|
||||
= f.error_messages
|
||||
%p
|
||||
= 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
|
||||
# (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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
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|
|
||||
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
|
||||
|
|
|
|||
|
|
@ -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 = "<blog>\n <title>yessir</title>\n <body>I hate WALRUSES!</body>\n <owner>Bob</owner>\n</blog>"
|
||||
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 "<title>yessir</title>"
|
||||
body.to_xml.to_s.should include "<body>penguins</body>"
|
||||
end
|
||||
|
||||
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.owner.should == "Bob"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
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
|
||||
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
|
||||
|
|
@ -24,7 +25,6 @@ describe StatusMessage do
|
|||
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 = "<statusmessage>\n <message>I hate WALRUSES!</message>\n <owner>Bob</owner>\n</statusmessage>"
|
||||
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 "<message>I hate WALRUSES!</message>"
|
||||
end
|
||||
|
||||
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.owner.should == "Bob"
|
||||
parsed.owner.should == "Bob@rob.ert"
|
||||
parsed.valid?.should be_true
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue