diff --git a/app/controllers/tracks_controller.rb b/app/controllers/tracks_controller.rb index 9305950e..6b584d22 100644 --- a/app/controllers/tracks_controller.rb +++ b/app/controllers/tracks_controller.rb @@ -53,7 +53,7 @@ class TracksController < ApplicationController private def track_params - params.require(:track).permit(:name, :description, :color, :short_name, :start_date, :end_date) + params.require(:track).permit(:name, :description, :color, :short_name, :start_date, :end_date, :relevance) end def update_state(transition, notice) diff --git a/app/models/track.rb b/app/models/track.rb index 5fb37549..2b09b654 100644 --- a/app/models/track.rb +++ b/app/models/track.rb @@ -27,6 +27,7 @@ class Track < ActiveRecord::Base validates :start_date, presence: true, if: :self_organized_and_accepted_or_confirmed? validates :end_date, presence: true, if: :self_organized_and_accepted_or_confirmed? validates :room, presence: true, if: :self_organized_and_accepted_or_confirmed? + validates :relevance, presence: true, if: :self_organized? validate :valid_dates validate :valid_room, if: :self_organized_and_accepted_or_confirmed? diff --git a/app/views/admin/tracks/show.html.haml b/app/views/admin/tracks/show.html.haml index 5e45d3a5..a8c13d9d 100644 --- a/app/views/admin/tracks/show.html.haml +++ b/app/views/admin/tracks/show.html.haml @@ -92,6 +92,12 @@ %b Description %td = markdown(@track.description) + - if @track.self_organized? + %tr + %td + %b Relevance + %td + = markdown(@track.relevance) .tab-pane#events .col-md-12 diff --git a/app/views/tracks/_form.html.haml b/app/views/tracks/_form.html.haml index 31e9deaf..ab693dc5 100644 --- a/app/views/tracks/_form.html.haml +++ b/app/views/tracks/_form.html.haml @@ -16,4 +16,5 @@ = f.input :start_date, as: :string, input_html: { id: 'registration-period-start-datepicker', start_date: @conference.start_date, end_date: @conference.end_date, readonly: 'readonly' } = f.input :end_date, as: :string, input_html: { id: 'registration-period-end-datepicker', readonly: 'readonly' } = f.input :description, input_html: {rows: 2, data: { provide: 'markdown-editable' } }, required: true, hint: "This will be public #{markdown_hint}".html_safe + = f.input :relevance, input_html: {rows: 5, data: { provide: 'markdown-editable' } }, required: true, hint: "Please explain here how this track relates to the conference, how you are related to it's content and why we should accept it. #{markdown_hint}".html_safe = f.action :submit, as: :button, button_html: { class: 'btn btn-primary' } diff --git a/app/views/tracks/show.html.haml b/app/views/tracks/show.html.haml index db437878..6014f23e 100644 --- a/app/views/tracks/show.html.haml +++ b/app/views/tracks/show.html.haml @@ -39,3 +39,7 @@ Description %dd = markdown(@track.description) + %dt + Relevance + %dd + = markdown(@track.relevance) diff --git a/db/migrate/20170726065629_add_relevance_to_tracks.rb b/db/migrate/20170726065629_add_relevance_to_tracks.rb new file mode 100644 index 00000000..215200c1 --- /dev/null +++ b/db/migrate/20170726065629_add_relevance_to_tracks.rb @@ -0,0 +1,5 @@ +class AddRelevanceToTracks < ActiveRecord::Migration + def change + add_column :tracks, :relevance, :text + end +end diff --git a/db/schema.rb b/db/schema.rb index f8cc3ddc..9e6123a3 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -525,6 +525,7 @@ ActiveRecord::Schema.define(version: 20170807092805) do t.integer "room_id" t.date "start_date" t.date "end_date" + t.text "relevance" end add_index "tracks", ["room_id"], name: "index_tracks_on_room_id" diff --git a/spec/controllers/tracks_controller_spec.rb b/spec/controllers/tracks_controller_spec.rb index 0e3a0553..a555dba8 100644 --- a/spec/controllers/tracks_controller_spec.rb +++ b/spec/controllers/tracks_controller_spec.rb @@ -60,7 +60,7 @@ describe TracksController do describe 'POST #create' do context 'saves successfuly' do before :each do - post :create, track: attributes_for(:track, short_name: 'my_track'), conference_id: conference.short_title + post :create, track: attributes_for(:track, :self_organized, short_name: 'my_track'), conference_id: conference.short_title end it 'redirects to tracks index path' do @@ -86,7 +86,7 @@ describe TracksController do context 'save fails' do before :each do allow_any_instance_of(Track).to receive(:save).and_return(false) - post :create, track: attributes_for(:track, short_name: 'my_track'), conference_id: conference.short_title + post :create, track: attributes_for(:track, :self_organized, short_name: 'my_track'), conference_id: conference.short_title end it 'assigns a new track with the correct conference' do @@ -126,7 +126,7 @@ describe TracksController do describe 'PATCH #update' do context 'updates successfully' do before :each do - patch :update, track: attributes_for(:track, color: '#FF0000'), + patch :update, track: attributes_for(:track, :self_organized, color: '#FF0000'), conference_id: conference.short_title, id: self_organized_track.short_name end @@ -152,7 +152,7 @@ describe TracksController do context 'update fails' do before :each do allow_any_instance_of(Track).to receive(:save).and_return(false) - patch :update, track: attributes_for(:track, color: '#FF0000'), + patch :update, track: attributes_for(:track, :self_organized, color: '#FF0000'), conference_id: conference.short_title, id: self_organized_track.short_name end diff --git a/spec/factories/tracks.rb b/spec/factories/tracks.rb index d61c9a1b..3c0042f2 100644 --- a/spec/factories/tracks.rb +++ b/spec/factories/tracks.rb @@ -15,6 +15,7 @@ FactoryGirl.define do start_date { Date.today } end_date { Date.today } room + relevance { Faker::Hipster.paragraph(2) } end end end diff --git a/spec/models/track_spec.rb b/spec/models/track_spec.rb index 158c6140..ed058176 100644 --- a/spec/models/track_spec.rb +++ b/spec/models/track_spec.rb @@ -48,6 +48,22 @@ describe Track do it { is_expected.to_not validate_presence_of(:room) } end + context 'when self_organized? returns true' do + before :each do + allow(subject).to receive(:self_organized?).and_return(true) + end + + it { is_expected.to validate_presence_of(:relevance) } + end + + context 'when self_organized? returns false' do + before :each do + allow(subject).to receive(:self_organized?).and_return(false) + end + + it { is_expected.to_not validate_presence_of(:relevance) } + end + describe '#valid_dates' do before :each do @conference = create(:conference, start_date: 1.day.ago, end_date: 2.days.from_now)