Skip to content

Commit

Permalink
Merge branch 'dev' into 633_update_to_rails5
Browse files Browse the repository at this point in the history
  • Loading branch information
cmfcmf committed Apr 30, 2018
2 parents f82cab3 + 8b5a0d2 commit 644bb61
Show file tree
Hide file tree
Showing 14 changed files with 141 additions and 41 deletions.
14 changes: 13 additions & 1 deletion app/controllers/requests_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,19 @@ def set_request

# Only allow a trusted parameter "white list" through.
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)
params.require(:request).permit(:form_of_address,
:first_name,
:last_name,
:phone_number,
:school_street,
:school_zip_code_city,
:topic_of_workshop,
:time_period,
:email,
:number_of_participants,
:knowledge_level,
:annotations,
:grade)
end

def contact_person_params
Expand Down
7 changes: 4 additions & 3 deletions app/models/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,22 @@
# first_name :string
# last_name :string
# phone_number :string
# street :string
# school_street :string
# email :string
# topic_of_workshop :text
# time_period :text
# number_of_participants :integer
# knowledge_level :string
# annotations :text
# status :integer default(0)
# zip_code_city :string
# school_zip_code_city :string
# contact_person :string
# notes :text
# grade :string
#

class Request < ActiveRecord::Base
validates_presence_of :form_of_address, :last_name, :first_name, :phone_number, :street, :zip_code_city, :email, :topic_of_workshop
validates_presence_of :form_of_address, :last_name, :first_name, :phone_number, :school_street, :school_zip_code_city, :email, :topic_of_workshop
validates :number_of_participants, numericality: { only_integer: true, greater_than: 0 }, allow_nil: :true
validates_format_of :email, with: Devise.email_regexp

Expand Down
28 changes: 24 additions & 4 deletions app/views/requests/_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<%= form_for @request, :html => {:class => "form-horizontal request"} do |f| %>
<%= render partial: "shared/error_message", locals: {entity: @request} %>

<h3><%=t 'requests.workshop_information' %></h3>
Expand All @@ -12,7 +12,7 @@
</div>
</div>

<% [:time_period, :number_of_participants, :knowledge_level].each do |attribute_name| %>
<% [:time_period, :number_of_participants, :grade].each do |attribute_name| %>
<div class="form-group">
<%= f.label attribute_name, :class => 'control-label col-lg-2 ' %>
<div class="col-lg-10">
Expand All @@ -22,6 +22,14 @@
</div>
<% end %>

<div class="form-group">
<%= f.label :knowledge_level, :class => 'control-label col-lg-2' %>
<div class="col-lg-10">
<%= f.text_area :knowledge_level, :class => 'form-control', :placeholder => I18n.t('requests.hints.please_be_descriptive') %>
<%= f.error_span(:knowledge_level) %>
</div>
</div>

<div class="form-group">
<%= f.label :annotations, :class => 'control-label col-lg-2' %>
<div class="col-lg-10">
Expand All @@ -30,7 +38,7 @@
</div>
</div>

<h3><%=t 'requests.personal_information' %></h3>
<h3><%=t 'requests.teacher_information' %></h3>

<div class="form-group">
<div class="btn-group col-lg-10 col-lg-offset-2" data-toggle="buttons">
Expand All @@ -46,7 +54,19 @@
</div>
</div>

<% [:first_name, :last_name, :phone_number, :street, :zip_code_city, :email].each do |attribute_name| %>
<% [:first_name, :last_name, :phone_number, :email].each do |attribute_name| %>
<div class="form-group">
<%= f.label attribute_name, :class => 'control-label col-lg-2 required' %>
<div class="col-lg-10">
<%= f.text_field attribute_name, :class => 'form-control' %>
<%= f.error_span(attribute_name) %>
</div>
</div>
<% end %>

<h3><%=t 'requests.school_information' %></h3>

