DG MS fixing tests

This commit is contained in:
maxwell 2010-06-24 20:45:49 -07:00
parent 5f3a6a7aa0
commit e558d4833f
20 changed files with 52 additions and 43 deletions

View file

@ -3,7 +3,7 @@ class BlogsController < ApplicationController
def index def index
@blogs = Blog.criteria.all.order_by( [:created_at, :desc] ) @blogs = Blog.sort(:created_at.desc).all
end end
def show def show
@ -16,6 +16,7 @@ class BlogsController < ApplicationController
def create def create
@blog = Blog.new(params[:blog]) @blog = Blog.new(params[:blog])
@blog.person = current_user
if @blog.save if @blog.save
flash[:notice] = "Successfully created blog." flash[:notice] = "Successfully created blog."
redirect_to @blog redirect_to @blog
@ -25,11 +26,11 @@ class BlogsController < ApplicationController
end end
def edit def edit
@blog = Blog.find(params[:id]) @blog = Blog.where(:id => params[:id]).first
end end
def update def update
@blog = Blog.find(params[:id]) @blog = Blog.where(:id => params[:id]).first
if @blog.update_attributes(params[:blog]) if @blog.update_attributes(params[:blog])
flash[:notice] = "Successfully updated blog." flash[:notice] = "Successfully updated blog."
redirect_to @blog redirect_to @blog
@ -39,7 +40,7 @@ class BlogsController < ApplicationController
end end
def destroy def destroy
@blog = Blog.find(params[:id]) @blog = Blog.where(:id => params[:id]).first
@blog.destroy @blog.destroy
flash[:notice] = "Successfully destroyed blog." flash[:notice] = "Successfully destroyed blog."
redirect_to blogs_url redirect_to blogs_url

View file

@ -2,7 +2,7 @@ class BookmarksController < ApplicationController
before_filter :authenticate_user! before_filter :authenticate_user!
def index def index
@bookmarks = Bookmark.criteria.all.order_by( [:created_at, :desc] ) @bookmarks = Bookmark.sort(:created_at.desc).all
end end
def edit def edit
@ -25,6 +25,7 @@ class BookmarksController < ApplicationController
def create def create
@bookmark = Bookmark.new(params[:bookmark]) @bookmark = Bookmark.new(params[:bookmark])
@bookmark.person = current_user
if @bookmark.save if @bookmark.save
flash[:notice] = "Successfully created bookmark." flash[:notice] = "Successfully created bookmark."
redirect_to @bookmark redirect_to @bookmark

View file

@ -4,8 +4,7 @@ class DashboardController < ApplicationController
include ApplicationHelper include ApplicationHelper
def index def index
posts = Post.all.order_by( [:created_at, :desc] ) @posts = Post.sort(:created_at.desc).all
@posts = posts
end end

View file

@ -2,15 +2,16 @@ class FriendsController < ApplicationController
before_filter :authenticate_user! before_filter :authenticate_user!
def index def index
@friends = Friend.criteria.all.order_by( [:created_at, :desc] ) @friends = Friend.all
end end
def show def show
@friend = Friend.first(:conditions=> {:id => params[:id]}) @friend = Friend.where(:id => params[:id]).first
@friend_posts = Post.where(:person_id => @friend.id).sort(:created_at.desc)
end end
def destroy def destroy
@friend = Friend.first(:conditions=> {:id => params[:id]}) @friend = Friend.where(:id => params[:id]).first
@friend.destroy @friend.destroy
flash[:notice] = "Successfully destroyed friend." flash[:notice] = "Successfully destroyed friend."
redirect_to friends_url redirect_to friends_url

View file

