From f7d6dd22cfd1dbb92271d65a8434a944bd278508 Mon Sep 17 00:00:00 2001 From: MoisesMachado Date: Wed, 20 Aug 2008 20:23:51 +0000 Subject: [PATCH] ActionItem371: initial implementation of ticket system --- app/controllers/my_profile/tasks_controller.rb | 9 +++++++++ app/models/ticket.rb | 25 +++++++++++++++++++++++++ app/views/tasks/new.rhtml | 9 +++++++++ test/functional/tasks_controller_test.rb | 18 ++++++++++++++++++ test/unit/ticket_test.rb | 11 +++++++++++ 5 files changed, 72 insertions(+), 0 deletions(-) create mode 100644 app/models/ticket.rb create mode 100644 app/views/tasks/new.rhtml create mode 100644 test/unit/ticket_test.rb diff --git a/app/controllers/my_profile/tasks_controller.rb b/app/controllers/my_profile/tasks_controller.rb index e9ade39..274360f 100644 --- a/app/controllers/my_profile/tasks_controller.rb +++ b/app/controllers/my_profile/tasks_controller.rb @@ -22,4 +22,13 @@ class TasksController < MyProfileController redirect_to :action => 'index' end + def new + @ticket = Ticket.new(params[:ticket]) + @ticket.requestor = profile + if request.post? + @ticket.save! + redirect_to :action => 'index' + end + end + end diff --git a/app/models/ticket.rb b/app/models/ticket.rb new file mode 100644 index 0000000..9b13217 --- /dev/null +++ b/app/models/ticket.rb @@ -0,0 +1,25 @@ +class Ticket < Task + + serialize :data, Hash + + def data + self[:data] ||= {} + end + + def title + data[:title] + end + + def title= value + data[:title] = value + end + + def description + data[:description] + end + + def description= value + data[:description] = value + end + +end diff --git a/app/views/tasks/new.rhtml b/app/views/tasks/new.rhtml new file mode 100644 index 0000000..1fe7f4f --- /dev/null +++ b/app/views/tasks/new.rhtml @@ -0,0 +1,9 @@ +<% labelled_form_for :ticket, @ticket do |f| %> + <%= f.text_field :title %> + <%= display_form_field( _('Owner: '), f.select(:target_id, profile.friends.map{|p|[p.name, p.id]})) %> + <%= f.text_area :description %> + + <% button_bar do %> + <%= submit_button('save', _('Create')) %> + <% end %> +<% end %> diff --git a/test/functional/tasks_controller_test.rb b/test/functional/tasks_controller_test.rb index 6d404ed..5bfc05d 100644 --- a/test/functional/tasks_controller_test.rb +++ b/test/functional/tasks_controller_test.rb @@ -103,4 +103,22 @@ class TasksControllerTest < Test::Unit::TestCase end end + should 'display a create ticket form' do + get :new, :profile => profile.identifier + + assert_template 'new' + end + + should 'create a ticket' do + assert_difference Ticket, :count do + post :new, :profile => profile.identifier, :ticket => {:title => 'test ticket'} + end + end + + should 'create a ticket with profile requestor' do + post :new, :profile => profile.identifier, :ticket => {:title => 'new task'} + + assert_equal profile, assigns(:ticket).requestor + end + end diff --git a/test/unit/ticket_test.rb b/test/unit/ticket_test.rb new file mode 100644 index 0000000..d0d88f5 --- /dev/null +++ b/test/unit/ticket_test.rb @@ -0,0 +1,11 @@ +require File.dirname(__FILE__) + '/../test_helper' + +class TicketTest < ActiveSupport::TestCase + + should 'have serialized data' do + t = Ticket.new + t.data[:test] = 'test' + + assert_equal({:test => 'test'}, t.data) + end +end -- libgit2 0.21.2