From f661d43a20539d1db6c81b1c01aedd87f2edaeec Mon Sep 17 00:00:00 2001 From: Antonio Terceiro Date: Mon, 10 Nov 2008 20:28:32 -0300 Subject: [PATCH] ActionItem836: not asking for target when coming with target_id as argument --- app/controllers/my_profile/tasks_controller.rb | 5 +++-- app/views/tasks/new.rhtml | 6 +++++- test/functional/tasks_controller_test.rb | 14 ++++++++++++++ 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/app/controllers/my_profile/tasks_controller.rb b/app/controllers/my_profile/tasks_controller.rb index 9d35e63..47945e0 100644 --- a/app/controllers/my_profile/tasks_controller.rb +++ b/app/controllers/my_profile/tasks_controller.rb @@ -23,9 +23,10 @@ class TasksController < MyProfileController end def new - target = profile.friends.find_by_id(params[:ticket][:target_id]) if params[:ticket] @ticket = Ticket.new(params[:ticket]) - @ticket.target = target + if params[:target_id] + @ticket.target = profile.friends.find(params[:target_id]) + end @ticket.requestor = profile if request.post? if @ticket.save diff --git a/app/views/tasks/new.rhtml b/app/views/tasks/new.rhtml index 369d208..ef61935 100644 --- a/app/views/tasks/new.rhtml +++ b/app/views/tasks/new.rhtml @@ -2,7 +2,11 @@ <%# FIXME: put style in css %> <% labelled_form_for :ticket, @ticket do |f| %> - <%= display_form_field( _('To: '), f.select(:target_id, profile.friends.map{|p|[p.name, p.id]})) unless @ticket.target %> + <% if @ticket.target %> + <%= f.hidden_field :target_id %> + <% else %> + <%= display_form_field( _('To: '), f.select(:target_id, profile.friends.map{|p|[p.name, p.id]})) %> + <% end %> <%= f.text_field :title, :style => 'width:80%;' %> <%= f.text_area :description, :style => 'height:200px; width:80%;' %> diff --git a/test/functional/tasks_controller_test.rb b/test/functional/tasks_controller_test.rb index f07ca68..24e6b32 100644 --- a/test/functional/tasks_controller_test.rb +++ b/test/functional/tasks_controller_test.rb @@ -110,6 +110,20 @@ class TasksControllerTest < Test::Unit::TestCase assert_template 'new' end + should 'add a hidden field with target_id when informed in the URL' do + friend = create_user('myfriend').person + profile.add_friend(friend) + + get :new, :profile => profile.identifier, :target_id => friend.id.to_s + + assert_tag :tag => 'input', :attributes => { :type => 'hidden', :name => 'ticket[target_id]', :value => friend.id } + end + + should 'select friend from list when not already informed' do + get :new, :profile => profile.identifier + assert_tag :tag => 'select', :attributes => { :name => 'ticket[target_id]' } + end + should 'create a ticket' do assert_difference Ticket, :count do post :new, :profile => profile.identifier, :ticket => {:title => 'test ticket'} -- libgit2 0.21.2