@ -3,7 +3,7 @@ class StatusMessagesController < ApplicationController
def index def index
@status_message = StatusMessage.new @status_message = StatusMessage.new
@status_messages = StatusMessage.criteria.all.order_by( [:created_at, :desc] ) @status_messages = StatusMessage.sort(:created_at.desc).all
respond_to do |format| respond_to do |format|
@ -16,6 +16,8 @@ class StatusMessagesController < ApplicationController
def create def create
@status_message = StatusMessage.new(params[:status_message]) @status_message = StatusMessage.new(params[:status_message])
@status_message.person = current_user
if @status_message.save if @status_message.save
flash[:notice] = "Successfully created status message." flash[:notice] = "Successfully created status message."
redirect_to status_messages_url redirect_to status_messages_url
@ -29,14 +31,14 @@ class StatusMessagesController < ApplicationController
end end
def destroy def destroy
@status_message = StatusMessage.first(:conditions => {:id => params[:id]}) @status_message = StatusMessage.where(:id => params[:id]).first
@status_message.destroy @status_message.destroy
flash[:notice] = "Successfully destroyed status message." flash[:notice] = "Successfully destroyed status message."
redirect_to status_messages_url redirect_to status_messages_url
end end
def show def show
@status_message = StatusMessage.first(:conditions => {:id => params[:id]}) @status_message = StatusMessage.where(:id => params[:id]).first
respond_to do |format| respond_to do |format|
format.html format.html

View file

@ -3,7 +3,7 @@ class UsersController < ApplicationController
before_filter :authenticate_user! before_filter :authenticate_user!
def index def index
@users = User.criteria.all.order_by( [:created_at, :desc] ) @users = User.sort(:created_at.desc).all
end end
end end

View file

@ -5,11 +5,12 @@ class Person
xml_accessor :email xml_accessor :email
xml_accessor :real_name xml_accessor :real_name
key :type, String
key :email, String key :email, String
key :real_name, String key :real_name, String
has_many :posts #key :post_ids, Array#, :typecast => ObjectId
many :posts, :class_name => 'Post', :foreign_key => :person_id
validates_presence_of :email, :real_name validates_presence_of :email, :real_name

View file

@ -9,15 +9,18 @@ class Post
include Diaspora::Webhooks include Diaspora::Webhooks
key :type, String
key :person_id, ObjectId key :person_id, ObjectId
belongs_to :person belongs_to :person, :class_name => 'Person'
timestamps!
#before_create :set_defaults
after_save :send_to_view after_save :send_to_view
after_save :print
def self.stream
Post.sort(:created_at.desc).all
end
def each def each
yield self yield self
@ -30,7 +33,6 @@ class Post
WebSocket.update_clients(self) WebSocket.update_clients(self)
end end
def set_defaults
end
end end

View file

@ -9,7 +9,9 @@ class StatusMessage < Post
validates_presence_of :message validates_presence_of :message
def self.my_newest
StatusMessage.where(:person_id => User.first.id).sort(:created_at.desc).first
end
end end

View file

@ -1,9 +1,16 @@
class User class User < Person
include MongoMapper::Document include MongoMapper::Document
timestamps!
# Include default devise modules. Others available are: # Include default devise modules. Others available are:
# :token_authenticatable, :confirmable, :lockable and :timeoutable # :token_authenticatable, :confirmable, :lockable and :timeoutable
devise :database_authenticatable, :registerable, devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable :recoverable, :rememberable, :trackable, :validatable
before_save :do_bad_things
def do_bad_things
self.password_confirmation = self.password
end
end end

View file

@ -8,7 +8,7 @@
= raw @blog.body = raw @blog.body
%p %p
%strong Owner: %strong Owner:
= @blog.owner = @blog.person.real_name
%p %p
= link_to "Edit", edit_blog_path(@blog) = link_to "Edit", edit_blog_path(@blog)

View file

@ -8,7 +8,7 @@
= link_to @bookmark.link = link_to @bookmark.link
%p %p
%strong Owner: %strong Owner:
= @bookmark.owner = @bookmark.person.real_name
%p %p
= link_to "Edit", edit_bookmark_path(@bookmark) = link_to "Edit", edit_bookmark_path(@bookmark)

View file

