From e558d4833fd3497ecc84c6b07560305ead7b5d4d Mon Sep 17 00:00:00 2001 From: maxwell Date: Thu, 24 Jun 2010 20:45:49 -0700 Subject: [PATCH] DG MS fixing tests --- app/controllers/blogs_controller.rb | 9 +++++---- app/controllers/bookmarks_controller.rb | 3 ++- app/controllers/dashboard_controller.rb | 3 +-- app/controllers/friends_controller.rb | 7 ++++--- app/controllers/status_messages_controller.rb | 8 +++++--- app/controllers/users_controller.rb | 2 +- app/models/person.rb | 5 +++-- app/models/post.rb | 14 ++++++++------ app/models/status_message.rb | 4 +++- app/models/user.rb | 9 ++++++++- app/views/blogs/show.html.haml | 2 +- app/views/bookmarks/show.html.haml | 2 +- app/views/friends/show.html.haml | 6 +----- .../status_messages/_status_message.html.haml | 2 +- app/views/status_messages/show.html.haml | 2 +- config/environments/test.rb | 2 +- spec/factories.rb | 1 + spec/models/blogs_spec.rb | 2 +- spec/models/status_message_spec.rb | 10 +++------- spec/spec_helper.rb | 2 +- 20 files changed, 52 insertions(+), 43 deletions(-) diff --git a/app/controllers/blogs_controller.rb b/app/controllers/blogs_controller.rb index f39cecdbf..c709b0801 100644 --- a/app/controllers/blogs_controller.rb +++ b/app/controllers/blogs_controller.rb @@ -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 diff --git a/app/controllers/bookmarks_controller.rb b/app/controllers/bookmarks_controller.rb index 6defe2f07..51f9fb6bb 100644 --- a/app/controllers/bookmarks_controller.rb +++ b/app/controllers/bookmarks_controller.rb @@ -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 diff --git a/app/controllers/dashboard_controller.rb b/app/controllers/dashboard_controller.rb index 6591f5925..c8d14858f 100644 --- a/app/controllers/dashboard_controller.rb +++ b/app/controllers/dashboard_controller.rb @@ -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 diff --git a/app/controllers/friends_controller.rb b/app/controllers/friends_controller.rb index 55778861f..ebf2c1df8 100644 --- a/app/controllers/friends_controller.rb +++ b/app/controllers/friends_controller.rb @@ -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 diff --git a/app/controllers/status_messages_controller.rb b/app/controllers/status_messages_controller.rb index c0507fcda..0c24a76bd 100644 --- a/app/controllers/status_messages_controller.rb +++ b/app/controllers/status_messages_controller.rb @@ -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 diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index da904fab0..393f3cffd 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -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 diff --git a/app/models/person.rb b/app/models/person.rb index fe6ac6f83..35c4cf116 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -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 diff --git a/app/models/post.rb b/app/models/post.rb index f8c3789f7..e91431fa1 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -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 diff --git a/app/models/status_message.rb b/app/models/status_message.rb index 5b7345288..9871f690d 100644 --- a/app/models/status_message.rb +++ b/app/models/status_message.rb @@ -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 diff --git a/app/models/user.rb b/app/models/user.rb index 2965da452..188a46579 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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 diff --git a/app/views/blogs/show.html.haml b/app/views/blogs/show.html.haml index b1e270b42..a4646414d 100644 --- a/app/views/blogs/show.html.haml +++ b/app/views/blogs/show.html.haml @@ -8,7 +8,7 @@ = raw @blog.body %p %strong Owner: - = @blog.owner + = @blog.person.real_name %p = link_to "Edit", edit_blog_path(@blog) diff --git a/app/views/bookmarks/show.html.haml b/app/views/bookmarks/show.html.haml index 2072f4cf9..4b22ba43a 100644 --- a/app/views/bookmarks/show.html.haml +++ b/app/views/bookmarks/show.html.haml @@ -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) diff --git a/app/views/friends/show.html.haml b/app/views/friends/show.html.haml index 8ca7c8c57..f4218409b 100644 --- a/app/views/friends/show.html.haml +++ b/app/views/friends/show.html.haml @@ -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! diff --git a/app/views/status_messages/_status_message.html.haml b/app/views/status_messages/_status_message.html.haml index 0c1e6786f..b27d8fb00 100644 --- a/app/views/status_messages/_status_message.html.haml +++ b/app/views/status_messages/_status_message.html.haml @@ -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 diff --git a/app/views/status_messages/show.html.haml b/app/views/status_messages/show.html.haml index 4be35c793..85c39c268 100644 --- a/app/views/status_messages/show.html.haml +++ b/app/views/status_messages/show.html.haml @@ -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 diff --git a/config/environments/test.rb b/config/environments/test.rb index a82ae0745..7f40c884b 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -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 diff --git a/spec/factories.rb b/spec/factories.rb index d995e1e88..adcd546e8 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -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| diff --git a/spec/models/blogs_spec.rb b/spec/models/blogs_spec.rb index 32c9557a4..384971f38 100644 --- a/spec/models/blogs_spec.rb +++ b/spec/models/blogs_spec.rb @@ -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 diff --git a/spec/models/status_message_spec.rb b/spec/models/status_message_spec.rb index 7bfa0af00..9773c8334 100644 --- a/spec/models/status_message_spec.rb +++ b/spec/models/status_message_spec.rb @@ -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 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 2ebfc5477..f9604803e 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -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