diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index 9536d39..0689cf3 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -1,5 +1,5 @@ class HomeController < ApplicationController def index - @current_conference = Conference.current || Conference.new + @current_conference = Conference.first end end diff --git a/app/controllers/lectures_controller.rb b/app/controllers/lectures_controller.rb deleted file mode 100644 index 1128938..0000000 --- a/app/controllers/lectures_controller.rb +++ /dev/null @@ -1,60 +0,0 @@ -class LecturesController < ApplicationController - before_filter :authenticate_user! - before_action :assign_lecture, only: [:show, :edit, :update, :confirm] - - def index - @lectures = Lecture.where user: current_user - end - - def new - @lecture = Lecture.new - end - - def create - @lecture = current_user.lectures.build lecture_params - - if @lecture.save - after_save_redirection - else - render :new, status: :unprocessable_entity - end - end - - def edit - end - - def update - if @lecture.update lecture_params - after_save_redirection - else - render :edit, status: :unprocessable_entity - end - end - - def show - end - - def confirm - @lecture.touch :confirmed_at - redirect_to @lecture, notice: I18n.t(:lecture_was_successfully_confirmed) - end - - private - - def assign_lecture - @lecture = current_user.lectures.find params[:id] - end - - def lecture_params - params.require(:lecture).permit [:title, :subtitle, :length, :language, :abstract, :description, :notes, :track_id, :agreement] - end - - def after_save_redirection - if current_user.speaker_profile.present? - redirect_to @lecture - else - redirect_to edit_user_registration_path, alert: I18n.t(:please_fill_in_your_speaker_profile) - end - end - -end diff --git a/app/controllers/registrations_controller.rb b/app/controllers/registrations_controller.rb deleted file mode 100644 index a781c0c..0000000 --- a/app/controllers/registrations_controller.rb +++ /dev/null @@ -1,35 +0,0 @@ -class RegistrationsController < Devise::RegistrationsController - def edit - resource.build_speaker_profile unless resource.speaker_profile.present? - end - - def update - @user = User.find(current_user.id) - - successfully_updated = if needs_password?(@user, params) - @user.update_with_password(devise_parameter_sanitizer.sanitize(:account_update)) - else - # remove the virtual current_password attribute - # update_without_password doesn't know how to ignore it - params[:user].delete(:current_password) - @user.update_without_password(devise_parameter_sanitizer.sanitize(:account_update)) - end - - if successfully_updated - set_flash_message :notice, :updated - # Sign in the user bypassing validation in case their password changed - sign_in @user, :bypass => true - redirect_to after_update_path_for(@user) - else - render "edit" - end - end - - private - - def needs_password?(user, params) - user.email != params[:user][:email] || - params[:user][:password].present? || - params[:user][:password_confirmation].present? - end -end diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb deleted file mode 100644 index 8848ad2..0000000 --- a/app/controllers/sessions_controller.rb +++ /dev/null @@ -1,12 +0,0 @@ -class SessionsController < Devise::SessionsController - def after_sign_in_path_for(user) - stored_location = stored_location_for user - - if user.speaker_profile.present? || stored_location - stored_location || signed_in_root_path(user) - else - flash[:alert] = I18n.t(:please_fill_in_your_speaker_profile) - edit_user_registration_path - end - end -end diff --git a/app/controllers/workshops_controller.rb b/app/controllers/workshops_controller.rb deleted file mode 100644 index 678939c..0000000 --- a/app/controllers/workshops_controller.rb +++ /dev/null @@ -1,59 +0,0 @@ -class WorkshopsController < ApplicationController - before_filter :authenticate_user! - before_action :assign_workshop, only: [:show, :edit, :update, :confirm] - - 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 - after_save_redirection - else - render :new, status: :unprocessable_entity - end - end - - def edit - end - - def update - if @workshop.update workshop_params - after_save_redirection - else - render :edit, status: :unprocessable_entity - end - end - - def show - end - - def confirm - @workshop.touch :confirmed_at - redirect_to @workshop, notice: I18n.t(:workshop_was_successfully_confirmed) - end - - private - - def assign_workshop - @workshop = current_user.workshops.find params[:id] - end - - def workshop_params - params.require(:workshop).permit [:title, :subtitle, :length, :language, :abstract, :description, :notes, :track_id, :agreement] - end - - def after_save_redirection - if current_user.speaker_profile.present? - redirect_to @workshop - else - redirect_to edit_user_registration_path, alert: I18n.t(:please_fill_in_your_speaker_profile) - end - end -end diff --git a/config/routes.rb b/config/routes.rb index 1e003db..db046bb 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,17 +1,5 @@ Rails.application.routes.draw do - resources :lectures, only: [:index, :new, :create, :edit, :update, :show] do - member do - get 'confirm' - end - end - - resources :workshops, only: [:index, :new, :create, :edit, :update, :show] do - member do - get 'confirm' - end - end - - devise_for :users, controllers: {registrations: 'registrations', sessions: 'sessions'} + devise_for :users namespace :management do get '/', to: 'events#index' @@ -45,58 +33,4 @@ Rails.application.routes.draw do end root 'home#index' - # The priority is based upon order of creation: first created -> highest priority. - # See how all your routes lay out with "rake routes". - - # You can have the root of your site routed with "root" - # root 'welcome#index' - - # Example of regular route: - # get 'products/:id' => 'catalog#view' - - # Example of named route that can be invoked with purchase_url(id: product.id) - # get 'products/:id/purchase' => 'catalog#purchase', as: :purchase - - # Example resource route (maps HTTP verbs to controller actions automatically): - # resources :products - - # Example resource route with options: - # resources :products do - # member do - # get 'short' - # post 'toggle' - # end - # - # collection do - # get 'sold' - # end - # end - - # Example resource route with sub-resources: - # resources :products do - # resources :comments, :sales - # resource :seller - # end - - # Example resource route with more complex sub-resources: - # resources :products do - # resources :comments - # resources :sales do - # get 'recent', on: :collection - # end - # end - - # Example resource route with concerns: - # concern :toggleable do - # post 'toggle' - # end - # resources :posts, concerns: :toggleable - # resources :photos, concerns: :toggleable - - # Example resource route within a namespace: - # namespace :admin do - # # Directs /admin/products/* to Admin::ProductsController - # # (app/controllers/admin/products_controller.rb) - # resources :products - # end end diff --git a/spec/controllers/lectures_controller_spec.rb b/spec/controllers/lectures_controller_spec.rb deleted file mode 100644 index b4095a2..0000000 --- a/spec/controllers/lectures_controller_spec.rb +++ /dev/null @@ -1,78 +0,0 @@ -require 'rails_helper' - -RSpec.describe LecturesController, 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 lectures of the current user to @lectures' - end - - describe 'GET new' do - it 'returns HTTP Success status code' do - get :new - expect(response).to be_success - end - - it 'assigns a blank lecture to @lecture' - end - - describe 'POST create' do - it 'assigns the new lecture to @lecture' - - 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 - 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 - 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 - 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/controllers/workshops_controller_spec.rb b/spec/controllers/workshops_controller_spec.rb deleted file mode 100644 index 34a528f..0000000 --- a/spec/controllers/workshops_controller_spec.rb +++ /dev/null @@ -1,78 +0,0 @@ -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 diff --git a/spec/factories/events.rb b/spec/factories/events.rb deleted file mode 100644 index c2b3c18..0000000 --- a/spec/factories/events.rb +++ /dev/null @@ -1,29 +0,0 @@ -# Read about factories at https://github.com/thoughtbot/factory_girl - -FactoryGirl.define do - factory :lecture do - title { |n| "Lecture #{n}" } - subtitle "Lorem Ipsum" - length 45 - language "bg_BG" - abstract "An Abstract" - description "A Description" - notes "Some Notes" - agreement true - track - user - end - - factory :workshop do - title { |n| "Workshop #{n}" } - subtitle "Lorem Ipsum" - length 60 - language "bg_BG" - abstract "An Abstract" - description "A Description" - notes "Some Notes" - agreement true - track - user - end -end diff --git a/spec/factories/speaker_profiles.rb b/spec/factories/speaker_profiles.rb deleted file mode 100644 index dbabf5a..0000000 --- a/spec/factories/speaker_profiles.rb +++ /dev/null @@ -1,16 +0,0 @@ -# Read about factories at https://github.com/thoughtbot/factory_girl - -FactoryGirl.define do - factory :speaker_profile do - first_name "John" - last_name "Doe" - organisation "Example Org" - public_email "a@b.com" - picture { Rack::Test::UploadedFile.new(File.join(Rails.root, 'spec', 'support', 'picture.jpg')) } - mobile_phone "0883444555" - biography "Lorem ipsum" - github "octocat" - twitter "handle" - user - end -end diff --git a/spec/models/lecture_spec.rb b/spec/models/lecture_spec.rb deleted file mode 100644 index 296eab1..0000000 --- a/spec/models/lecture_spec.rb +++ /dev/null @@ -1,23 +0,0 @@ -require 'rails_helper' - -RSpec.describe Lecture, :type => :model do - let(:event) { build :lecture } - - it_behaves_like 'an event' - - describe 'length' do - it 'must be between 40 and 45 minutes' do - event.length = 30 - expect(event).to have_error_on :length - - event.length = 60 - expect(event).to have_error_on :length - - event.length = 40 - expect(event).to_not have_error_on :length - - event.length = 45 - expect(event).to_not have_error_on :length - end - end -end diff --git a/spec/models/speaker_profile_spec.rb b/spec/models/speaker_profile_spec.rb deleted file mode 100644 index 76453df..0000000 --- a/spec/models/speaker_profile_spec.rb +++ /dev/null @@ -1,96 +0,0 @@ -require 'rails_helper' - -RSpec.describe SpeakerProfile, :type => :model do - it 'is invalid without a first name' do - expect(build(:speaker_profile, first_name: nil)).to have_error_on :first_name - end - - it 'is invalid without a last name' do - expect(build(:speaker_profile, last_name: nil)).to have_error_on :last_name - end - - it 'is invalid without a picture' do - expect(build(:speaker_profile, picture: nil)).to have_error_on :picture - end - - describe 'mobile_phone' do - it 'must be present' do - expect(build(:speaker_profile, mobile_phone: nil)).to have_error_on :mobile_phone - end - - it 'must be a valid phone number' do - expect(build(:speaker_profile, mobile_phone: 'abc')).to have_error_on :mobile_phone - end - - it 'is stored in a normalized form' do - speaker_profile = create :speaker_profile, mobile_phone: '0883444555' - expect(speaker_profile.mobile_phone).to eq '359883444555' - - speaker_profile.mobile_phone = '+1883444555' - speaker_profile.save - expect(speaker_profile.mobile_phone).to eq '1883444555' - end - end - - describe 'public email' do - it 'can be absent' do - expect(build(:speaker_profile, public_email: '')).to_not have_error_on :public_email - end - - it 'can contain exatly one @ when present' do - expect(build(:speaker_profile, public_email: 'test@@example.com')).to have_error_on :public_email - expect(build(:speaker_profile, public_email: 'test@example.com')).to_not have_error_on :public_email - expect(build(:speaker_profile, public_email: 'testexample.com')).to have_error_on :public_email - end - end - - describe 'twitter handle' do - it 'can be absent' do - expect(build(:speaker_profile, twitter: '')).to_not have_error_on :twitter - end - - context 'when present' do - it 'is stored without a starting @' do - expect(create(:speaker_profile, twitter: '@foobar').twitter).to eq 'foobar' - end - - it 'must contain only alphanumeric symbols or an underscore' do - speaker_profile = build :speaker_profile - speaker_profile.twitter = 'fooBar_1' - expect(speaker_profile).to_not have_error_on :twitter - - speaker_profile.twitter = 'foobar!' - expect(speaker_profile).to have_error_on :twitter - end - - it 'must be maximum 15 symbols long' do - expect(build(:speaker_profile, twitter: 'a'*16)).to have_error_on :twitter - end - end - end - - describe 'github account' do - it 'can be absent' do - expect(build(:speaker_profile, github: '')).to_not have_error_on :twitter - end - - context 'when present' do - it 'must contain only alphanumeric symbols or a dash' do - speaker_profile = build :speaker_profile - speaker_profile.github = 'fooBar-1' - expect(speaker_profile).to_not have_error_on :github - - speaker_profile.github = 'foobar!' - expect(speaker_profile).to have_error_on :github - end - - it 'must not start with a dash' do - expect(build(:speaker_profile, github: '-foobar')).to have_error_on :github - end - end - end - - it 'is invalid without a bio' do - expect(build(:speaker_profile, biography: nil)).to have_error_on :biography - end -end diff --git a/spec/models/workshop_spec.rb b/spec/models/workshop_spec.rb deleted file mode 100644 index c55dcad..0000000 --- a/spec/models/workshop_spec.rb +++ /dev/null @@ -1,23 +0,0 @@ -require 'rails_helper' - -RSpec.describe Workshop, :type => :model do - let(:event) { build :workshop } - - it_behaves_like 'an event' - - describe 'length' do - it 'must be between 30 and 120 minutes' do - event.length = 20 - expect(event).to have_error_on :length - - event.length = 240 - expect(event).to have_error_on :length - - event.length = 30 - expect(event).to_not have_error_on :length - - event.length = 120 - expect(event).to_not have_error_on :length - end - end -end diff --git a/spec/support/shared_examples/.keep b/spec/support/shared_examples/.keep new file mode 100644 index 0000000..e69de29 diff --git a/spec/support/shared_examples/shared_examples_for_events.rb b/spec/support/shared_examples/shared_examples_for_events.rb deleted file mode 100644 index 3bb5847..0000000 --- a/spec/support/shared_examples/shared_examples_for_events.rb +++ /dev/null @@ -1,38 +0,0 @@ -RSpec.shared_examples 'an event' do - it 'is invalid if the event agrement is not accepted' do - event.agreement = false - expect(event).to have_error_on :agreement - end - - it 'is invalid without a title' do - event.title = '' - expect(event).to have_error_on :title - end - - describe 'length' do - it 'must be present' do - event.length = '' - expect(event).to have_error_on :length - end - - it 'must be a number' do - event.length = 'foo' - expect(event).to have_error_on :length - end - - it 'must be larger than zero' do - event.length = '-10' - expect(event).to have_error_on :length - end - end - - it 'is invalid without an abstract' do - event.abstract = '' - expect(event).to have_error_on :abstract - end - - it 'is invalid without a description' do - event.description = '' - expect(event).to have_error_on :description - end -end