From c6783f98fd8b484c41cfc7fcbd2498614b04f223 Mon Sep 17 00:00:00 2001 From: Eric Davis Date: Mon, 21 Jun 2010 14:25:48 -0700 Subject: [PATCH] [#4177] Refactored new Contract form to be used with editing a contract. --- app/controllers/contracts_controller.rb | 6 +++- app/models/contract.rb | 2 +- app/views/contracts/_form.html.erb | 26 +++++++++++++++++ app/views/contracts/edit.html.erb | 9 ++++++ app/views/contracts/new.html.erb | 27 +----------------- app/views/contracts/show.html.erb | 2 ++ init.rb | 2 +- test/integration/contracts_edit_test.rb | 37 +++++++++++++++++++++++++ 8 files changed, 82 insertions(+), 29 deletions(-) create mode 100644 app/views/contracts/_form.html.erb create mode 100644 app/views/contracts/edit.html.erb create mode 100644 test/integration/contracts_edit_test.rb diff --git a/app/controllers/contracts_controller.rb b/app/controllers/contracts_controller.rb index c80eda6..6a353fb 100644 --- a/app/controllers/contracts_controller.rb +++ b/app/controllers/contracts_controller.rb @@ -9,7 +9,11 @@ class ContractsController < InheritedResources::Base def create create! { contract_url(@project, resource) } end - + + def update + update! { contract_url(@project, resource) } + end + protected def begin_of_association_chain diff --git a/app/models/contract.rb b/app/models/contract.rb index f1fa41c..bcb309a 100644 --- a/app/models/contract.rb +++ b/app/models/contract.rb @@ -38,7 +38,7 @@ class Contract < ActiveRecord::Base def payment_terms_for_select PaymentTerms.collect {|value, label| - [l(label), value] + [l(label), value.to_s] } end diff --git a/app/views/contracts/_form.html.erb b/app/views/contracts/_form.html.erb new file mode 100644 index 0000000..1bcc744 --- /dev/null +++ b/app/views/contracts/_form.html.erb @@ -0,0 +1,26 @@ +<% form.inputs do %> + <%= form.input :name, :required => true %> + <%= form.input :account_executive, :required => true %> +
  • + <%= label('contract', 'executed') %> + <%= check_box 'contract', 'executed' %> +
  • + <%= form.input :start_date, :required => true, :as => :string, :input_html => {:size => 10}, :hint => calendar_for('contract_start_date') %> + <%= form.input :end_date, :required => true, :as => :string, :input_html => {:size => 10}, :hint => calendar_for('contract_end_date') %> + <%= form.input :billable_rate, :input_html => {:size => 20}, :hint => l(:field_billable_rate_hint) %> + <%= form.input :discount, :input_html => {:size => 20}, :hint => l(:field_discount_hint) %> + <%= form.input :discount_note, :input_html => {:class => 'wiki-edit', :rows => '5'} %> + <%= form.input :payment_terms, :as => :select, :collection => resource.payment_terms_for_select %> + <%= form.input :client_ap_contact_information, :input_html => {:class => 'wiki-edit', :rows => '5'} %> + <%= form.input :po_number %> + <%= form.input :details, :input_html => {:class => 'wiki-edit'} %> +<% end %> +<% form.buttons do %> + <%= form.commit_button %> + <%= link_to(l(:button_cancel), contracts_path) %> +<% end %> + +<%= wikitoolbar_for 'contract_discount_note' %> +<%= wikitoolbar_for 'contract_client_ap_contact_information' %> +<%= wikitoolbar_for 'contract_details' %> + diff --git a/app/views/contracts/edit.html.erb b/app/views/contracts/edit.html.erb new file mode 100644 index 0000000..883d7c0 --- /dev/null +++ b/app/views/contracts/edit.html.erb @@ -0,0 +1,9 @@ +<%= content_tag(:h2, h(resource.name)) %> + +<% semantic_form_for resource, :url => contract_path(@project, resource), :html => {:class => 'tabular'} do |form| %> +<%= render :partial => 'form', :object => form %> +<% end %> + +<% content_for(:header_tags) do %> + <%= stylesheet_link_tag "redmine_contracts", :plugin => "redmine_contracts", :media => "screen" %> +<% end %> diff --git a/app/views/contracts/new.html.erb b/app/views/contracts/new.html.erb index 3511c2a..1d02069 100644 --- a/app/views/contracts/new.html.erb +++ b/app/views/contracts/new.html.erb @@ -1,33 +1,8 @@ <%= content_tag(:h2, l(:text_new_contract)) %> <% semantic_form_for resource, :html => {:class => 'tabular'} do |form| %> -<% form.inputs do %> - <%= form.input :name, :required => true %> - <%= form.input :account_executive, :required => true %> -
  • - <%= label('contract', 'executed') %> - <%= check_box 'contract', 'executed' %> -
  • - <%= form.input :start_date, :required => true, :as => :string, :input_html => {:size => 10}, :hint => calendar_for('contract_start_date') %> - <%= form.input :end_date, :required => true, :as => :string, :input_html => {:size => 10}, :hint => calendar_for('contract_end_date') %> - <%= form.input :billable_rate, :input_html => {:size => 20}, :hint => l(:field_billable_rate_hint) %> - <%= form.input :discount, :input_html => {:size => 20}, :hint => l(:field_discount_hint) %> - <%= form.input :discount_note, :input_html => {:class => 'wiki-edit', :rows => '5'} %> - <%= form.input :payment_terms, :as => :select, :collection => resource.payment_terms_for_select %> - <%= form.input :client_ap_contact_information, :input_html => {:class => 'wiki-edit', :rows => '5'} %> - <%= form.input :po_number %> - <%= form.input :details, :input_html => {:class => 'wiki-edit'} %> +<%= render :partial => 'form', :object => form %> <% end %> -<% form.buttons do %> - <%= form.commit_button %> - <%= link_to(l(:button_cancel), contracts_path) %> -<% end %> -<% end %> - -<%= wikitoolbar_for 'contract_discount_note' %> -<%= wikitoolbar_for 'contract_client_ap_contact_information' %> -<%= wikitoolbar_for 'contract_details' %> - <% content_for(:header_tags) do %> <%= stylesheet_link_tag "redmine_contracts", :plugin => "redmine_contracts", :media => "screen" %> diff --git a/app/views/contracts/show.html.erb b/app/views/contracts/show.html.erb index b642a4e..0700263 100644 --- a/app/views/contracts/show.html.erb +++ b/app/views/contracts/show.html.erb @@ -13,3 +13,5 @@ <%= content_tag(:p, h(resource.po_number)) %> <%= content_tag(:p, h(resource.details)) %> <% end %> + +<%= link_to(l(:button_update), edit_contract_path(@project, resource)) %> diff --git a/init.rb b/init.rb index 622e3f7..abf3866 100644 --- a/init.rb +++ b/init.rb @@ -14,7 +14,7 @@ Redmine::Plugin.register :redmine_contracts do requires_redmine_plugin :redmine_rate, :version_or_higher => '0.1.0' project_module :contracts do - permission :manage_budget, {:contracts => [:index, :new, :create, :show] }, :public => true + permission :manage_budget, {:contracts => [:index, :new, :create, :show, :edit, :update] }, :public => true end menu(:project_menu, diff --git a/test/integration/contracts_edit_test.rb b/test/integration/contracts_edit_test.rb new file mode 100644 index 0000000..4840985 --- /dev/null +++ b/test/integration/contracts_edit_test.rb @@ -0,0 +1,37 @@ +require 'test_helper' + +class ContractsEditTest < ActionController::IntegrationTest + include Redmine::I18n + + def setup + @project = Project.generate!(:identifier => 'main') + @contract = Contract.generate!(:project => @project, :name => 'A Contract', :payment_terms => 'net_15') + end + + should "allow any user to edit the contract" do + visit_contracts_for_project(@project) + click_link @contract.id + assert_response :success + + click_link 'Update' + assert_response :success + assert_template 'contracts/edit' + + assert_select "h2", :text => @contract.name + assert_select "form#edit_contract_#{@contract.id}.contract" do + assert_select "input[value=?]", /#{@contract.name}/ + assert_select "select#contract_payment_terms" do + assert_select "option[selected=selected][value=net_15]" + end + end + + fill_in "Name", :with => 'An updated name' + click_button "Update Contract" + + assert_response :success + assert_template 'contracts/show' + + assert_equal "An updated name", @contract.reload.name + + end +end