DG IZ; user's own post gets referenced in group model
This commit is contained in:
parent
2409fd3f20
commit
b0088c73d8
5 changed files with 24 additions and 5 deletions
|
|
@ -19,7 +19,6 @@ class ApplicationController < ActionController::Base
|
|||
if current_user
|
||||
@groups = current_user.groups
|
||||
@friends = current_user.friends
|
||||
@latest_status_message = StatusMessage.newest_for(current_user.person)
|
||||
@group = params[:group] ? current_user.group_by_id(params[:group]) : current_user.groups.first
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -3,12 +3,9 @@ class StatusMessagesController < ApplicationController
|
|||
|
||||
def index
|
||||
@status_messages = StatusMessage.paginate :page => params[:page], :order => 'created_at DESC'
|
||||
|
||||
|
||||
respond_to do |format|
|
||||
format.html
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def create
|
||||
|
|
|
|||
|
|
@ -5,9 +5,11 @@ class Group
|
|||
|
||||
key :person_ids, Array
|
||||
key :request_ids, Array
|
||||
key :my_post_ids, Array
|
||||
|
||||
many :people, :in => :person_ids, :class_name => 'Person'
|
||||
many :requests, :in => :request_ids, :class_name => 'Request'
|
||||
many :my_posts, :in => :my_post_ids, :class_name => 'Post'
|
||||
|
||||
belongs_to :user, :class_name => 'User'
|
||||
|
||||
|
|
|
|||
|
|
@ -41,6 +41,10 @@ class User
|
|||
######## Posting ########
|
||||
def post(class_name, options = {})
|
||||
options[:person] = self.person
|
||||
|
||||
group = options[:group]
|
||||
options.delete(:group)
|
||||
|
||||
model_class = class_name.to_s.camelize.constantize
|
||||
post = model_class.instantiate(options)
|
||||
post.creator_signature = post.sign_with_key(encryption_key)
|
||||
|
|
@ -51,6 +55,11 @@ class User
|
|||
|
||||
self.raw_visible_posts << post
|
||||
self.save
|
||||
|
||||
if group
|
||||
group.my_posts << post
|
||||
group.save
|
||||
end
|
||||
|
||||
post
|
||||
end
|
||||
|
|
|
|||
|
|
@ -33,7 +33,6 @@ describe Group do
|
|||
group.people.include?(@friend_2).should be true
|
||||
group.people.size.should == 2
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe 'querying' do
|
||||
|
|
@ -52,4 +51,17 @@ describe Group do
|
|||
@group.people.size.should == 1
|
||||
end
|
||||
end
|
||||
|
||||
describe 'posting' do
|
||||
|
||||
it 'should add post to group via post method' do
|
||||
@group = @user.group(:name => 'losers', :people => [@friend])
|
||||
|
||||
status_message = @user.post( :status_message, :message => "hey", :group => @group )
|
||||
|
||||
@group.reload
|
||||
@group.my_posts.include?(status_message).should be true
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue