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"