From fa63c14e4717aa1fcdb2d1ee6099b7912a33214d Mon Sep 17 00:00:00 2001 From: Petko Bordjukov Date: Sun, 10 Aug 2014 22:05:25 +0300 Subject: [PATCH 01/10] Add current and future scopes for Conference --- app/models/conference.rb | 3 +++ spec/factories/conferences.rb | 10 ++++++++++ spec/models/conference_spec.rb | 14 ++++++++++++++ 3 files changed, 27 insertions(+) diff --git a/app/models/conference.rb b/app/models/conference.rb index 37a2107..05f7d18 100644 --- a/app/models/conference.rb +++ b/app/models/conference.rb @@ -9,6 +9,9 @@ class Conference < ActiveRecord::Base has_many :tracks has_many :events, through: :tracks + scope :future, -> { where 'start_date >= ?', Date.today } + scope :current, -> { future.first || last } + private def end_date_is_before_start_date diff --git a/spec/factories/conferences.rb b/spec/factories/conferences.rb index 0cb8c16..457a71d 100644 --- a/spec/factories/conferences.rb +++ b/spec/factories/conferences.rb @@ -7,5 +7,15 @@ FactoryGirl.define do description 'MyText' start_date '2014-07-29 21:29:13' end_date '2014-07-31 21:29:13' + + factory :past_conference do + start_date Date.today - 10.days + end_date Date.today - 5.days + end + + factory :future_conference do + start_date Date.today + 5.days + end_date Date.today + 10.days + end end end diff --git a/spec/models/conference_spec.rb b/spec/models/conference_spec.rb index 2294fd0..ab32526 100644 --- a/spec/models/conference_spec.rb +++ b/spec/models/conference_spec.rb @@ -39,4 +39,18 @@ RSpec.describe Conference, :type => :model do it 'is invalid when the end date is before the start date' do expect(build(:conference, start_date: '2014-07-29 21:29:13', end_date: '2014-07-28 01:00:00')).to have_error_on :end_date end + + describe '::current' do + it 'returns the next conference if there is one' do + create :past_conference + conference = create :future_conference + create :future_conference, start_date: Date.today + 100.years, end_date: Date.today + 150.years + expect(Conference.current).to eq conference + end + + it 'returns the last conference if there is no future conference' do + conference = create :past_conference + expect(Conference.current).to eq conference + end + end end -- 2.40.1 From df7317c7468f929262bf0367bbbf142c72d297ab Mon Sep 17 00:00:00 2001 From: Petko Bordjukov Date: Sun, 10 Aug 2014 23:50:44 +0300 Subject: [PATCH 02/10] Initial implementation of the LecturesController --- app/controllers/lectures_controller.rb | 18 ++++++++ app/views/lectures/_form.html.slim | 14 ++++++ app/views/lectures/create.html.slim | 2 + app/views/lectures/edit.html.slim | 2 + app/views/lectures/new.html.slim | 2 + app/views/lectures/show.html.slim | 2 + app/views/lectures/update.html.slim | 2 + config/locales/bg.yml | 17 +++++++- config/locales/simple_form.bg.yml | 12 +++++- config/routes.rb | 2 +- spec/controllers/lectures_controller_spec.rb | 45 ++++++++++++++++++++ 11 files changed, 115 insertions(+), 3 deletions(-) create mode 100644 app/controllers/lectures_controller.rb create mode 100644 app/views/lectures/_form.html.slim create mode 100644 app/views/lectures/create.html.slim create mode 100644 app/views/lectures/edit.html.slim create mode 100644 app/views/lectures/new.html.slim create mode 100644 app/views/lectures/show.html.slim create mode 100644 app/views/lectures/update.html.slim create mode 100644 spec/controllers/lectures_controller_spec.rb diff --git a/app/controllers/lectures_controller.rb b/app/controllers/lectures_controller.rb new file mode 100644 index 0000000..1a32a6c --- /dev/null +++ b/app/controllers/lectures_controller.rb @@ -0,0 +1,18 @@ +class LecturesController < ApplicationController + def new + @lecture = Lecture.new + end + + def create + head :created + end + + def edit + end + + def update + end + + def show + end +end diff --git a/app/views/lectures/_form.html.slim b/app/views/lectures/_form.html.slim new file mode 100644 index 0000000..50db059 --- /dev/null +++ b/app/views/lectures/_form.html.slim @@ -0,0 +1,14 @@ +== simple_form_for @lecture do |form| + p + = form.error_notification + + .form-inputs + = form.input :title, autofocus: true + = form.input :subtitle + = form.association :track + = form.input :length + = 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/lectures/create.html.slim b/app/views/lectures/create.html.slim new file mode 100644 index 0000000..7ded307 --- /dev/null +++ b/app/views/lectures/create.html.slim @@ -0,0 +1,2 @@ +h1 Lectures#create +p Find me in app/views/lectures/create.html.slim diff --git a/app/views/lectures/edit.html.slim b/app/views/lectures/edit.html.slim new file mode 100644 index 0000000..8963bd0 --- /dev/null +++ b/app/views/lectures/edit.html.slim @@ -0,0 +1,2 @@ +h1 Lectures#edit +p Find me in app/views/lectures/edit.html.slim diff --git a/app/views/lectures/new.html.slim b/app/views/lectures/new.html.slim new file mode 100644 index 0000000..db3d176 --- /dev/null +++ b/app/views/lectures/new.html.slim @@ -0,0 +1,2 @@ +h1 Предложи нова лекция += render 'form' diff --git a/app/views/lectures/show.html.slim b/app/views/lectures/show.html.slim new file mode 100644 index 0000000..4ff9a4e --- /dev/null +++ b/app/views/lectures/show.html.slim @@ -0,0 +1,2 @@ +h1 Lectures#show +p Find me in app/views/lectures/show.html.slim diff --git a/app/views/lectures/update.html.slim b/app/views/lectures/update.html.slim new file mode 100644 index 0000000..9eb4837 --- /dev/null +++ b/app/views/lectures/update.html.slim @@ -0,0 +1,2 @@ +h1 Lectures#update +p Find me in app/views/lectures/update.html.slim diff --git a/config/locales/bg.yml b/config/locales/bg.yml index c9472f4..abcbc92 100644 --- a/config/locales/bg.yml +++ b/config/locales/bg.yml @@ -20,7 +20,22 @@ # available at http://guides.rubyonrails.org/i18n.html. bg: - hello: "Здравей, свят" + activerecord: + models: + lecture: + one: Лекция + other: Лекции + track: Поток от лекции + attributes: + lecture: + 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 23ff75d..13766d4 100644 --- a/config/locales/simple_form.bg.yml +++ b/config/locales/simple_form.bg.yml @@ -6,4 +6,14 @@ bg: text: 'Задължително поле' mark: '*' error_notification: - default_message: "Моля разгледайте проблемите по-долу:" \ No newline at end of file + default_message: "Моля разгледайте проблемите по-долу:" + hints: + lecture: + title: Заглавието на лекцията Ви + subtitle: Подзаглавието на лекцията Ви (ако има такова) + track: Потокът от лекции, в който искате да попадне лекцията Ви + length: Продължителността на лекция може да бъде от 40 до 45 минути + language: Език, на който ще бъде водена лекцията + abstract: Резюме на лекцията, което да може да бъде прочетено от посетителите + description: Подробно описание на лекцията, което да бъде използвано от организаторския екип + notes: Забележки, които искате да споделите с организаторския екип \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 03b07dc..a08d41f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,5 +1,5 @@ Rails.application.routes.draw do - get 'home/index' + resources :lectures, only: [:new, :create, :edit, :update, :show] devise_for :users diff --git a/spec/controllers/lectures_controller_spec.rb b/spec/controllers/lectures_controller_spec.rb new file mode 100644 index 0000000..7602c72 --- /dev/null +++ b/spec/controllers/lectures_controller_spec.rb @@ -0,0 +1,45 @@ +require 'rails_helper' + +RSpec.describe LecturesController, :type => :controller do + + describe "GET new" do + it "returns http success" do + get :new + expect(response).to be_success + end + end + + describe "POST create" do + it "returns http success" do + new_track = create :track + new_user = create :user + + post :create, lecture: build(:lecture, track: new_track, user: new_user).attributes + expect(response.status).to eq 201 + end + end + + describe "GET edit" do + it "returns http success" do + event = create :lecture + get :edit, id: event.id + expect(response).to be_success + end + end + + describe "PUT update" do + it "returns http success" do + event = create :lecture + put :update, id: event.id, lecture: event.attributes + expect(response).to be_success + end + end + + describe "GET show" do + it "returns http success" do + event = create :lecture + get :show, id: event.id + expect(response).to be_success + end + end +end -- 2.40.1 From a02ac5d7e2c7d3b30d10e77eea9990bd71ded73e Mon Sep 17 00:00:00 2001 From: Petko Bordjukov Date: Tue, 12 Aug 2014 16:37:25 +0300 Subject: [PATCH 03/10] Form styling by @krasimir --- app/assets/stylesheets/forms.css.scss | 74 +++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 app/assets/stylesheets/forms.css.scss diff --git a/app/assets/stylesheets/forms.css.scss b/app/assets/stylesheets/forms.css.scss new file mode 100644 index 0000000..0a51e9d --- /dev/null +++ b/app/assets/stylesheets/forms.css.scss @@ -0,0 +1,74 @@ +#main { + font-size: 16px; +} +h1 { + margin: 0 0 1em 0; + font-size: 2em; +} +.input { + position: relative; + margin: 0 0 1em 0; + border-top: 0.1em dotted #999; + padding: 1em 0; +} +.input label { + font-size: 1em; + display: block; + width: 12em; + float: left; +} +.input input, .input textarea, .input select { + font-size: 1em; + width: 20em; + float: left; +} +.input textarea { + height: 8em; +} +.input .hint, .input .error { + display: block; + clear: both; + font-size: 0.75em; + font-style: italic; + width: 20em; + margin: 0 0 0 16em; + padding: 1em 0 0 0; +} +.input .error { + font-style: normal; + padding: 1em 0 0 0; + color: #F00; +} +.input .error::before { + content: "⇧"; + display: inline-block; + font-size: 2em; + margin: 0 0.2em 0 0; + transform: translate(0, 0.1em); +} +.btn { + display: block; + margin: 2em 0 0 13em; +} + +/* styling of the button */ +.btn { + background: #233e83; + padding: 0.4em 0.8em; + border-radius: 0.2em; + color: #FFF; + border: none; + border-bottom: 0.2em solid #7A95DC; + cursor: pointer; + transition: background 200ms, border 200ms, transform 200ms; + -webkit-transition: background 200ms, border 200ms, transform 200ms; +} +.btn:hover { + background: #152551; +} +.btn:active { + background: #597AD2; + border-bottom: 0.2em solid #000; + transform: translate(0, 0.1em); + -webkit-transform: translate(0, 0.1em); +} -- 2.40.1 From 0db959bf8484368409e479ea89a778e1c88a5160 Mon Sep 17 00:00:00 2001 From: Petko Bordjukov Date: Sat, 30 Aug 2014 16:05:29 +0300 Subject: [PATCH 04/10] Update the bundle --- Gemfile | 2 +- Gemfile.lock | 80 ++++++++++++++++++++++++++-------------------------- 2 files changed, 41 insertions(+), 41 deletions(-) diff --git a/Gemfile b/Gemfile index 0310d89..d09fcca 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,6 @@ source 'https://rubygems.org' -gem 'rails', '4.1.4' +gem 'rails', '4.1.5' gem 'sqlite3' gem 'pg' diff --git a/Gemfile.lock b/Gemfile.lock index 64602a0..2c5503c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,27 +1,27 @@ GEM remote: https://rubygems.org/ specs: - actionmailer (4.1.4) - actionpack (= 4.1.4) - actionview (= 4.1.4) + actionmailer (4.1.5) + actionpack (= 4.1.5) + actionview (= 4.1.5) mail (~> 2.5.4) - actionpack (4.1.4) - actionview (= 4.1.4) - activesupport (= 4.1.4) + actionpack (4.1.5) + actionview (= 4.1.5) + activesupport (= 4.1.5) rack (~> 1.5.2) rack-test (~> 0.6.2) - actionview (4.1.4) - activesupport (= 4.1.4) + actionview (4.1.5) + activesupport (= 4.1.5) builder (~> 3.1) erubis (~> 2.7.0) - activemodel (4.1.4) - activesupport (= 4.1.4) + activemodel (4.1.5) + activesupport (= 4.1.5) builder (~> 3.1) - activerecord (4.1.4) - activemodel (= 4.1.4) - activesupport (= 4.1.4) + activerecord (4.1.5) + activemodel (= 4.1.5) + activesupport (= 4.1.5) arel (~> 5.0.0) - activesupport (4.1.4) + activesupport (4.1.5) i18n (~> 0.6, >= 0.6.9) json (~> 1.7, >= 1.7.7) minitest (~> 5.1) @@ -46,17 +46,17 @@ GEM coffee-script (2.3.0) coffee-script-source execjs - coffee-script-source (1.7.1) + coffee-script-source (1.8.0) countries (0.9.3) currencies (~> 0.4.2) currencies (0.4.2) - devise (3.2.4) + devise (3.3.0) bcrypt (~> 3.0) orm_adapter (~> 0.1) railties (>= 3.2.6, < 5) thread_safe (~> 0.1) warden (~> 1.2.3) - devise-i18n (0.10.3) + devise-i18n (0.11.0) diff-lcs (1.2.5) erubis (2.7.0) execjs (2.2.1) @@ -65,7 +65,7 @@ GEM factory_girl_rails (4.4.1) factory_girl (~> 4.4.0) railties (>= 3.0.0) - faker (1.4.2) + faker (1.4.3) i18n (~> 0.5) ffi (1.9.3) formatador (0.2.5) @@ -75,7 +75,7 @@ GEM lumberjack (~> 1.0) pry (>= 0.9.12) thor (>= 0.18.1) - guard-rspec (4.2.10) + guard-rspec (4.3.1) guard (~> 2.1) rspec (>= 2.14, < 4.0) hike (1.2.3) @@ -96,34 +96,34 @@ GEM method_source (0.8.2) mime-types (1.25.1) mini_portile (0.6.0) - minitest (5.4.0) + minitest (5.4.1) multi_json (1.10.1) nokogiri (1.6.3.1) mini_portile (= 0.6.0) orm_adapter (0.5.0) pg (0.17.1) - phony (2.2.14) - phony_rails (0.6.1) + phony (2.2.15) + phony_rails (0.6.2) activesupport (>= 3.0) countries (>= 0.8.2) phony (~> 2.1) polyglot (0.3.5) - pry (0.10.0) + pry (0.10.1) coderay (~> 1.1.0) method_source (~> 0.8.1) slop (~> 3.4) rack (1.5.2) rack-test (0.6.2) rack (>= 1.0) - rails (4.1.4) - actionmailer (= 4.1.4) - actionpack (= 4.1.4) - actionview (= 4.1.4) - activemodel (= 4.1.4) - activerecord (= 4.1.4) - activesupport (= 4.1.4) + rails (4.1.5) + actionmailer (= 4.1.5) + actionpack (= 4.1.5) + actionview (= 4.1.5) + activemodel (= 4.1.5) + activerecord (= 4.1.5) + activesupport (= 4.1.5) bundler (>= 1.3.0, < 2.0) - railties (= 4.1.4) + railties (= 4.1.5) sprockets-rails (~> 2.0) rails-erd (1.1.0) activerecord (>= 3.0) @@ -133,9 +133,9 @@ GEM rails-i18n (4.0.2) i18n (~> 0.6) rails (>= 4.0) - railties (4.1.4) - actionpack (= 4.1.4) - activesupport (= 4.1.4) + railties (4.1.5) + actionpack (= 4.1.5) + activesupport (= 4.1.5) rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) rake (10.3.2) @@ -147,12 +147,12 @@ GEM rspec-core (~> 3.0.0) rspec-expectations (~> 3.0.0) rspec-mocks (~> 3.0.0) - rspec-core (3.0.3) + rspec-core (3.0.4) rspec-support (~> 3.0.0) - rspec-expectations (3.0.3) + rspec-expectations (3.0.4) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.0.0) - rspec-mocks (3.0.3) + rspec-mocks (3.0.4) rspec-support (~> 3.0.0) rspec-rails (3.0.2) actionpack (>= 3.0) @@ -162,7 +162,7 @@ GEM rspec-expectations (~> 3.0.0) rspec-mocks (~> 3.0.0) rspec-support (~> 3.0.0) - rspec-support (3.0.3) + rspec-support (3.0.4) ruby-graphviz (1.0.9) sass (3.2.19) sass-rails (4.0.3) @@ -206,7 +206,7 @@ GEM treetop (1.4.15) polyglot polyglot (>= 0.3.1) - tzinfo (1.2.1) + tzinfo (1.2.2) thread_safe (~> 0.1) uglifier (2.5.3) execjs (>= 0.3.0) @@ -230,7 +230,7 @@ DEPENDENCIES jquery-rails pg phony_rails - rails (= 4.1.4) + rails (= 4.1.5) rails-erd rails-i18n rspec-rails -- 2.40.1 From 0190ee077f06c674242ab67d5a0b39e6a49bb0d0 Mon Sep 17 00:00:00 2001 From: Petko Bordjukov Date: Sat, 30 Aug 2014 16:58:42 +0300 Subject: [PATCH 05/10] Make the home page dynamic --- app/controllers/home_controller.rb | 1 + app/models/conference.rb | 7 +++++-- app/views/home/index.html.slim | 19 +++++-------------- 3 files changed, 11 insertions(+), 16 deletions(-) diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index 95f2992..9536d39 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -1,4 +1,5 @@ class HomeController < ApplicationController def index + @current_conference = Conference.current || Conference.new end end diff --git a/app/models/conference.rb b/app/models/conference.rb index 05f7d18..145b427 100644 --- a/app/models/conference.rb +++ b/app/models/conference.rb @@ -9,8 +9,11 @@ class Conference < ActiveRecord::Base has_many :tracks has_many :events, through: :tracks - scope :future, -> { where 'start_date >= ?', Date.today } - scope :current, -> { future.first || last } + scope :future, -> { where('start_date >= ?', Date.today).order('start_date ASC') } + + def self.current + future.first || last + end private diff --git a/app/views/home/index.html.slim b/app/views/home/index.html.slim index ef4b05e..46bff6f 100644 --- a/app/views/home/index.html.slim +++ b/app/views/home/index.html.slim @@ -1,23 +1,14 @@ -h1.entry-title OpenFest 2014 – призив за лектори +h1.entry-title #{@current_conference.title} - призив за лектори -p OpenFest e единствената по рода си в България конференция, посветена на - свободната култура, свободния софтуер и софтуера с отворен код, свободното - споделяне на знания – фестивал на свободното творчество. OpenFest е ежегодна - среща на всички почитатели, създатели, поддръжници и нови фенове на свободните - изкуства и свободния софтуер. - -p Целта на OpenFest е да популяризира проекти, реализирани с помощта на свободен - софтуер и софтуер с отворен код, както и да бъде форум за обмен на идеи и добри - практики в областта. Същевременно организаторите всякога се стараят да дадат - поле за изява и на свободното изкуство. += simple_format @current_conference.description p Бихме искали да получим предложенията Ви за лекции и уъркшопи, принадлежащи към следните категории: ul - li Lorem - li Ipsum + - for track in @current_conference.tracks + li = track.name .centered - button type="button" Предложи лекция + = link_to 'Предложи лекция', new_lecture_path button type="button" Предложи уъркшоп -- 2.40.1 From 6728b3d059877f2042572f0878679ad05dea6d72 Mon Sep 17 00:00:00 2001 From: Petko Bordjukov Date: Sat, 30 Aug 2014 17:31:29 +0300 Subject: [PATCH 06/10] Lecture creation --- app/controllers/lectures_controller.rb | 21 ++++++++++++++++++++- app/models/event.rb | 1 + app/models/user.rb | 3 +++ app/views/lectures/new.html.slim | 2 +- app/views/lectures/show.html.slim | 22 ++++++++++++++++++++-- 5 files changed, 45 insertions(+), 4 deletions(-) diff --git a/app/controllers/lectures_controller.rb b/app/controllers/lectures_controller.rb index 1a32a6c..af3ade6 100644 --- a/app/controllers/lectures_controller.rb +++ b/app/controllers/lectures_controller.rb @@ -1,10 +1,19 @@ class LecturesController < ApplicationController + before_filter :authenticate_user! + before_action :assign_lecture, only: [:show] + def new @lecture = Lecture.new end def create - head :created + @lecture = current_user.lectures.build lecture_params + + if @lecture.save + redirect_to @lecture + else + render :new, status: :unprocessable_entity + end end def edit @@ -15,4 +24,14 @@ class LecturesController < ApplicationController def show end + + private + + def assign_lecture + @lecture = Lecture.find params[:id] + end + + def lecture_params + params.require(:lecture).permit [:title, :subtitle, :length, :language, :abstract, :description, :notes, :track_id] + end end diff --git a/app/models/event.rb b/app/models/event.rb index 3cd353d..50312ab 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -3,6 +3,7 @@ class Event < ActiveRecord::Base validates :length, presence: true, numericality: {only_integer: true, greater_than: 0} validates :abstract, presence: true validates :description, presence: true + validates :track, inclusion: { in: (Conference.current.try(:tracks) || []) } belongs_to :track has_one :conference, through: :track diff --git a/app/models/user.rb b/app/models/user.rb index 58df7b8..f7fa261 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -3,5 +3,8 @@ class User < ActiveRecord::Base # :lockable, :timeoutable and :omniauthable devise :database_authenticatable, :registerable, :confirmable, :recoverable, :rememberable, :trackable, :validatable + has_one :speaker_profile + has_many :lectures + has_many :workshops end diff --git a/app/views/lectures/new.html.slim b/app/views/lectures/new.html.slim index db3d176..84cebb5 100644 --- a/app/views/lectures/new.html.slim +++ b/app/views/lectures/new.html.slim @@ -1,2 +1,2 @@ -h1 Предложи нова лекция +h1.entry-title Предложи нова лекция = render 'form' diff --git a/app/views/lectures/show.html.slim b/app/views/lectures/show.html.slim index 4ff9a4e..89ab7ef 100644 --- a/app/views/lectures/show.html.slim +++ b/app/views/lectures/show.html.slim @@ -1,2 +1,20 @@ -h1 Lectures#show -p Find me in app/views/lectures/show.html.slim +h1.entry-title Преглед на лекция + +h2.lecture-title + = @lecture.title + span.subtitle = @lecture.subtitle + .entry-meta + | + поток: „#{@lecture.track.name}“, + продължителност: #{@lecture.length} мин. + +section.abstract + h3 Резюме + = simple_format @lecture.abstract + +section.description + h3 Описание + = simple_format @lecture.description + +- if current_user == @lecture.user + = link_to 'Редактирай', edit_lecture_path(@lecture) -- 2.40.1 From 90c3361f882d10043affe4099a912f7596305599 Mon Sep 17 00:00:00 2001 From: Petko Bordjukov Date: Sat, 30 Aug 2014 17:37:08 +0300 Subject: [PATCH 07/10] Lecture editing --- app/controllers/lectures_controller.rb | 7 ++++++- app/views/lectures/edit.html.slim | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/app/controllers/lectures_controller.rb b/app/controllers/lectures_controller.rb index af3ade6..1397267 100644 --- a/app/controllers/lectures_controller.rb +++ b/app/controllers/lectures_controller.rb @@ -1,6 +1,6 @@ class LecturesController < ApplicationController before_filter :authenticate_user! - before_action :assign_lecture, only: [:show] + before_action :assign_lecture, only: [:show, :edit, :update] def new @lecture = Lecture.new @@ -20,6 +20,11 @@ class LecturesController < ApplicationController end def update + if @lecture.update lecture_params + redirect_to @lecture + else + render :edit, status: :unprocessable_entity + end end def show diff --git a/app/views/lectures/edit.html.slim b/app/views/lectures/edit.html.slim index 8963bd0..404990a 100644 --- a/app/views/lectures/edit.html.slim +++ b/app/views/lectures/edit.html.slim @@ -1,2 +1,2 @@ -h1 Lectures#edit -p Find me in app/views/lectures/edit.html.slim +h1.entry-title Редакция на лекция += render 'form' -- 2.40.1 From 663cd6bcdebf4357c4b185de4dbadc53d21686ee Mon Sep 17 00:00:00 2001 From: Petko Bordjukov Date: Sat, 30 Aug 2014 19:33:13 +0300 Subject: [PATCH 08/10] Add a bunch of pending specs for the lectures --- spec/controllers/lectures_controller_spec.rb | 76 +++++++++++++------- spec/support/devise.rb | 3 + 2 files changed, 55 insertions(+), 24 deletions(-) create mode 100644 spec/support/devise.rb diff --git a/spec/controllers/lectures_controller_spec.rb b/spec/controllers/lectures_controller_spec.rb index 7602c72..637c2c6 100644 --- a/spec/controllers/lectures_controller_spec.rb +++ b/spec/controllers/lectures_controller_spec.rb @@ -1,45 +1,73 @@ require 'rails_helper' -RSpec.describe LecturesController, :type => :controller do +RSpec.describe LecturesController, type: :controller do + let(:user) { create :user, confirmed_at: Time.now } - describe "GET new" do - it "returns http success" do + before do + sign_in user + end + + describe 'GET new' do + it 'returns http success' do get :new expect(response).to be_success end + + it 'assigns a blank lecture to @lecture' end - describe "POST create" do - it "returns http success" do - new_track = create :track - new_user = create :user + describe 'POST create' do + it 'assigns the new lecture to @lecture' - post :create, lecture: build(:lecture, track: new_track, user: new_user).attributes - expect(response.status).to eq 201 + context 'when passed correct parameters' do + it 'creates a new lecture' + it 'redirects to the created lecture' + 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 - it "returns http success" do - event = create :lecture - get :edit, id: event.id - expect(response).to be_success + describe 'GET edit' do + context 'when the lecture exists' do + it 'returns http success' + it 'assigns the lecture to @lecture' + end + + context 'when the lecture does not exist' do + it 'returns HTTP Not Found status code' end end - describe "PUT update" do - it "returns http success" do - event = create :lecture - put :update, id: event.id, lecture: event.attributes - expect(response).to be_success + describe 'PUT update' do + context 'when the lecture does not exist' do + it 'returns HTTP Not Found status code' + end + + context 'when the lecture exists' do + it 'assigns the lecture to @lecture' + + context 'when passed correct parameters' do + it 'redirects to the updated lecture' + 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 - it "returns http success" do - event = create :lecture - get :show, id: event.id - expect(response).to be_success + describe 'GET show' do + context 'when the lecture exists' do + it 'returns HTTP Success status code' + it 'assigns the lecture to @lecture' + end + + context 'when the lecture does not exist' do + it 'returns HTTP Not Found status code' end end end diff --git a/spec/support/devise.rb b/spec/support/devise.rb new file mode 100644 index 0000000..7999895 --- /dev/null +++ b/spec/support/devise.rb @@ -0,0 +1,3 @@ +RSpec.configure do |config| + config.include Devise::TestHelpers, type: :controller +end -- 2.40.1 From d43a9bc941966a0a429866569cb1cc9eef570fdc Mon Sep 17 00:00:00 2001 From: Petko Bordjukov Date: Sat, 30 Aug 2014 19:45:25 +0300 Subject: [PATCH 09/10] Add a LecturesController#index action --- app/controllers/lectures_controller.rb | 4 ++++ app/views/layouts/_nav.html.erb | 6 +++--- app/views/lectures/index.html.slim | 7 +++++++ config/routes.rb | 2 +- spec/controllers/lectures_controller_spec.rb | 7 ++++++- 5 files changed, 21 insertions(+), 5 deletions(-) create mode 100644 app/views/lectures/index.html.slim diff --git a/app/controllers/lectures_controller.rb b/app/controllers/lectures_controller.rb index 1397267..c18612b 100644 --- a/app/controllers/lectures_controller.rb +++ b/app/controllers/lectures_controller.rb @@ -2,6 +2,10 @@ class LecturesController < ApplicationController before_filter :authenticate_user! before_action :assign_lecture, only: [:show, :edit, :update] + def index + @lectures = Lecture.where user: current_user + end + def new @lecture = Lecture.new end diff --git a/app/views/layouts/_nav.html.erb b/app/views/layouts/_nav.html.erb index 2a04c27..bc5ecf2 100644 --- a/app/views/layouts/_nav.html.erb +++ b/app/views/layouts/_nav.html.erb @@ -8,10 +8,10 @@ <%= content_tag :li, class: [('current_page_item' if controller_name == 'sessions')] do %> <%= link_to "Вход", new_user_session_path %> <% end %> - <%= content_tag :li, class: [('current_page_item' if controller_name == 'registrations')] do %> - <%= link_to "Регистрация", new_user_registration_path %> - <% end %> <% else %> + <%= 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 == 'registrations')] do %> <%= link_to "Редакция на профил", edit_user_registration_path %> <% end %> diff --git a/app/views/lectures/index.html.slim b/app/views/lectures/index.html.slim new file mode 100644 index 0000000..3324930 --- /dev/null +++ b/app/views/lectures/index.html.slim @@ -0,0 +1,7 @@ +h1.entry-title Моите предложения за лекции + +ul + - for lecture in @lectures + li = link_to lecture.title, lecture + += link_to 'Предложи лекция', new_lecture_path diff --git a/config/routes.rb b/config/routes.rb index a08d41f..6b707c3 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,5 +1,5 @@ Rails.application.routes.draw do - resources :lectures, only: [:new, :create, :edit, :update, :show] + resources :lectures, only: [:index, :new, :create, :edit, :update, :show] devise_for :users diff --git a/spec/controllers/lectures_controller_spec.rb b/spec/controllers/lectures_controller_spec.rb index 637c2c6..b4095a2 100644 --- a/spec/controllers/lectures_controller_spec.rb +++ b/spec/controllers/lectures_controller_spec.rb @@ -7,8 +7,13 @@ RSpec.describe LecturesController, type: :controller do sign_in user end + describe 'GET index' do + it 'returns HTTP Success status code' + it 'assigns the lectures of the current user to @lectures' + end + describe 'GET new' do - it 'returns http success' do + it 'returns HTTP Success status code' do get :new expect(response).to be_success end -- 2.40.1 From c33e95bdd8d2da784f78b8bfa615ddf18b57f9c7 Mon Sep 17 00:00:00 2001 From: Petko Bordjukov Date: Sat, 30 Aug 2014 19:59:33 +0300 Subject: [PATCH 10/10] Add Workshop controller functionality --- app/controllers/workshops_controller.rb | 46 +++++++++++ app/views/home/index.html.slim | 3 +- app/views/layouts/_nav.html.erb | 3 + app/views/workshops/_form.html.slim | 14 ++++ app/views/workshops/edit.html.slim | 2 + app/views/workshops/index.html.slim | 7 ++ app/views/workshops/new.html.slim | 2 + app/views/workshops/show.html.slim | 20 +++++ config/locales/bg.yml | 12 +++ config/locales/simple_form.bg.yml | 9 +++ config/routes.rb | 1 + spec/controllers/workshops_controller_spec.rb | 78 +++++++++++++++++++ 12 files changed, 196 insertions(+), 1 deletion(-) create mode 100644 app/controllers/workshops_controller.rb create mode 100644 app/views/workshops/_form.html.slim create mode 100644 app/views/workshops/edit.html.slim create mode 100644 app/views/workshops/index.html.slim create mode 100644 app/views/workshops/new.html.slim create mode 100644 app/views/workshops/show.html.slim create mode 100644 spec/controllers/workshops_controller_spec.rb 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 -- 2.40.1