Skip to content
Extraits de code Groupes Projets
Valider 48adc9eb rédigé par maxwell's avatar maxwell
Parcourir les fichiers

DG MS; person object now properly stored with request object save

parent d21a3baf
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -15,11 +15,11 @@ class ApplicationController < ActionController::Base ...@@ -15,11 +15,11 @@ class ApplicationController < ActionController::Base
end end
def set_friends def set_friends
@friends = Person.friends.all @friends = Person.friends.all if current_user
end end
def count_requests def count_requests
@request_count = Request.for_user(current_user).size @request_count = Request.for_user(current_user).size if current_user
end end
end end
...@@ -7,10 +7,15 @@ class RequestsController < ApplicationController ...@@ -7,10 +7,15 @@ class RequestsController < ApplicationController
end end
def destroy def destroy
@request = Request.where(:id => params[:id]).first if params[:accept]
@request.destroy current_user.accept_friend_request params[:id]
flash[:notice] = "Successfully destroyed person request." flash[:notice] = "you are now friends with #{@request.person.real_name}"
else
current_user.ignore_friend_request params[:id]
flash[:notice] = "ignored friend request"
end
redirect_to requests_url redirect_to requests_url
end end
def new def new
...@@ -27,4 +32,6 @@ class RequestsController < ApplicationController ...@@ -27,4 +32,6 @@ class RequestsController < ApplicationController
render :action => 'new' render :action => 'new'
end end
end end
end end
...@@ -5,7 +5,8 @@ class Person ...@@ -5,7 +5,8 @@ class Person
xml_accessor :email xml_accessor :email
xml_accessor :url xml_accessor :url
xml_accessor :profile, :as => Profile xml_accessor :profile, :as => Profile
xml_accessor :_id
key :email, String key :email, String
key :url, String key :url, String
key :active, Boolean, :default => false key :active, Boolean, :default => false
......
...@@ -4,7 +4,7 @@ class User < Person ...@@ -4,7 +4,7 @@ class User < Person
:recoverable, :rememberable, :trackable, :validatable :recoverable, :rememberable, :trackable, :validatable
before_create :assign_key #before_create :assign_key
validates_presence_of :profile validates_presence_of :profile
before_validation :do_bad_things before_validation :do_bad_things
...@@ -53,7 +53,6 @@ class User < Person ...@@ -53,7 +53,6 @@ class User < Person
friend_request.activate_friend friend_request.activate_friend
friend_request.destroy friend_request.destroy
else else
#does this actually save as the same id?
friend_request.save friend_request.save
end end
end end
......
...@@ -4,4 +4,6 @@ ...@@ -4,4 +4,6 @@
= "#{request.destination_url}" = "#{request.destination_url}"
.destroy_link .destroy_link
= link_to 'Accept', request_path(request, :accept => true), :confirm => 'Are you sure?', :method => :delete
|
= link_to 'Ignore', request_path(request), :confirm => 'Are you sure?', :method => :delete = link_to 'Ignore', request_path(request), :confirm => 'Are you sure?', :method => :delete
...@@ -4,6 +4,6 @@ ...@@ -4,6 +4,6 @@
%h3= "currently #{@request_count} requests" %h3= "currently #{@request_count} requests"
%ul#stream %ul#stream
- for request in @remote_requests - for request in @remote_requests
= render "request", :request => request = render "request", :request => request
...@@ -5,18 +5,14 @@ describe DashboardsController do ...@@ -5,18 +5,14 @@ describe DashboardsController do
before do before do
request.env['warden'] = mock_model(Warden, :authenticate? => @user, :authenticate! => @user) request.env['warden'] = mock_model(Warden, :authenticate? => @user, :authenticate! => @user)
Factory.create(:user, :profile => Profile.create( :first_name => "bob", :last_name => "smith")) @user = Factory.create(:user, :profile => Profile.create( :first_name => "bob", :last_name => "smith"))
end end
it "index action should render index template" do it "on index sets a variable containing all a user's friends when a user is signed in" do
get :index sign_in :user, @user
response.should render_template(:index)
end
it "on index sets a person's variable" do
Factory.create :person Factory.create :person
get :index get :index
assigns[:people].should == Person.friends.all assigns[:friends].should == Person.friends.all
end end
end end
...@@ -112,14 +112,18 @@ describe "parser in application helper" do ...@@ -112,14 +112,18 @@ describe "parser in application helper" do
it "should create a new person upon getting a person request" do it "should create a new person upon getting a person request" do
request = Request.instantiate(:to =>"http://www.google.com/", :from => @person) request = Request.instantiate(:to =>"http://www.google.com/", :from => @person)
original_person_id = @person.id
xml = Request.build_xml_for [request] xml = Request.build_xml_for [request]
@person.destroy @person.destroy
Person.friends.all.count.should be 0 Person.friends.all.count.should be 0
store_objects_from_xml(xml) store_objects_from_xml(xml)
Person.friends.all.count.should be 1 Person.friends.all.count.should be 1
Person.friends.first.id.should == original_person_id
end end
it "should activate the Person if I initiated a request to that url" do it "should activate the Person if I initiated a request to that url" do
request = Request.instantiate(:to => @person.url, :from => @user).save request = Request.instantiate(:to => @person.url, :from => @user).save
......
...@@ -22,10 +22,6 @@ describe Request do ...@@ -22,10 +22,6 @@ describe Request do
xml = request.to_xml.to_s xml = request.to_xml.to_s
puts xml
puts user.profile.first_name
puts user.profile.last_name
xml.include?(user.email).should be true xml.include?(user.email).should be true
xml.include?(user.url).should be true xml.include?(user.url).should be true
xml.include?(user.profile.first_name).should be true xml.include?(user.profile.first_name).should be true
......
...@@ -10,16 +10,19 @@ describe User do ...@@ -10,16 +10,19 @@ describe User do
it "should be able to accept a pending friend request" do it "should be able to accept a pending friend request" do
@user = Factory.create(:user) @user = Factory.create(:user)
@friend = Factory.create(:person) @friend = Factory.create(:person)
r = Request.instantiate(:to => @user.url, :from => @friend) r = Request.instantiate(:to => @user.url, :from => @friend)
r.save r.save
Person.all.count.should == 2 Person.all.count.should == 2
Request.for_user(@user).all.count.should == 1 Request.for_user(@user).all.count.should == 1
@user.accept_friend_request(r.id) @user.accept_friend_request(r.id)
Request.for_user(@user).all.count.should == 0 Request.for_user(@user).all.count.should == 0
Person.where(:id => @friend.id).first.active.should == true Person.where(:id => @friend.id).first.active.should == true
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