Skip to content

Commit

Permalink
Add field to set contact person on request show page. Fixes hpi-swt2#313
Browse files Browse the repository at this point in the history
. (hpi-swt2#362)

* Add field to set contact person on request show page

* Allow unsetting contact
  • Loading branch information
tom95 authored Jan 20, 2017
1 parent c522419 commit 81204b2
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 10 deletions.
14 changes: 14 additions & 0 deletions app/controllers/requests_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ def update
end
end

def set_contact_person
@request = Request.find(params[:request_id])
update_params = contact_person_params
if !update_params[:contact_person].nil? and @request.update(update_params)
redirect_to @request, notice: I18n.t('requests.notice.was_updated')
else
render :show
end
end

# DELETE /requests/1
def destroy
@request.destroy
Expand All @@ -63,4 +73,8 @@ def set_request
def request_params
params.require(:request).permit(:form_of_address, :first_name, :last_name, :phone_number, :street, :zip_code_city, :topic_of_workshop, :time_period, :email, :number_of_participants, :knowledge_level, :annotations)
end

def contact_person_params
params.require(:request).permit(:contact_person)
end
end
15 changes: 15 additions & 0 deletions app/views/requests/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,21 @@
<dt><strong><%= model_class.human_attribute_name(:status) %>:</strong></dt>
<dd><%= t(@request.status, scope: 'activerecord.attributes.request.statuses') %></dd>
</dl>
<dl class="dl-horizontal">
<dt><strong><%= model_class.human_attribute_name(:contact_person) %>:</strong></td>
<dd>
<%= form_for @request, url: request_set_contact_person_path(@request), html: { class: 'form-inline' } do |f| %>
<div class="m-b-1">
<div class="input-group">
<%= f.text_field :contact_person, class: 'form-control', placeholder: t('activerecord.attributes.request.contact_person') %>
<span class="input-group-btn">
<%= f.submit t('requests.form.set_contact_person'), class: 'btn btn-default' %>
</span>
</div>
</div>
<% end %>
</dd>
</dl>

<%= link_to t('.back', :default => t("helpers.links.back")),
requests_path, :class => 'btn btn-default' %>
Expand Down
2 changes: 2 additions & 0 deletions config/locales/de.requests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ de:
form:
create_request: "Anfrage erstellen"
accept: "Annehmen"
set_contact_person: "Ansprechpartner festlegen"
hints:
please_enter_two_topics: "Bitte 2 Wünsche angeben"
notice:
Expand Down Expand Up @@ -40,6 +41,7 @@ de:
annotations: "Anmerkungen"
id: "Nummer"
created_at: "Erstellt am"
contact_person: "Ansprechpartner"
status: "Status"
statuses:
open: "Noch nicht angenommen"
Expand Down
4 changes: 3 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
post 'agreement_letters/create'
get 'agreement_letters/show'

resources :requests
resources :requests do
patch 'contact_person' => 'requests#set_contact_person', as: :set_contact_person
end

put 'applications/:id/status' => 'application_letters#update_status', as: :update_application_letter_status
get 'applications/:id/check' => 'application_letters#check', as: :check_application_letter
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20170119223355_add_contact_person_to_requests.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddContactPersonToRequests < ActiveRecord::Migration
def change
add_column :requests, :contact_person, :string
end
end
17 changes: 8 additions & 9 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.


ActiveRecord::Schema.define(version: 20170118185870) do

ActiveRecord::Schema.define(version: 20170119223355) do

create_table "agreement_letters", force: :cascade do |t|
t.integer "user_id", null: false
Expand All @@ -28,11 +26,11 @@

create_table "application_letters", force: :cascade do |t|
t.string "motivation"
t.integer "user_id", null: false
t.integer "event_id", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "status", default: 2, null: false
t.integer "user_id", null: false
t.integer "event_id", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "status", default: 2, null: false
t.integer "grade"
t.string "experience"
t.string "coding_skills"
Expand Down Expand Up @@ -85,8 +83,8 @@
t.string "knowledge_level"
t.date "application_deadline"
t.boolean "application_status_locked"
t.boolean "participants_are_unlimited", default: false
t.text "custom_application_fields"
t.boolean "participants_are_unlimited", default: false
end

create_table "profiles", force: :cascade do |t|
Expand Down Expand Up @@ -124,6 +122,7 @@
t.text "annotations"
t.integer "status", default: 0
t.string "zip_code_city"
t.string "contact_person"
end

create_table "users", force: :cascade do |t|
Expand Down
22 changes: 22 additions & 0 deletions spec/controllers/requests_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,28 @@
end
end

describe "PATCH #set_contact_person" do
before :each do
@a_request = Request.create! valid_attributes
end

context "with valid params" do
it "saves the name" do
name = 'Me'
patch :set_contact_person, request_id: @a_request.to_param, request: {contact_person: name}, session: valid_session
@a_request.reload
expect(@a_request.contact_person).to eq(name)
end
end

context "with invalid params" do
it "re-renders the 'show' template" do
patch :set_contact_person, request_id: @a_request.to_param, request: invalid_attributes, session: valid_session
expect(response).to render_template("show")
end
end
end

describe "POST #create" do
context "with valid params" do
it "creates a new Request" do
Expand Down
12 changes: 12 additions & 0 deletions spec/features/request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,18 @@ def fill_in_required_fields
accepted_status = I18n.t 'activerecord.attributes.request.statuses.accepted'
expect(page).to have_text(accepted_status)
end

it 'should allow me to enter an contact person' do
request = FactoryGirl.create(:request)

visit(request_path(request))
expect(page).to have_field('request_contact_person')
fill_in 'request_contact_person', with: 'Me'
click_button I18n.t('requests.form.set_contact_person')

visit(request_path(request))
expect(page).to have_field('request_contact_person', with: 'Me')
end
end
end
end

0 comments on commit 81204b2

Please sign in to comment.