Fix new request view

This commit is contained in:
Raphael 2010-11-09 15:03:56 -08:00
parent 98fe1d357b
commit 390fffdee6
4 changed files with 23 additions and 32 deletions

View file

@ -32,8 +32,8 @@ class RequestsController < ApplicationController
end end
def create def create
aspect = current_user.aspect_by_id(params[:request][:aspect_id]) aspect = current_user.aspect_by_id(params[:aspect_id])
account = params[:request][:destination_url].strip account = params[:destination_handle].strip
begin begin
finger = EMWebfinger.new(account) finger = EMWebfinger.new(account)

View file

@ -67,12 +67,5 @@ class Request
def diaspora_handle def diaspora_handle
self.from.diaspora_handle self.from.diaspora_handle
end end
protected
def clean_link
if self.destination_url
self.destination_url = self.destination_url.strip
self.destination_url = 'http://' + self.destination_url unless self.destination_url.match('https?://')
self.destination_url = self.destination_url + '/' if self.destination_url[-1,1] != '/'
end
end
end end

View file

@ -14,22 +14,20 @@
.span-7.last .span-7.last
%h3 Add a new contact %h3 Add a new contact
= form_for(Request.new, :html => {:id => "new_request_to_#{aspect.id}"}) do |fr_request| = form_tag(requests_path, :id => "new_request_to_#{aspect.id}") do
= fr_request.error_messages
=t('.enter_a_diaspora_username') =t('.enter_a_diaspora_username')
%br %br
%i= t '.your_diaspora_username_is', :diaspora_handle => current_user.diaspora_handle %i= t '.your_diaspora_username_is', :diaspora_handle => current_user.diaspora_handle
%p %p
= fr_request.label :destination_url, t('.friends_username'), :for => "request_d_url_to_#{aspect.id}" = label_tag :destination_handle, t('.friends_username'), :for => "request_d_handle_to_#{aspect.id}"
= fr_request.text_field :destination_url, :id => "request_d_url_to_#{aspect.id}" = text_field_tag :destination_handle,'', :id => "request_d_handle_to_#{aspect.id}"
= fr_request.hidden_field :aspect_id, :value => aspect.id = hidden_field_tag :aspect_id, :value => aspect.id
- if defined?(getting_started) - if defined?(getting_started)
= hidden_field_tag :getting_started, getting_started = hidden_field_tag :getting_started, getting_started
- if defined?(manage) - if defined?(manage)
= hidden_field_tag :manage, true = hidden_field_tag :manage, true
= fr_request.submit t('.create_request') = submit_tag t('.create_request')

View file

@ -15,18 +15,18 @@ describe RequestsController do
describe '#create' do describe '#create' do
it "redirects when requesting to be friends with yourself" do it "redirects when requesting to be friends with yourself" do
put("create", "request" => { put(:create, {
"destination_url" => @user.diaspora_handle, :destination_handle => @user.diaspora_handle,
"aspect_id" => @user.aspects[0].id :aspect_id => @user.aspects[0].id
} }
) )
response.should redirect_to aspects_manage_path response.should redirect_to aspects_manage_path
end end
it "flashes and redirects when requesting an invalid identity" do it "flashes and redirects when requesting an invalid identity" do
put("create", "request" => { put(:create, {
"destination_url" => "not_a_@valid_email", :destination_handle => "not_a_@valid_email",
"aspect_id" => @user.aspects[0].id :aspect_id => @user.aspects[0].id
} }
) )
flash[:error].should_not be_blank flash[:error].should_not be_blank
@ -34,9 +34,9 @@ describe RequestsController do
end end
it "flashes and redirects when requesting an invalid identity with a port number" do it "flashes and redirects when requesting an invalid identity with a port number" do
put("create", "request" => { put(:create, {
"destination_url" => "johndoe@email.com:3000", :destination_handle => "johndoe@email.com:3000",
"aspect_id" => @user.aspects[0].id :aspect_id => @user.aspects[0].id
} }
) )
flash[:error].should_not be_blank flash[:error].should_not be_blank
@ -45,9 +45,9 @@ describe RequestsController do
it "redirects when requesting an identity from an invalid server" do it "redirects when requesting an identity from an invalid server" do
stub_request(:get, /notadiasporaserver\.com/).to_raise(Errno::ETIMEDOUT) stub_request(:get, /notadiasporaserver\.com/).to_raise(Errno::ETIMEDOUT)
put("create", "request" => { put(:create, {
"destination_url" => "johndoe@notadiasporaserver.com", :destination_handle => "johndoe@notadiasporaserver.com",
"aspect_id" => @user.aspects[0].id :aspect_id => @user.aspects[0].id
} }
) )
response.should redirect_to aspects_manage_path response.should redirect_to aspects_manage_path
@ -55,9 +55,9 @@ describe RequestsController do
it 'should redirect to the page which you called it from ' do it 'should redirect to the page which you called it from ' do
pending "This controller should probably redirect to :back" pending "This controller should probably redirect to :back"
put("create", "request" => { put(:create, {
"destination_url" => "johndoe@notadiasporaserver.com", :destination_handle => "johndoe@notadiasporaserver.com",
"aspect_id" => @user.aspects[0].id :aspect_id => @user.aspects[0].id
} }
) )
response.should redirect_to(:back) response.should redirect_to(:back)