diff --git a/app/controllers/workshops_controller.rb b/app/controllers/workshops_controller.rb new file mode 100644 index 0000000..34d8da9 --- /dev/null +++ b/app/controllers/workshops_controller.rb @@ -0,0 +1,46 @@ +class WorkshopsController < ApplicationController + before_filter :authenticate_user! + before_action :assign_lecture, only: [:show, :edit, :update] + + def index + @workshops = Workshop.where user: current_user + end + + def new + @workshop = Workshop.new + end + + def create + @workshop = current_user.workshops.build workshop_params + + if @workshop.save + redirect_to @workshop + else + render :new, status: :unprocessable_entity + end + end + + def edit + end + + def update + if @workshop.update workshop_params + redirect_to @workshop + else + render :edit, status: :unprocessable_entity + end + end + + def show + end + + private + + def assign_workshop + @workshop = Workshop.find params[:id] + end + + def workshop_params + params.require(:workshop).permit [:title, :subtitle, :length, :language, :abstract, :description, :notes, :track_id] + end +end diff --git a/app/views/home/index.html.slim b/app/views/home/index.html.slim index 46bff6f..ad83144 100644 --- a/app/views/home/index.html.slim +++ b/app/views/home/index.html.slim @@ -11,4 +11,5 @@ ul .centered = link_to 'Предложи лекция', new_lecture_path - button type="button" Предложи уъркшоп + + = link_to 'Предложи уъркшоп', new_workshop_path diff --git a/app/views/layouts/_nav.html.erb b/app/views/layouts/_nav.html.erb index bc5ecf2..2910ab5 100644 --- a/app/views/layouts/_nav.html.erb +++ b/app/views/layouts/_nav.html.erb @@ -12,6 +12,9 @@ <%= content_tag :li, class: [('current_page_item' if controller_name == 'lectures')] do %> <%= link_to "Лекции", lectures_path %> <% end %> + <%= content_tag :li, class: [('current_page_item' if controller_name == 'workshops')] do %> + <%= link_to "Уъркшопи", workshops_path %> + <% end %> <%= content_tag :li, class: [('current_page_item' if controller_name == 'registrations')] do %> <%= link_to "Редакция на профил", edit_user_registration_path %> <% end %> diff --git a/app/views/workshops/_form.html.slim b/app/views/workshops/_form.html.slim new file mode 100644 index 0000000..d4c5026 --- /dev/null +++ b/app/views/workshops/_form.html.slim @@ -0,0 +1,14 @@ +== simple_form_for @workshop do |form| + p + = form.error_notification + + .form-inputs + = form.input :title, autofocus: true + = form.input :subtitle + = form.association :track + = form.input :length, input_html: {value: 60} + = form.input :language, collection: I18n.available_locales, include_blank: false, default: I18n.locale + = form.input :abstract + = form.input :description + = form.input :notes + = form.button :submit diff --git a/app/views/workshops/edit.html.slim b/app/views/workshops/edit.html.slim new file mode 100644 index 0000000..febda47 --- /dev/null +++ b/app/views/workshops/edit.html.slim @@ -0,0 +1,2 @@ +h1.entry-title Редакция на уъркшоп += render 'form' diff --git a/app/views/workshops/index.html.slim b/app/views/workshops/index.html.slim new file mode 100644 index 0000000..b9ba7be --- /dev/null +++ b/app/views/workshops/index.html.slim @@ -0,0 +1,7 @@ +h1.entry-title Моите предложения за уъркшопи + +ul + - for workshop in @workshops + li = link_to workshop.title, workshop + += link_to 'Предложи уъркшоп', new_workshop_path diff --git a/app/views/workshops/new.html.slim b/app/views/workshops/new.html.slim new file mode 100644 index 0000000..b4c5d2f --- /dev/null +++ b/app/views/workshops/new.html.slim @@ -0,0 +1,2 @@ +h1.entry-title Предложи нов уъркшоп += render 'form' diff --git a/app/views/workshops/show.html.slim b/app/views/workshops/show.html.slim new file mode 100644 index 0000000..6cbdf39 --- /dev/null +++ b/app/views/workshops/show.html.slim @@ -0,0 +1,20 @@ +h1.entry-title Преглед на уъркшоп + +h2.workshop-title + = @workshop.title + span.subtitle = @workshop.subtitle + .entry-meta + | + поток: „#{@workshop.track.name}“, + продължителност: #{@workshop.length} мин. + +section.abstract + h3 Резюме + = simple_format @workshop.abstract + +section.description + h3 Описание + = simple_format @workshop.description + +- if current_user == @workshop.user + = link_to 'Редактирай', edit_workshop_path(@workshop) diff --git a/config/locales/bg.yml b/config/locales/bg.yml index abcbc92..f26b51b 100644 --- a/config/locales/bg.yml +++ b/config/locales/bg.yml @@ -25,6 +25,9 @@ bg: lecture: one: Лекция other: Лекции + workshop: + one: Уъркшоп + other: Уъркшопи track: Поток от лекции attributes: lecture: @@ -36,6 +39,15 @@ bg: description: Описание notes: Забележки track: Поток от лекции + workshop: + title: Заглавие + subtitle: Подзаглавие + length: Продължителност + language: Език + abstract: Резюме + description: Описание + notes: Забележки + track: Поток от лекции errors: messages: improbable_phone: 'не е валиден телефонен номер' \ No newline at end of file diff --git a/config/locales/simple_form.bg.yml b/config/locales/simple_form.bg.yml index 13766d4..4641608 100644 --- a/config/locales/simple_form.bg.yml +++ b/config/locales/simple_form.bg.yml @@ -16,4 +16,13 @@ bg: language: Език, на който ще бъде водена лекцията abstract: Резюме на лекцията, което да може да бъде прочетено от посетителите description: Подробно описание на лекцията, което да бъде използвано от организаторския екип + notes: Забележки, които искате да споделите с организаторския екип + workshop: + title: Заглавието на уъркшопа Ви + subtitle: Подзаглавието на уъркшопа Ви (ако има такова) + track: Потокът от уъркшопи, в който искате да попадне уъркшопа Ви + length: Продължителността на уъркшоп може да бъде от 30 до 120 минути + language: Език, на който ще бъде воден уъркшопа + abstract: Резюме на уъркшопа, което да може да бъде прочетено от посетителите + description: Подробно описание на уъркшопа, което да бъде използвано от организаторския екип notes: Забележки, които искате да споделите с организаторския екип \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 6b707c3..65c7913 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,5 +1,6 @@ Rails.application.routes.draw do resources :lectures, only: [:index, :new, :create, :edit, :update, :show] + resources :workshops, only: [:index, :new, :create, :edit, :update, :show] devise_for :users diff --git a/spec/controllers/workshops_controller_spec.rb b/spec/controllers/workshops_controller_spec.rb new file mode 100644 index 0000000..34a528f --- /dev/null +++ b/spec/controllers/workshops_controller_spec.rb @@ -0,0 +1,78 @@ +require 'rails_helper' + +RSpec.describe WorkshopsController, type: :controller do + let(:user) { create :user, confirmed_at: Time.now } + + before do + sign_in user + end + + describe 'GET index' do + it 'returns HTTP Success status code' + it 'assigns the workshops of the current user to @workshops' + end + + describe 'GET new' do + it 'returns HTTP Success status code' do + get :new + expect(response).to be_success + end + + it 'assigns a blank workshop to @workshop' + end + + describe 'POST create' do + it 'assigns the new workshop to @workshop' + + context 'when passed correct parameters' do + it 'creates a new workshop' + it 'redirects to the created workshop' + end + + context 'when passed incorrect parameters' do + it 'renders the edit template' + it 'returns HTTP Unprocessable Entity status code' + end + end + + describe 'GET edit' do + context 'when the workshop exists' do + it 'returns http success' + it 'assigns the workshop to @workshop' + end + + context 'when the workshop does not exist' do + it 'returns HTTP Not Found status code' + end + end + + describe 'PUT update' do + context 'when the workshop does not exist' do + it 'returns HTTP Not Found status code' + end + + context 'when the workshop exists' do + it 'assigns the workshop to @workshop' + + context 'when passed correct parameters' do + it 'redirects to the updated workshop' + end + + context 'when passed incorrect parameters' do + it 'renders the edit template' + it 'returns HTTP Unprocessable Entity status code' + end + end + end + + describe 'GET show' do + context 'when the workshop exists' do + it 'returns HTTP Success status code' + it 'assigns the workshop to @workshop' + end + + context 'when the workshop does not exist' do + it 'returns HTTP Not Found status code' + end + end +end