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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -3,7 +3,7 @@
= link_to_person post.person
= post.message
%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)
= link_to 'Destroy', status_message_path(post), :confirm => 'Are you sure?', :method => :delete

View file

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

View file

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

View file

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

View file

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

View file

@ -2,7 +2,7 @@ require File.dirname(__FILE__) + '/../spec_helper'
describe StatusMessage do
before do
Factory.create(:user, :email => "bob@aol.com", :password => "diggity")
@user = Factory.create(:user, :email => "bob@aol.com")
end
it "should have a message" do
@ -11,15 +11,11 @@ describe StatusMessage do
n.message = "wales"
n.valid?.should be true
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
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) }
end

View file

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