Skip to content
Extraits de code Groupes Projets
Valider 9fe37b1d rédigé par Raphael's avatar Raphael
Parcourir les fichiers

RS, IZ; Cleaned up user spec, started to add current_user.post

parent 8432db34
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -26,6 +26,11 @@ class Post ...@@ -26,6 +26,11 @@ class Post
before_destroy :propagate_retraction before_destroy :propagate_retraction
after_destroy :destroy_comments, :remove_from_view after_destroy :destroy_comments, :remove_from_view
def self.instantiate params
self.create params
end
#Querying
def self.stream def self.stream
Post.sort(:created_at.desc).all Post.sort(:created_at.desc).all
end end
......
...@@ -13,6 +13,13 @@ class User < Person ...@@ -13,6 +13,13 @@ class User < Person
######## Posting ########
def post(class_name, options = {})
options[:person] = self
model_class = class_name.to_s.camelize.constantize
post = model_class.instantiate(options)
end
######## Commenting ######## ######## Commenting ########
def comment(text, options = {}) def comment(text, options = {})
......
...@@ -11,7 +11,11 @@ describe StatusMessage do ...@@ -11,7 +11,11 @@ describe StatusMessage do
n.message = "wales" n.message = "wales"
n.valid?.should be true n.valid?.should be true
end end
it 'should be postable through the user' do
status = @user.post(:status_message, :message => "Users do things")
end
describe "XML" do describe "XML" do
it 'should serialize to XML' do it 'should serialize to XML' do
message = Factory.create(:status_message, :message => "I hate WALRUSES!") message = Factory.create(:status_message, :message => "I hate WALRUSES!")
......
...@@ -7,75 +7,69 @@ describe User do ...@@ -7,75 +7,69 @@ describe User do
Person.count.should == n+1 Person.count.should == n+1
end end
it "should be able to accept a pending friend request" do describe 'friend requesting' do
@user = Factory.create(:user) before do
@friend = Factory.create(:person, :active => false) @user = Factory.create(:user)
r = Request.instantiate(:to => @user.url, :from => @friend)
r.save
Person.all.count.should == 2
Request.for_user(@user).all.count.should == 1
@user.accept_friend_request(r.id)
Request.for_user(@user).all.count.should == 0
Person.where(:id => @friend.id).first.active.should == true
end
it 'should be able to ignore a pending friend request' do end
@user = Factory.create(:user)
@friend = Factory.create(:person, :active => false)
r = Request.instantiate(:to => @user.url, :from => @friend)
r.save
Person.count.should == 2 it "should be able to accept a pending friend request" do
@friend.active.should == false friend = Factory.create(:person, :active => false)
r = Request.instantiate(:to => @user.url, :from => friend)
r.save
Person.all.count.should == 2
Request.for_user(@user).all.count.should == 1
@user.accept_friend_request(r.id)
Request.for_user(@user).all.count.should == 0
Person.where(:id => friend.id).first.active.should == true
end
@user.ignore_friend_request(r.id) it 'should be able to ignore a pending friend request' do
friend = Factory.create(:person, :active => false)
r = Request.instantiate(:to => @user.url, :from => friend)
r.save
Person.count.should == 1 Person.count.should == 2
Request.count.should == 0 friend.active.should == false
end
it 'should not be able to friend request an existing friend' do @user.ignore_friend_request(r.id)
@user = Factory.create(:user)
@friend = Factory.create(:person)
@user.send_friend_request_to( @friend.url ).should be nil Person.count.should == 1
end Request.count.should == 0
end
it 'should be able to give me the terse url for webfinger' do it 'should not be able to friend request an existing friend' do
user = Factory.create(:user) friend = Factory.create(:person)
user.terse_url.should == 'example.com'
end
it 'should be able to unsubscribe from a status.net user' do @user.send_friend_request_to( friend.url ).should be nil
@user = Factory.create(:user) end
author = Factory.create(:author)
Author.all.count.should == 1
q = Request.send :class_variable_get, :@@queue
q.stub!(:add_hub_unsubscribe_request)
q.should_receive(:add_hub_unsubscribe_request)
@user.unsubscribe_from_pubsub(author.id) it 'should be able to give me the terse url for webfinger' do
Author.all.count.should == 0 @user.terse_url.should == 'example.com'
end end
it 'should be able to update their profile and send it to their friends' do it 'should be able to unsubscribe from a status.net user' do
Factory.create(:person) author = Factory.create(:author)
p = {:profile => {:first_name => 'bob', :last_name => 'billytown', :image_url => "http://clowntown.com"}} Author.all.count.should == 1
q = Request.send :class_variable_get, :@@queue
@user = Factory.create(:user) q.stub!(:add_hub_unsubscribe_request)
p = {:profile => {:first_name => 'bob', :last_name => 'billytown', :image_url => "http://clown.com"}} q.should_receive(:add_hub_unsubscribe_request)
n = Profile.send :class_variable_get, :@@queue
n.should_receive(:process)
@user.update_profile(p).should == true
@user.profile.image_url.should == "http://clown.com"
@user.unsubscribe_from_pubsub(author.id)
Author.all.count.should == 0
end
it 'should be able to update their profile and send it to their friends' do
Factory.create(:person)
updated_profile = {:profile => {:first_name => 'bob', :last_name => 'billytown', :image_url => "http://clown.com"}}
queue = Profile.send :class_variable_get, :@@queue
queue.should_receive(:process)
@user.update_profile(updated_profile).should == true
@user.profile.image_url.should == "http://clown.com"
end
end end
end end
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter