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
def create
aspect = current_user.aspect_by_id(params[:request][:aspect_id])
account = params[:request][:destination_url].strip
aspect = current_user.aspect_by_id(params[:aspect_id])
account = params[:destination_handle].strip
begin
finger = EMWebfinger.new(account)

View file

@ -67,12 +67,5 @@ class Request
def diaspora_handle
self.from.diaspora_handle
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

View file

@ -14,22 +14,20 @@
.span-7.last
%h3 Add a new contact
= form_for(Request.new, :html => {:id => "new_request_to_#{aspect.id}"}) do |fr_request|
= fr_request.error_messages
= form_tag(requests_path, :id => "new_request_to_#{aspect.id}") do
=t('.enter_a_diaspora_username')
%br
%i= t '.your_diaspora_username_is', :diaspora_handle => current_user.diaspora_handle
%p
= fr_request.label :destination_url, t('.friends_username'), :for => "request_d_url_to_#{aspect.id}"
= fr_request.text_field :destination_url, :id => "request_d_url_to_#{aspect.id}"
= fr_request.hidden_field :aspect_id, :value => aspect.id
= label_tag :destination_handle, t('.friends_username'), :for => "request_d_handle_to_#{aspect.id}"
= text_field_tag :destination_handle,'', :id => "request_d_handle_to_#{aspect.id}"
= hidden_field_tag :aspect_id, :value => aspect.id
- if defined?(getting_started)
= hidden_field_tag :getting_started, getting_started
- if defined?(manage)
= 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
it "redirects when requesting to be friends with yourself" do
put("create", "request" => {
"destination_url" => @user.diaspora_handle,
"aspect_id" => @user.aspects[0].id
put(:create, {
:destination_handle => @user.diaspora_handle,
:aspect_id => @user.aspects[0].id
}
)
response.should redirect_to aspects_manage_path
end
it "flashes and redirects when requesting an invalid identity" do
put("create", "request" => {
"destination_url" => "not_a_@valid_email",
"aspect_id" => @user.aspects[0].id
put(:create, {
:destination_handle => "not_a_@valid_email",
:aspect_id => @user.aspects[0].id
}
)
flash[:error].should_not be_blank
@ -34,9 +34,9 @@ describe RequestsController do
end
it "flashes and redirects when requesting an invalid identity with a port number" do
put("create", "request" => {
"destination_url" => "johndoe@email.com:3000",
"aspect_id" => @user.aspects[0].id
put(:create, {
:destination_handle => "johndoe@email.com:3000",
:aspect_id => @user.aspects[0].id
}
)
flash[:error].should_not be_blank
@ -45,9 +45,9 @@ describe RequestsController do
it "redirects when requesting an identity from an invalid server" do
stub_request(:get, /notadiasporaserver\.com/).to_raise(Errno::ETIMEDOUT)
put("create", "request" => {
"destination_url" => "johndoe@notadiasporaserver.com",
"aspect_id" => @user.aspects[0].id
put(:create, {
:destination_handle => "johndoe@notadiasporaserver.com",
:aspect_id => @user.aspects[0].id
}
)
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
pending "This controller should probably redirect to :back"
put("create", "request" => {
"destination_url" => "johndoe@notadiasporaserver.com",
"aspect_id" => @user.aspects[0].id
put(:create, {
:destination_handle => "johndoe@notadiasporaserver.com",
:aspect_id => @user.aspects[0].id
}
)
response.should redirect_to(:back)