@ -1,11 +1,7 @@
%h1= "#{@friend.real_name}'s network stream" %h1= "#{@friend.real_name}'s network stream"
- if @friend.posts - if @friend.posts
%ul#stream %ul#stream
- for post in @friend.posts - for post in @friend_posts
= render type_partial(post), :post => post = render type_partial(post), :post => post
- else - else
%h3 no posts to display! %h3 no posts to display!

View file

@ -3,7 +3,7 @@
= link_to_person post.person = link_to_person post.person
= post.message = post.message
%div.time %div.time
= "#{time_ago_in_words(post.updated_at)} ago" = link_to "#{time_ago_in_words(post.updated_at)} ago", status_message_path(post)
- if mine?(post) - if mine?(post)
= link_to 'Destroy', status_message_path(post), :confirm => 'Are you sure?', :method => :delete = link_to 'Destroy', status_message_path(post), :confirm => 'Are you sure?', :method => :delete

View file

@ -6,7 +6,7 @@
%p %p
%strong Owner: %strong Owner:
= @status_message.owner = @status_message.person.real_name
%p %p
= link_to "Destroy", @status_message, :confirm => 'Are you sure?', :method => :delete = link_to "Destroy", @status_message, :confirm => 'Are you sure?', :method => :delete

View file

@ -36,7 +36,7 @@ Diaspora::Application.configure do
begin begin
require 'database_cleaner' require 'database_cleaner'
DatabaseCleaner.strategy = :truncation DatabaseCleaner.strategy = :truncation
DatabaseCleaner.orm = "mongoid" DatabaseCleaner.orm = "mongo_mapper"
rescue LoadError => ignore_if_database_cleaner_not_present rescue LoadError => ignore_if_database_cleaner_not_present
puts "Error on cleaner" puts "Error on cleaner"
end end

View file

@ -21,6 +21,7 @@ Factory.define :user do |u|
u.real_name 'Bob Smith' u.real_name 'Bob Smith'
u.sequence(:email) {|n| "bob#{n}@aol.com"} u.sequence(:email) {|n| "bob#{n}@aol.com"}
u.password "bluepin7" u.password "bluepin7"
u.password_confirmation "bluepin7"
end end
Factory.define :bookmark do |b| Factory.define :bookmark do |b|

View file

@ -2,7 +2,7 @@ require File.dirname(__FILE__) + '/../spec_helper'
describe Blog do describe Blog do
before do before do
Factory.create(:user, :email => "bob@aol.com", :password => "diggity") Factory.create(:user, :email => "bob@aol.com")
end end
it "should have a title and body" do it "should have a title and body" do

View file

@ -2,7 +2,7 @@ require File.dirname(__FILE__) + '/../spec_helper'
describe StatusMessage do describe StatusMessage do
before do before do
Factory.create(:user, :email => "bob@aol.com", :password => "diggity") @user = Factory.create(:user, :email => "bob@aol.com")
end end
it "should have a message" do it "should have a message" do
@ -12,14 +12,10 @@ describe StatusMessage do
n.valid?.should be true n.valid?.should be true
end end
it "should add an owner if none is present" do
n = Factory.create(:status_message)
n.owner.should == "bob@aol.com"
end
describe "newest" do describe "newest" do
before do before do
(1..5).each { Factory.create(:status_message, :owner => "some@dudes.com") } @friend = Factory.build(:friend, :email => "robert@grimm.com")
(1..5).each { Factory.create(:status_message, :person => @friend) }
(6..10).each { Factory.create(:status_message) } (6..10).each { Factory.create(:status_message) }
end end

View file

@ -18,7 +18,7 @@ Rspec.configure do |config|
config.mock_with :rspec config.mock_with :rspec
DatabaseCleaner.strategy = :truncation DatabaseCleaner.strategy = :truncation
DatabaseCleaner.orm = "mongoid" DatabaseCleaner.orm = "mongo_mapper"
config.before(:suite) do config.before(:suite) do
DatabaseCleaner.strategy = :transaction DatabaseCleaner.strategy = :transaction