<% [:school_street, :school_zip_code_city].each do |attribute_name| %>
<div class="form-group">
<%= f.label attribute_name, :class => 'control-label col-lg-2 required' %>
<div class="col-lg-10">
Expand Down
18 changes: 12 additions & 6 deletions app/views/requests/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,15 @@
<dd><%= @request.number_of_participants %></dd>
<dt><strong><%= model_class.human_attribute_name(:time_period) %>:</strong></dt>
<dd><%= @request.time_period %></dd>
<dt><strong><%= model_class.human_attribute_name(:knowledge_level) %>:</strong></dt>
<dd><%= simple_format(@request.knowledge_level) %></dd>
<dt><strong><%= model_class.human_attribute_name(:grade) %>:</strong></dt>
<dd><%= @request.grade %></dd>
<dt><strong><%= model_class.human_attribute_name(:status) %>:</strong></dt>
<dd><%= t(@request.status, scope: 'activerecord.attributes.request.statuses') %></dd>
<% if can? :view_annotations, @request %>
<dt><strong><%= model_class.human_attribute_name(:annotations) %>:</strong></dt>
<dd><%= @request.annotations %></dd>
<dd><%= simple_format(@request.annotations) %></dd>
<% end %>
</dl>

Expand Down Expand Up @@ -51,7 +55,7 @@
</dl>
<% end %>

<h3><%= t('requests.personal_information') %></h3>
<h3><%= t('requests.teacher_information') %></h3>
<dl class="dl-horizontal request_details">
<dt><strong><%= model_class.human_attribute_name(:first_name) %>:</strong></dt>
<dd><%= @request.first_name %></dd>
Expand All @@ -61,10 +65,12 @@
<dd><a href="<%= "mailto:#{@request.email}"%>"><%= @request.email %></a></dd>
<dt><strong><%= model_class.human_attribute_name(:phone_number) %>:</strong></dt>
<dd><%= @request.phone_number %></dd>
<dt><strong><%= model_class.human_attribute_name(:street) %>:</strong></dt>
<dd><%= @request.street %></dd>
<dt><strong><%= model_class.human_attribute_name(:zip_code_city) %>:</strong></dt>
<dd><%= @request.zip_code_city %></dd>

<h3><%= t('requests.school_information') %></h3>
<dt><strong><%= model_class.human_attribute_name(:school_street) %>:</strong></dt>
<dd><%= @request.school_street %></dd>
<dt><strong><%= model_class.human_attribute_name(:school_zip_code_city) %>:</strong></dt>
<dd><%= @request.school_zip_code_city %></dd>

</dl>

Expand Down
11 changes: 7 additions & 4 deletions config/locales/de.requests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ de:
new:
title: "Neue Anfrage stellen"
workshop_information: "Informationen über den gewünschten Workshop"
personal_information: "Persönliche Daten"
teacher_information: "Lehrerinformationen"
school_information: "Schulinformationen"
form_of_addresses:
mr: "Herr"
mrs: "Frau"
Expand All @@ -55,6 +56,7 @@ de:
set_notes: "Notizen speichern"
hints:
please_enter_two_topics: "Bitte 2 Wünsche angeben"
please_be_descriptive: "Bitte seien Sie so genau wie möglich, diese Angabe hilft uns den Workshop besser zu gestalten."
notice:
was_created: "Ihre Anfrage wurde erfolgreich abgesendet"
was_updated: "Die Anfrage wurde aktualisiert"
Expand All @@ -78,14 +80,15 @@ de:
request:
first_name: "Vorname"
last_name: "Nachname"
phone_number: "Telefonnummer"
street: "Straße und Hausnummer"
zip_code_city: "PLZ und Stadt"
phone_number: "Mobiltelefonnummer"
school_street: "Straße und Hausnummer"
school_zip_code_city: "PLZ und Stadt"
email: "E-Mail-Adresse"
topic_of_workshop: "Thema des Workshops"
time_period: "Zeitrahmen"
number_of_participants: "Teilnehmeranzahl"
knowledge_level: "Kenntnisstand"
grade: "Klassenstufe"
annotations: "Anmerkungen"
id: "Nummer"
created_at: "Erstellt am"
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20180423164856_add_grade_to_requests.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddGradeToRequests < ActiveRecord::Migration
def change
add_column :requests, :grade, :string
end
end
6 changes: 6 additions & 0 deletions db/migrate/20180423170641_rename_address.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class RenameAddress < ActiveRecord::Migration
def change
rename_column :requests, :street, :school_street
rename_column :requests, :zip_code_city, :school_zip_code_city
end
end
5 changes: 3 additions & 2 deletions db/sample_data/requests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ def request_hardware_entwicklung
first_name: "Martina",
last_name: "Mustermann",
phone_number: "0123456789",
street: "Musterstraße 1",
zip_code_city: "12345 Musterstadt",
school_street: "Musterstraße 1",
school_zip_code_city: "12345 Musterstadt",
email: "mustermann@example.de",
topic_of_workshop: "Hardware-Entwicklung mit einem CAD-System",
number_of_participants: 12,
grade: "8. Klasse",
status: :open
)
end
19 changes: 15 additions & 4 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20170605080836) do
ActiveRecord::Schema.define(version: 20180423170641) do

