From 8829714e2dbdadbc4c99d72f03e458744c803d47 Mon Sep 17 00:00:00 2001 From: ilya Date: Wed, 23 Jun 2010 20:17:44 -0400 Subject: [PATCH 01/11] RS, IZ, Cleaned up Post, finished Person refactor, FactoryGirl sequences are unpleasant --- Gemfile | 2 +- app/helpers/application_helper.rb | 15 ++++--- app/models/blog.rb | 7 --- app/models/person.rb | 5 ++- app/models/post.rb | 21 ++++----- app/models/status_message.rb | 14 +----- app/views/blogs/show.html.haml | 2 +- app/views/bookmarks/_bookmark.html.haml | 2 +- app/views/bookmarks/show.html.haml | 2 +- app/views/status_messages/show.html.haml | 2 +- lib/common.rb | 4 +- .../status_messages_controller_spec.rb | 2 +- spec/factories.rb | 2 - spec/helpers/parser_spec.rb | 45 ++++++++++++++----- spec/lib/common_spec.rb | 3 +- spec/models/blogs_spec.rb | 16 ++++--- spec/models/bookmark_spec.rb | 5 +-- spec/models/post_spec.rb | 13 +----- spec/models/status_message_spec.rb | 18 ++++---- spec/spec_helper.rb | 1 + 20 files changed, 91 insertions(+), 90 deletions(-) diff --git a/Gemfile b/Gemfile index 836a5c285..5cf621b4e 100644 --- a/Gemfile +++ b/Gemfile @@ -3,7 +3,7 @@ source 'http://gemcutter.org' gem 'rails', '3.0.0.beta4' -gem "mongoid", :git => "git://github.com/durran/mongoid.git" +gem "mongoid", :git => "git://github.com/durran/mongoid.git", :ref => "79b4d3710d17c949544f" gem "bson_ext", "1.0.1" gem "haml" gem "devise", :git => "git://github.com/plataformatec/devise.git", :ref => "cfadaf80a2b7e9c0b255" diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index e56227538..438c3f9c6 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -14,8 +14,9 @@ module ApplicationHelper def parse_sender_object_from_xml(xml) sender_id = parse_sender_id_from_xml(xml) - Person.where(:email => sender_id).first - end + Friend.where(:email => sender_id).first + + end def parse_body_contents_from_xml(xml) doc = Nokogiri::XML(xml) { |cfg| cfg.noblanks } @@ -24,11 +25,13 @@ module ApplicationHelper def parse_posts_from_xml(xml) posts = [] + sender = parse_sender_object_from_xml(xml) body = parse_body_contents_from_xml(xml) body.children.each do |post| begin object = post.name.camelize.constantize.from_xml post.to_s - posts << object if object.is_a? Post + object.person = sender + posts << object if object.is_a? Post rescue puts "Not a real type: #{post.to_s}" end @@ -37,17 +40,15 @@ module ApplicationHelper end def store_posts_from_xml(xml) - sender_object = parse_sender_object_from_xml(xml) posts = parse_posts_from_xml(xml) posts.each do |p| - p.person = sender_object - p.save + p.save unless p.person.nil? end end def mine?(post) - post.owner == User.first.email + post.person == User.first end def type_partial(post) diff --git a/app/models/blog.rb b/app/models/blog.rb index 3da382754..b52ebee7f 100644 --- a/app/models/blog.rb +++ b/app/models/blog.rb @@ -9,11 +9,4 @@ class Blog < Post validates_presence_of :title, :body - def self.newest(owner_email) - Blog.last(:conditions => {:owner => owner_email}) - end - - def self.my_newest - Blog.newest(User.first.email) - end end diff --git a/app/models/person.rb b/app/models/person.rb index 399dbb394..ea7157d30 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -11,5 +11,8 @@ class Person has_many_related :posts validates_presence_of :email, :real_name - + + # def newest(type = nil) + # type.constantize.where(:person_id => id).last + # end end diff --git a/app/models/post.rb b/app/models/post.rb index 9dc312309..8b3ff61f2 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -9,14 +9,6 @@ class Post include ROXML include Diaspora::Webhooks - xml_accessor :owner - xml_accessor :snippet - xml_accessor :source - - field :owner - field :source - field :snippet - belongs_to_related :person @@ -41,6 +33,15 @@ class Post yield self end + def self.newest(person = nil) + return self.last if person.nil? + self.where(:person_id => person.id).last + end + + def self.newest_by_email(email) + self.where(:person_id => Person.where(:email => email).first.id).last + end + protected @@ -50,10 +51,6 @@ class Post end def set_defaults - user_email = User.first.email - self.owner ||= user_email - self.source ||= user_email - self.snippet ||= user_email self.person ||= User.first end end diff --git a/app/models/status_message.rb b/app/models/status_message.rb index e22bcb621..0e1269ba5 100644 --- a/app/models/status_message.rb +++ b/app/models/status_message.rb @@ -9,18 +9,8 @@ class StatusMessage < Post validates_presence_of :message - - def self.newest(owner_email) - StatusMessage.last(:conditions => {:owner => owner_email}) - end - - def self.my_newest - StatusMessage.newest(User.first.email) - end - - - def ==(other) - (self.message == other.message) && (self.owner == other.owner) + def ==(other) + (self.message == other.message) && (self.person.email == other.person.email) end end diff --git a/app/views/blogs/show.html.haml b/app/views/blogs/show.html.haml index b1e270b42..3b541de2e 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.email %p = link_to "Edit", edit_blog_path(@blog) diff --git a/app/views/bookmarks/_bookmark.html.haml b/app/views/bookmarks/_bookmark.html.haml index ca90be1fe..2a457866a 100644 --- a/app/views/bookmarks/_bookmark.html.haml +++ b/app/views/bookmarks/_bookmark.html.haml @@ -1,6 +1,6 @@ %li.message{:class => ("mine" if mine?(post))} %span.from - = link_to post.owner, "#" + = link_to post.person.email, "#" %b shared a link %br = post.title diff --git a/app/views/bookmarks/show.html.haml b/app/views/bookmarks/show.html.haml index 2072f4cf9..ba142025d 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.email %p = link_to "Edit", edit_bookmark_path(@bookmark) diff --git a/app/views/status_messages/show.html.haml b/app/views/status_messages/show.html.haml index 4be35c793..ee969a983 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.email %p = link_to "Destroy", @status_message, :confirm => 'Are you sure?', :method => :delete diff --git a/lib/common.rb b/lib/common.rb index 8da6ddd31..e0283d333 100644 --- a/lib/common.rb +++ b/lib/common.rb @@ -1,13 +1,13 @@ module Diaspora - module Webhooks + include ApplicationHelper def self.included(klass) klass.class_eval do after_save :notify_friends @@queue = MessageHandler.new def notify_friends - if self.owner == User.first.email + if mine? self xml = Post.build_xml_for(self) @@queue.add_post_request( friends_with_permissions, xml ) @@queue.process diff --git a/spec/controllers/status_messages_controller_spec.rb b/spec/controllers/status_messages_controller_spec.rb index ecea61257..37bd1c128 100644 --- a/spec/controllers/status_messages_controller_spec.rb +++ b/spec/controllers/status_messages_controller_spec.rb @@ -61,7 +61,7 @@ describe StatusMessagesController do get :index StatusMessage.all.each do |message| response.body.include?(message.message).should be true - response.body.include?(message.owner).should be true + response.body.include?(message.person.email).should be true end end end diff --git a/spec/factories.rb b/spec/factories.rb index d995e1e88..93d27498e 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -28,6 +28,4 @@ Factory.define :bookmark do |b| end Factory.define :post do |p| - p.source "New York Times" - p.sequence(:snippet) {|n| "This is some information #{n}"} end diff --git a/spec/helpers/parser_spec.rb b/spec/helpers/parser_spec.rb index d1d991a8f..7130ed5fa 100644 --- a/spec/helpers/parser_spec.rb +++ b/spec/helpers/parser_spec.rb @@ -4,38 +4,61 @@ include ApplicationHelper describe ApplicationHelper do before do - @user = Factory.create(:user, :email => "bob@aol.com") + @user = Factory.create(:user, :email => "bob@aol.com") @friend =Factory.create(:friend, :email => "bill@gates.com") end - it "should store objects sent from xml" do + it "should not store posts from me" do status_messages = [] - 10.times { status_messages << Factory.build(:status_message)} - + 10.times { status_messages << Factory.build(:status_message, :person => @user)} xml = Post.build_xml_for(status_messages) - store_posts_from_xml(xml) - StatusMessage.count.should == 10 + StatusMessage.count.should == 0 end - it 'should discard posts where it does not know the type' do xml = " - #{User.first.email} + #{Friend.first.email} \n Here is another message\n a@a.com\n a@a.com\n a@a.com\n \n HEY DUDE\n a@a.com\n a@a.com\n a@a.com\n " store_posts_from_xml(xml) Post.count.should == 2 + Post.first.person.email.should == Friend.first.email end + it "should reject xml with no sender" do + xml = " + + + \n Here is another message\n a@a.com\n a@a.com\n a@a.com\n + + \n HEY DUDE\n a@a.com\n a@a.com\n a@a.com\n + " + store_posts_from_xml(xml) + Post.count.should == 0 + end + it "should reject xml with a sender not in the database" do + xml = " + + + foo@example.com + + + \n Here is another message\n a@a.com\n a@a.com\n a@a.com\n + + \n HEY DUDE\n a@a.com\n a@a.com\n a@a.com\n + " + store_posts_from_xml(xml) + Post.count.should == 0 + end it 'should discard types which are not of type post' do xml = " - #{User.first.email} + #{Friend.first.email} \n Here is another message\n a@a.com\n a@a.com\n a@a.com\n @@ -44,6 +67,7 @@ describe ApplicationHelper do " store_posts_from_xml(xml) Post.count.should == 2 + Post.first.person.email.should == Friend.first.email end @@ -58,9 +82,6 @@ describe ApplicationHelper do parse_sender_id_from_xml(@xml).should == @user.email end - it 'should be able to retrieve the sender\'s local Person object' do - parse_sender_object_from_xml(@xml).should == @user - end it 'should be able to parse the body\'s contents' do body = parse_body_contents_from_xml(@xml).to_s diff --git a/spec/lib/common_spec.rb b/spec/lib/common_spec.rb index dc99c3aeb..c8c14f7c4 100644 --- a/spec/lib/common_spec.rb +++ b/spec/lib/common_spec.rb @@ -67,7 +67,8 @@ describe Diaspora do it "should check that it does not send a friends post to an owners friends" do Post.stub(:build_xml_for).and_return(true) Post.should_not_receive(:build_xml_for) - Factory.create(:status_message, :owner => "nottheowner@post.com") + + Factory.create(:status_message, :person => Factory.create(:friend)) end it "should ensure one url is created for every friend" do diff --git a/spec/models/blogs_spec.rb b/spec/models/blogs_spec.rb index 32c9557a4..cc4a735dd 100644 --- a/spec/models/blogs_spec.rb +++ b/spec/models/blogs_spec.rb @@ -16,24 +16,30 @@ describe Blog do it "should add an owner if none is present" do b = Factory.create(:blog) - b.owner.should == "bob@aol.com" + b.person.email.should == "bob@aol.com" end describe "newest" do before do - (2..4).each { Factory.create(:blog, :owner => "some@dudes.com") } + @friend_one = Factory.create(:friend, :email => "some@dudes.com") + @friend_two = Factory.create(:friend, :email => "other@dudes.com") + (2..4).each { Factory.create(:blog, :person => @friend_one) } (5..8).each { Factory.create(:blog) } - (9..11).each { Factory.create(:blog, :owner => "other@dudes.com") } + (9..11).each { Factory.create(:blog, :person => @friend_two) } + Factory.create(:status_message) + Factory.create(:bookmark) end it "should give the most recent blog title and body from owner" do - blog = Blog.my_newest + blog = Blog.newest(User.first) + blog.class.should == Blog 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 = Blog.newest_by_email("some@dudes.com") + blog.class.should == Blog blog.title.should == "bobby's 14 penguins" blog.body.should == "jimmy's huge 14 whales" end diff --git a/spec/models/bookmark_spec.rb b/spec/models/bookmark_spec.rb index 4c9ecd9c8..4d253a7a6 100644 --- a/spec/models/bookmark_spec.rb +++ b/spec/models/bookmark_spec.rb @@ -11,7 +11,7 @@ describe Bookmark do it "should add an owner if none is present" do Factory.create(:user, :email => "bob@aol.com") n = Factory.create(:bookmark) - n.owner.should == "bob@aol.com" + n.person.email.should == "bob@aol.com" end it 'should validate its link' do @@ -67,11 +67,10 @@ describe Bookmark do end it 'should marshal serialized XML to object' do - xml = "Reddit</message><link>http://reddit.com/</link><owner>bob@aol.com</owner></bookmark>" + xml = "<bookmark><title>Reddit</message><link>http://reddit.com/</link></bookmark>" parsed = Bookmark.from_xml(xml) parsed.title.should == "Reddit" parsed.link.should == "http://reddit.com/" - parsed.owner.should == "bob@aol.com" parsed.valid?.should be_true end end diff --git a/spec/models/post_spec.rb b/spec/models/post_spec.rb index 61bd5efbc..a7a0919b7 100644 --- a/spec/models/post_spec.rb +++ b/spec/models/post_spec.rb @@ -8,24 +8,13 @@ describe Post do describe 'defaults' do before do WebSocket.stub!(:update_clients) - @post = Factory.create(:post, :person => nil, :owner => nil, :source => nil, :snippet => nil) + @post = Factory.create(:post, :person => nil) end it "should associate the owner if none is present" do @post.person.should == User.first end - 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 it "should list child types in reverse chronological order" do diff --git a/spec/models/status_message_spec.rb b/spec/models/status_message_spec.rb index 7bfa0af00..ba63f2642 100644 --- a/spec/models/status_message_spec.rb +++ b/spec/models/status_message_spec.rb @@ -14,21 +14,24 @@ describe StatusMessage do it "should add an owner if none is present" do n = Factory.create(:status_message) - n.owner.should == "bob@aol.com" + n.person.email.should == "bob@aol.com" end describe "newest" do before do - (1..5).each { Factory.create(:status_message, :owner => "some@dudes.com") } - (6..10).each { Factory.create(:status_message) } + @person_one = Factory.create(:friend,:email => "some@dudes.com") + (1..10).each { Factory.create(:status_message, :person => @person_one) } + (1..5).each { Factory.create(:status_message) } + Factory.create(:bookmark) + Factory.create(:bookmark, :person => @person_one) end - it "should give the most recent message from owner" do - StatusMessage.my_newest.message.should == "jimmy's 11 whales" + it "should give the most recent message from a friend" do + StatusMessage.newest(@person_one).message.should == "jimmy's 13 whales" end it "should give the most recent message for a given email" do - StatusMessage.newest("some@dudes.com").message.should == "jimmy's 16 whales" + StatusMessage.newest_by_email(@person_one.email).message.should == "jimmy's 28 whales" end end @@ -39,10 +42,9 @@ describe StatusMessage do end it 'should marshal serialized XML to object' do - xml = "<statusmessage><message>I hate WALRUSES!</message><owner>Bob@rob.ert</owner></statusmessage>" + xml = "<statusmessage><message>I hate WALRUSES!</message></statusmessage>" parsed = StatusMessage.from_xml(xml) parsed.message.should == "I hate WALRUSES!" - parsed.owner.should == "Bob@rob.ert" parsed.valid?.should be_true end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 2ebfc5477..b4499cd5a 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -32,6 +32,7 @@ Rspec.configure do |config| config.after(:each) do DatabaseCleaner.clean + #Factory.sequences.each{ |s| s.reset} end From b4cc4e797f3cd310ffeff9de0bff4f838eea7721 Mon Sep 17 00:00:00 2001 From: ilya <ilya@laptop.(none)> Date: Wed, 23 Jun 2010 20:29:57 -0400 Subject: [PATCH 02/11] RS IZ my newest fix --- app/models/post.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/models/post.rb b/app/models/post.rb index 8b3ff61f2..1e61c60ef 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -38,6 +38,9 @@ class Post self.where(:person_id => person.id).last end + def self.my_newest + self.newest(User.first) + end def self.newest_by_email(email) self.where(:person_id => Person.where(:email => email).first.id).last end From f0db58f9121c4a01cc2df6f20cd83de523ef5115 Mon Sep 17 00:00:00 2001 From: Raphael <raphael@joindiaspora.com> Date: Thu, 24 Jun 2010 17:10:45 -0700 Subject: [PATCH 04/11] Moved authentication to applicationcontroller for now, refactored posting statusmessages --- app/controllers/application_controller.rb | 7 +++++++ app/controllers/blogs_controller.rb | 1 - app/controllers/bookmarks_controller.rb | 1 - app/controllers/friends_controller.rb | 1 - app/controllers/status_messages_controller.rb | 5 ++--- app/controllers/users_controller.rb | 1 - app/models/post.rb | 4 ---- app/models/user.rb | 9 ++++++++- spec/models/status_message_spec.rb | 2 ++ spec/models/user_spec.rb | 15 +++++++++++++-- spec/spec_helper.rb | 4 ++-- 11 files changed, 34 insertions(+), 16 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 83445dbde..f5fcad855 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,4 +1,11 @@ class ApplicationController < ActionController::Base + before_filter :authenticate_user! + before_filter :set_user + def set_user + @user = current_user + true + end + protect_from_forgery :except => :receive layout 'application' diff --git a/app/controllers/blogs_controller.rb b/app/controllers/blogs_controller.rb index f39cecdbf..2509d9e72 100644 --- a/app/controllers/blogs_controller.rb +++ b/app/controllers/blogs_controller.rb @@ -1,5 +1,4 @@ class BlogsController < ApplicationController - before_filter :authenticate_user! def index diff --git a/app/controllers/bookmarks_controller.rb b/app/controllers/bookmarks_controller.rb index 6defe2f07..9ed215880 100644 --- a/app/controllers/bookmarks_controller.rb +++ b/app/controllers/bookmarks_controller.rb @@ -1,5 +1,4 @@ class BookmarksController < ApplicationController - before_filter :authenticate_user! def index @bookmarks = Bookmark.criteria.all.order_by( [:created_at, :desc] ) diff --git a/app/controllers/friends_controller.rb b/app/controllers/friends_controller.rb index 55778861f..31be0a1f4 100644 --- a/app/controllers/friends_controller.rb +++ b/app/controllers/friends_controller.rb @@ -1,5 +1,4 @@ class FriendsController < ApplicationController - before_filter :authenticate_user! def index @friends = Friend.criteria.all.order_by( [:created_at, :desc] ) diff --git a/app/controllers/status_messages_controller.rb b/app/controllers/status_messages_controller.rb index c0507fcda..bf53ac7c5 100644 --- a/app/controllers/status_messages_controller.rb +++ b/app/controllers/status_messages_controller.rb @@ -1,5 +1,4 @@ class StatusMessagesController < ApplicationController - before_filter :authenticate_user! def index @status_message = StatusMessage.new @@ -15,11 +14,11 @@ class StatusMessagesController < ApplicationController end def create - @status_message = StatusMessage.new(params[:status_message]) - if @status_message.save + if current_user.post :status_message, params[:status_message] flash[:notice] = "Successfully created status message." redirect_to status_messages_url else + flash[:notics] = "You have failed to update your status." render :action => 'new' end end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index da904fab0..10d0ffa4a 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,6 +1,5 @@ class UsersController < ApplicationController - before_filter :authenticate_user! def index @users = User.criteria.all.order_by( [:created_at, :desc] ) diff --git a/app/models/post.rb b/app/models/post.rb index 1e61c60ef..021b8a7cd 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -13,7 +13,6 @@ class Post belongs_to_related :person - before_create :set_defaults after_save :send_to_view @@ -53,8 +52,5 @@ class Post WebSocket.update_clients(self) end - def set_defaults - self.person ||= User.first - end end diff --git a/app/models/user.rb b/app/models/user.rb index a1ac4217f..c4d28c0ba 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -4,5 +4,12 @@ class User < Person # :token_authenticatable, :confirmable, :lockable and :timeoutable devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable - + def post(post_type, options) + case post_type + when :status_message + StatusMessage.new(:person => self, :message => options[:message]).save + else + raise "Not a type I can post yet" + end + end end diff --git a/spec/models/status_message_spec.rb b/spec/models/status_message_spec.rb index ba63f2642..1e47c1bde 100644 --- a/spec/models/status_message_spec.rb +++ b/spec/models/status_message_spec.rb @@ -8,6 +8,8 @@ describe StatusMessage do it "should have a message" do n = Factory.build(:status_message, :message => nil) n.valid?.should be false + n.message = "" + n.valid?.should be false n.message = "wales" n.valid?.should be true end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index b52406211..bf5c7e15c 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require File.dirname(__FILE__) + '/../spec_helper' describe User do it "should require a real name" do @@ -16,5 +16,16 @@ describe User do Factory.create(:user) Person.count.should == n+1 end - + describe 'when posting' do + before do + @user = Factory.create :user + end + it "should be able to set a status message" do + @user.post :status_message, :text => "I feel good" + StatusMessage.where(:person_id => @user.id).last.message.should == "I feel good" + end + it "should return nil from an invalid post" do + @user.post(:status_message, :text => "").should be_false + end + end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index b4499cd5a..fbaa9182c 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,7 +1,7 @@ # This file is copied to ~/spec when you run 'ruby script/generate rspec' # from the project root directory. ENV["RAILS_ENV"] ||= 'test' -require File.dirname(__FILE__) + "/../config/environment" unless defined?(Rails) +require File.dirname(__FILE__) + "/../config/environment" #unless defined?(Rails) require 'rspec/rails' require 'database_cleaner' #require File.dirname(__FILE__) + "/factories" @@ -21,7 +21,7 @@ Rspec.configure do |config| DatabaseCleaner.orm = "mongoid" config.before(:suite) do - DatabaseCleaner.strategy = :transaction + # DatabaseCleaner.strategy = :transaction DatabaseCleaner.clean_with(:truncation) end From c39b69ed8cc9cd3499c9f1e6e1db1c75b98999e9 Mon Sep 17 00:00:00 2001 From: Raphael <raphael@joindiaspora.com> Date: Thu, 24 Jun 2010 17:26:33 -0700 Subject: [PATCH 05/11] Rolled back some changes to spec_helper --- spec/spec_helper.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index fbaa9182c..117daaf74 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,7 +1,7 @@ # This file is copied to ~/spec when you run 'ruby script/generate rspec' # from the project root directory. ENV["RAILS_ENV"] ||= 'test' -require File.dirname(__FILE__) + "/../config/environment" #unless defined?(Rails) +require File.dirname(__FILE__) + "/../config/environment" unless defined?(Rails) require 'rspec/rails' require 'database_cleaner' #require File.dirname(__FILE__) + "/factories" @@ -21,7 +21,7 @@ Rspec.configure do |config| DatabaseCleaner.orm = "mongoid" config.before(:suite) do - # DatabaseCleaner.strategy = :transaction + DatabaseCleaner.strategy = :transaction DatabaseCleaner.clean_with(:truncation) end @@ -39,5 +39,5 @@ Rspec.configure do |config| # If you're not using ActiveRecord, or you'd prefer not to run each of your # examples within a transaction, comment the following line or assign false # instead of true. -# config.use_transactional_fixtures = true + config.use_transactional_fixtures = true end From e44c6d9edad5edadfadbce1807b34d53baf4ff7b Mon Sep 17 00:00:00 2001 From: ilya <ilya@laptop.(none)> Date: Thu, 24 Jun 2010 20:33:40 -0400 Subject: [PATCH 06/11] RS IZ fixed the specs running --- spec/spec_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index b4499cd5a..62a4b907e 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -21,7 +21,7 @@ Rspec.configure do |config| DatabaseCleaner.orm = "mongoid" config.before(:suite) do - DatabaseCleaner.strategy = :transaction + #DatabaseCleaner.strategy = :transaction DatabaseCleaner.clean_with(:truncation) end From db8970eb48a65b906b933042713254963652c450 Mon Sep 17 00:00:00 2001 From: ilya <ilya@laptop.(none)> Date: Thu, 24 Jun 2010 20:44:32 -0400 Subject: [PATCH 07/11] RS, IZ, reversing Rafi's stupidity --- spec/spec_helper.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index e23502036..2446f406b 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,7 +1,7 @@ # This file is copied to ~/spec when you run 'ruby script/generate rspec' # from the project root directory. ENV["RAILS_ENV"] ||= 'test' -require File.dirname(__FILE__) + "/../config/environment" unless defined?(Rails) +require File.dirname(__FILE__) + "/../config/environment" #unless defined?(Rails) require 'rspec/rails' require 'database_cleaner' #require File.dirname(__FILE__) + "/factories" @@ -21,7 +21,6 @@ Rspec.configure do |config| DatabaseCleaner.orm = "mongoid" config.before(:suite) do - #DatabaseCleaner.strategy = :transaction DatabaseCleaner.clean_with(:truncation) end @@ -39,5 +38,5 @@ Rspec.configure do |config| # If you're not using ActiveRecord, or you'd prefer not to run each of your # examples within a transaction, comment the following line or assign false # instead of true. - config.use_transactional_fixtures = true +# config.use_transactional_fixtures = true end From 4323bc5fe7f05dfa8829a3edf4a5c7d3ab8de2ac Mon Sep 17 00:00:00 2001 From: ilya <ilya@laptop.(none)> Date: Thu, 24 Jun 2010 20:47:03 -0400 Subject: [PATCH 08/11] RS, IZ, specs working again for real --- app/controllers/application_controller.rb | 7 ------- app/controllers/blogs_controller.rb | 1 + app/controllers/bookmarks_controller.rb | 1 + app/controllers/friends_controller.rb | 1 + app/controllers/status_messages_controller.rb | 5 +++-- app/controllers/users_controller.rb | 1 + app/models/post.rb | 4 ++++ app/models/user.rb | 9 +-------- spec/models/status_message_spec.rb | 2 -- spec/models/user_spec.rb | 15 ++------------- spec/spec_helper.rb | 2 +- 11 files changed, 15 insertions(+), 33 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index f5fcad855..83445dbde 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,11 +1,4 @@ class ApplicationController < ActionController::Base - before_filter :authenticate_user! - before_filter :set_user - def set_user - @user = current_user - true - end - protect_from_forgery :except => :receive layout 'application' diff --git a/app/controllers/blogs_controller.rb b/app/controllers/blogs_controller.rb index 2509d9e72..f39cecdbf 100644 --- a/app/controllers/blogs_controller.rb +++ b/app/controllers/blogs_controller.rb @@ -1,4 +1,5 @@ class BlogsController < ApplicationController + before_filter :authenticate_user! def index diff --git a/app/controllers/bookmarks_controller.rb b/app/controllers/bookmarks_controller.rb index 9ed215880..6defe2f07 100644 --- a/app/controllers/bookmarks_controller.rb +++ b/app/controllers/bookmarks_controller.rb @@ -1,4 +1,5 @@ class BookmarksController < ApplicationController + before_filter :authenticate_user! def index @bookmarks = Bookmark.criteria.all.order_by( [:created_at, :desc] ) diff --git a/app/controllers/friends_controller.rb b/app/controllers/friends_controller.rb index 31be0a1f4..55778861f 100644 --- a/app/controllers/friends_controller.rb +++ b/app/controllers/friends_controller.rb @@ -1,4 +1,5 @@ class FriendsController < ApplicationController + before_filter :authenticate_user! def index @friends = Friend.criteria.all.order_by( [:created_at, :desc] ) diff --git a/app/controllers/status_messages_controller.rb b/app/controllers/status_messages_controller.rb index bf53ac7c5..c0507fcda 100644 --- a/app/controllers/status_messages_controller.rb +++ b/app/controllers/status_messages_controller.rb @@ -1,4 +1,5 @@ class StatusMessagesController < ApplicationController + before_filter :authenticate_user! def index @status_message = StatusMessage.new @@ -14,11 +15,11 @@ class StatusMessagesController < ApplicationController end def create - if current_user.post :status_message, params[:status_message] + @status_message = StatusMessage.new(params[:status_message]) + if @status_message.save flash[:notice] = "Successfully created status message." redirect_to status_messages_url else - flash[:notics] = "You have failed to update your status." render :action => 'new' end end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 10d0ffa4a..da904fab0 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,5 +1,6 @@ class UsersController < ApplicationController + before_filter :authenticate_user! def index @users = User.criteria.all.order_by( [:created_at, :desc] ) diff --git a/app/models/post.rb b/app/models/post.rb index 021b8a7cd..1e61c60ef 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -13,6 +13,7 @@ class Post belongs_to_related :person + before_create :set_defaults after_save :send_to_view @@ -52,5 +53,8 @@ class Post WebSocket.update_clients(self) end + def set_defaults + self.person ||= User.first + end end diff --git a/app/models/user.rb b/app/models/user.rb index c4d28c0ba..a1ac4217f 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -4,12 +4,5 @@ class User < Person # :token_authenticatable, :confirmable, :lockable and :timeoutable devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable - def post(post_type, options) - case post_type - when :status_message - StatusMessage.new(:person => self, :message => options[:message]).save - else - raise "Not a type I can post yet" - end - end + end diff --git a/spec/models/status_message_spec.rb b/spec/models/status_message_spec.rb index 1e47c1bde..ba63f2642 100644 --- a/spec/models/status_message_spec.rb +++ b/spec/models/status_message_spec.rb @@ -8,8 +8,6 @@ describe StatusMessage do it "should have a message" do n = Factory.build(:status_message, :message => nil) n.valid?.should be false - n.message = "" - n.valid?.should be false n.message = "wales" n.valid?.should be true end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index bf5c7e15c..b52406211 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -1,4 +1,4 @@ -require File.dirname(__FILE__) + '/../spec_helper' +require 'spec_helper' describe User do it "should require a real name" do @@ -16,16 +16,5 @@ describe User do Factory.create(:user) Person.count.should == n+1 end - describe 'when posting' do - before do - @user = Factory.create :user - end - it "should be able to set a status message" do - @user.post :status_message, :text => "I feel good" - StatusMessage.where(:person_id => @user.id).last.message.should == "I feel good" - end - it "should return nil from an invalid post" do - @user.post(:status_message, :text => "").should be_false - end - end + end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 2446f406b..b837bc5fe 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,7 +1,7 @@ # This file is copied to ~/spec when you run 'ruby script/generate rspec' # from the project root directory. ENV["RAILS_ENV"] ||= 'test' -require File.dirname(__FILE__) + "/../config/environment" #unless defined?(Rails) +require File.dirname(__FILE__) + "/../config/environment" unless defined?(Rails) require 'rspec/rails' require 'database_cleaner' #require File.dirname(__FILE__) + "/factories" From ade43e74f89d2c6717555eda44b87d1d01784d56 Mon Sep 17 00:00:00 2001 From: ilya <ilya@laptop.(none)> Date: Thu, 24 Jun 2010 22:23:12 -0400 Subject: [PATCH 09/11] science eliminated... --- science | 5 ----- 1 file changed, 5 deletions(-) delete mode 100755 science diff --git a/science b/science deleted file mode 100755 index 87ce701e0..000000000 --- a/science +++ /dev/null @@ -1,5 +0,0 @@ -#!/usr/bin/env ruby -`sprinkle -s config/sprinkle/provision.rb -v` -`cap deploy:setup` -`cap deploy:cold` -puts 'bababababa bababababa' From db08ef9a1abf4916b795091fa837c4b8c87f6814 Mon Sep 17 00:00:00 2001 From: Raphael <raphael@joindiaspora.com> Date: Thu, 24 Jun 2010 19:44:55 -0700 Subject: [PATCH 10/11] Revert "science eliminated..." This reverts commit 644d2943c0632365a7ecf9c4c7f95f763b3e1b03. --- science | 5 +++++ 1 file changed, 5 insertions(+) create mode 100755 science diff --git a/science b/science new file mode 100755 index 000000000..87ce701e0 --- /dev/null +++ b/science @@ -0,0 +1,5 @@ +#!/usr/bin/env ruby +`sprinkle -s config/sprinkle/provision.rb -v` +`cap deploy:setup` +`cap deploy:cold` +puts 'bababababa bababababa' From 305cfb5eb0beb7eb665dc5f253943fa269073819 Mon Sep 17 00:00:00 2001 From: Raphael <raphael@joindiaspora.com> Date: Thu, 24 Jun 2010 19:45:25 -0700 Subject: [PATCH 11/11] removing science for real --- science | 5 ----- 1 file changed, 5 deletions(-) delete mode 100755 science diff --git a/science b/science deleted file mode 100755 index 87ce701e0..000000000 --- a/science +++ /dev/null @@ -1,5 +0,0 @@ -#!/usr/bin/env ruby -`sprinkle -s config/sprinkle/provision.rb -v` -`cap deploy:setup` -`cap deploy:cold` -puts 'bababababa bababababa'