Commit f661d43a20539d1db6c81b1c01aedd87f2edaeec
1 parent
0b8c2b19
Exists in
master
and in
28 other branches
ActionItem836: not asking for target when coming with target_id as argument
Showing
3 changed files
with
22 additions
and
3 deletions
Show diff stats
app/controllers/my_profile/tasks_controller.rb
| ... | ... | @@ -23,9 +23,10 @@ class TasksController < MyProfileController |
| 23 | 23 | end |
| 24 | 24 | |
| 25 | 25 | def new |
| 26 | - target = profile.friends.find_by_id(params[:ticket][:target_id]) if params[:ticket] | |
| 27 | 26 | @ticket = Ticket.new(params[:ticket]) |
| 28 | - @ticket.target = target | |
| 27 | + if params[:target_id] | |
| 28 | + @ticket.target = profile.friends.find(params[:target_id]) | |
| 29 | + end | |
| 29 | 30 | @ticket.requestor = profile |
| 30 | 31 | if request.post? |
| 31 | 32 | if @ticket.save | ... | ... |
app/views/tasks/new.rhtml
| ... | ... | @@ -2,7 +2,11 @@ |
| 2 | 2 | |
| 3 | 3 | <%# FIXME: put style in css %> |
| 4 | 4 | <% labelled_form_for :ticket, @ticket do |f| %> |
| 5 | - <%= display_form_field( _('To: '), f.select(:target_id, profile.friends.map{|p|[p.name, p.id]})) unless @ticket.target %> | |
| 5 | + <% if @ticket.target %> | |
| 6 | + <%= f.hidden_field :target_id %> | |
| 7 | + <% else %> | |
| 8 | + <%= display_form_field( _('To: '), f.select(:target_id, profile.friends.map{|p|[p.name, p.id]})) %> | |
| 9 | + <% end %> | |
| 6 | 10 | <%= f.text_field :title, :style => 'width:80%;' %> |
| 7 | 11 | <%= f.text_area :description, :style => 'height:200px; width:80%;' %> |
| 8 | 12 | ... | ... |
test/functional/tasks_controller_test.rb
| ... | ... | @@ -110,6 +110,20 @@ class TasksControllerTest < Test::Unit::TestCase |
| 110 | 110 | assert_template 'new' |
| 111 | 111 | end |
| 112 | 112 | |
| 113 | + should 'add a hidden field with target_id when informed in the URL' do | |
| 114 | + friend = create_user('myfriend').person | |
| 115 | + profile.add_friend(friend) | |
| 116 | + | |
| 117 | + get :new, :profile => profile.identifier, :target_id => friend.id.to_s | |
| 118 | + | |
| 119 | + assert_tag :tag => 'input', :attributes => { :type => 'hidden', :name => 'ticket[target_id]', :value => friend.id } | |
| 120 | + end | |
| 121 | + | |
| 122 | + should 'select friend from list when not already informed' do | |
| 123 | + get :new, :profile => profile.identifier | |
| 124 | + assert_tag :tag => 'select', :attributes => { :name => 'ticket[target_id]' } | |
| 125 | + end | |
| 126 | + | |
| 113 | 127 | should 'create a ticket' do |
| 114 | 128 | assert_difference Ticket, :count do |
| 115 | 129 | post :new, :profile => profile.identifier, :ticket => {:title => 'test ticket'} | ... | ... |