create_table "agreement_letters", force: :cascade do |t|
t.integer "user_id", null: false
Expand Down Expand Up @@ -70,6 +70,16 @@
t.boolean "hide_recipients"
end

create_table "emails", force: :cascade do |t|
t.boolean "hide_recipients"
t.string "recipients"
t.string "reply_to"
t.string "subject"
t.string "content"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end

create_table "events", force: :cascade do |t|
t.string "name"
t.text "description"
Expand All @@ -82,9 +92,9 @@
t.date "application_deadline"
t.text "custom_application_fields"
t.boolean "hidden", default: false
t.string "image"
t.boolean "rejections_have_been_sent", default: false
t.boolean "acceptances_have_been_sent", default: false
t.string "image"
t.string "custom_image"
end

Expand Down Expand Up @@ -122,17 +132,18 @@
t.string "first_name"
t.string "last_name"
t.string "phone_number"
t.string "street"
t.string "school_street"
t.string "email"
t.text "topic_of_workshop"
t.text "time_period"
t.integer "number_of_participants"
t.string "knowledge_level"
t.text "annotations"
t.integer "status", default: 0
t.string "zip_code_city"
t.string "school_zip_code_city"
t.string "contact_person"
t.text "notes"
t.string "grade"
end

create_table "users", force: :cascade do |t|
Expand Down
29 changes: 24 additions & 5 deletions spec/factories/requests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,41 @@
#
# Table name: requests
#
# id :integer not null, primary key
# created_at :datetime not null
# updated_at :datetime not null
# id :integer not null, primary key
# created_at :datetime not null
# updated_at :datetime not null
# form_of_address :integer
# first_name :string
# last_name :string
# phone_number :string
# school_street :string
# email :string
# topic_of_workshop :text
# time_period :text
# number_of_participants :integer
# knowledge_level :string
# annotations :text
# status :integer default(0)
# school_zip_code_city :string
# contact_person :string
# notes :text
# grade :string
#


