Skip to content

Commit

Permalink
Merge branch 'dev' into fix-add-default-value-to-application-status-m…
Browse files Browse the repository at this point in the history
…igration
  • Loading branch information
cmfcmf committed Dec 2, 2016
2 parents 6b8ff5a + 910150e commit a1301ef
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 6 deletions.
2 changes: 1 addition & 1 deletion app/controllers/events_controller.rb
Expand Up @@ -91,6 +91,6 @@ def date_from_form(date_info)

# Only allow a trusted parameter "white list" through.
def event_params
params.require(:event).permit(:name, :description, :max_participants, :active, :organizer, :knowledge_level)
params.require(:event).permit(:name, :description, :max_participants, :active, :kind, :organizer, :knowledge_level)
end
end
2 changes: 2 additions & 0 deletions app/models/event.rb
Expand Up @@ -69,6 +69,8 @@ def agreement_letter_for(user)
self.agreement_letters.where(user: user).take
end

enum kind: [ :workshop, :camp ]

# Returns the number of free places of the event, this value may be negative
#
# @param none
Expand Down
12 changes: 12 additions & 0 deletions app/views/events/_form.html.erb
Expand Up @@ -20,6 +20,18 @@
</div>
<% end %>

<div class="form-group">
<div class="btn-group col-lg-10 col-lg-offset-2" data-toggle="buttons">
<% Event.kinds.keys.each do |key| %>
<label class="btn btn-default <%= 'active' if @event.kind == key %>">
<%= f.radio_button :kind, key %>
<%= key.humanize %>
</label>
<% end %>
</div>
<%=f.error_span(:kind) %>
</div>

<div class="form-group">
<%= f.label :name, :class => 'control-label col-lg-2' %>
<div class="col-lg-10">
Expand Down
2 changes: 1 addition & 1 deletion app/views/events/show.html.erb
@@ -1,6 +1,6 @@
<%- model_class = Event -%>
<div class="page-header">
<h1><%= t '.title', :default => model_class.model_name.human.titleize %></h1>
<h1><%=t '.title', :default => model_class.model_name.human.titleize %> (<%= @event.kind.humanize %>)</h1>
</div>

<% if @event.unreasonably_long %>
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20161126113138_add_kind_to_events.rb
@@ -0,0 +1,5 @@
class AddKindToEvents < ActiveRecord::Migration
def change
add_column :events, :kind, :integer, default: 0
end
end
5 changes: 3 additions & 2 deletions db/schema.rb
Expand Up @@ -68,8 +68,9 @@
t.string "description"
t.integer "max_participants"
t.boolean "active"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "kind", default: 0
t.string "organizer"
t.string "knowledge_level"
end
Expand Down
6 changes: 5 additions & 1 deletion spec/controllers/events_controller_spec.rb
Expand Up @@ -47,8 +47,12 @@
}
}

# This should return the minimal set of attributes required to create a valid
# Event. As you add validations to Event, be sure to
# adjust the attributes here as well.
let(:valid_attributes) { FactoryGirl.attributes_for(:event) }
let(:invalid_attributes) { FactoryGirl.build(:event, max_participants: "twelve").attributes }

let(:invalid_attributes) { FactoryGirl.attributes_for(:event, max_participants: "twelve") }

let(:valid_attributes_for_having_participants) { FactoryGirl.attributes_for(:event_with_accepted_applications) }
# This should return the minimal set of values that should be in the session
Expand Down
3 changes: 2 additions & 1 deletion spec/factories/events.rb
Expand Up @@ -16,7 +16,8 @@
factory :event do
name "Event-Name"
description "Event-Description"
max_participants 100
max_participants 1
kind :workshop
active false
organizer "Workshop-Organizer"
knowledge_level "Workshop-Knowledge Level"
Expand Down
24 changes: 24 additions & 0 deletions spec/features/event_spec.rb
Expand Up @@ -2,6 +2,16 @@

describe "Event", type: :feature do
describe "create page" do
['Camp', 'Workshop'].each do |kind|
it "should allow picking the #{kind} kind camp" do
visit new_event_path
fill_in "Maximale Teilnehmerzahl", :with => 25
choose(kind)
click_button "Veranstaltung erstellen"
expect(page).to have_text(kind)
end
end

it "should not allow dates in the past" do
visit new_event_path
select_date_within_selector(Date.yesterday.prev_day, '.event-date-picker-start')
Expand Down Expand Up @@ -30,6 +40,14 @@
end

describe "show page" do
it "should display the event kind" do
%i[camp workshop].each do |kind|
event = FactoryGirl.create(:event, kind: kind)
visit event_path(event)
expect(page).to have_text(kind.to_s.humanize)
end
end

it "should display all date ranges" do
event = FactoryGirl.create(:event, :with_two_date_ranges)
visit event_path(event.id)
Expand All @@ -42,6 +60,12 @@
end

describe "edit page" do
it "should preselect the event kind" do
event = FactoryGirl.create(:event, kind: :camp)
visit edit_event_path(event)
expect(find_field('Camp')[:checked]).to_not be_nil
end

it "should display all existing date ranges" do
event = FactoryGirl.create(:event, :with_two_date_ranges)
visit edit_event_path(event.id)
Expand Down
10 changes: 10 additions & 0 deletions spec/models/event_spec.rb
Expand Up @@ -21,6 +21,16 @@
expect(event).to be_valid
end

it "is either a camp or a workshop" do
expect { FactoryGirl.build(:event, kind: :smth_invalid) }.to raise_error(ArgumentError)

event = FactoryGirl.build(:event, kind: :camp)
expect(event).to be_valid

event = FactoryGirl.build(:event, kind: :workshop)
expect(event).to be_valid
end

it "should have one or more date-ranges" do

#checking if the event model can handle date_ranges
Expand Down

0 comments on commit a1301ef

Please sign in to comment.