Commit f7d6dd22cfd1dbb92271d65a8434a944bd278508
1 parent
ea538e32
Exists in
master
and in
23 other branches
ActionItem371: initial implementation of ticket system
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@2406 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
5 changed files
with
72 additions
and
0 deletions
Show diff stats
app/controllers/my_profile/tasks_controller.rb
| @@ -22,4 +22,13 @@ class TasksController < MyProfileController | @@ -22,4 +22,13 @@ class TasksController < MyProfileController | ||
| 22 | redirect_to :action => 'index' | 22 | redirect_to :action => 'index' |
| 23 | end | 23 | end |
| 24 | 24 | ||
| 25 | + def new | ||
| 26 | + @ticket = Ticket.new(params[:ticket]) | ||
| 27 | + @ticket.requestor = profile | ||
| 28 | + if request.post? | ||
| 29 | + @ticket.save! | ||
| 30 | + redirect_to :action => 'index' | ||
| 31 | + end | ||
| 32 | + end | ||
| 33 | + | ||
| 25 | end | 34 | end |
| @@ -0,0 +1,25 @@ | @@ -0,0 +1,25 @@ | ||
| 1 | +class Ticket < Task | ||
| 2 | + | ||
| 3 | + serialize :data, Hash | ||
| 4 | + | ||
| 5 | + def data | ||
| 6 | + self[:data] ||= {} | ||
| 7 | + end | ||
| 8 | + | ||
| 9 | + def title | ||
| 10 | + data[:title] | ||
| 11 | + end | ||
| 12 | + | ||
| 13 | + def title= value | ||
| 14 | + data[:title] = value | ||
| 15 | + end | ||
| 16 | + | ||
| 17 | + def description | ||
| 18 | + data[:description] | ||
| 19 | + end | ||
| 20 | + | ||
| 21 | + def description= value | ||
| 22 | + data[:description] = value | ||
| 23 | + end | ||
| 24 | + | ||
| 25 | +end |
| @@ -0,0 +1,9 @@ | @@ -0,0 +1,9 @@ | ||
| 1 | +<% labelled_form_for :ticket, @ticket do |f| %> | ||
| 2 | + <%= f.text_field :title %> | ||
| 3 | + <%= display_form_field( _('Owner: '), f.select(:target_id, profile.friends.map{|p|[p.name, p.id]})) %> | ||
| 4 | + <%= f.text_area :description %> | ||
| 5 | + | ||
| 6 | + <% button_bar do %> | ||
| 7 | + <%= submit_button('save', _('Create')) %> | ||
| 8 | + <% end %> | ||
| 9 | +<% end %> |
test/functional/tasks_controller_test.rb
| @@ -103,4 +103,22 @@ class TasksControllerTest < Test::Unit::TestCase | @@ -103,4 +103,22 @@ class TasksControllerTest < Test::Unit::TestCase | ||
| 103 | end | 103 | end |
| 104 | end | 104 | end |
| 105 | 105 | ||
| 106 | + should 'display a create ticket form' do | ||
| 107 | + get :new, :profile => profile.identifier | ||
| 108 | + | ||
| 109 | + assert_template 'new' | ||
| 110 | + end | ||
| 111 | + | ||
| 112 | + should 'create a ticket' do | ||
| 113 | + assert_difference Ticket, :count do | ||
| 114 | + post :new, :profile => profile.identifier, :ticket => {:title => 'test ticket'} | ||
| 115 | + end | ||
| 116 | + end | ||
| 117 | + | ||
| 118 | + should 'create a ticket with profile requestor' do | ||
| 119 | + post :new, :profile => profile.identifier, :ticket => {:title => 'new task'} | ||
| 120 | + | ||
| 121 | + assert_equal profile, assigns(:ticket).requestor | ||
| 122 | + end | ||
| 123 | + | ||
| 106 | end | 124 | end |