FactoryGirl.define do
factory :request do
form_of_address :mrs
first_name "Martina"
last_name "Mustermann"
phone_number "0123456789"
street "Musterstraße 1"
zip_code_city "12345 Musterstadt"
school_street "Musterstraße 1"
school_zip_code_city "12345 Musterstadt"
email "mustermann@example.de"
topic_of_workshop "Hardware-Entwicklung mit einem CAD-System"
number_of_participants 12
grade "8. Klasse"
knowledge_level "Haben gerade mit Java-Kara angefangen"
status :open
annotations "Notes about this workshop"
time_period "Zwischen Ende Januar und Mitte März"
Expand Down
4 changes: 2 additions & 2 deletions spec/features/request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ def fill_in_required_fields
fill_in I18n.t('activerecord.attributes.request.first_name'), :with => 'Martina'
fill_in I18n.t('activerecord.attributes.request.last_name'), :with => 'Mustermann'
fill_in I18n.t('activerecord.attributes.request.phone_number'), :with => '0123456789'
fill_in I18n.t('activerecord.attributes.request.street'), :with => 'Musterstraße 3'
fill_in I18n.t('activerecord.attributes.request.zip_code_city'), :with => '12345 Musterstadt'
fill_in I18n.t('activerecord.attributes.request.school_street'), :with => 'Musterstraße 3'
fill_in I18n.t('activerecord.attributes.request.school_zip_code_city'), :with => '12345 Musterstadt'
fill_in I18n.t('activerecord.attributes.request.email'), :with => 'martina@mustermann.de'
fill_in I18n.t('activerecord.attributes.request.topic_of_workshop'), :with => 'Musterthema'
end
Expand Down
24 changes: 19 additions & 5 deletions spec/models/request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,25 @@
#
# Table name: requests
#
# id :integer not null, primary key
# topics :string
# user_id :integer not null
# created_at :datetime not null
# updated_at :datetime not null
# id :integer not null, primary key
# created_at :datetime not null
# updated_at :datetime not null
# form_of_address :integer
# first_name :string
# last_name :string
# phone_number :string
# school_street :string
# email :string
# topic_of_workshop :text
# time_period :text
# number_of_participants :integer
# knowledge_level :string
# annotations :text
# status :integer default(0)
# school_zip_code_city :string
# contact_person :string
# notes :text
# grade :string
#

require 'rails_helper'
Expand Down
7 changes: 4 additions & 3 deletions spec/views/requests/new.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,15 @@
assert_select "input#request_first_name[name=?]", "request[first_name]"
assert_select "input#request_last_name[name=?]", "request[last_name]"
assert_select "input#request_phone_number[name=?]", "request[phone_number]"
assert_select "input#request_street[name=?]", "request[street]"
assert_select "input#request_zip_code_city[name=?]", "request[zip_code_city]"
assert_select "input#request_school_street[name=?]", "request[school_street]"
assert_select "input#request_school_zip_code_city[name=?]", "request[school_zip_code_city]"
assert_select "input#request_email[name=?]", "request[email]"
assert_select "input#request_topic_of_workshop[name=?]", "request[topic_of_workshop]"
assert_select "input#request_time_period[name=?]", "request[time_period]"
assert_select "input#request_number_of_participants[name=?]", "request[number_of_participants]"
assert_select "input#request_knowledge_level[name=?]", "request[knowledge_level]"
assert_select "textarea#request_knowledge_level[name=?]", "request[knowledge_level]"
assert_select "textarea#request_annotations[name=?]", "request[annotations]"
assert_select "input#request_grade[name=?]", "request[grade]"
end
end
end
5 changes: 3 additions & 2 deletions spec/views/requests/show.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@
expect(rendered).to have_text(@aRequest.last_name)
expect(rendered).to have_link(href: "mailto:#{@aRequest.email}")
expect(rendered).to have_text(@aRequest.phone_number)
expect(rendered).to have_text(@aRequest.street)
expect(rendered).to have_text(@aRequest.school_street)
expect(rendered).to have_text(@aRequest.time_period)
expect(rendered).to have_text(@aRequest.knowledge_level)
expect(rendered).to have_text(@aRequest.zip_code_city)
expect(rendered).to have_text(@aRequest.school_zip_code_city)
expect(rendered).to have_text(@aRequest.contact_person)
expect(rendered).to have_text(@aRequest.number_of_participants)
expect(rendered).to have_text(@aRequest.grade)
expect(rendered).to have_text(I18n.t(@aRequest.status, scope: 'activerecord.attributes.request.statuses'))
end

Expand Down

0 comments on commit 644bb61

Please sign in to comment.