diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index df354b726486ecd32dff1d35862a709c9ed9e64a..26b76f21b001b6ad9fb59b255d9f406397f2ed60 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -15,11 +15,11 @@ class ApplicationController < ActionController::Base end def set_friends - @friends = Person.friends.all + @friends = Person.friends.all if current_user end def count_requests - @request_count = Request.for_user(current_user).size + @request_count = Request.for_user(current_user).size if current_user end end diff --git a/app/controllers/requests_controller.rb b/app/controllers/requests_controller.rb index 0f8f5c88b68e2a2af6b1f065f0c22f75eecc8676..4bafd6d54f140b64212a6289f0864e8d81a5c389 100644 --- a/app/controllers/requests_controller.rb +++ b/app/controllers/requests_controller.rb @@ -7,10 +7,15 @@ class RequestsController < ApplicationController end def destroy - @request = Request.where(:id => params[:id]).first - @request.destroy - flash[:notice] = "Successfully destroyed person request." + if params[:accept] + current_user.accept_friend_request params[:id] + 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 + end def new @@ -27,4 +32,6 @@ class RequestsController < ApplicationController render :action => 'new' end end + + end diff --git a/app/models/person.rb b/app/models/person.rb index 624f9f85a290fa579b522bfc9178f28e87c5b1b1..082bf80a2fe94ac87525539f11b9ee8eaea82593 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -5,7 +5,8 @@ class Person xml_accessor :email xml_accessor :url xml_accessor :profile, :as => Profile - + xml_accessor :_id + key :email, String key :url, String key :active, Boolean, :default => false diff --git a/app/models/user.rb b/app/models/user.rb index 43f48b70d8379b5899273fb64389d4b67c560d79..7e29f84c0b6589c515c0e0104e0211454f6f45d9 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -4,7 +4,7 @@ class User < Person :recoverable, :rememberable, :trackable, :validatable - before_create :assign_key + #before_create :assign_key validates_presence_of :profile before_validation :do_bad_things @@ -53,7 +53,6 @@ class User < Person friend_request.activate_friend friend_request.destroy else - #does this actually save as the same id? friend_request.save end end diff --git a/app/views/requests/_request.html.haml b/app/views/requests/_request.html.haml index 76b6e4ac45b7153bc03089651a1770828d2ca52a..84284151af5c92bcda891961d2c9c2dcff344c39 100644 --- a/app/views/requests/_request.html.haml +++ b/app/views/requests/_request.html.haml @@ -4,4 +4,6 @@ = "#{request.destination_url}" .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 diff --git a/app/views/requests/index.html.haml b/app/views/requests/index.html.haml index 6a7b8df9485acc7f939056c77f5195180ea1438d..f5f82f5cc01a6fd7bcc0da82fad24017c435abac 100644 --- a/app/views/requests/index.html.haml +++ b/app/views/requests/index.html.haml @@ -4,6 +4,6 @@ %h3= "currently #{@request_count} requests" %ul#stream -- for request in @remote_requests - = render "request", :request => request + - for request in @remote_requests + = render "request", :request => request diff --git a/spec/controllers/dashboards_controller_spec.rb b/spec/controllers/dashboards_controller_spec.rb index 34186d8df66cf31c4a1a9b2c1dd05c0c2a25fe5f..6b48d9a638d81a6aeba20c5b89d93ac1e9cc55a2 100644 --- a/spec/controllers/dashboards_controller_spec.rb +++ b/spec/controllers/dashboards_controller_spec.rb @@ -5,18 +5,14 @@ describe DashboardsController do before do 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 - - it "index action should render index template" do - get :index - response.should render_template(:index) - end - - it "on index sets a person's variable" do + + it "on index sets a variable containing all a user's friends when a user is signed in" do + sign_in :user, @user Factory.create :person get :index - assigns[:people].should == Person.friends.all + assigns[:friends].should == Person.friends.all end end diff --git a/spec/lib/parser_spec.rb b/spec/lib/parser_spec.rb index f3eafdb2a10c53d24c405c4d357a5cf54b9584e3..f73945c506d95cc03b332e7dd5dc5480668e2aec 100644 --- a/spec/lib/parser_spec.rb +++ b/spec/lib/parser_spec.rb @@ -112,14 +112,18 @@ describe "parser in application helper" do it "should create a new person upon getting a person request" do request = Request.instantiate(:to =>"http://www.google.com/", :from => @person) - + + original_person_id = @person.id xml = Request.build_xml_for [request] @person.destroy Person.friends.all.count.should be 0 store_objects_from_xml(xml) Person.friends.all.count.should be 1 + + Person.friends.first.id.should == original_person_id end + it "should activate the Person if I initiated a request to that url" do request = Request.instantiate(:to => @person.url, :from => @user).save diff --git a/spec/models/request_spec.rb b/spec/models/request_spec.rb index 9669ff38c4d65708ea66d35df15afa2de83fa7fb..f3357fc739ad0211f47adecf6ddd1d7e5709d62b 100644 --- a/spec/models/request_spec.rb +++ b/spec/models/request_spec.rb @@ -22,10 +22,6 @@ describe Request do 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.url).should be true xml.include?(user.profile.first_name).should be true diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 120b68c1edc9c62ec3b33b158a42deccc9c9deb6..0979db2bbd23c38e93ff6ecef2c29f5445eed7e8 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -10,16 +10,19 @@ describe User do it "should be able to accept a pending friend request" do @user = Factory.create(:user) @friend = Factory.create(:person) - 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 + + + + + + + end