From 6b23a7820a6159ffe73b76a541dd006962fcffb2 Mon Sep 17 00:00:00 2001 From: Jordan Hatch Date: Mon, 21 Jul 2014 16:19:35 +0100 Subject: [PATCH 01/34] Bump Rails to 3.2.19 This includes multiple security and bug fixes. --- Gemfile | 2 +- Gemfile.lock | 96 ++++++++++++++++++++++++++++++---------------------- 2 files changed, 56 insertions(+), 42 deletions(-) diff --git a/Gemfile b/Gemfile index b7827e8..16cefe5 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,6 @@ source 'http://rubygems.org' -gem 'rails', '~> 3.2.12' +gem 'rails', '~> 3.2.19' gem 'unicorn' gem 'pg' diff --git a/Gemfile.lock b/Gemfile.lock index 19e9ea7..d103fcc 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -7,12 +7,12 @@ GIT GEM remote: http://rubygems.org/ specs: - actionmailer (3.2.12) - actionpack (= 3.2.12) - mail (~> 2.4.4) - actionpack (3.2.12) - activemodel (= 3.2.12) - activesupport (= 3.2.12) + actionmailer (3.2.19) + actionpack (= 3.2.19) + mail (~> 2.5.4) + actionpack (3.2.19) + activemodel (= 3.2.19) + activesupport (= 3.2.19) builder (~> 3.0.0) erubis (~> 2.7.0) journey (~> 1.0.4) @@ -20,21 +20,21 @@ GEM rack-cache (~> 1.2) rack-test (~> 0.6.1) sprockets (~> 2.2.1) - activemodel (3.2.12) - activesupport (= 3.2.12) + activemodel (3.2.19) + activesupport (= 3.2.19) builder (~> 3.0.0) - activerecord (3.2.12) - activemodel (= 3.2.12) - activesupport (= 3.2.12) + activerecord (3.2.19) + activemodel (= 3.2.19) + activesupport (= 3.2.19) arel (~> 3.0.2) tzinfo (~> 0.3.29) - activeresource (3.2.12) - activemodel (= 3.2.12) - activesupport (= 3.2.12) - activesupport (3.2.12) - i18n (~> 0.6) + activeresource (3.2.19) + activemodel (= 3.2.19) + activesupport (= 3.2.19) + activesupport (3.2.19) + i18n (~> 0.6, >= 0.6.4) multi_json (~> 1.0) - arel (3.0.2) + arel (3.0.3) aws-sdk (1.8.3.1) json (~> 1.4) nokogiri (>= 1.4.4) @@ -87,8 +87,8 @@ GEM gherkin (2.11.6) json (>= 1.7.6) has_scope (0.5.1) - hike (1.2.1) - i18n (0.6.4) + hike (1.2.3) + i18n (0.6.11) inherited_resources (1.3.1) has_scope (~> 0.5.0) responders (~> 0.6) @@ -98,12 +98,11 @@ GEM thor (>= 0.14, < 2.0) json (1.7.7) kgio (2.8.0) - mail (2.4.4) - i18n (>= 0.4.0) + mail (2.5.4) mime-types (~> 1.16) treetop (~> 1.4.8) - mime-types (1.21) - multi_json (1.6.1) + mime-types (1.25.1) + multi_json (1.10.1) nokogiri (1.5.6) orm_adapter (0.0.7) paper_trail (2.7.1) @@ -115,33 +114,33 @@ GEM cocaine (>= 0.0.2) mime-types pg (0.14.1) - polyglot (0.3.3) + polyglot (0.3.5) rabl (0.8.0) activesupport (>= 2.3.14) rack (1.4.5) rack-cache (1.2) rack (>= 0.4) - rack-ssl (1.3.3) + rack-ssl (1.3.4) rack rack-test (0.6.2) rack (>= 1.0) - rails (3.2.12) - actionmailer (= 3.2.12) - actionpack (= 3.2.12) - activerecord (= 3.2.12) - activeresource (= 3.2.12) - activesupport (= 3.2.12) + rails (3.2.19) + actionmailer (= 3.2.19) + actionpack (= 3.2.19) + activerecord (= 3.2.19) + activeresource (= 3.2.19) + activesupport (= 3.2.19) bundler (~> 1.0) - railties (= 3.2.12) - railties (3.2.12) - actionpack (= 3.2.12) - activesupport (= 3.2.12) + railties (= 3.2.19) + railties (3.2.19) + actionpack (= 3.2.19) + activesupport (= 3.2.19) rack-ssl (~> 1.3.2) rake (>= 0.8.7) rdoc (~> 3.4) thor (>= 0.14.6, < 2.0) raindrops (0.10.0) - rake (10.0.3) + rake (10.3.2) rdiscount (1.6.8) rdoc (3.12.2) json (~> 1.4) @@ -174,12 +173,27 @@ GEM multi_json (~> 1.0) rack (~> 1.0) tilt (~> 1.1, != 1.3.0) - thor (0.17.0) - tilt (1.3.4) - treetop (1.4.12) + thor (0.19.1) + tilt (1.4.1) + treetop (1.4.15) polyglot + polyglot + polyglot + polyglot + polyglot + polyglot + polyglot + polyglot + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) + polyglot (>= 0.3.1) polyglot (>= 0.3.1) - tzinfo (0.3.36) + tzinfo (0.3.40) uglifier (1.3.0) execjs (>= 0.3.0) multi_json (~> 1.0, >= 1.0.2) @@ -215,7 +229,7 @@ DEPENDENCIES paperclip (~> 2.4) pg rabl - rails (~> 3.2.12) + rails (~> 3.2.19) rdiscount (~> 1.6.8) rspec-rails (~> 2.6) sass-rails (~> 3.2.5) From f3a62cfd434853a20683ff6854d03789f130cdfb Mon Sep 17 00:00:00 2001 From: Jordan Hatch Date: Mon, 6 Jul 2015 14:45:10 +0100 Subject: [PATCH 02/34] Use Ruby 2.2.2 --- .ruby-version | 1 + 1 file changed, 1 insertion(+) create mode 100644 .ruby-version diff --git a/.ruby-version b/.ruby-version new file mode 100644 index 0000000..b1b25a5 --- /dev/null +++ b/.ruby-version @@ -0,0 +1 @@ +2.2.2 From b6d5f94fe5baad8b9dbaf34cd8b21cc00acff73f Mon Sep 17 00:00:00 2001 From: Jordan Hatch Date: Mon, 6 Jul 2015 14:45:22 +0100 Subject: [PATCH 03/34] Update to Rails 4.0.x --- Gemfile | 13 +-- Gemfile.lock | 299 ++++++++++++++++++++++++--------------------------- 2 files changed, 144 insertions(+), 168 deletions(-) diff --git a/Gemfile b/Gemfile index 16cefe5..98faa50 100644 --- a/Gemfile +++ b/Gemfile @@ -1,11 +1,10 @@ source 'http://rubygems.org' -gem 'rails', '~> 3.2.19' +gem 'rails', '~> 4.0.12' gem 'unicorn' gem 'pg' -gem 'json', '1.7.7' gem 'jquery-rails' gem "aws-sdk", "~> 1.8.3.1" @@ -16,20 +15,18 @@ gem "comma", "~> 3.0.4" gem "rdiscount", "~> 1.6.8" gem "paperclip", "~> 2.4" -gem 'paper_trail', '~> 2' +gem 'paper_trail', '~> 3.0.3' # admin -gem "devise", "~> 2.0.5" +gem "devise", "~> 3.0" gem "inherited_resources" gem "formtastic", "~> 2.2" gem "nested_form", :git => "git://github.com/ryanb/nested_form.git" -group :assets do - gem 'sass-rails', '~> 3.2.5' - gem 'uglifier', '>= 1.0.3' -end +gem 'sass-rails', '~> 4.0.3' +gem 'uglifier', '>= 1.0.3' group :test do gem 'cucumber-rails', require: false diff --git a/Gemfile.lock b/Gemfile.lock index d103fcc..f49dcd7 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,211 +1,191 @@ GIT remote: git://github.com/ryanb/nested_form.git - revision: 8f89b2ee38808c7e3af6797c11092b5600e09376 + revision: 1b0689dfb4d230ceabd278eba159fcb02f23c68a specs: - nested_form (0.3.1) + nested_form (0.3.2) GEM remote: http://rubygems.org/ specs: - actionmailer (3.2.19) - actionpack (= 3.2.19) - mail (~> 2.5.4) - actionpack (3.2.19) - activemodel (= 3.2.19) - activesupport (= 3.2.19) - builder (~> 3.0.0) + actionmailer (4.0.13) + actionpack (= 4.0.13) + mail (~> 2.5, >= 2.5.4) + actionpack (4.0.13) + activesupport (= 4.0.13) + builder (~> 3.1.0) erubis (~> 2.7.0) - journey (~> 1.0.4) - rack (~> 1.4.5) - rack-cache (~> 1.2) - rack-test (~> 0.6.1) - sprockets (~> 2.2.1) - activemodel (3.2.19) - activesupport (= 3.2.19) - builder (~> 3.0.0) - activerecord (3.2.19) - activemodel (= 3.2.19) - activesupport (= 3.2.19) - arel (~> 3.0.2) - tzinfo (~> 0.3.29) - activeresource (3.2.19) - activemodel (= 3.2.19) - activesupport (= 3.2.19) - activesupport (3.2.19) - i18n (~> 0.6, >= 0.6.4) - multi_json (~> 1.0) - arel (3.0.3) + rack (~> 1.5.2) + rack-test (~> 0.6.2) + activemodel (4.0.13) + activesupport (= 4.0.13) + builder (~> 3.1.0) + activerecord (4.0.13) + activemodel (= 4.0.13) + activerecord-deprecated_finders (~> 1.0.2) + activesupport (= 4.0.13) + arel (~> 4.0.0) + activerecord-deprecated_finders (1.0.4) + activesupport (4.0.13) + i18n (~> 0.6, >= 0.6.9) + minitest (~> 4.2) + multi_json (~> 1.3) + thread_safe (~> 0.1) + tzinfo (~> 0.3.37) + arel (4.0.2) aws-sdk (1.8.3.1) json (~> 1.4) nokogiri (>= 1.4.4) uuidtools (~> 2.1) - bcrypt-ruby (3.0.1) - breadcrumbs (0.1.6) + bcrypt (3.1.10) + breadcrumbs (0.1.7) i18n - builder (3.0.4) - capybara (2.0.2) + builder (3.1.4) + capybara (2.4.4) mime-types (>= 1.16) nokogiri (>= 1.3.3) rack (>= 1.0.0) rack-test (>= 0.5.4) - selenium-webdriver (~> 2.0) - xpath (~> 1.0.0) - childprocess (0.3.9) - ffi (~> 1.0, >= 1.0.11) + xpath (~> 2.0) climate_control (0.0.3) activesupport (>= 3.0) - cocaine (0.5.1) + cocaine (0.5.7) climate_control (>= 0.0.3, < 1.0) - comma (3.0.4) - cucumber (1.2.2) + comma (3.0.6) + activesupport (>= 3.0.0) + cucumber (1.3.20) builder (>= 2.1.2) diff-lcs (>= 1.1.3) - gherkin (~> 2.11.6) - multi_json (~> 1.3) - cucumber-rails (1.3.0) - capybara (>= 1.1.2) - cucumber (>= 1.1.8) - nokogiri (>= 1.5.0) - database_cleaner (0.9.1) - devise (2.0.5) - bcrypt-ruby (~> 3.0) - orm_adapter (~> 0.0.3) - railties (~> 3.1) - warden (~> 1.1.1) - diff-lcs (1.2.1) + gherkin (~> 2.12) + multi_json (>= 1.7.5, < 2.0) + multi_test (>= 0.1.2) + cucumber-rails (1.4.2) + capybara (>= 1.1.2, < 3) + cucumber (>= 1.3.8, < 2) + mime-types (>= 1.16, < 3) + nokogiri (~> 1.5) + rails (>= 3, < 5) + database_cleaner (1.4.1) + devise (3.5.1) + bcrypt (~> 3.0) + orm_adapter (~> 0.1) + railties (>= 3.2.6, < 5) + responders + thread_safe (~> 0.1) + warden (~> 1.2.3) + diff-lcs (1.2.5) erubis (2.7.0) - execjs (1.4.0) - multi_json (~> 1.0) - factory_girl (4.2.0) + execjs (2.5.2) + factory_girl (4.5.0) activesupport (>= 3.0.0) - factory_girl_rails (4.2.1) - factory_girl (~> 4.2.0) + factory_girl_rails (4.5.0) + factory_girl (~> 4.5.0) railties (>= 3.0.0) - ffi (1.4.0) - formtastic (2.2.1) + formtastic (2.3.1) actionpack (>= 3.0) - gherkin (2.11.6) - json (>= 1.7.6) - has_scope (0.5.1) + gherkin (2.12.2) + multi_json (~> 1.3) + has_scope (0.6.0) + actionpack (>= 3.2, < 5) + activesupport (>= 3.2, < 5) hike (1.2.3) - i18n (0.6.11) - inherited_resources (1.3.1) - has_scope (~> 0.5.0) - responders (~> 0.6) - journey (1.0.4) - jquery-rails (2.2.1) + i18n (0.7.0) + inherited_resources (1.6.0) + actionpack (>= 3.2, < 5) + has_scope (~> 0.6.0.rc) + railties (>= 3.2, < 5) + responders + jquery-rails (3.1.3) railties (>= 3.0, < 5.0) thor (>= 0.14, < 2.0) - json (1.7.7) - kgio (2.8.0) - mail (2.5.4) - mime-types (~> 1.16) - treetop (~> 1.4.8) - mime-types (1.25.1) - multi_json (1.10.1) - nokogiri (1.5.6) - orm_adapter (0.0.7) - paper_trail (2.7.1) - activerecord (~> 3.0) - railties (~> 3.0) + json (1.8.3) + kgio (2.9.3) + mail (2.6.3) + mime-types (>= 1.16, < 3) + mime-types (2.6.1) + mini_portile (0.6.2) + minitest (4.7.5) + multi_json (1.11.2) + multi_test (0.1.2) + nokogiri (1.6.6.2) + mini_portile (~> 0.6.0) + orm_adapter (0.5.0) + paper_trail (3.0.8) + activerecord (>= 3.0, < 5.0) + activesupport (>= 3.0, < 5.0) paperclip (2.8.0) activerecord (>= 2.3.0) activesupport (>= 2.3.2) cocaine (>= 0.0.2) mime-types - pg (0.14.1) - polyglot (0.3.5) - rabl (0.8.0) + pg (0.18.2) + rabl (0.11.6) activesupport (>= 2.3.14) - rack (1.4.5) - rack-cache (1.2) - rack (>= 0.4) - rack-ssl (1.3.4) - rack - rack-test (0.6.2) + rack (1.5.5) + rack-test (0.6.3) rack (>= 1.0) - rails (3.2.19) - actionmailer (= 3.2.19) - actionpack (= 3.2.19) - activerecord (= 3.2.19) - activeresource (= 3.2.19) - activesupport (= 3.2.19) - bundler (~> 1.0) - railties (= 3.2.19) - railties (3.2.19) - actionpack (= 3.2.19) - activesupport (= 3.2.19) - rack-ssl (~> 1.3.2) + rails (4.0.13) + actionmailer (= 4.0.13) + actionpack (= 4.0.13) + activerecord (= 4.0.13) + activesupport (= 4.0.13) + bundler (>= 1.3.0, < 2.0) + railties (= 4.0.13) + sprockets-rails (~> 2.0) + railties (4.0.13) + actionpack (= 4.0.13) + activesupport (= 4.0.13) rake (>= 0.8.7) - rdoc (~> 3.4) - thor (>= 0.14.6, < 2.0) - raindrops (0.10.0) - rake (10.3.2) + thor (>= 0.18.1, < 2.0) + raindrops (0.14.0) + rake (10.4.2) rdiscount (1.6.8) - rdoc (3.12.2) - json (~> 1.4) - responders (0.9.3) - railties (~> 3.1) - rspec-core (2.13.0) - rspec-expectations (2.13.0) + responders (1.1.2) + railties (>= 3.2, < 4.2) + rspec-collection_matchers (1.1.2) + rspec-expectations (>= 2.99.0.beta1) + rspec-core (2.99.2) + rspec-expectations (2.99.2) diff-lcs (>= 1.1.3, < 2.0) - rspec-mocks (2.13.0) - rspec-rails (2.13.0) + rspec-mocks (2.99.4) + rspec-rails (2.99.0) actionpack (>= 3.0) + activemodel (>= 3.0) activesupport (>= 3.0) railties (>= 3.0) - rspec-core (~> 2.13.0) - rspec-expectations (~> 2.13.0) - rspec-mocks (~> 2.13.0) - rubyzip (0.9.9) - sass (3.2.6) - sass-rails (3.2.6) - railties (~> 3.2.0) - sass (>= 3.1.10) - tilt (~> 1.3) - selenium-webdriver (2.31.0) - childprocess (>= 0.2.5) - multi_json (~> 1.0) - rubyzip - websocket (~> 1.0.4) - sprockets (2.2.2) + rspec-collection_matchers + rspec-core (~> 2.99.0) + rspec-expectations (~> 2.99.0) + rspec-mocks (~> 2.99.0) + sass (3.2.19) + sass-rails (4.0.5) + railties (>= 4.0.0, < 5.0) + sass (~> 3.2.2) + sprockets (~> 2.8, < 3.0) + sprockets-rails (~> 2.0) + sprockets (2.12.4) hike (~> 1.2) multi_json (~> 1.0) rack (~> 1.0) tilt (~> 1.1, != 1.3.0) + sprockets-rails (2.3.2) + actionpack (>= 3.0) + activesupport (>= 3.0) + sprockets (>= 2.8, < 4.0) thor (0.19.1) + thread_safe (0.3.5) tilt (1.4.1) - treetop (1.4.15) - polyglot - polyglot - polyglot - polyglot - polyglot - polyglot - polyglot - polyglot - polyglot (>= 0.3.1) - polyglot (>= 0.3.1) - polyglot (>= 0.3.1) - polyglot (>= 0.3.1) - polyglot (>= 0.3.1) - polyglot (>= 0.3.1) - polyglot (>= 0.3.1) - polyglot (>= 0.3.1) - polyglot (>= 0.3.1) - tzinfo (0.3.40) - uglifier (1.3.0) + tzinfo (0.3.44) + uglifier (2.7.1) execjs (>= 0.3.0) - multi_json (~> 1.0, >= 1.0.2) - unicorn (4.6.2) + json (>= 1.8.0) + unicorn (4.9.0) kgio (~> 2.6) rack raindrops (~> 0.7) - uuidtools (2.1.3) - warden (1.1.1) + uuidtools (2.1.5) + warden (1.2.3) rack (>= 1.0) - websocket (1.0.7) - xpath (1.0.0) + xpath (2.0.0) nokogiri (~> 1.3) PLATFORMS @@ -218,20 +198,19 @@ DEPENDENCIES comma (~> 3.0.4) cucumber-rails database_cleaner - devise (~> 2.0.5) + devise (~> 3.0) factory_girl_rails formtastic (~> 2.2) inherited_resources jquery-rails - json (= 1.7.7) nested_form! - paper_trail (~> 2) + paper_trail (~> 3.0.3) paperclip (~> 2.4) pg rabl - rails (~> 3.2.19) + rails (~> 4.0.12) rdiscount (~> 1.6.8) rspec-rails (~> 2.6) - sass-rails (~> 3.2.5) + sass-rails (~> 4.0.3) uglifier (>= 1.0.3) unicorn From 06c6b47d9c9513192e3ef59deac5d02ae0e272e2 Mon Sep 17 00:00:00 2001 From: Jordan Hatch Date: Mon, 6 Jul 2015 14:45:34 +0100 Subject: [PATCH 04/34] Update Bundle.require statement --- config/application.rb | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/config/application.rb b/config/application.rb index 115864b..3cff7ff 100644 --- a/config/application.rb +++ b/config/application.rb @@ -3,10 +3,7 @@ require 'rails/all' if defined?(Bundler) - # If you precompile assets before deploying to production, use this line - Bundler.require(*Rails.groups(:assets => %w(development test))) - # If you want your assets lazily compiled in production, use this line - # Bundler.require(:default, :assets, Rails.env) + Bundler.require(:default, Rails.env) end module Projects From 5089790e334d11132ce993ddc6603aefa42028b9 Mon Sep 17 00:00:00 2001 From: Jordan Hatch Date: Mon, 6 Jul 2015 14:45:44 +0100 Subject: [PATCH 05/34] Remove .rbenv-version file --- .rbenv-version | 1 - 1 file changed, 1 deletion(-) delete mode 100644 .rbenv-version diff --git a/.rbenv-version b/.rbenv-version deleted file mode 100644 index 0a95b9f..0000000 --- a/.rbenv-version +++ /dev/null @@ -1 +0,0 @@ -1.9.2-p290 From 7a17917c3098f29b23b05aece9b6629ddc72f1bb Mon Sep 17 00:00:00 2001 From: Jordan Hatch Date: Mon, 6 Jul 2015 14:45:50 +0100 Subject: [PATCH 06/34] Add binstubs --- bin/autospec | 16 ++++++++++++++++ bin/bundle | 3 +++ bin/rails | 4 ++++ bin/rake | 4 ++++ bin/rspec | 16 ++++++++++++++++ 5 files changed, 43 insertions(+) create mode 100755 bin/autospec create mode 100755 bin/bundle create mode 100755 bin/rails create mode 100755 bin/rake create mode 100755 bin/rspec diff --git a/bin/autospec b/bin/autospec new file mode 100755 index 0000000..64dcb9c --- /dev/null +++ b/bin/autospec @@ -0,0 +1,16 @@ +#!/usr/bin/env ruby +# +# This file was generated by Bundler. +# +# The application 'autospec' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +require 'pathname' +ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile", + Pathname.new(__FILE__).realpath) + +require 'rubygems' +require 'bundler/setup' + +load Gem.bin_path('rspec-core', 'autospec') diff --git a/bin/bundle b/bin/bundle new file mode 100755 index 0000000..66e9889 --- /dev/null +++ b/bin/bundle @@ -0,0 +1,3 @@ +#!/usr/bin/env ruby +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) +load Gem.bin_path('bundler', 'bundle') diff --git a/bin/rails b/bin/rails new file mode 100755 index 0000000..728cd85 --- /dev/null +++ b/bin/rails @@ -0,0 +1,4 @@ +#!/usr/bin/env ruby +APP_PATH = File.expand_path('../../config/application', __FILE__) +require_relative '../config/boot' +require 'rails/commands' diff --git a/bin/rake b/bin/rake new file mode 100755 index 0000000..1724048 --- /dev/null +++ b/bin/rake @@ -0,0 +1,4 @@ +#!/usr/bin/env ruby +require_relative '../config/boot' +require 'rake' +Rake.application.run diff --git a/bin/rspec b/bin/rspec new file mode 100755 index 0000000..0c86b5c --- /dev/null +++ b/bin/rspec @@ -0,0 +1,16 @@ +#!/usr/bin/env ruby +# +# This file was generated by Bundler. +# +# The application 'rspec' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +require 'pathname' +ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile", + Pathname.new(__FILE__).realpath) + +require 'rubygems' +require 'bundler/setup' + +load Gem.bin_path('rspec-core', 'rspec') From a0608d22651d90731a6bffd9c4412016ba21d79d Mon Sep 17 00:00:00 2001 From: Jordan Hatch Date: Mon, 6 Jul 2015 14:46:02 +0100 Subject: [PATCH 07/34] Remove vendor/plugins directory --- vendor/plugins/.gitkeep | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 vendor/plugins/.gitkeep diff --git a/vendor/plugins/.gitkeep b/vendor/plugins/.gitkeep deleted file mode 100644 index e69de29..0000000 From 90514dccb94498728985af6d2cf58c1249e7107d Mon Sep 17 00:00:00 2001 From: Jordan Hatch Date: Mon, 6 Jul 2015 14:48:00 +0100 Subject: [PATCH 08/34] Convert scopes to use block format --- app/models/.gitkeep | 0 app/models/award_category.rb | 2 +- app/models/centre.rb | 2 +- app/models/event.rb | 2 +- app/models/project.rb | 2 +- 5 files changed, 4 insertions(+), 4 deletions(-) delete mode 100644 app/models/.gitkeep diff --git a/app/models/.gitkeep b/app/models/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/app/models/award_category.rb b/app/models/award_category.rb index c24238c..1d4705e 100644 --- a/app/models/award_category.rb +++ b/app/models/award_category.rb @@ -2,7 +2,7 @@ class AwardCategory < ActiveRecord::Base belongs_to :event default_scope order('format DESC, level ASC, title ASC') - scope :featured, where(:featured => true) + scope :featured, -> { where(:featured => true) } has_many :awards, :dependent => :destroy has_many :award_winners, :through => :awards, :source => :project diff --git a/app/models/centre.rb b/app/models/centre.rb index 3b2bbb9..45e25bc 100644 --- a/app/models/centre.rb +++ b/app/models/centre.rb @@ -2,7 +2,7 @@ class Centre < ActiveRecord::Base belongs_to :event has_many :projects - default_scope order('name ASC') + default_scope -> { order('name ASC') } validates :name, :slug, :presence => true validates :slug, :uniqueness => { :case_sensitive => false, :scope => :event_id } diff --git a/app/models/event.rb b/app/models/event.rb index 5cbc019..f419fde 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -14,7 +14,7 @@ class Event < ActiveRecord::Base validates :title, :slug, :presence => true validates :slug, :uniqueness => { :case_sensitive => false } - scope :recent_first, order("start_date desc") + scope :recent_first, -> { order("start_date desc") } def to_param self.slug diff --git a/app/models/project.rb b/app/models/project.rb index 3f096ef..b6bbad4 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -5,7 +5,7 @@ class Project < ActiveRecord::Base has_paper_trail - default_scope order('title ASC') + default_scope -> { order('title ASC') } after_initialize :set_default_values has_many :awards From 0397ef6ca774fd3e2357989fb0a58fd93b75766e Mon Sep 17 00:00:00 2001 From: Jordan Hatch Date: Mon, 6 Jul 2015 14:53:14 +0100 Subject: [PATCH 09/34] Add secret_key_base --- config/initializers/secret_token.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/config/initializers/secret_token.rb b/config/initializers/secret_token.rb index a293b45..f89e5db 100644 --- a/config/initializers/secret_token.rb +++ b/config/initializers/secret_token.rb @@ -5,3 +5,4 @@ # Make sure the secret is at least 30 characters and all random, # no regular words or you'll be exposed to dictionary attacks. Projects::Application.config.secret_token = ENV['SECRET_TOKEN'] || "an_insecure_secret_token_key_which_should_not_be_used_in_production" +Projects::Application.config.secret_key_base = ENV['SECRET_KEY_BASE'] || "an_insecure_secret_token_key_which_should_not_be_used_in_production" From 59cbeed185e0d4038c41373f687ee562b341c6ba Mon Sep 17 00:00:00 2001 From: Jordan Hatch Date: Mon, 6 Jul 2015 14:53:27 +0100 Subject: [PATCH 10/34] Update environment settings for Rails 4 --- config/environments/development.rb | 5 ++--- config/environments/production.rb | 1 + config/environments/test.rb | 2 ++ 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/config/environments/development.rb b/config/environments/development.rb index 3142540..13b9bde 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -6,9 +6,6 @@ # since you don't have to restart the web server when you make code changes. config.cache_classes = false - # Log error messages when you accidentally call methods on nil. - config.whiny_nils = true - # Show full error reports and disable caching config.consider_all_requests_local = true config.action_controller.perform_caching = false @@ -29,4 +26,6 @@ config.assets.debug = true config.attachment_settings = { } + + config.eager_load = false end diff --git a/config/environments/production.rb b/config/environments/production.rb index 3daeffc..e20d138 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -69,4 +69,5 @@ path: "/:attachment/:id/:style/:filename" } + config.eager_load = true end diff --git a/config/environments/test.rb b/config/environments/test.rb index 7ad8302..6005bfa 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -38,4 +38,6 @@ config.active_support.deprecation = :stderr config.attachment_settings = { } + + config.eager_load = false end From 5c8a17b389f511a67dca96450b4c405419d18871 Mon Sep 17 00:00:00 2001 From: Jordan Hatch Date: Mon, 6 Jul 2015 14:53:40 +0100 Subject: [PATCH 11/34] Regenerate Devise config --- config/initializers/devise.rb | 138 ++++++++++++++++++++++------------ 1 file changed, 90 insertions(+), 48 deletions(-) diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb index 4bcf2af..67295bc 100644 --- a/config/initializers/devise.rb +++ b/config/initializers/devise.rb @@ -1,16 +1,21 @@ # Use this hook to configure devise mailer, warden hooks and so forth. # Many of these configuration options can be set straight in your model. Devise.setup do |config| + # The secret key used by Devise. Devise uses this key to generate + # random tokens. Changing this key will render invalid all existing + # confirmation, reset password and unlock tokens in the database. + # Devise will use the `secret_key_base` on Rails 4+ applications as its `secret_key` + # by default. You can change it below and use your own secret key. + # config.secret_key = '495893c9211f6b5486829e92025dbd389124362a4cff2cf0baf79155247c25b1466b151c551ecdd9a1e1156857806ed056d9ea6464c988fd8f5ef9ab48abc484' + # ==> Mailer Configuration # Configure the e-mail address which will be shown in Devise::Mailer, - # note that it will be overwritten if you use your own mailer class with default "from" parameter. - config.mailer_sender = "please-change-me-at-config-initializers-devise@example.com" + # note that it will be overwritten if you use your own mailer class + # with default "from" parameter. + config.mailer_sender = 'please-change-me-at-config-initializers-devise@example.com' # Configure the class responsible to send e-mails. - # config.mailer = "Devise::Mailer" - - # Automatically apply schema changes in tableless databases - config.apply_schema = false + # config.mailer = 'Devise::Mailer' # ==> ORM configuration # Load and configure the ORM. Supports :active_record (default) and @@ -26,7 +31,7 @@ # session. If you need permissions, you should implement that in a before filter. # You can also supply a hash where the value is a boolean determining whether # or not authentication should be aborted when the value is not present. - # config.authentication_keys = [ :email ] + # config.authentication_keys = [:email] # Configure parameters from the request object used for authentication. Each entry # given should be a request method and it will automatically be passed to the @@ -38,12 +43,12 @@ # Configure which authentication keys should be case-insensitive. # These keys will be downcased upon creating or modifying a user and when used # to authenticate or find a user. Default is :email. - config.case_insensitive_keys = [ :email ] + config.case_insensitive_keys = [:email] # Configure which authentication keys should have whitespace stripped. # These keys will have whitespace before and after removed upon creating or # modifying a user and when used to authenticate or find a user. Default is :email. - config.strip_whitespace_keys = [ :email ] + config.strip_whitespace_keys = [:email] # Tell if authentication through request.params is enabled. True by default. # It can be set to an array that will enable params authentication only for the @@ -51,17 +56,18 @@ # enable it only for database (email + password) authentication. # config.params_authenticatable = true - # Tell if authentication through HTTP Basic Auth is enabled. False by default. + # Tell if authentication through HTTP Auth is enabled. False by default. # It can be set to an array that will enable http authentication only for the - # given strategies, for example, `config.http_authenticatable = [:token]` will - # enable it only for token authentication. + # given strategies, for example, `config.http_authenticatable = [:database]` will + # enable it only for database authentication. The supported strategies are: + # :database = Support basic authentication with authentication key + password # config.http_authenticatable = false - # If http headers should be returned for AJAX requests. True by default. + # If 401 status code should be returned for AJAX requests. True by default. # config.http_authenticatable_on_xhr = true - # The realm used in Http Basic Authentication. "Application" by default. - # config.http_authentication_realm = "Application" + # The realm used in Http Basic Authentication. 'Application' by default. + # config.http_authentication_realm = 'Application' # It will change confirmation, password recovery and other workflows # to behave the same regardless if the e-mail provided was right or wrong. @@ -69,62 +75,77 @@ # config.paranoid = true # By default Devise will store the user in session. You can skip storage for - # :http_auth and :token_auth by adding those symbols to the array below. + # particular strategies by setting this option. # Notice that if you are skipping storage for all authentication paths, you # may want to disable generating routes to Devise's sessions controller by - # passing :skip => :sessions to `devise_for` in your config/routes.rb + # passing skip: :sessions to `devise_for` in your config/routes.rb config.skip_session_storage = [:http_auth] + # By default, Devise cleans up the CSRF token on authentication to + # avoid CSRF token fixation attacks. This means that, when using AJAX + # requests for sign in and sign up, you need to get a new CSRF token + # from the server. You can disable this option at your own risk. + # config.clean_up_csrf_token_on_authentication = true + # ==> Configuration for :database_authenticatable # For bcrypt, this is the cost for hashing the password and defaults to 10. If # using other encryptors, it sets how many times you want the password re-encrypted. # # Limiting the stretches to just one in testing will increase the performance of # your test suite dramatically. However, it is STRONGLY RECOMMENDED to not use - # a value less than 10 in other environments. + # a value less than 10 in other environments. Note that, for bcrypt (the default + # encryptor), the cost increases exponentially with the number of stretches (e.g. + # a value of 20 is already extremely slow: approx. 60 seconds for 1 calculation). config.stretches = Rails.env.test? ? 1 : 10 # Setup a pepper to generate the encrypted password. - # config.pepper = "a085156992a1884924a588a771b83e9d2fc1cc5b36dfd3793b0068b5fa2617504bb162b2c9c79827d2eee685f9a985eaf16f4ad99f2a2dc31d1c4e1b4adfa6e1" + # config.pepper = 'ab4bcfb765f6fc04a5f116b569c264551a8d024291ada36c4f9659a6e1d2d8d50a9f0b5628399a90877d589c4f427f447b020aeb4a51015de45323c019b1f53b' # ==> Configuration for :confirmable # A period that the user is allowed to access the website even without - # confirming his account. For instance, if set to 2.days, the user will be - # able to access the website for two days without confirming his account, + # confirming their account. For instance, if set to 2.days, the user will be + # able to access the website for two days without confirming their account, # access will be blocked just in the third day. Default is 0.days, meaning - # the user cannot access the website without confirming his account. + # the user cannot access the website without confirming their account. # config.allow_unconfirmed_access_for = 2.days - # If true, requires any email changes to be confirmed (exctly the same way as + # A period that the user is allowed to confirm their account before their + # token becomes invalid. For example, if set to 3.days, the user can confirm + # their account within 3 days after the mail was sent, but on the fourth day + # their account can't be confirmed with the token any more. + # Default is nil, meaning there is no restriction on how long a user can take + # before confirming their account. + # config.confirm_within = 3.days + + # If true, requires any email changes to be confirmed (exactly the same way as # initial account confirmation) to be applied. Requires additional unconfirmed_email - # db field (see migrations). Until confirmed new email is stored in - # unconfirmed email column, and copied to email column on successful confirmation. + # db field (see migrations). Until confirmed, new email is stored in + # unconfirmed_email column, and copied to email column on successful confirmation. config.reconfirmable = true # Defines which key will be used when confirming an account - # config.confirmation_keys = [ :email ] + # config.confirmation_keys = [:email] # ==> Configuration for :rememberable # The time the user will be remembered without asking for credentials again. # config.remember_for = 2.weeks + # Invalidates all the remember me tokens when the user signs out. + config.expire_all_remember_me_on_sign_out = true + # If true, extends the user's remember period when remembered via cookie. # config.extend_remember_period = false - # If true, uses the password salt as remember token. This should be turned - # to false if you are not using database authenticatable. - config.use_salt_as_remember_token = true - # Options to be passed to the created cookie. For instance, you can set - # :secure => true in order to force SSL only cookies. - # config.cookie_options = {} + # secure: true in order to force SSL only cookies. + # config.rememberable_options = {} # ==> Configuration for :validatable - # Range for password length. Default is 6..128. - # config.password_length = 6..128 + # Range for password length. + config.password_length = 8..72 # Email regex used to validate email formats. It simply asserts that - # an one (and only one) @ exists in the given string. This is mainly + # one (and only one) @ exists in the given string. This is mainly # to give user feedback and not to assert the e-mail validity. # config.email_regexp = /\A[^@]+@[^@]+\z/ @@ -133,6 +154,9 @@ # time the user will be asked for credentials again. Default is 30 minutes. # config.timeout_in = 30.minutes + # If true, expires auth token on session timeout. + # config.expire_auth_token_on_timeout = false + # ==> Configuration for :lockable # Defines which strategy will be used to lock an account. # :failed_attempts = Locks an account after a number of failed attempts to sign in. @@ -140,7 +164,7 @@ # config.lock_strategy = :failed_attempts # Defines which key will be used when locking and unlocking an account - # config.unlock_keys = [ :email ] + # config.unlock_keys = [:email] # Defines which strategy will be used to unlock an account. # :email = Sends an unlock link to the user email @@ -156,28 +180,33 @@ # Time interval to unlock the account if :time is enabled as unlock_strategy. # config.unlock_in = 1.hour + # Warn on the last attempt before the account is locked. + # config.last_attempt_warning = true + # ==> Configuration for :recoverable # # Defines which key will be used when recovering the password for an account - # config.reset_password_keys = [ :email ] + # config.reset_password_keys = [:email] # Time interval you can reset your password with a reset password key. # Don't put a too small interval or your users won't have the time to # change their passwords. config.reset_password_within = 6.hours + # When set to false, does not sign a user in automatically after their password is + # reset. Defaults to true, so a user is signed in automatically after a reset. + # config.sign_in_after_reset_password = true + # ==> Configuration for :encryptable # Allow you to use another encryption algorithm besides bcrypt (default). You can use # :sha1, :sha512 or encryptors from others authentication tools as :clearance_sha1, # :authlogic_sha512 (then you should set stretches above to 20 for default behavior) # and :restful_authentication_sha1 (then you should set stretches to 10, and copy - # REST_AUTH_SITE_KEY to pepper) + # REST_AUTH_SITE_KEY to pepper). + # + # Require the `devise-encryptable` gem when using anything other than bcrypt # config.encryptor = :sha512 - # ==> Configuration for :token_authenticatable - # Defines name of the authentication token params key - # config.token_authentication_key = :auth_token - # ==> Scopes configuration # Turn scoped views on. Before rendering "sessions/new", it will first check for # "users/sessions/new". It's turned off by default because it's slower if you @@ -188,9 +217,8 @@ # devise role declared in your routes (usually :user). # config.default_scope = :user - # Configure sign_out behavior. - # Sign_out action can be scoped (i.e. /users/sign_out affects only :user scope). - # The default is true, which means any logout action will sign out all active scopes. + # Set this configuration to false if you want /users/sign_out to sign out + # only the current scope. By default, Devise signs out all scopes. # config.sign_out_all_scopes = true # ==> Navigation configuration @@ -202,7 +230,7 @@ # should add them to the navigational formats lists. # # The "*/*" below is required to match Internet Explorer requests. - # config.navigational_formats = ["*/*", :html] + # config.navigational_formats = ['*/*', :html] # The default HTTP method used to sign out a resource. Default is :delete. config.sign_out_via = :delete @@ -210,7 +238,7 @@ # ==> OmniAuth # Add a new OmniAuth provider. Check the wiki for more information on setting # up on your models and hooks. - # config.omniauth :github, 'APP_ID', 'APP_SECRET', :scope => 'user,public_repo' + # config.omniauth :github, 'APP_ID', 'APP_SECRET', scope: 'user,public_repo' # ==> Warden configuration # If you want to use other strategies, that are not supported by Devise, or @@ -218,6 +246,20 @@ # # config.warden do |manager| # manager.intercept_401 = false - # manager.default_strategies(:scope => :user).unshift :some_external_strategy + # manager.default_strategies(scope: :user).unshift :some_external_strategy # end + + # ==> Mountable engine configurations + # When using Devise inside an engine, let's call it `MyEngine`, and this engine + # is mountable, there are some extra configurations to be taken into account. + # The following options are available, assuming the engine is mounted as: + # + # mount MyEngine, at: '/my_engine' + # + # The router that invoked `devise_for`, in the example above, would be: + # config.router_name = :my_engine + # + # When using OmniAuth, Devise cannot automatically set OmniAuth path, + # so you need to do it manually. For the users scope, it would be: + # config.omniauth_path_prefix = '/my_engine/users/auth' end From e44e5e9e03b1b3ed35135d5815d7b5984de29f2a Mon Sep 17 00:00:00 2001 From: Jordan Hatch Date: Mon, 6 Jul 2015 15:10:23 +0100 Subject: [PATCH 12/34] Update specs to RSpec 3.x format --- Gemfile | 2 +- Gemfile.lock | 34 ++++++++------- .../admin/events_controller_spec.rb | 8 ++-- .../admin/projects_controller_spec.rb | 10 +++-- spec/controllers/events_controller_spec.rb | 2 +- spec/controllers/projects_controller_spec.rb | 6 +-- spec/helpers/projects_helper_spec.rb | 4 +- spec/models/award_category_spec.rb | 4 +- spec/models/centre_spec.rb | 4 +- spec/models/event_spec.rb | 4 +- spec/models/project_spec.rb | 4 +- spec/rails_helper.rb | 29 +++++++++++++ spec/spec_helper.rb | 42 ++++++++++--------- spec/support/controller_macros.rb | 15 ++++--- 14 files changed, 105 insertions(+), 63 deletions(-) create mode 100644 spec/rails_helper.rb diff --git a/Gemfile b/Gemfile index 98faa50..824e1d2 100644 --- a/Gemfile +++ b/Gemfile @@ -35,6 +35,6 @@ group :test do end group :development, :test do - gem 'rspec-rails', '~> 2.6' + gem 'rspec-rails', '~> 3.1' gem 'capybara' end diff --git a/Gemfile.lock b/Gemfile.lock index f49dcd7..a2d4247 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -141,21 +141,23 @@ GEM rdiscount (1.6.8) responders (1.1.2) railties (>= 3.2, < 4.2) - rspec-collection_matchers (1.1.2) - rspec-expectations (>= 2.99.0.beta1) - rspec-core (2.99.2) - rspec-expectations (2.99.2) - diff-lcs (>= 1.1.3, < 2.0) - rspec-mocks (2.99.4) - rspec-rails (2.99.0) - actionpack (>= 3.0) - activemodel (>= 3.0) - activesupport (>= 3.0) - railties (>= 3.0) - rspec-collection_matchers - rspec-core (~> 2.99.0) - rspec-expectations (~> 2.99.0) - rspec-mocks (~> 2.99.0) + rspec-core (3.3.1) + rspec-support (~> 3.3.0) + rspec-expectations (3.3.0) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.3.0) + rspec-mocks (3.3.1) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.3.0) + rspec-rails (3.3.2) + actionpack (>= 3.0, < 4.3) + activesupport (>= 3.0, < 4.3) + railties (>= 3.0, < 4.3) + rspec-core (~> 3.3.0) + rspec-expectations (~> 3.3.0) + rspec-mocks (~> 3.3.0) + rspec-support (~> 3.3.0) + rspec-support (3.3.0) sass (3.2.19) sass-rails (4.0.5) railties (>= 4.0.0, < 5.0) @@ -210,7 +212,7 @@ DEPENDENCIES rabl rails (~> 4.0.12) rdiscount (~> 1.6.8) - rspec-rails (~> 2.6) + rspec-rails (~> 3.1) sass-rails (~> 4.0.3) uglifier (>= 1.0.3) unicorn diff --git a/spec/controllers/admin/events_controller_spec.rb b/spec/controllers/admin/events_controller_spec.rb index a72ab04..7e0e721 100644 --- a/spec/controllers/admin/events_controller_spec.rb +++ b/spec/controllers/admin/events_controller_spec.rb @@ -1,6 +1,6 @@ -require 'spec_helper' +require 'rails_helper' -describe Admin::EventsController do +RSpec.describe Admin::EventsController do context "when not signed in" do describe "GET 'index'" do @@ -12,7 +12,9 @@ end context "when signed in" do - login_admin + before(:each) { + login_admin + } describe "GET index" do it "should be successful" do diff --git a/spec/controllers/admin/projects_controller_spec.rb b/spec/controllers/admin/projects_controller_spec.rb index 226a60e..c1025ad 100644 --- a/spec/controllers/admin/projects_controller_spec.rb +++ b/spec/controllers/admin/projects_controller_spec.rb @@ -1,6 +1,6 @@ -require 'spec_helper' +require 'rails_helper' -describe Admin::ProjectsController do +RSpec.describe Admin::ProjectsController do before do @event = FactoryGirl.create(:event_without_secret) @@ -16,7 +16,9 @@ end context "when signed in" do - login_admin + before(:each) { + login_admin + } describe "GET index" do it "should be successful" do @@ -73,4 +75,4 @@ end end -end \ No newline at end of file +end diff --git a/spec/controllers/events_controller_spec.rb b/spec/controllers/events_controller_spec.rb index b5ee6f0..3cb6263 100644 --- a/spec/controllers/events_controller_spec.rb +++ b/spec/controllers/events_controller_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require 'rails_helper' describe EventsController do describe "GET index" do diff --git a/spec/controllers/projects_controller_spec.rb b/spec/controllers/projects_controller_spec.rb index 3bd2c29..2afdc79 100644 --- a/spec/controllers/projects_controller_spec.rb +++ b/spec/controllers/projects_controller_spec.rb @@ -1,6 +1,6 @@ -require 'spec_helper' +require 'rails_helper' -describe ProjectsController do +RSpec.describe ProjectsController do before do @event = FactoryGirl.create(:event_without_secret) @@ -88,4 +88,4 @@ end end -end \ No newline at end of file +end diff --git a/spec/helpers/projects_helper_spec.rb b/spec/helpers/projects_helper_spec.rb index be5dd3f..a4e44a9 100644 --- a/spec/helpers/projects_helper_spec.rb +++ b/spec/helpers/projects_helper_spec.rb @@ -1,6 +1,6 @@ -require 'spec_helper' +require 'rails_helper' -describe ProjectsHelper do +RSpec.describe ProjectsHelper do describe "#format_github_url" do it "returns the username and repository when given a valid http url" do diff --git a/spec/models/award_category_spec.rb b/spec/models/award_category_spec.rb index d51043c..9d3a482 100644 --- a/spec/models/award_category_spec.rb +++ b/spec/models/award_category_spec.rb @@ -1,6 +1,6 @@ -require 'spec_helper' +require 'rails_helper' -describe AwardCategory do +RSpec.describe AwardCategory do describe "creating an award category" do before do diff --git a/spec/models/centre_spec.rb b/spec/models/centre_spec.rb index ddf4a3c..0ad5eaf 100644 --- a/spec/models/centre_spec.rb +++ b/spec/models/centre_spec.rb @@ -1,6 +1,6 @@ -require 'spec_helper' +require 'rails_helper' -describe Centre do +RSpec.describe Centre do describe "creating a centre" do before do diff --git a/spec/models/event_spec.rb b/spec/models/event_spec.rb index 2558f2c..e12ce97 100644 --- a/spec/models/event_spec.rb +++ b/spec/models/event_spec.rb @@ -1,6 +1,6 @@ -require 'spec_helper' +require 'rails_helper' -describe Event do +RSpec.describe Event do describe "creating an event" do before do diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 99ae303..b47e389 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -1,6 +1,6 @@ -require 'spec_helper' +require 'rails_helper' -describe Project do +RSpec.describe Project do describe "creating an project" do before do diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb new file mode 100644 index 0000000..7c03318 --- /dev/null +++ b/spec/rails_helper.rb @@ -0,0 +1,29 @@ +ENV["RAILS_ENV"] ||= 'test' +require 'spec_helper' +require File.expand_path("../../config/environment", __FILE__) +require 'rspec/rails' +require 'capybara/rspec' + +Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f} + +# ActiveRecord::Migration.maintain_test_schema! + +require 'database_cleaner' + +RSpec.configure do |config| + config.before(:suite) do + DatabaseCleaner.strategy = :transaction + end + + config.before(:each) do + DatabaseCleaner.start + end + + config.after(:each) do + DatabaseCleaner.clean + end + + config.infer_base_class_for_anonymous_controllers = false + + config.infer_spec_type_from_file_location! +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 01654eb..4f2563a 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,27 +1,29 @@ -ENV["RAILS_ENV"] ||= 'test' -require File.expand_path("../../config/environment", __FILE__) -require 'rspec/rails' -require 'rspec/autorun' - -Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f} - -require 'database_cleaner' - RSpec.configure do |config| - config.before(:suite) do - DatabaseCleaner.strategy = :transaction + config.expect_with :rspec do |expectations| + expectations.include_chain_clauses_in_custom_matcher_descriptions = true end - config.before(:each) do - DatabaseCleaner.start + config.mock_with :rspec do |mocks| + mocks.verify_partial_doubles = true end - config.after(:each) do - DatabaseCleaner.clean - end + # Limits the available syntax to the non-monkey patched syntax that is recommended. + # For more details, see: + # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax + # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/ + # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching + # config.disable_monkey_patching! - config.include Devise::TestHelpers, :type => :controller - config.extend ControllerMacros, :type => :controller + # Many RSpec users commonly either run the entire suite or an individual + # file, and it's useful to allow more verbose output when running an + # individual spec file. + if config.files_to_run.one? + # Use the documentation formatter for detailed output, + # unless a formatter has already been configured + # (e.g. via a command-line flag). + config.default_formatter = 'doc' + end - config.infer_base_class_for_anonymous_controllers = false -end \ No newline at end of file + config.order = :random + Kernel.srand config.seed +end diff --git a/spec/support/controller_macros.rb b/spec/support/controller_macros.rb index 6879f0f..7020db8 100644 --- a/spec/support/controller_macros.rb +++ b/spec/support/controller_macros.rb @@ -1,8 +1,13 @@ module ControllerMacros + include Devise::TestHelpers + def login_admin - before(:each) do - @request.env["devise.mapping"] = Devise.mappings[:admin] - sign_in FactoryGirl.create(:admin) - end + @request.env["devise.mapping"] = Devise.mappings[:admin] + sign_in FactoryGirl.create(:admin) end -end \ No newline at end of file +end + +RSpec.configure do |config| + config.include Devise::TestHelpers, type: :controller + config.include ControllerMacros, :type => :controller +end From d6c4fa420c3b68bc3250b8bb43762fe70d8d793d Mon Sep 17 00:00:00 2001 From: Jordan Hatch Date: Mon, 6 Jul 2015 15:10:34 +0100 Subject: [PATCH 13/34] Remove whiny_nils config in test.rb --- config/environments/test.rb | 3 --- 1 file changed, 3 deletions(-) diff --git a/config/environments/test.rb b/config/environments/test.rb index 6005bfa..6933be0 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -11,9 +11,6 @@ config.serve_static_assets = true config.static_cache_control = "public, max-age=3600" - # Log error messages when you accidentally call methods on nil - config.whiny_nils = true - # Show full error reports and disable caching config.consider_all_requests_local = true config.action_controller.perform_caching = false From 86e3c7e7e83939aec93464585007625ef8baa500 Mon Sep 17 00:00:00 2001 From: Jordan Hatch Date: Mon, 6 Jul 2015 15:10:42 +0100 Subject: [PATCH 14/34] Simplify local db configuration --- config/database.yml | 43 +------------------------------------------ 1 file changed, 1 insertion(+), 42 deletions(-) diff --git a/config/database.yml b/config/database.yml index 8260c4f..d2bcee7 100644 --- a/config/database.yml +++ b/config/database.yml @@ -1,55 +1,14 @@ -# PostgreSQL. Versions 8.2 and up are supported. -# -# Install the pg driver: -# gem install pg -# On Mac OS X with macports: -# gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config -# On Windows: -# gem install pg -# Choose the win32 build. -# Install PostgreSQL and put its /bin directory on your path. -# -# Configure Using Gemfile -# gem 'pg' -# development: adapter: postgresql encoding: unicode - database: hacks_development - pool: 5 - username: hacks - password: + host: localhost - # Connect on a TCP socket. Omitted by default since the client uses a - # domain socket that doesn't need configuration. Windows does not have - # domain sockets, so uncomment these lines. - #host: localhost - #port: 5432 - - # Schema search path. The server defaults to $user,public - #schema_search_path: myapp,sharedapp,public - - # Minimum log levels, in increasing order: - # debug5, debug4, debug3, debug2, debug1, - # log, notice, warning, error, fatal, and panic - # The server defaults to notice. - #min_messages: warning - -# Warning: The database defined as "test" will be erased and -# re-generated from your development database when you run "rake". -# Do not set this db to the same as development or production. test: adapter: postgresql encoding: unicode database: hacks_test - pool: 5 - username: hacks - password: production: adapter: postgresql encoding: unicode database: hacks_production - pool: 5 - username: hacks - password: From 3eca4c423e4e330f85edfb9f4df9ae6b33d1d8f7 Mon Sep 17 00:00:00 2001 From: Jordan Hatch Date: Tue, 7 Jul 2015 11:17:21 +0100 Subject: [PATCH 15/34] Refactor test helpers --- spec/support/attachment_helper.rb | 22 +++++++++++++++++++ .../controller_authentication_helper.rb | 13 +++++++++++ spec/support/controller_macros.rb | 13 ----------- spec/support/factory_girl.rb | 3 +++ spec/support/file_uploads.rb | 8 ------- 5 files changed, 38 insertions(+), 21 deletions(-) create mode 100644 spec/support/attachment_helper.rb create mode 100644 spec/support/controller_authentication_helper.rb delete mode 100644 spec/support/controller_macros.rb create mode 100644 spec/support/factory_girl.rb delete mode 100644 spec/support/file_uploads.rb diff --git a/spec/support/attachment_helper.rb b/spec/support/attachment_helper.rb new file mode 100644 index 0000000..642b03a --- /dev/null +++ b/spec/support/attachment_helper.rb @@ -0,0 +1,22 @@ +module AttachmentHelper + def stub_attachment_behaviour + # by stubbing out the has_attached_file class method call on the Project + # model, this should stop Paperclip from being initialized during test runs, + # therefore our tests should run faster + # + allow(Project).to receive(:has_attached_file).and_return(true) + end + + def stub_uploaded_image(filename = 'image.jpg', filetype = 'image/jpeg') + Rack::Test::UploadedFile.new("spec/fixtures/paperclip/#{filename}", filetype) + end +end + +RSpec.configure do |config| + config.include AttachmentHelper + + config.before(:each) do + # stub_attachment_behaviour + end +end +FactoryGirl::SyntaxRunner.send(:include, AttachmentHelper) diff --git a/spec/support/controller_authentication_helper.rb b/spec/support/controller_authentication_helper.rb new file mode 100644 index 0000000..0d4e0ab --- /dev/null +++ b/spec/support/controller_authentication_helper.rb @@ -0,0 +1,13 @@ +module ControllerAuthenticationHelper + def sign_in_admin + @request.env["devise.mapping"] = Devise.mappings[:admin] + + @user = create(:admin) + sign_in @user + end +end + +RSpec.configure do |config| + config.include Devise::TestHelpers, type: :controller + config.include ControllerAuthenticationHelper, type: :controller +end diff --git a/spec/support/controller_macros.rb b/spec/support/controller_macros.rb deleted file mode 100644 index 7020db8..0000000 --- a/spec/support/controller_macros.rb +++ /dev/null @@ -1,13 +0,0 @@ -module ControllerMacros - include Devise::TestHelpers - - def login_admin - @request.env["devise.mapping"] = Devise.mappings[:admin] - sign_in FactoryGirl.create(:admin) - end -end - -RSpec.configure do |config| - config.include Devise::TestHelpers, type: :controller - config.include ControllerMacros, :type => :controller -end diff --git a/spec/support/factory_girl.rb b/spec/support/factory_girl.rb new file mode 100644 index 0000000..eec437f --- /dev/null +++ b/spec/support/factory_girl.rb @@ -0,0 +1,3 @@ +RSpec.configure do |config| + config.include FactoryGirl::Syntax::Methods +end diff --git a/spec/support/file_uploads.rb b/spec/support/file_uploads.rb deleted file mode 100644 index f3a1550..0000000 --- a/spec/support/file_uploads.rb +++ /dev/null @@ -1,8 +0,0 @@ -def stub_uploaded_image(filename = 'image.jpg') - Project.stub!(:has_attached_file).with(:image).and_return(true) - File.new("spec/fixtures/paperclip/#{filename}") -end - -def stub_uploaded_file(filename = 'image.jpg', filetype = 'image/jpg') - Rack::Test::UploadedFile.new("spec/fixtures/paperclip/#{filename}", filetype) -end \ No newline at end of file From 59ebab602fb324625b7255f5b63047d61d679b80 Mon Sep 17 00:00:00 2001 From: Jordan Hatch Date: Tue, 7 Jul 2015 11:18:52 +0100 Subject: [PATCH 16/34] Update models for Rails 4 --- app/models/award_category.rb | 2 +- app/models/centre.rb | 2 +- app/models/event.rb | 2 +- app/models/project.rb | 25 ++++++++++++------------- 4 files changed, 15 insertions(+), 16 deletions(-) diff --git a/app/models/award_category.rb b/app/models/award_category.rb index 1d4705e..9e0d49e 100644 --- a/app/models/award_category.rb +++ b/app/models/award_category.rb @@ -1,7 +1,7 @@ class AwardCategory < ActiveRecord::Base belongs_to :event - default_scope order('format DESC, level ASC, title ASC') + default_scope -> { order('format DESC, level ASC, title ASC') } scope :featured, -> { where(:featured => true) } has_many :awards, :dependent => :destroy diff --git a/app/models/centre.rb b/app/models/centre.rb index 45e25bc..1be5c81 100644 --- a/app/models/centre.rb +++ b/app/models/centre.rb @@ -11,7 +11,7 @@ class Centre < ActiveRecord::Base private def create_slug - existing_slugs = event.centres.all.select {|a| a.slug.match(/^#{self.name.parameterize}(\-[0-9]+)?$/) }.size + existing_slugs = event.centres.select {|a| a.slug.match(/^#{self.name.parameterize}(\-[0-9]+)?$/) }.size self.slug = (existing_slugs > 0 ? "#{self.name.parameterize}-#{existing_slugs+1}" : self.name.parameterize) end end diff --git a/app/models/event.rb b/app/models/event.rb index f419fde..40dedca 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -21,7 +21,7 @@ def to_param end def winners - self.award_categories.featured.all.map {|i| i.award_winners.all }.flatten.uniq + self.award_categories.featured.map(&:award_winners).flatten.uniq end def has_secret? diff --git a/app/models/project.rb b/app/models/project.rb index b6bbad4..1221966 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -11,9 +11,6 @@ class Project < ActiveRecord::Base has_many :awards has_many :award_categories, :class_name => 'AwardCategory', :through => :awards - attr_accessible :title, :team, :url, :secret, :my_secret, :image, :summary, :description, :ideas, :data, :twitter, :github_url, :svn_url, :code_url, :centre, :centre_id - attr_accessible :title, :team, :url, :secret, :image, :summary, :description, :ideas, :data, :twitter, :github_url, :svn_url, :code_url, :awards_attributes, :centre, :centre_id, :slug, :as => :admin - accepts_nested_attributes_for :awards, :reject_if => :all_blank, :allow_destroy => true has_attached_file( :image, Rails.application.config.attachment_settings.merge({ @@ -47,16 +44,18 @@ class Project < ActiveRecord::Base validates :centre, :presence => true, :if => proc { |a| a.event.use_centres == true } validate :ensure_project_creation_is_enabled, :on => :create - validates_attachment_presence :image, :on => :create - validates_attachment_size :image, :less_than=>1.megabyte, :if => Proc.new { |i| !i.image.file? } + validates_attachment :image, presence: true, + content_type: { + content_type: ["image/jpeg", "image/gif", "image/png"] + }, + size: { + less_than: 1.megabyte, + } + + validates_each :my_secret, :on => :create, :if => :event_secret_required? do |model, attr, value| + model.errors.add(attr, "is incorrect") if (value != model.event.secret) + end - with_options :unless => :managing do |o| - o.validates_each :my_secret, :on => :create, :if => :event_secret_required? do |model, attr, value| - model.errors.add(attr, "is incorrect") if (value != model.event.secret) - end - o.validates_each :my_secret, :on => :update do |model, attr, value| - model.errors.add(attr, 'is incorrect') if (value != model.project_or_event_secret) - end end def to_param @@ -89,7 +88,7 @@ def has_won_award? end def notes - "" + "" end def project_url From 2a8b49f086a4c0098c2617582c9acc812241d692 Mon Sep 17 00:00:00 2001 From: Jordan Hatch Date: Tue, 7 Jul 2015 11:19:17 +0100 Subject: [PATCH 17/34] Refactor Admin#EventsController --- app/controllers/admin/events_controller.rb | 47 ++++++++++++++++--- app/views/admin/events/_form.html.erb | 8 ++-- app/views/admin/events/edit.html.erb | 6 +-- app/views/admin/events/index.html.erb | 4 +- app/views/admin/events/new.html.erb | 2 +- .../admin/events_controller_spec.rb | 34 +++++--------- 6 files changed, 63 insertions(+), 38 deletions(-) diff --git a/app/controllers/admin/events_controller.rb b/app/controllers/admin/events_controller.rb index 7986c83..e0eed0c 100644 --- a/app/controllers/admin/events_controller.rb +++ b/app/controllers/admin/events_controller.rb @@ -1,16 +1,49 @@ class Admin::EventsController < Admin::BaseController + before_filter do + breadcrumbs.add "Events", admin_events_path + end - inherit_resources + def create + event.assign_attributes(event_params) - actions :all, :except => :show + if event.save + redirect_to admin_events_path + else + render action: :new + end + end - before_filter do - breadcrumbs.add "Events", collection_path + def update + if event.update_attributes(event_params) + redirect_to admin_events_path + else + render action: :edit + end end - protected - def resource + def destroy + event.destroy + redirect_to admin_events_path + end + + def event + if params.key?(:id) @event ||= Event.find_by_slug(params[:id]) + else + @event ||= Event.new + end + end + helper_method :event + + def events + @events ||= Event.all + end + helper_method :events + + private + def event_params + params.fetch(:event, {}).permit(:title, :slug, :hashtag, :use_centres, + :secret, :active, :url, :enable_project_creation, :start_date) end -end \ No newline at end of file +end diff --git a/app/views/admin/events/_form.html.erb b/app/views/admin/events/_form.html.erb index 28b9bcf..1126ee9 100644 --- a/app/views/admin/events/_form.html.erb +++ b/app/views/admin/events/_form.html.erb @@ -1,20 +1,20 @@ -<%= semantic_nested_form_for [:admin,resource] do |f| %> +<%= semantic_nested_form_for [:admin, event] do |f| %> <%= f.semantic_errors %> <%= f.inputs do %> <%= f.input :title %> <%= f.input :start_date, :as => :string %> - <%= f.input :slug, ( resource.persisted? ? { :input_html => { :disabled => true } } : { } ) %> + <%= f.input :slug, ( event.persisted? ? { :input_html => { :disabled => true } } : { } ) %> <%= f.input :secret, :label => "Event secret", :input_html => { :placeholder => "If blank, projects must create their own passwords"} %> <%= f.input :url, :label => "Event homepage", :input_html => { :placeholder => "http://" } %> - <%= f.input :use_centres, disable_if_persisted(resource, { :input_html => { :disabled => true } }).merge({ :as => :select, :label => "Event type", :collection => { "Hacks shown together in list" => false, "Hacks grouped by centre" => true }, :include_blank => false }) %> + <%= f.input :use_centres, disable_if_persisted(event, { :input_html => { :disabled => true } }).merge({ :as => :select, :label => "Event type", :collection => { "Hacks shown together in list" => false, "Hacks grouped by centre" => true }, :include_blank => false }) %> <% end %> <%= f.inputs do %> <%= f.input :enable_project_creation, :label => "Allow new hacks to be created?" %> <% end %> - <% unless resource.new_record? or !resource.use_centres %> + <% unless event.new_record? or !event.use_centres %> <%= f.inputs "Centres" do %> <%= f.semantic_fields_for :centres do |centre_fields| %> <%= centre_fields.input :name %> diff --git a/app/views/admin/events/edit.html.erb b/app/views/admin/events/edit.html.erb index 612bf90..561a915 100644 --- a/app/views/admin/events/edit.html.erb +++ b/app/views/admin/events/edit.html.erb @@ -1,5 +1,5 @@ -<% content_for(:title) { "Edit #{resource.title}" } %> +<% content_for(:title) { "Edit #{event.title}" } %> -

Edit <%= resource.title %>

+

Edit <%= event.title %>

-<%= render :partial => "form" %> \ No newline at end of file +<%= render :partial => "form" %> diff --git a/app/views/admin/events/index.html.erb b/app/views/admin/events/index.html.erb index 09edc32..aa1f97e 100644 --- a/app/views/admin/events/index.html.erb +++ b/app/views/admin/events/index.html.erb @@ -15,6 +15,6 @@ - <%= render :partial => "event", :collection => collection %> + <%= render :partial => "event", :collection => events %> - \ No newline at end of file + diff --git a/app/views/admin/events/new.html.erb b/app/views/admin/events/new.html.erb index 2ecb2c8..af12f58 100644 --- a/app/views/admin/events/new.html.erb +++ b/app/views/admin/events/new.html.erb @@ -2,4 +2,4 @@

New Event

-<%= render :partial => "form" %> \ No newline at end of file +<%= render :partial => "form" %> diff --git a/spec/controllers/admin/events_controller_spec.rb b/spec/controllers/admin/events_controller_spec.rb index 7e0e721..1d137b4 100644 --- a/spec/controllers/admin/events_controller_spec.rb +++ b/spec/controllers/admin/events_controller_spec.rb @@ -6,20 +6,20 @@ describe "GET 'index'" do it "should redirect to the login form" do get :index - response.should be_redirect + expect(response).to be_redirect end end end context "when signed in" do before(:each) { - login_admin + sign_in_admin } describe "GET index" do it "should be successful" do get :index - response.should be_success + expect(response).to be_success end it "can assign a collection of all the events" do @@ -27,40 +27,32 @@ @event_two = FactoryGirl.create(:event) get :index - assigns(:events).should =~ [@event_one, @event_two] + expect(controller.events).to contain_exactly(@event_one, @event_two) end end describe "POST create" do context "given valid attributes" do - before do - @valid_attributes = { - :title => "Example Event", - :secret => nil, - :start_date => "1 January 2013", - :award_categories_attributes => [ - { :title => "Best in Show", :format => "overall", :level => "1" } - ] - } - end + let(:attributes) { attributes_for(:event) } it "should create the event" do - post :create, :event => @valid_attributes - assigns(:event).should be_persisted - assigns(:event).title.should == "Example Event" - assigns(:event).start_date.should == Date.parse("1 January 2013") + post :create, :event => attributes + + expect(controller.event).to be_persisted + expect(controller.event.title).to eq(attributes[:title]) end it "should redirect to the event list" do - post :create, :event => @valid_attributes - response.should redirect_to(admin_events_path) + post :create, :event => attributes + + expect(response).to redirect_to(admin_events_path) end end context "given invalid attributes" do it "should render the form" do post :create, :event => { } - response.should render_template(:new) + expect(response).to render_template(:new) end end end From 091ccc857083ef7131009ba4575a89938e0582e1 Mon Sep 17 00:00:00 2001 From: Jordan Hatch Date: Tue, 7 Jul 2015 11:19:40 +0100 Subject: [PATCH 18/34] Update ProjectsController spec --- spec/controllers/projects_controller_spec.rb | 94 ++++++++++---------- 1 file changed, 45 insertions(+), 49 deletions(-) diff --git a/spec/controllers/projects_controller_spec.rb b/spec/controllers/projects_controller_spec.rb index 2afdc79..19f1bf0 100644 --- a/spec/controllers/projects_controller_spec.rb +++ b/spec/controllers/projects_controller_spec.rb @@ -1,89 +1,85 @@ require 'rails_helper' -RSpec.describe ProjectsController do +RSpec.describe ProjectsController, type: :controller do - before do - @event = FactoryGirl.create(:event_without_secret) - end + let(:event) { FactoryGirl.create(:event_without_secret) } describe "POST create" do context "given valid attributes" do - before do - @valid_attributes = { - :title => "Project One", - :team => "Roland and Michael", - :description => "The ultimate hack. Every hack you've ever dreamed of in one. Defining an entire genre of hacks.", - :summary => "A shorter summary of how awesome this project is", - :url => "http://example.project.com/", - :twitter => "@rewiredstate", - :github_url => "http://github.com/rewiredstate/hacks", - :image => stub_uploaded_file, - :secret => "secret" - } - end + let(:attributes) { attributes_for(:project_with_secret) } it "should create the project" do - post :create, :event_id => @event.slug, :project => @valid_attributes - assigns(:project).title.should == "Project One" - assigns(:project).team.should == "Roland and Michael" + expect { + post :create, :event_id => event.slug, :project => attributes + }.to change { + Project.count + }.by(1) + + expect(assigns(:project)).to be_persisted + expect(assigns(:project).title).to eq(attributes[:title]) end it "should redirect to the project" do - post :create, :event_id => @event.slug, :project => @valid_attributes - response.should redirect_to(event_project_path(@event,"project-one")) + post :create, :event_id => event.slug, :project => attributes + + expect(response).to redirect_to( + event_project_path(event, assigns(:project)) + ) end end context "given invalid attributes" do - before do - @invalid_attributes = { - :title => "" - } - end + let(:invalid_attributes) { + { title: "" } + } it "should render the new form" do - post :create, :event_id => @event.slug, :project => @invalid_attributes - response.should render_template(:new) + post :create, :event_id => event.slug, :project => invalid_attributes + + expect(response).to render_template(:new) end end end describe "PUT update" do - before do - @project = FactoryGirl.create(:project, :event => @event, :secret => 'secret') - end + let(:project) { + FactoryGirl.create(:project, :event => event, :secret => 'secret') + } context "given valid attributes" do - before do - @valid_attributes = { - :title => "Modified Project Title", - :team => "Ian and Mark", - :my_secret => "secret" + let(:valid_attributes) { + { + title: "Modified Project Title", + team: "Ian and Mark", + my_secret: "secret", } - end + } it "should create the project" do - put :update, :id => @project.slug, :event_id => @event.slug, :project => @valid_attributes - assigns(:project).title.should == "Modified Project Title" - assigns(:project).team.should == "Ian and Mark" + put :update, :id => project.slug, :event_id => event.slug, :project => valid_attributes + + expect(assigns(:project).title).to eq("Modified Project Title") + expect(assigns(:project).team).to eq("Ian and Mark") end it "should redirect to the project" do - post :update, :id => @project.slug, :event_id => @event.slug, :project => @valid_attributes - response.should redirect_to(event_project_path(@event, @project)) + post :update, :id => project.slug, :event_id => event.slug, :project => valid_attributes + + expect(response).to redirect_to(event_project_path(event, project)) end end context "given invalid attributes" do - before do - @invalid_attributes = { - :title => "" + let(:invalid_attributes) { + { + title: "" } - end + } it "should render the new form" do - put :update, :id => @project.slug, :event_id => @event.slug, :project => @invalid_attributes - response.should render_template(:edit) + put :update, :id => project.slug, :event_id => event.slug, :project => invalid_attributes + + expect(response).to render_template(:edit) end end end From 5e3cbfb22299fccc1d5fc8b20fd1f9b813286f8f Mon Sep 17 00:00:00 2001 From: Jordan Hatch Date: Tue, 7 Jul 2015 11:20:05 +0100 Subject: [PATCH 19/34] Refactor Admin#ProjectsController --- app/controllers/admin/projects_controller.rb | 49 +++++++++----- app/views/admin/projects/_form.html.erb | 12 ++-- app/views/admin/projects/_project.html.erb | 8 +-- app/views/admin/projects/edit.html.erb | 6 +- app/views/admin/projects/index.html.erb | 4 +- .../admin/projects_controller_spec.rb | 66 ++++++++++--------- 6 files changed, 83 insertions(+), 62 deletions(-) diff --git a/app/controllers/admin/projects_controller.rb b/app/controllers/admin/projects_controller.rb index 510f176..f5bcaba 100644 --- a/app/controllers/admin/projects_controller.rb +++ b/app/controllers/admin/projects_controller.rb @@ -1,24 +1,43 @@ class Admin::ProjectsController < Admin::BaseController + before_filter do + breadcrumbs.add "Events", admin_events_path + breadcrumbs.add event.title, edit_admin_event_path(event) + breadcrumbs.add "Projects", admin_event_projects_path(event) + end + + def update + if project.update_attributes(project_params) + redirect_to admin_event_projects_path(event) + else + render action: :edit + end + end - inherit_resources + def destroy + project.destroy + redirect_to admin_event_projects_path + end - belongs_to :event, :finder => :find_by_slug, :param => :event_id - with_role :admin - actions :all, :except => [:show, :new, :create] + def projects + @projects ||= event.projects + end + helper_method :projects - before_filter do - breadcrumbs.add "Events", admin_events_path - breadcrumbs.add parent.title, edit_parent_path - breadcrumbs.add "Projects", collection_path + def project + @project ||= projects.find_by_slug(params[:id]) end + helper_method :project - before_filter :only => :update do - resource.managing = true + def event + @event ||= Event.find_by_slug(params[:event_id]) end + helper_method :event - protected - def resource - @project ||= @event.projects.find_by_slug(params[:id]) - end +private + def project_params + params.fetch(:project, {}).permit(:title, :team, :url, :secret, :image, + :summary, :description, :ideas, :data, :twitter, :github_url, :svn_url, + :code_url, :awards_attributes, :centre, :centre_id, :slug) + end -end \ No newline at end of file +end diff --git a/app/views/admin/projects/_form.html.erb b/app/views/admin/projects/_form.html.erb index f81b0c9..616d82c 100644 --- a/app/views/admin/projects/_form.html.erb +++ b/app/views/admin/projects/_form.html.erb @@ -1,15 +1,15 @@ -<%= semantic_nested_form_for([:admin, parent, resource]) do |f| %> +<%= semantic_nested_form_for([:admin, event, project]) do |f| %> <%= f.semantic_errors %> <%= f.inputs "Basic Info" do %> <%= f.input :title %> - <% if parent.use_centres %> + <% if event.use_centres %> <%= f.input :centre %> <% end %> <%= f.input :slug, :input_html => { :disabled => true } %> <%= f.input :team %> <%= f.input :url %> - <% if ! parent.secret.present? %> + <% if ! event.secret.present? %> <%= f.input :secret %> <% end %> <% end %> @@ -30,16 +30,16 @@ <%= f.inputs "Image" do %> <%= f.input :image %> -
  • <%= label_tag nil, "Current screenshot", :class => 'label' %><%= image_tag resource.image.url(:mini) %>
  • +
  • <%= label_tag nil, "Current screenshot", :class => 'label' %><%= image_tag project.image.url(:mini) %>
  • <% end %> <%= f.inputs "Awards" do %> <%= f.semantic_fields_for :awards do |award_fields| %> - <%= award_fields.input :award_category, :collection => resource.event.award_categories %> + <%= award_fields.input :award_category, :collection => event.award_categories %> <%= award_fields.link_to_remove "Remove this award" %> <% end %> <%= f.link_to_add "Add an award", :awards %> <% end %> <%= render :partial => "admin/shared/actions", :locals => { :f => f } %> -<% end %> \ No newline at end of file +<% end %> diff --git a/app/views/admin/projects/_project.html.erb b/app/views/admin/projects/_project.html.erb index e1da07d..92f2a22 100644 --- a/app/views/admin/projects/_project.html.erb +++ b/app/views/admin/projects/_project.html.erb @@ -1,5 +1,5 @@ - <%= link_to project.title, event_project_path(parent, project) %> + <%= link_to project.title, event_project_path(event, project) %> <%= truncate( project.slug, :length => 20 ) %> <%= truncate( project.team, :length => 30 ) %> @@ -9,6 +9,6 @@ <% end %> - <%= link_to "Edit", edit_admin_event_project_path(parent, project) %> - <%= link_to "Delete", admin_event_project_path(parent, project), :method => "DELETE", :confirm => "Are you sure you want to *permanently* delete this project, and all its hacks?" %> - \ No newline at end of file + <%= link_to "Edit", edit_admin_event_project_path(event, project) %> + <%= link_to "Delete", admin_event_project_path(event, project), :method => "DELETE", :confirm => "Are you sure you want to *permanently* delete this project, and all its hacks?" %> + diff --git a/app/views/admin/projects/edit.html.erb b/app/views/admin/projects/edit.html.erb index 612bf90..0ceffea 100644 --- a/app/views/admin/projects/edit.html.erb +++ b/app/views/admin/projects/edit.html.erb @@ -1,5 +1,5 @@ -<% content_for(:title) { "Edit #{resource.title}" } %> +<% content_for(:title) { "Edit #{project.title}" } %> -

    Edit <%= resource.title %>

    +

    Edit <%= project.title %>

    -<%= render :partial => "form" %> \ No newline at end of file +<%= render :partial => "form" %> diff --git a/app/views/admin/projects/index.html.erb b/app/views/admin/projects/index.html.erb index aba62ce..c38cb51 100644 --- a/app/views/admin/projects/index.html.erb +++ b/app/views/admin/projects/index.html.erb @@ -14,6 +14,6 @@ - <%= render :partial => "project", :collection => collection %> + <%= render :partial => "project", :collection => projects %> - \ No newline at end of file + diff --git a/spec/controllers/admin/projects_controller_spec.rb b/spec/controllers/admin/projects_controller_spec.rb index c1025ad..af96477 100644 --- a/spec/controllers/admin/projects_controller_spec.rb +++ b/spec/controllers/admin/projects_controller_spec.rb @@ -1,75 +1,77 @@ require 'rails_helper' RSpec.describe Admin::ProjectsController do - - before do - @event = FactoryGirl.create(:event_without_secret) - end + let(:event) { FactoryGirl.create(:event_without_secret) } context "when not signed in" do describe "GET 'index'" do it "should redirect to the login form" do - get :index, :event_id => @event.id - response.should redirect_to(new_admin_session_path) + get :index, :event_id => event.id + + expect(response).to redirect_to(new_admin_session_path) end end end context "when signed in" do before(:each) { - login_admin + sign_in_admin } describe "GET index" do it "should be successful" do - get :index, :event_id => @event.slug - response.should be_success + get :index, :event_id => event.slug + + expect(response).to be_success end it "can assign a collection of all the projects" do - @project_one = FactoryGirl.create(:project_with_secret, :event => @event) - @project_two = FactoryGirl.create(:project_with_secret, :event => @event) + project_one = create(:project_with_secret, :event => event) + project_two = create(:project_with_secret, :event => event) - get :index, :event_id => @event.slug - assigns(:projects).should =~ [@project_one, @project_two] + get :index, :event_id => event.slug + expect(controller.projects).to contain_exactly(project_one, project_two) end end describe "PUT update" do - before do - @project = FactoryGirl.create(:project_with_secret, :event => @event) - end + let(:project) { create(:project_with_secret, :event => event) } context "given valid attributes" do - before do - @valid_attributes = { - :title => "Alt Project Title", - :team => "Team Name" + let(:valid_attributes) { + { + title: "Alt Project Title", + team: "Team Name", } - end + } it "should update the project" do - put :update, :event_id => @event.slug, :id => @project.slug, :project => @valid_attributes - assigns(:project).title.should == "Alt Project Title" - assigns(:project).team.should == "Team Name" + put :update, :event_id => event.slug, :id => project.slug, :project => valid_attributes + + expect(controller.project.title).to eq("Alt Project Title") + expect(controller.project.team).to eq("Team Name") end it "should redirect to the project list" do - put :update, :event_id => @event.slug, :id => @project.slug, :project => @valid_attributes - response.should redirect_to(admin_event_projects_path(@event)) + put :update, :event_id => event.slug, :id => project.slug, :project => valid_attributes + + expect(response).to redirect_to(admin_event_projects_path(event)) end end context "given invalid attributes" do - before do - @invalid_attributes = { - :title => "" + let(:invalid_attributes) { + { + title: "" } - end + } it "should render the edit form" do - put :update, :event_id => @event.slug, :id => @project.slug, :project => @invalid_attributes - response.should render_template(:edit) + put :update, event_id: event.slug, + id: project.slug, + project: invalid_attributes + + expect(response).to render_template(:edit) end end end From ad73656730bcc322cfffc4d119df1792d46ebedb Mon Sep 17 00:00:00 2001 From: Jordan Hatch Date: Tue, 7 Jul 2015 11:20:18 +0100 Subject: [PATCH 20/34] Use strong parameters in ProjectsController --- app/controllers/projects_controller.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 51ed9d8..c7cc770 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -14,7 +14,7 @@ def new end def create - @project = @event.projects.build(params[:project]) + @project = @event.projects.build(project_params) if @project.save flash[:notice] = 'Your project has been created.' @@ -40,7 +40,7 @@ def edit end def update - if @project.update_attributes(params[:project]) + if @project.update_attributes(project_params) flash[:notice] = 'Your project has been updated.' redirect_to event_project_url(@event,@project) else @@ -60,4 +60,10 @@ def find_project breadcrumbs.add @project.centre.name, centre_event_path(@event, @project.centre.slug) if @event.use_centres breadcrumbs.add @project.title, event_project_path(@event, @project) end + + def project_params + params.require(:project).permit(:title, :team, :url, :secret, :my_secret, + :image, :summary, :description, :ideas, :data, :twitter, :github_url, + :svn_url, :code_url, :centre, :centre_id) + end end From 54bbba1feeae0d4dacd01e0be02f2248dbfd7687 Mon Sep 17 00:00:00 2001 From: Jordan Hatch Date: Tue, 7 Jul 2015 11:20:35 +0100 Subject: [PATCH 21/34] Update Event model spec --- spec/models/event_spec.rb | 142 ++++++++++++++++++++------------------ 1 file changed, 76 insertions(+), 66 deletions(-) diff --git a/spec/models/event_spec.rb b/spec/models/event_spec.rb index e12ce97..9763aac 100644 --- a/spec/models/event_spec.rb +++ b/spec/models/event_spec.rb @@ -1,134 +1,144 @@ require 'rails_helper' -RSpec.describe Event do +RSpec.describe Event, type: :model do describe "creating an event" do - before do - @valid_attributes = { - :title => "Event Title", - :slug => "event-slug", - :secret => "secret", - :start_date => Date.parse("1 January 2013") + let(:valid_attributes) { + { + title: "Event Title", + slug: "event-slug", + secret: "secret", + start_date: Date.parse("1 January 2013"), } - end + } context "given valid attributes" do it "can create an event" do - Event.create!(@valid_attributes) + Event.create!(valid_attributes) end it "can set a slug if none exists" do - @event = Event.create!( @valid_attributes.merge({:slug => nil}) ) - @event.slug.should == "event-title" + event = Event.create!( valid_attributes.merge({:slug => nil}) ) + + expect(event.slug).to eq("event-title") end it "doesn't generate a slug if one is present" do - @event = Event.create!( @valid_attributes ) - @event.slug.should == "event-slug" + event = Event.create!( valid_attributes ) + + expect(event.slug).to eq("event-slug") end it "can generate a unique slug where an event with the same title exists" do - @event_one = Event.create!( @valid_attributes.merge({:slug => nil}) ) - @event_two = Event.create!( @valid_attributes.merge({:slug => nil}) ) + event_one = Event.create!( valid_attributes.merge({:slug => nil}) ) + event_two = Event.create!( valid_attributes.merge({:slug => nil}) ) - @event_one.slug.should == "event-title" - @event_two.slug.should == "event-title-2" + expect(event_one.slug).to eq("event-title") + expect(event_two.slug).to eq("event-title-2") end it "does not have a password if the secret is blank" do - @event = Event.create!(@valid_attributes.merge({:secret => ''})) - @event.should_not have_secret + event = Event.create!(valid_attributes.merge({:secret => ''})) + + expect(event).to_not have_secret end it "does not use centres by default" do - @event = Event.create!( @valid_attributes ) - @event.use_centres.should be_false + event = Event.create!( valid_attributes ) + + expect(event.use_centres).to eq(false) end it "can be created as an event with centres" do - @event = Event.create!( @valid_attributes.merge({:use_centres => true}) ) - @event.use_centres.should be_true + event = Event.create!( valid_attributes.merge({:use_centres => true}) ) + + expect(event.use_centres).to eq(true) end end context "given invalid attributes" do it "can't create an event with an empty title" do - @event = Event.new @valid_attributes.merge({:title => ''}) - @event.should_not be_valid + event = Event.new(valid_attributes.merge({:title => ''})) + + expect(event).to_not be_valid end end end describe "creating award categories for event" do - before do - @event = FactoryGirl.create(:event) - @award_category_atts = { - :title => 'Best in Show', - :description => 'The best hack', - :level => '1', - :format => 'overall', - :featured => true + let(:event) { FactoryGirl.create(:event) } + let(:award_category_atts) { + { + title: 'Best in Show', + description: 'The best hack', + level: '1', + format: 'overall', + featured: true, } - end + } it "can accept attributes for an award category" do - @event.update_attributes!({ :award_categories_attributes => [ @award_category_atts ] }) + event.update_attributes!({ :award_categories_attributes => [ award_category_atts ] }) - @event.award_categories.should be_any - @event.award_categories.first.title.should == "Best in Show" + expect(event.award_categories).to_not be_empty + expect(event.award_categories.first.title).to eq("Best in Show") end it "can remove an award category" do - @award_category = @event.award_categories.create!(@award_category_atts) + award_category = event.award_categories.create!(award_category_atts) + + event.update_attributes!( + award_categories_attributes: [ + { :id => award_category.id, :'_destroy' => '1' } + ] + ) - @event.update_attributes!({ :award_categories_attributes => [{ :id => @award_category.id, :'_destroy' => '1' }] }) - @event.award_categories.count.should == 0 + expect(event.award_categories.count).to eq(0) end context "given projects which have won awards" do + let(:project_one) { FactoryGirl.create(:project_with_event_secret, event: event) } + let(:project_two) { FactoryGirl.create(:project_with_event_secret, event: event) } - it "should only return featured award categories as winners" do - @featured_award_category = @event.award_categories.create!(@award_category_atts) - @other_award_category = @event.award_categories.create!(@award_category_atts.merge({:featured => false})) - - @project_one = FactoryGirl.create(:project_with_event_secret) - @project_two = FactoryGirl.create(:project_with_event_secret) - @project_one.update_attribute(:event_id, @event.id) - @project_two.update_attribute(:event_id, @event.id) + let(:featured_award_category) { event.award_categories.create!(award_category_atts) } + let(:other_award_category) { event.award_categories.create!(award_category_atts.merge(featured: false)) } - @featured_award_category.award_to(@project_one) - @other_award_category.award_to(@project_two) + it "should only return featured award categories as winners" do + featured_award_category.award_to(project_one) + other_award_category.award_to(project_two) - @event.winners.count.should == 1 - @event.winners.should =~ [ @project_one ] + expect(event.winners.count).to eq(1) + expect(event.winners).to contain_exactly(project_one) - @event.award_winners.count.should == 2 - @event.award_winners.should =~ [ @project_one, @project_two ] + expect(event.award_winners.count).to eq(2) + expect(event.award_winners).to contain_exactly(project_one, project_two) end end end describe "creating centres for events" do - before do - @event = FactoryGirl.create(:event) - @centre_atts = { - :name => 'Manchester', - :slug => 'manchester' + let(:event) { FactoryGirl.create(:event) } + let(:centre_atts) { + { + name: 'Manchester', + slug: 'manchester', } - end + } it "can accept attributes for a centre" do - @event.update_attributes!({ :centres_attributes => [ @centre_atts ] }) + event.update_attributes!({ :centres_attributes => [ centre_atts ] }) - @event.centres.should be_any - @event.centres.first.name.should == "Manchester" + expect(event.centres).to_not be_empty + expect(event.centres.first.name).to eq("Manchester") end it "cannot remove a centre" do - @centre = @event.centres.create!(@centre_atts) + centre = event.centres.create!(centre_atts) - @event.update_attributes!({ :centres_attributes => [{ :id => @centre.id, :'_destroy' => '1' }] }) - @event.centres.count.should == 1 + event.update_attributes!(centres_attributes: [ + { :id => centre.id, :'_destroy' => '1' } + ]) + expect(event.centres.count).to eq(1) end end From f9489475cd087850cf98e94e1d32f7f294fc37d6 Mon Sep 17 00:00:00 2001 From: Jordan Hatch Date: Tue, 7 Jul 2015 11:20:57 +0100 Subject: [PATCH 22/34] Update Project model spec --- spec/models/project_spec.rb | 110 ++++++++++++++++++------------------ 1 file changed, 56 insertions(+), 54 deletions(-) diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index b47e389..66f6d80 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -24,19 +24,19 @@ describe "given valid attributes" do it "can be created" do - @project = @event.projects.create!(@valid_attributes) - @project.should be_persisted + project = @event.projects.create!(@valid_attributes) + expect(project).to be_persisted end it "sets the slug based on the title" do - @project = @event.projects.create!(@valid_attributes) - @project.slug.should == "project-one" + project = @event.projects.create!(@valid_attributes) + expect(project.slug).to eq("project-one") end describe "the created project" do it "has not won awards" do - @project = @event.projects.create!(@valid_attributes) - @project.should_not have_won_award + project = @event.projects.create!(@valid_attributes) + expect(project).to_not have_won_award end end end @@ -44,62 +44,62 @@ describe "given invalid attributes" do it "can't be created with the wrong event password" do @valid_attributes.merge!({ :my_secret => "not the event secret" }) - @project = @event.projects.build(@valid_attributes) - @project.should_not be_valid + project = @event.projects.build(@valid_attributes) + expect(project).to_not be_valid end it "can't be created if the event no longer allows new projects to be created" do @event = FactoryGirl.create(:event, :enable_project_creation => false) - @project = @event.projects.build(@valid_attributes) - @project.should_not be_valid + project = @event.projects.build(@valid_attributes) + expect(project).to_not be_valid end it "can't be created without a screenshot" do @valid_attributes.merge!({ :image => nil }) - @project = @event.projects.build(@valid_attributes) - @project.should_not be_valid + project = @event.projects.build(@valid_attributes) + expect(project).to_not be_valid end it "can't be created without a title" do @valid_attributes.merge!({ :title => nil }) - @project = @event.projects.build(@valid_attributes) - @project.should_not be_valid + project = @event.projects.build(@valid_attributes) + expect(project).to_not be_valid end it "can't be created without a team name" do @valid_attributes.merge!({ :team => nil }) - @project = @event.projects.build(@valid_attributes) - @project.should_not be_valid + project = @event.projects.build(@valid_attributes) + expect(project).to_not be_valid end it "can't be created without a summary" do @valid_attributes.merge!({ :summary => nil }) - @project = @event.projects.build(@valid_attributes) - @project.should_not be_valid + project = @event.projects.build(@valid_attributes) + expect(project).to_not be_valid end it "can't be created with a summary longer than 180 characters" do @valid_attributes.merge!({ :summary => "test".ljust(181) }) - @project = @event.projects.build(@valid_attributes) - @project.should_not be_valid + project = @event.projects.build(@valid_attributes) + expect(project).to_not be_valid end it "can't be created without a description" do @valid_attributes.merge!({ :description => nil }) - @project = @event.projects.build(@valid_attributes) - @project.should_not be_valid + project = @event.projects.build(@valid_attributes) + expect(project).to_not be_valid end it "can't be created with an invalid url" do @valid_attributes.merge!({ :url => "this does not look like a valid url" }) - @project = @event.projects.build(@valid_attributes) - @project.should_not be_valid + project = @event.projects.build(@valid_attributes) + expect(project).to_not be_valid end it "can't be created with an invalid image" do @valid_attributes.merge!({ :image => stub_uploaded_image("invalid_image_file") }) - @project = @event.projects.build(@valid_attributes) - @project.should_not be_valid + project = @event.projects.build(@valid_attributes) + expect(project).to_not be_valid end end end @@ -112,16 +112,16 @@ describe "given valid attributes" do it "can be created" do - @project = @event.projects.create!(@valid_attributes) - @project.should be_persisted + project = @event.projects.create!(@valid_attributes) + expect(project).to be_persisted end end describe "given invalid attributes" do it "can't be created with an empty project password" do @valid_attributes.merge!({ :secret => nil }) - @project = @event.projects.build(@valid_attributes) - @project.should_not be_valid + project = @event.projects.build(@valid_attributes) + expect(project).to_not be_valid end end end @@ -135,16 +135,16 @@ describe "given valid attributes" do it "can be created" do - @project = @event.projects.create!(@valid_attributes) - @project.should be_persisted + project = @event.projects.create!(@valid_attributes) + expect(project).to be_persisted end end describe "given invalid attributes" do it "can't be created without a centre" do @invalid_attributes = @valid_attributes.merge({ :centre => nil }) - @project = @event.projects.build(@invalid_attributes) - @project.should_not be_valid + project = @event.projects.build(@invalid_attributes) + expect(project).to_not be_valid end end end @@ -161,63 +161,65 @@ describe "as a user" do describe "where the event does not have a password" do - before do - @project = FactoryGirl.create(:project_with_secret) - end + let(:project) { FactoryGirl.create(:project_with_secret) } describe "given valid attributes" do before do - @valid_attributes.merge!({ :my_secret => @project.secret }) + @valid_attributes.merge!({ :my_secret => project.secret }) end it "can be updated" do - @project.update_attributes!(@valid_attributes) - @project.title.should == @valid_attributes[:title] - @project.summary.should == @valid_attributes[:summary] - @project.image.url.should =~ /alternative\.jpg/ + project.update_attributes!(@valid_attributes) + + expect(project.title).to eq(@valid_attributes[:title]) + expect(project.summary).to eq(@valid_attributes[:summary]) + expect(project.image.url).to match(/alternative\.jpg/) end end describe "given invalid attributes" do it "can not update a project with an empty project password" do @valid_attributes.merge!({ :my_secret => nil }) - @project.update_attributes(@valid_attributes).should be_false + + expect(project.update_attributes(@valid_attributes)).to eq(false) end it "can not update a project with an invalid project password" do @valid_attributes.merge!({ :my_secret => "not the correct project password" }) - @project.update_attributes(@valid_attributes).should be_false + + expect(project.update_attributes(@valid_attributes)).to eq(false) end end end describe "where the event has a password" do - before do - @project = FactoryGirl.create(:project_with_event_secret) - end + let(:project) { FactoryGirl.create(:project_with_event_secret) } describe "given valid attributes" do before do - @valid_attributes.merge!({ :my_secret => @project.event.secret }) + @valid_attributes.merge!({ :my_secret => project.event.secret }) end it "can be updated" do - @project.update_attributes!(@valid_attributes) - @project.title.should == @valid_attributes[:title] - @project.summary.should == @valid_attributes[:summary] - @project.image.url.should =~ /alternative\.jpg/ + project.update_attributes!(@valid_attributes) + + expect(project.title).to eq(@valid_attributes[:title]) + expect(project.summary).to eq(@valid_attributes[:summary]) + expect(project.image.url).to match(/alternative\.jpg/) end end describe "given invalid attributes" do it "can not update a project with an empty event password" do @valid_attributes.merge!({ :my_secret => nil }) - @project.update_attributes(@valid_attributes).should be_false + + expect(project.update_attributes(@valid_attributes)).to eq(false) end it "can not update a project with an invalid event password" do @valid_attributes.merge!({ :my_secret => "not the correct event password" }) - @project.update_attributes(@valid_attributes).should be_false + + expect(project.update_attributes(@valid_attributes)).to eq(false) end end end From 008f10f304e79b435499e2ef57006c96ea2bf4a1 Mon Sep 17 00:00:00 2001 From: Jordan Hatch Date: Tue, 7 Jul 2015 11:21:05 +0100 Subject: [PATCH 23/34] Remove .rvmrc file --- .rvmrc | 55 ------------------------------------------------------- 1 file changed, 55 deletions(-) delete mode 100644 .rvmrc diff --git a/.rvmrc b/.rvmrc deleted file mode 100644 index e09c5c8..0000000 --- a/.rvmrc +++ /dev/null @@ -1,55 +0,0 @@ -#!/usr/bin/env bash - -# This is an RVM Project .rvmrc file, used to automatically load the ruby -# development environment upon cd'ing into the directory - -# First we specify our desired [@], the @gemset name is optional. -environment_id="ruby-1.9.2-p290" - -# -# Uncomment following line if you want options to be set only for given project. -# -# PROJECT_JRUBY_OPTS=( --1.9 ) - -# -# First we attempt to load the desired environment directly from the environment -# file. This is very fast and efficient compared to running through the entire -# CLI and selector. If you want feedback on which environment was used then -# insert the word 'use' after --create as this triggers verbose mode. -# -if [[ -d "${rvm_path:-$HOME/.rvm}/environments" \ - && -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]] -then - \. "${rvm_path:-$HOME/.rvm}/environments/$environment_id" - - if [[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]] - then - . "${rvm_path:-$HOME/.rvm}/hooks/after_use" - fi -else - # If the environment file has not yet been created, use the RVM CLI to select. - if ! rvm --create "$environment_id" - then - echo "Failed to create RVM environment '${environment_id}'." - exit 1 - fi -fi - -# -# If you use an RVM gemset file to install a list of gems (*.gems), you can have -# it be automatically loaded. Uncomment the following and adjust the filename if -# necessary. -# -# filename=".gems" -# if [[ -s "$filename" ]] -# then -# rvm gemset import "$filename" | grep -v already | grep -v listed | grep -v complete | sed '/^$/d' -# fi - -# If you use bundler, this might be useful to you: -# if command -v bundle && [[ -s Gemfile ]] -# then -# bundle install -# fi - - From cf55c605b9d5dd75718934394799e0fe2e449707 Mon Sep 17 00:00:00 2001 From: Jordan Hatch Date: Tue, 7 Jul 2015 11:21:16 +0100 Subject: [PATCH 24/34] Update Paperclip gem, and add Puma --- Gemfile | 4 +++- Gemfile.lock | 15 ++++++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/Gemfile b/Gemfile index 824e1d2..34517df 100644 --- a/Gemfile +++ b/Gemfile @@ -13,7 +13,7 @@ gem "breadcrumbs", "~> 0.1.6" gem "comma", "~> 3.0.4" gem "rdiscount", "~> 1.6.8" -gem "paperclip", "~> 2.4" +gem "paperclip" gem 'paper_trail', '~> 3.0.3' @@ -28,6 +28,8 @@ gem "nested_form", :git => "git://github.com/ryanb/nested_form.git" gem 'sass-rails', '~> 4.0.3' gem 'uglifier', '>= 1.0.3' +gem 'puma' + group :test do gem 'cucumber-rails', require: false gem 'database_cleaner' diff --git a/Gemfile.lock b/Gemfile.lock index a2d4247..e625f9b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -102,6 +102,7 @@ GEM mail (2.6.3) mime-types (>= 1.16, < 3) mime-types (2.6.1) + mimemagic (0.3.0) mini_portile (0.6.2) minitest (4.7.5) multi_json (1.11.2) @@ -112,12 +113,15 @@ GEM paper_trail (3.0.8) activerecord (>= 3.0, < 5.0) activesupport (>= 3.0, < 5.0) - paperclip (2.8.0) - activerecord (>= 2.3.0) - activesupport (>= 2.3.2) - cocaine (>= 0.0.2) + paperclip (4.3.0) + activemodel (>= 3.2.0) + activesupport (>= 3.2.0) + cocaine (~> 0.5.5) mime-types + mimemagic (= 0.3.0) pg (0.18.2) + puma (2.11.3) + rack (>= 1.1, < 2.0) rabl (0.11.6) activesupport (>= 2.3.14) rack (1.5.5) @@ -207,8 +211,9 @@ DEPENDENCIES jquery-rails nested_form! paper_trail (~> 3.0.3) - paperclip (~> 2.4) + paperclip pg + puma rabl rails (~> 4.0.12) rdiscount (~> 1.6.8) From 17575e2f980860e63557842b7d3d1500b533ac74 Mon Sep 17 00:00:00 2001 From: Jordan Hatch Date: Tue, 7 Jul 2015 12:13:14 +0100 Subject: [PATCH 25/34] Simplify project secret behaviour This removes the complicated old behaviour where the secret could be *either* the event secret, or a secret just for the project. Now, the secret is always on the project - we don't allow a secret to be set for the event anymore. This also includes simpler methods to check the secret when a project is updated, which doesn't require using conditional validation methods. --- app/controllers/admin/events_controller.rb | 2 +- app/controllers/projects_controller.rb | 81 +++-- app/models/manageable.rb | 8 - app/models/project.rb | 33 +- app/views/admin/events/_form.html.erb | 1 - app/views/projects/_form.html.erb | 42 +-- .../admin/projects_controller_spec.rb | 8 +- spec/controllers/events_controller_spec.rb | 6 +- spec/controllers/projects_controller_spec.rb | 45 ++- spec/factories/factories.rb | 23 +- spec/models/event_spec.rb | 4 +- spec/models/project_spec.rb | 324 ++++++------------ 12 files changed, 226 insertions(+), 351 deletions(-) delete mode 100644 app/models/manageable.rb diff --git a/app/controllers/admin/events_controller.rb b/app/controllers/admin/events_controller.rb index e0eed0c..fe8101d 100644 --- a/app/controllers/admin/events_controller.rb +++ b/app/controllers/admin/events_controller.rb @@ -43,7 +43,7 @@ def events private def event_params params.fetch(:event, {}).permit(:title, :slug, :hashtag, :use_centres, - :secret, :active, :url, :enable_project_creation, :start_date) + :active, :url, :enable_project_creation, :start_date) end end diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index c7cc770..896d9d8 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -1,69 +1,80 @@ class ProjectsController < ApplicationController - before_filter :find_event - before_filter :find_project, :except => [:new, :create] + before_filter :set_breadcrumbs def new - @project = @event.projects.build - - unless @event.enable_project_creation - flash[:alert] = 'Projects can no longer be created here for this event. Please get in touch if you\'d like to add a project here.' - redirect_to event_path(@event) + unless event.enable_project_creation + flash.alert = 'Projects can no longer be created here for this event. Please get in touch if you\'d like to add a project here.' + redirect_to event_path(event) end - breadcrumbs.add "New project", new_event_project_path(@event, @project) + breadcrumbs.add "New project", new_event_project_path(event) end def create - @project = @event.projects.build(project_params) + project.assign_attributes(project_params) - if @project.save - flash[:notice] = 'Your project has been created.' - redirect_to event_project_url(@event, @project) + if project.save + flash.notice = 'Your project has been created.' + redirect_to event_project_url(event, project) else - breadcrumbs.add "New project", new_event_project_path(@event, @project) - render :action => :new + breadcrumbs.add "New project", new_event_project_path(event) + render action: :new end end def show respond_to do |format| - format.html { # show.html.erb - } - format.json { # show.json.rabl - } + format.html + format.json end end def edit - # edit.html.erb - breadcrumbs.add "Edit project", edit_event_project_path(@event, @project) + breadcrumbs.add "Edit project", edit_event_project_path(event, project) end def update - if @project.update_attributes(project_params) - flash[:notice] = 'Your project has been updated.' - redirect_to event_project_url(@event,@project) + submitted_secret = project_params.delete(:submitted_secret) + + if project.update_attributes_with_secret(submitted_secret, project_params) + flash.notice = 'Your project has been updated.' + redirect_to event_project_url(event, project) else - breadcrumbs.add "Edit project", edit_event_project_path(@event, @project) - render :action => :edit + breadcrumbs.add "Edit project", edit_event_project_path(event, project) + render action: :edit end end - private - def find_event - @event = Event.find_by_slug(params[:event_id]) || not_found - breadcrumbs.add @event.title, event_path(@event) + def event + @event ||= Event.find_by_slug(params[:event_id]) || not_found + end + helper_method :event + + def project + if params[:id] + @project ||= event.projects.find_by_slug(params[:id]) || not_found + else + @project ||= event.projects.build end + end + helper_method :project + + private + def set_breadcrumbs + breadcrumbs.add event.title, event_path(event) + + if project.persisted? + if event.use_centres? + breadcrumbs.add project.centre.name, centre_event_path(event, project.centre.slug) if event.use_centres + end - def find_project - @project = @event.projects.find_by_slug(params[:id]) || not_found - breadcrumbs.add @project.centre.name, centre_event_path(@event, @project.centre.slug) if @event.use_centres - breadcrumbs.add @project.title, event_project_path(@event, @project) + breadcrumbs.add project.title, event_project_path(event, project) + end end def project_params - params.require(:project).permit(:title, :team, :url, :secret, :my_secret, + params.require(:project).permit(:title, :team, :url, :secret, :image, :summary, :description, :ideas, :data, :twitter, :github_url, - :svn_url, :code_url, :centre, :centre_id) + :svn_url, :code_url, :centre_id, :submitted_secret) end end diff --git a/app/models/manageable.rb b/app/models/manageable.rb deleted file mode 100644 index 6affa9b..0000000 --- a/app/models/manageable.rb +++ /dev/null @@ -1,8 +0,0 @@ -module Manageable - extend ActiveSupport::Concern - - included do - attr_accessor :managing - attr_protected :managing - end -end \ No newline at end of file diff --git a/app/models/project.rb b/app/models/project.rb index 1221966..2f6ddfe 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -1,7 +1,6 @@ class Project < ActiveRecord::Base belongs_to :event belongs_to :centre - include Manageable has_paper_trail @@ -31,7 +30,7 @@ class Project < ActiveRecord::Base notes end - attr_accessor :my_secret + attr_accessor :submitted_secret before_validation :create_slug, :if => proc { self.slug.blank? and ! self.title.blank? } before_validation :blank_url_fields @@ -39,7 +38,7 @@ class Project < ActiveRecord::Base validates :title, :team, :description, :presence => true validates :summary, :presence => true, :length => { :maximum => 180 } validates :slug, :uniqueness => { :case_sensitive => false } - validates :secret, :presence => true, :on => :create, :if => :secret_required? + validates :secret, :presence => true, :on => :create validates :url, :code_url, :github_url, :svn_url, :format => { :with => URI::regexp, :allow_blank => true } validates :centre, :presence => true, :if => proc { |a| a.event.use_centres == true } validate :ensure_project_creation_is_enabled, :on => :create @@ -52,28 +51,19 @@ class Project < ActiveRecord::Base less_than: 1.megabyte, } - validates_each :my_secret, :on => :create, :if => :event_secret_required? do |model, attr, value| - model.errors.add(attr, "is incorrect") if (value != model.event.secret) - end - + def update_attributes_with_secret(submitted_secret, attributes) + if valid_secret?(submitted_secret) + update_attributes(attributes) + else + self.errors.add(:secret, 'is not correct') + return false + end end def to_param self.slug end - def event_secret_required? - self.event.has_secret? - end - - def secret_required? - ! self.event_secret_required? - end - - def project_or_event_secret - self.event_secret_required? ? self.event.secret : self.secret - end - def format_url(url) url_parts = url.match(/https?:\/\/(.*)/i) url_parts ? url_parts[1].sub(/\/$/i,'') : url @@ -120,4 +110,9 @@ def ensure_project_creation_is_enabled errors.add(:event, "no longer allows projects to be created") end end + + def valid_secret?(submitted_secret) + submitted_secret.present? && + submitted_secret == secret + end end diff --git a/app/views/admin/events/_form.html.erb b/app/views/admin/events/_form.html.erb index 1126ee9..931de42 100644 --- a/app/views/admin/events/_form.html.erb +++ b/app/views/admin/events/_form.html.erb @@ -5,7 +5,6 @@ <%= f.input :title %> <%= f.input :start_date, :as => :string %> <%= f.input :slug, ( event.persisted? ? { :input_html => { :disabled => true } } : { } ) %> - <%= f.input :secret, :label => "Event secret", :input_html => { :placeholder => "If blank, projects must create their own passwords"} %> <%= f.input :url, :label => "Event homepage", :input_html => { :placeholder => "http://" } %> <%= f.input :use_centres, disable_if_persisted(event, { :input_html => { :disabled => true } }).merge({ :as => :select, :label => "Event type", :collection => { "Hacks shown together in list" => false, "Hacks grouped by centre" => true }, :include_blank => false }) %> <% end %> diff --git a/app/views/projects/_form.html.erb b/app/views/projects/_form.html.erb index 131c751..bcd3fd2 100644 --- a/app/views/projects/_form.html.erb +++ b/app/views/projects/_form.html.erb @@ -1,6 +1,6 @@ -<% if @project.errors.any? %> +<% if project.errors.any? %>
      - <% @project.errors.full_messages.each do |msg| %> + <% project.errors.full_messages.each do |msg| %> <% next if msg == "Image file name can't be empty" %>
    • <%= msg %>
    • <% end %> @@ -8,23 +8,17 @@ <% end %>
      -<% if @event.has_secret? -%> +<% unless project.new_record? %>

      - <%= f.label :my_secret, "Event Password *".html_safe %> - <%= f.text_field :my_secret %> - Enter the event password, as given out at the hack day, to <%= (@project.new_record?) ? "add" : "update" %> this project. -

      -<% elsif !@project.new_record? -%> -

      - <%= f.label :my_secret, "Project Password *".html_safe %> - <%= f.text_field :my_secret %> + <%= f.label :submitted_secret, "Project Password *".html_safe %> + <%= f.text_field :submitted_secret %> Enter the project password to make changes to this project.

      -<% end -%> -<% if @event.use_centres %> +<% end %> +<% if event.use_centres? %>

      <%= f.label :centre_id, "Centre *".html_safe %> - <%= f.collection_select :centre_id, @event.centres.all, :id, :name, :include_blank => true %> + <%= f.collection_select :centre_id, event.centres.all, :id, :name, :include_blank => true %> The centre where you created this project.

      <% end %> @@ -58,27 +52,27 @@ <%= f.text_area :description %> Tell us about your project. You can use Markdown in this field.

      -<% unless @project.data.nil? or @project.data.empty? %> +<% unless project.data.nil? or project.data.empty? %>

      <%= f.label :data, "Data used in your project" %> <%= f.text_area :data %> What data did you use in your project? You can use Markdown in this field.

      -<% end -%> -<% unless @project.ideas.nil? or @project.ideas.empty? %> +<% end %> +<% unless project.ideas.nil? or project.ideas.empty? %>

      <%= f.label :ideas, "Ideas for taking your project forwards" %> <%= f.text_area :ideas %> What else would you like to add to your project? You can use Markdown in this field.

      -<% end -%> -<% unless @project.costs.nil? or @project.costs.empty? %> +<% end %> +<% unless project.costs.nil? or project.costs.empty? %>

      <%= f.label :costs, "Costs for taking your project forwards" %> <%= f.text_area :costs %> What costs, if any, are involved in taking your project forwards? You can use Markdown in this field.

      -<% end -%> +<% end %>
      @@ -107,8 +101,8 @@

      -<% if @project.new_record? %> - <% unless @event.has_secret? -%> +<% if project.new_record? %> + <% unless event.has_secret? %>

      <%= f.label :secret, "Choose a project password *".html_safe %> @@ -116,9 +110,9 @@ Enter a word which will be required to make further changes to this project.

      - <% end -%> + <% end %> -

      Once you're happy with the details, hit Create below. Your project will appear immediately on the <%= @event.title %> event page.

      +

      Once you're happy with the details, hit Create below. Your project will appear immediately on the <%= event.title %> event page.

      <%= f.submit "Create Project" %>

      <% else %>

      <%= f.submit "Save Project" %>

      diff --git a/spec/controllers/admin/projects_controller_spec.rb b/spec/controllers/admin/projects_controller_spec.rb index af96477..30afb3d 100644 --- a/spec/controllers/admin/projects_controller_spec.rb +++ b/spec/controllers/admin/projects_controller_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' RSpec.describe Admin::ProjectsController do - let(:event) { FactoryGirl.create(:event_without_secret) } + let(:event) { FactoryGirl.create(:event) } context "when not signed in" do describe "GET 'index'" do @@ -26,8 +26,8 @@ end it "can assign a collection of all the projects" do - project_one = create(:project_with_secret, :event => event) - project_two = create(:project_with_secret, :event => event) + project_one = create(:project, :event => event) + project_two = create(:project, :event => event) get :index, :event_id => event.slug expect(controller.projects).to contain_exactly(project_one, project_two) @@ -35,7 +35,7 @@ end describe "PUT update" do - let(:project) { create(:project_with_secret, :event => event) } + let(:project) { create(:project, :event => event) } context "given valid attributes" do let(:valid_attributes) { diff --git a/spec/controllers/events_controller_spec.rb b/spec/controllers/events_controller_spec.rb index 3cb6263..9cc1aaa 100644 --- a/spec/controllers/events_controller_spec.rb +++ b/spec/controllers/events_controller_spec.rb @@ -29,7 +29,7 @@ context "given an event exists" do before do - @event = FactoryGirl.create(:event_without_secret) + @event = FactoryGirl.create(:event) end describe "GET show" do @@ -44,8 +44,8 @@ end it "can assign a collection of all the projects" do - @project_one = FactoryGirl.create(:project_with_secret, :event => @event) - @project_two = FactoryGirl.create(:project_with_secret, :event => @event) + @project_one = FactoryGirl.create(:project, :event => @event) + @project_two = FactoryGirl.create(:project, :event => @event) get :show, :id => @event.slug assigns(:event).projects.should =~ [@project_one, @project_two] diff --git a/spec/controllers/projects_controller_spec.rb b/spec/controllers/projects_controller_spec.rb index 19f1bf0..b05f66d 100644 --- a/spec/controllers/projects_controller_spec.rb +++ b/spec/controllers/projects_controller_spec.rb @@ -2,11 +2,11 @@ RSpec.describe ProjectsController, type: :controller do - let(:event) { FactoryGirl.create(:event_without_secret) } + let(:event) { FactoryGirl.create(:event) } describe "POST create" do context "given valid attributes" do - let(:attributes) { attributes_for(:project_with_secret) } + let(:attributes) { attributes_for(:project) } it "should create the project" do expect { @@ -42,42 +42,51 @@ end describe "PUT update" do - let(:project) { - FactoryGirl.create(:project, :event => event, :secret => 'secret') - } + let(:project) { create(:project, event: event) } context "given valid attributes" do - let(:valid_attributes) { + let(:attributes) { { - title: "Modified Project Title", - team: "Ian and Mark", - my_secret: "secret", + title: "modified title", + submitted_secret: project.secret, } } - it "should create the project" do - put :update, :id => project.slug, :event_id => event.slug, :project => valid_attributes + it "should update the project" do + put :update, id: project.slug, event_id: event.slug, project: attributes - expect(assigns(:project).title).to eq("Modified Project Title") - expect(assigns(:project).team).to eq("Ian and Mark") + expect(assigns(:project).title).to eq(attributes[:title]) end it "should redirect to the project" do - post :update, :id => project.slug, :event_id => event.slug, :project => valid_attributes + put :update, id: project.slug, event_id: event.slug, project: attributes expect(response).to redirect_to(event_project_path(event, project)) end end context "given invalid attributes" do - let(:invalid_attributes) { + let(:attributes) { + { title: "" } + } + + it "should show the edit form" do + put :update, id: project.slug, event_id: event.slug, project: attributes + + expect(response).to render_template(:edit) + end + end + + context 'given an incorrect secret' do + let(:attributes) { { - title: "" + title: 'updated title', + secret: 'not the correct secret', } } - it "should render the new form" do - put :update, :id => project.slug, :event_id => event.slug, :project => invalid_attributes + it 'should show the edit form' do + put :update, id: project.slug, event_id: event.slug, project: attributes expect(response).to render_template(:edit) end diff --git a/spec/factories/factories.rb b/spec/factories/factories.rb index 2ad46c4..47d6dfa 100644 --- a/spec/factories/factories.rb +++ b/spec/factories/factories.rb @@ -8,14 +8,20 @@ factory :event do sequence(:title) {|n| "Hack all the things ##{n}"} sequence(:slug) {|n| "hack-everything-#{n}"} - secret "secret" start_date { Date.today } - factory :event_without_secret do - secret nil + factory :event_with_centres do + use_centres true end end + factory :centre do + sequence(:name) {|n| "Centre #{n}"} + sequence(:slug) {|n| "centre-#{n}"} + + event + end + factory :project do sequence(:title) {|n| "Project ##{n}"} team "Lots of people" @@ -26,15 +32,8 @@ github_url "https://github.com/github/github" image { stub_uploaded_image } - factory :project_with_secret do - association :event, :secret => nil - secret "secret" - end - - factory :project_with_event_secret do - association :event, :secret => "secret" - my_secret "secret" - end + secret "secret" + event end factory :award_category do diff --git a/spec/models/event_spec.rb b/spec/models/event_spec.rb index 9763aac..6b5da7d 100644 --- a/spec/models/event_spec.rb +++ b/spec/models/event_spec.rb @@ -97,8 +97,8 @@ end context "given projects which have won awards" do - let(:project_one) { FactoryGirl.create(:project_with_event_secret, event: event) } - let(:project_two) { FactoryGirl.create(:project_with_event_secret, event: event) } + let(:project_one) { FactoryGirl.create(:project, event: event) } + let(:project_two) { FactoryGirl.create(:project, event: event) } let(:featured_award_category) { event.award_categories.create!(award_category_atts) } let(:other_award_category) { event.award_categories.create!(award_category_atts.merge(featured: false)) } diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 66f6d80..45b732b 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -2,279 +2,155 @@ RSpec.describe Project do - describe "creating an project" do - before do - @valid_attributes = { - :title => "Project One", - :team => "Roland and Michael", - :description => "The ultimate hack. Every hack you've ever dreamed of in one. Defining an entire genre of hacks.", - :summary => "A shorter summary of how awesome this project is", - :url => "http://example.project.com/", - :twitter => "@rewiredstate", - :github_url => "http://github.com/rewiredstate/hacks", - :image => stub_uploaded_image - } - end + let(:event) { create(:event) } + + describe "#create" do + let(:valid_attributes) { attributes_for(:project) } - describe "where the event has a password" do - before do - @event = FactoryGirl.create(:event, :secret => "secret") - @valid_attributes.merge!({ :my_secret => @event.secret }) + describe "given valid attributes" do + it "can be created" do + project = event.projects.create!(valid_attributes) + expect(project).to be_persisted end - describe "given valid attributes" do - it "can be created" do - project = @event.projects.create!(@valid_attributes) - expect(project).to be_persisted - end + it "sets the slug based on the title" do + project = event.projects.create!(valid_attributes) - it "sets the slug based on the title" do - project = @event.projects.create!(@valid_attributes) - expect(project.slug).to eq("project-one") - end + expect(project.slug).to eq(valid_attributes[:title].parameterize) + end - describe "the created project" do - it "has not won awards" do - project = @event.projects.create!(@valid_attributes) - expect(project).to_not have_won_award - end + describe "the created project" do + it "has not won awards" do + project = event.projects.create!(valid_attributes) + expect(project).to_not have_won_award end end + end - describe "given invalid attributes" do - it "can't be created with the wrong event password" do - @valid_attributes.merge!({ :my_secret => "not the event secret" }) - project = @event.projects.build(@valid_attributes) - expect(project).to_not be_valid - end + describe "given invalid attributes" do + it "can't be created if the event no longer allows new projects to be created" do + event = create(:event, enable_project_creation: false) + project = event.projects.build(valid_attributes) - it "can't be created if the event no longer allows new projects to be created" do - @event = FactoryGirl.create(:event, :enable_project_creation => false) - project = @event.projects.build(@valid_attributes) - expect(project).to_not be_valid - end + expect(project).to_not be_valid + end - it "can't be created without a screenshot" do - @valid_attributes.merge!({ :image => nil }) - project = @event.projects.build(@valid_attributes) - expect(project).to_not be_valid - end + it "can't be created with an empty project password" do + valid_attributes.merge!(secret: nil) + project = event.projects.build(valid_attributes) - it "can't be created without a title" do - @valid_attributes.merge!({ :title => nil }) - project = @event.projects.build(@valid_attributes) - expect(project).to_not be_valid - end + expect(project).to_not be_valid + end - it "can't be created without a team name" do - @valid_attributes.merge!({ :team => nil }) - project = @event.projects.build(@valid_attributes) - expect(project).to_not be_valid - end + it "can't be created without a screenshot" do + valid_attributes.merge!(image: nil) + project = event.projects.build(valid_attributes) - it "can't be created without a summary" do - @valid_attributes.merge!({ :summary => nil }) - project = @event.projects.build(@valid_attributes) - expect(project).to_not be_valid - end + expect(project).to_not be_valid + end - it "can't be created with a summary longer than 180 characters" do - @valid_attributes.merge!({ :summary => "test".ljust(181) }) - project = @event.projects.build(@valid_attributes) - expect(project).to_not be_valid - end + it "can't be created without a title" do + valid_attributes.merge!(title: nil) + project = event.projects.build(valid_attributes) - it "can't be created without a description" do - @valid_attributes.merge!({ :description => nil }) - project = @event.projects.build(@valid_attributes) - expect(project).to_not be_valid - end + expect(project).to_not be_valid + end - it "can't be created with an invalid url" do - @valid_attributes.merge!({ :url => "this does not look like a valid url" }) - project = @event.projects.build(@valid_attributes) - expect(project).to_not be_valid - end + it "can't be created without a team name" do + valid_attributes.merge!(team: nil) + project = event.projects.build(valid_attributes) - it "can't be created with an invalid image" do - @valid_attributes.merge!({ :image => stub_uploaded_image("invalid_image_file") }) - project = @event.projects.build(@valid_attributes) - expect(project).to_not be_valid - end + expect(project).to_not be_valid end - end - describe "where the event does not have a password" do - before do - @event = FactoryGirl.create(:event, :secret => nil) - @valid_attributes.merge!({ :secret => "secret" }) + it "can't be created without a summary" do + valid_attributes.merge!(summary: nil) + project = event.projects.build(valid_attributes) + + expect(project).to_not be_valid end - describe "given valid attributes" do - it "can be created" do - project = @event.projects.create!(@valid_attributes) - expect(project).to be_persisted - end + it "can't be created with a summary longer than 180 characters" do + valid_attributes.merge!(summary: "test".ljust(181)) + project = event.projects.build(valid_attributes) + + expect(project).to_not be_valid end - describe "given invalid attributes" do - it "can't be created with an empty project password" do - @valid_attributes.merge!({ :secret => nil }) - project = @event.projects.build(@valid_attributes) - expect(project).to_not be_valid - end + it "can't be created without a description" do + valid_attributes.merge!(description: nil) + project = event.projects.build(valid_attributes) + + expect(project).to_not be_valid + end + + it "can't be created with an invalid url" do + valid_attributes.merge!(url: "this does not look like a valid url") + project = event.projects.build(valid_attributes) + + expect(project).to_not be_valid + end + + it "can't be created with an invalid image" do + valid_attributes.merge!(image: stub_uploaded_image("invalid_image_file")) + project = event.projects.build(valid_attributes) + + expect(project).to_not be_valid end end describe "where the event has centres" do - before do - @event = FactoryGirl.create(:event, :secret => "secret", :use_centres => true) - @centre = @event.centres.create!(:name => "London", :slug => "london") - @valid_attributes.merge!({ :my_secret => @event.secret, :centre => @centre }) - end + let(:event) { create(:event_with_centres) } + let(:centre) { create(:centre, event: event) } + let(:attributes) { + attributes_for(:project).merge(centre: centre) + } describe "given valid attributes" do it "can be created" do - project = @event.projects.create!(@valid_attributes) + project = event.projects.create!(attributes) + expect(project).to be_persisted end end describe "given invalid attributes" do it "can't be created without a centre" do - @invalid_attributes = @valid_attributes.merge({ :centre => nil }) - project = @event.projects.build(@invalid_attributes) + project = event.projects.build(attributes.merge(centre: nil)) + expect(project).to_not be_valid end end end end - describe "updating a project" do - before do - @valid_attributes = { - :title => "Updated Title", - :summary => "An updated summary", - :image => stub_uploaded_image('alternative.jpg') - } - end - - describe "as a user" do - describe "where the event does not have a password" do - let(:project) { FactoryGirl.create(:project_with_secret) } - - describe "given valid attributes" do - before do - @valid_attributes.merge!({ :my_secret => project.secret }) - end - - it "can be updated" do - project.update_attributes!(@valid_attributes) - - expect(project.title).to eq(@valid_attributes[:title]) - expect(project.summary).to eq(@valid_attributes[:summary]) - expect(project.image.url).to match(/alternative\.jpg/) - end - end - - describe "given invalid attributes" do - it "can not update a project with an empty project password" do - @valid_attributes.merge!({ :my_secret => nil }) - - expect(project.update_attributes(@valid_attributes)).to eq(false) - end + describe '#update_attributes_with_secret' do + let(:project) { create(:project) } + let(:attributes) { + { title: 'updated title' } + } - it "can not update a project with an invalid project password" do - @valid_attributes.merge!({ :my_secret => "not the correct project password" }) + it 'updates attributes given the valid secret' do + project.update_attributes_with_secret(project.secret, attributes) + project.reload - expect(project.update_attributes(@valid_attributes)).to eq(false) - end - end - end - - describe "where the event has a password" do - let(:project) { FactoryGirl.create(:project_with_event_secret) } - - describe "given valid attributes" do - before do - @valid_attributes.merge!({ :my_secret => project.event.secret }) - end - - it "can be updated" do - project.update_attributes!(@valid_attributes) - - expect(project.title).to eq(@valid_attributes[:title]) - expect(project.summary).to eq(@valid_attributes[:summary]) - expect(project.image.url).to match(/alternative\.jpg/) - end - end - - describe "given invalid attributes" do - it "can not update a project with an empty event password" do - @valid_attributes.merge!({ :my_secret => nil }) - - expect(project.update_attributes(@valid_attributes)).to eq(false) - end - - it "can not update a project with an invalid event password" do - @valid_attributes.merge!({ :my_secret => "not the correct event password" }) - - expect(project.update_attributes(@valid_attributes)).to eq(false) - end - end - end + expect(project.title).to eq(attributes[:title]) end - describe "as an admin" do - describe "updating a project" do - describe "where the event has a password" do - before do - @project = FactoryGirl.create(:project_with_event_secret) - @project.managing = true - end - - it "can update a project without the password" do - @valid_attributes.merge!({ :my_secret => nil }) - - @project.update_attributes!(@valid_attributes) - @project.title.should == @valid_attributes[:title] - @project.summary.should == @valid_attributes[:summary] - @project.image.url.should =~ /alternative\.jpg/ - end - end - - describe "where the event does not have a password" do - before do - @project = FactoryGirl.create(:project_with_secret) - @project.managing = true - end - - it "can update a project without the password" do - @valid_attributes.merge!({ :my_secret => nil }) + it 'does not update attributes given an invalid secret' do + expect( + project.update_attributes_with_secret('not the secret', attributes) + ).to eq(false) - @project.update_attributes!(@valid_attributes) - @project.title.should == @valid_attributes[:title] - @project.summary.should == @valid_attributes[:summary] - @project.image.url.should =~ /alternative\.jpg/ - end - end - - describe "giving awards to a project" do - before do - @event = FactoryGirl.create(:event_without_secret) - @award_category = FactoryGirl.create(:award_category, :event => @event) + expect(project.errors).to have_key(:secret) + end - @project = FactoryGirl.create(:project_with_secret, :event => @event) - @project.managing = true - end + it 'does not update attributes given a blank secret' do + expect( + project.update_attributes_with_secret('', attributes) + ).to eq(false) - it "can assign an award category to a project" do - @project.awards.create!(:award_category => @award_category) - @project.should have_won_award - @project.award_categories.size.should == 1 - end - end - end + expect(project.errors).to have_key(:secret) end end From b653c161ccf00a75d2a1ff2ce42589f4afc1ec1b Mon Sep 17 00:00:00 2001 From: Jordan Hatch Date: Tue, 7 Jul 2015 12:24:10 +0100 Subject: [PATCH 26/34] Remove attr_accessible from Admin model --- app/models/admin.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/models/admin.rb b/app/models/admin.rb index d916dad..1d1a91a 100644 --- a/app/models/admin.rb +++ b/app/models/admin.rb @@ -1,6 +1,4 @@ class Admin < ActiveRecord::Base devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable - - attr_accessible :email, :password, :password_confirmation, :remember_me end From 81494b43d22eaf98f6625549a4b7476f9414df8d Mon Sep 17 00:00:00 2001 From: Jordan Hatch Date: Tue, 7 Jul 2015 12:38:01 +0100 Subject: [PATCH 27/34] Don't set defaults for Project anymore --- app/models/project.rb | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/app/models/project.rb b/app/models/project.rb index 2f6ddfe..483c931 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -5,7 +5,6 @@ class Project < ActiveRecord::Base has_paper_trail default_scope -> { order('title ASC') } - after_initialize :set_default_values has_many :awards has_many :award_categories, :class_name => 'AwardCategory', :through => :awards @@ -33,7 +32,6 @@ class Project < ActiveRecord::Base attr_accessor :submitted_secret before_validation :create_slug, :if => proc { self.slug.blank? and ! self.title.blank? } - before_validation :blank_url_fields validates :title, :team, :description, :presence => true validates :summary, :presence => true, :length => { :maximum => 180 } @@ -91,20 +89,6 @@ def create_slug self.slug = (existing_slugs > 0 ? "#{self.title.parameterize}-#{existing_slugs+1}" : self.title.parameterize) end - def blank_url_fields - self.url = '' if self.url == 'http://' - self.github_url = '' if self.github_url == 'http://' - self.code_url = '' if self.code_url == 'http://' - self.svn_url = '' if self.svn_url == 'http://' - end - - def set_default_values - self.url ||= 'http://' - self.github_url ||= 'http://' - self.svn_url ||= 'http://' - self.code_url ||= 'http://' - end - def ensure_project_creation_is_enabled unless event.enable_project_creation errors.add(:event, "no longer allows projects to be created") From 836722f60a8b8a99078027de660901a71c44bdec Mon Sep 17 00:00:00 2001 From: Jordan Hatch Date: Tue, 7 Jul 2015 12:40:05 +0100 Subject: [PATCH 28/34] Update to Rails 4.2.3 --- Gemfile | 2 +- Gemfile.lock | 112 +++++++++++++++++----------- config/environments/development.rb | 1 + config/environments/production.rb | 2 +- config/environments/test.rb | 3 +- config/initializers/secret_token.rb | 8 -- config/secrets.yml | 8 ++ spec/rails_helper.rb | 4 +- 8 files changed, 84 insertions(+), 56 deletions(-) delete mode 100644 config/initializers/secret_token.rb create mode 100644 config/secrets.yml diff --git a/Gemfile b/Gemfile index 34517df..37549d7 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,6 @@ source 'http://rubygems.org' -gem 'rails', '~> 4.0.12' +gem 'rails', '~> 4.2.3' gem 'unicorn' gem 'pg' diff --git a/Gemfile.lock b/Gemfile.lock index e625f9b..0f5c119 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -7,31 +7,42 @@ GIT GEM remote: http://rubygems.org/ specs: - actionmailer (4.0.13) - actionpack (= 4.0.13) + actionmailer (4.2.3) + actionpack (= 4.2.3) + actionview (= 4.2.3) + activejob (= 4.2.3) mail (~> 2.5, >= 2.5.4) - actionpack (4.0.13) - activesupport (= 4.0.13) - builder (~> 3.1.0) - erubis (~> 2.7.0) - rack (~> 1.5.2) + rails-dom-testing (~> 1.0, >= 1.0.5) + actionpack (4.2.3) + actionview (= 4.2.3) + activesupport (= 4.2.3) + rack (~> 1.6) rack-test (~> 0.6.2) - activemodel (4.0.13) - activesupport (= 4.0.13) - builder (~> 3.1.0) - activerecord (4.0.13) - activemodel (= 4.0.13) - activerecord-deprecated_finders (~> 1.0.2) - activesupport (= 4.0.13) - arel (~> 4.0.0) - activerecord-deprecated_finders (1.0.4) - activesupport (4.0.13) - i18n (~> 0.6, >= 0.6.9) - minitest (~> 4.2) - multi_json (~> 1.3) - thread_safe (~> 0.1) - tzinfo (~> 0.3.37) - arel (4.0.2) + rails-dom-testing (~> 1.0, >= 1.0.5) + rails-html-sanitizer (~> 1.0, >= 1.0.2) + actionview (4.2.3) + activesupport (= 4.2.3) + builder (~> 3.1) + erubis (~> 2.7.0) + rails-dom-testing (~> 1.0, >= 1.0.5) + rails-html-sanitizer (~> 1.0, >= 1.0.2) + activejob (4.2.3) + activesupport (= 4.2.3) + globalid (>= 0.3.0) + activemodel (4.2.3) + activesupport (= 4.2.3) + builder (~> 3.1) + activerecord (4.2.3) + activemodel (= 4.2.3) + activesupport (= 4.2.3) + arel (~> 6.0) + activesupport (4.2.3) + i18n (~> 0.7) + json (~> 1.7, >= 1.7.7) + minitest (~> 5.1) + thread_safe (~> 0.3, >= 0.3.4) + tzinfo (~> 1.1) + arel (6.0.0) aws-sdk (1.8.3.1) json (~> 1.4) nokogiri (>= 1.4.4) @@ -39,7 +50,7 @@ GEM bcrypt (3.1.10) breadcrumbs (0.1.7) i18n - builder (3.1.4) + builder (3.2.2) capybara (2.4.4) mime-types (>= 1.16) nokogiri (>= 1.3.3) @@ -84,6 +95,8 @@ GEM actionpack (>= 3.0) gherkin (2.12.2) multi_json (~> 1.3) + globalid (0.3.5) + activesupport (>= 4.1.0) has_scope (0.6.0) actionpack (>= 3.2, < 5) activesupport (>= 3.2, < 5) @@ -94,17 +107,20 @@ GEM has_scope (~> 0.6.0.rc) railties (>= 3.2, < 5) responders - jquery-rails (3.1.3) - railties (>= 3.0, < 5.0) + jquery-rails (4.0.4) + rails-dom-testing (~> 1.0) + railties (>= 4.2.0) thor (>= 0.14, < 2.0) json (1.8.3) kgio (2.9.3) + loofah (2.0.2) + nokogiri (>= 1.5.9) mail (2.6.3) mime-types (>= 1.16, < 3) mime-types (2.6.1) mimemagic (0.3.0) mini_portile (0.6.2) - minitest (4.7.5) + minitest (5.7.0) multi_json (1.11.2) multi_test (0.1.2) nokogiri (1.6.6.2) @@ -124,27 +140,38 @@ GEM rack (>= 1.1, < 2.0) rabl (0.11.6) activesupport (>= 2.3.14) - rack (1.5.5) + rack (1.6.4) rack-test (0.6.3) rack (>= 1.0) - rails (4.0.13) - actionmailer (= 4.0.13) - actionpack (= 4.0.13) - activerecord (= 4.0.13) - activesupport (= 4.0.13) + rails (4.2.3) + actionmailer (= 4.2.3) + actionpack (= 4.2.3) + actionview (= 4.2.3) + activejob (= 4.2.3) + activemodel (= 4.2.3) + activerecord (= 4.2.3) + activesupport (= 4.2.3) bundler (>= 1.3.0, < 2.0) - railties (= 4.0.13) - sprockets-rails (~> 2.0) - railties (4.0.13) - actionpack (= 4.0.13) - activesupport (= 4.0.13) + railties (= 4.2.3) + sprockets-rails + rails-deprecated_sanitizer (1.0.3) + activesupport (>= 4.2.0.alpha) + rails-dom-testing (1.0.6) + activesupport (>= 4.2.0.beta, < 5.0) + nokogiri (~> 1.6.0) + rails-deprecated_sanitizer (>= 1.0.1) + rails-html-sanitizer (1.0.2) + loofah (~> 2.0) + railties (4.2.3) + actionpack (= 4.2.3) + activesupport (= 4.2.3) rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) raindrops (0.14.0) rake (10.4.2) rdiscount (1.6.8) - responders (1.1.2) - railties (>= 3.2, < 4.2) + responders (2.1.0) + railties (>= 4.2.0, < 5) rspec-core (3.3.1) rspec-support (~> 3.3.0) rspec-expectations (3.3.0) @@ -180,7 +207,8 @@ GEM thor (0.19.1) thread_safe (0.3.5) tilt (1.4.1) - tzinfo (0.3.44) + tzinfo (1.2.2) + thread_safe (~> 0.1) uglifier (2.7.1) execjs (>= 0.3.0) json (>= 1.8.0) @@ -215,7 +243,7 @@ DEPENDENCIES pg puma rabl - rails (~> 4.0.12) + rails (~> 4.2.3) rdiscount (~> 1.6.8) rspec-rails (~> 3.1) sass-rails (~> 4.0.3) diff --git a/config/environments/development.rb b/config/environments/development.rb index 13b9bde..39aa3af 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -28,4 +28,5 @@ config.attachment_settings = { } config.eager_load = false + config.active_record.raise_in_transactional_callbacks = true end diff --git a/config/environments/production.rb b/config/environments/production.rb index e20d138..66379e0 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -9,7 +9,7 @@ config.action_controller.perform_caching = true # Disable Rails's static asset server (Apache or nginx will already do this) - config.serve_static_assets = false + config.serve_static_files = false # Compress JavaScripts and CSS config.assets.compress = true diff --git a/config/environments/test.rb b/config/environments/test.rb index 6933be0..40dae40 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -8,7 +8,7 @@ config.cache_classes = true # Configure static asset server for tests with Cache-Control for performance - config.serve_static_assets = true + config.serve_static_files = true config.static_cache_control = "public, max-age=3600" # Show full error reports and disable caching @@ -37,4 +37,5 @@ config.attachment_settings = { } config.eager_load = false + config.active_record.raise_in_transactional_callbacks = true end diff --git a/config/initializers/secret_token.rb b/config/initializers/secret_token.rb deleted file mode 100644 index f89e5db..0000000 --- a/config/initializers/secret_token.rb +++ /dev/null @@ -1,8 +0,0 @@ -# Be sure to restart your server when you modify this file. - -# Your secret key for verifying the integrity of signed cookies. -# If you change this key, all old signed cookies will become invalid! -# Make sure the secret is at least 30 characters and all random, -# no regular words or you'll be exposed to dictionary attacks. -Projects::Application.config.secret_token = ENV['SECRET_TOKEN'] || "an_insecure_secret_token_key_which_should_not_be_used_in_production" -Projects::Application.config.secret_key_base = ENV['SECRET_KEY_BASE'] || "an_insecure_secret_token_key_which_should_not_be_used_in_production" diff --git a/config/secrets.yml b/config/secrets.yml new file mode 100644 index 0000000..978af3d --- /dev/null +++ b/config/secrets.yml @@ -0,0 +1,8 @@ +development: + secret_key_base: an_insecure_secret_token_key_which_should_not_be_used_in_production + +test: + secret_key_base: an_insecure_secret_token_key_which_should_not_be_used_in_production + +production: + secret_key_base: <%= ENV["SECRET_KEY_BASE"] %> diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 7c03318..e3ad251 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -6,8 +6,6 @@ Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f} -# ActiveRecord::Migration.maintain_test_schema! - require 'database_cleaner' RSpec.configure do |config| @@ -24,6 +22,6 @@ end config.infer_base_class_for_anonymous_controllers = false - + config.infer_spec_type_from_file_location! end From 29f2a611f9ed558d0a484c6d713649f04492f1ee Mon Sep 17 00:00:00 2001 From: Jordan Hatch Date: Tue, 7 Jul 2015 12:44:25 +0100 Subject: [PATCH 29/34] Update ProjectsHelper spec with new syntax --- spec/helpers/projects_helper_spec.rb | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/spec/helpers/projects_helper_spec.rb b/spec/helpers/projects_helper_spec.rb index a4e44a9..6f21efc 100644 --- a/spec/helpers/projects_helper_spec.rb +++ b/spec/helpers/projects_helper_spec.rb @@ -4,23 +4,33 @@ describe "#format_github_url" do it "returns the username and repository when given a valid http url" do - helper.format_github_url("http://github.com/someuser/somerepo").should == "someuser/somerepo" + output = helper.format_github_url("http://github.com/someuser/somerepo") + + expect(output).to eq("someuser/somerepo") end it "returns the username and repository when given a valid https url" do - helper.format_github_url("https://github.com/someuser/somerepo").should == "someuser/somerepo" + output = helper.format_github_url("https://github.com/someuser/somerepo") + + expect(output).to eq("someuser/somerepo") end it "returns the full url when a url with another host is provided" do - helper.format_github_url("https://definitely-not-github.com/blah").should == "https://definitely-not-github.com/blah" + output = helper.format_github_url("https://definitely-not-github.com/blah") + + expect(output).to eq("https://definitely-not-github.com/blah") end it "returns the full url when a url with another host is provided with two parts to the path" do - helper.format_github_url("https://definitely-not-github.com/someuser/somerepo").should == "https://definitely-not-github.com/someuser/somerepo" + output = helper.format_github_url("https://definitely-not-github.com/someuser/somerepo") + + expect(output).to eq("https://definitely-not-github.com/someuser/somerepo") end it "returns the username when a url on github.com does not have a user and repo" do - helper.format_github_url("https://github.com/someuser").should == "someuser" + output = helper.format_github_url("https://github.com/someuser") + + expect(output).to eq("someuser") end end From 5d41361d6e6194cb45d668fd81392f13a4f9a804 Mon Sep 17 00:00:00 2001 From: Jordan Hatch Date: Tue, 7 Jul 2015 12:49:13 +0100 Subject: [PATCH 30/34] Update ProjectsHelper spec with new syntax --- spec/models/centre_spec.rb | 42 ++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/spec/models/centre_spec.rb b/spec/models/centre_spec.rb index 0ad5eaf..261cf1c 100644 --- a/spec/models/centre_spec.rb +++ b/spec/models/centre_spec.rb @@ -1,44 +1,46 @@ require 'rails_helper' -RSpec.describe Centre do +RSpec.describe Centre, type: :model do + + let(:event) { create(:event_with_centres) } describe "creating a centre" do - before do - @event = FactoryGirl.create(:event, :use_centres => true) - @valid_attributes = { - :name => "London", - :slug => "centre-slug" - } - end + let(:attributes) { + attributes_for(:centre) + } context "given valid attributes" do it "can create a centre" do - @event.centres.create!(@valid_attributes) + event.centres.create!(attributes) end it "can set a slug if none exists" do - @centre = @event.centres.create!( @valid_attributes.merge({:slug => nil}) ) - @centre.slug.should == "london" + centre = event.centres.create!( attributes.merge(slug: nil) ) + + expect(centre.slug).to eq(attributes[:name].parameterize) end it "doesn't generate a slug if one is present" do - @centre = @event.centres.create!( @valid_attributes ) - @centre.slug.should == "centre-slug" + centre = event.centres.create!( attributes ) + + expect(centre.slug).to eq(attributes[:slug]) end it "can generate a unique slug where a centre with the same name exists" do - @centre_one = @event.centres.create!( @valid_attributes.merge({:slug => nil}) ) - @centre_two = @event.centres.create!( @valid_attributes.merge({:slug => nil}) ) + centre_one = event.centres.create!( attributes.merge(slug: nil) ) + centre_two = event.centres.create!( attributes.merge(slug: nil) ) - @centre_one.slug.should == "london" - @centre_two.slug.should == "london-2" + expect(centre_one.slug).to eq(attributes[:name].parameterize) + expect(centre_two.slug).to eq("#{attributes[:name].parameterize}-2") end end context "given invalid attributes" do - it "can't create an award category without a name" do - @centre = @event.centres.build(@valid_attributes.merge({ :name => nil })) - @centre.should_not be_valid + it "can't create a centre without a name" do + centre = event.centres.build(attributes.merge(name: nil)) + + expect(centre).to_not be_valid + expect(centre.errors).to have_key(:name) end end end From 5c787c32b00862d7adff5211665c156d6bb6027d Mon Sep 17 00:00:00 2001 From: Jordan Hatch Date: Tue, 7 Jul 2015 12:57:24 +0100 Subject: [PATCH 31/34] Refactor EventsController and spec --- app/controllers/events_controller.rb | 46 +++++++++++---------- app/views/events/_centre_list.html.erb | 4 +- app/views/events/_display_standard.html.erb | 4 +- app/views/events/_display_winners.html.erb | 6 +-- app/views/events/_event_header.html.erb | 7 ++-- app/views/events/_single_project.html.erb | 6 +-- app/views/events/index.html.erb | 4 +- app/views/events/index.json.rabl | 4 +- app/views/events/show.html.erb | 8 ++-- app/views/events/show.json.rabl | 8 ++-- app/views/events/show_centre.html.erb | 8 ++-- app/views/events/show_centre.json.rabl | 6 +-- spec/controllers/events_controller_spec.rb | 43 ++++++++++--------- 13 files changed, 80 insertions(+), 74 deletions(-) diff --git a/app/controllers/events_controller.rb b/app/controllers/events_controller.rb index 3dae016..277ac43 100644 --- a/app/controllers/events_controller.rb +++ b/app/controllers/events_controller.rb @@ -1,32 +1,23 @@ class EventsController < ApplicationController - before_filter :find_event, :except => :index - - respond_to :html, :json - - def index - @events = Event.recent_first.all - respond_with @events - end + before_filter :set_breadcrumbs def show respond_to do |format| - format.html { # show.html.erb - } - format.json { # show.json.rabl - } - format.csv { render :csv => @event.projects } + format.html + format.json + format.csv { render :csv => event.projects } end end def show_centre - unless @event.use_centres and !params[:centre].blank? - redirect_to event_path(@event) + unless event.use_centres and !params[:centre].blank? + redirect_to event_path(event) return end - @centre = @event.centres.where(:slug => params[:centre]).first || not_found + @centre = event.centres.where(:slug => params[:centre]).first || not_found - breadcrumbs.add @centre.name, centre_event_path(@event, @centre.slug) + breadcrumbs.add @centre.name, centre_event_path(event, @centre.slug) respond_to do |format| format.html { @@ -36,10 +27,23 @@ def show_centre end end - private - def find_event - @event = Event.find_by_slug(params[:id]) || not_found - breadcrumbs.add @event.title, event_path(@event) + def events + @events ||= Event.recent_first.all + end + helper_method :events + + def event + if params[:id] + @event ||= Event.find_by_slug(params[:id]) || not_found end + end + helper_method :event + +private + def set_breadcrumbs + if event.present? + breadcrumbs.add event.title, event_path(event) + end + end end diff --git a/app/views/events/_centre_list.html.erb b/app/views/events/_centre_list.html.erb index b22b406..580bc73 100644 --- a/app/views/events/_centre_list.html.erb +++ b/app/views/events/_centre_list.html.erb @@ -1,7 +1,7 @@
        - <% @event.centres.each do |c| %> + <% event.centres.each do |c| %>
      • - +

        <%= c.name %>

        <%= pluralize c.projects.count, "hack" %>
        diff --git a/app/views/events/_display_standard.html.erb b/app/views/events/_display_standard.html.erb index 072afa1..53c4899 100644 --- a/app/views/events/_display_standard.html.erb +++ b/app/views/events/_display_standard.html.erb @@ -1,7 +1,7 @@
          - <% @event.projects.each do |project| -%> + <% event.projects.each do |project| -%> <%= render :partial => 'single_project', :locals => {:project => project, :winners => false} %> <% end -%>
        -
        \ No newline at end of file + diff --git a/app/views/events/_display_winners.html.erb b/app/views/events/_display_winners.html.erb index 78033bd..c1445c2 100644 --- a/app/views/events/_display_winners.html.erb +++ b/app/views/events/_display_winners.html.erb @@ -1,8 +1,8 @@
        -

        <%= pluralize @event.winners.count, "winner" %>

        +

        <%= pluralize event.winners.count, "winner" %>

        -
          <% @event.winners.each do |project| -%> +
            <% event.winners.each do |project| -%> <%= render :partial => 'single_project', :locals => {:project => project, :winners => true} %> <% end -%>
          -
        \ No newline at end of file + diff --git a/app/views/events/_event_header.html.erb b/app/views/events/_event_header.html.erb index d8c4cf5..695116d 100644 --- a/app/views/events/_event_header.html.erb +++ b/app/views/events/_event_header.html.erb @@ -1,6 +1,5 @@ -<% content_for(:title) { "#{@event.title}" } %> +<% content_for(:title) { "#{event.title}" } %> -

        <%= @event.title %>

        -<%- if @event.enable_project_creation -%>
        <%= link_to "New project", new_event_project_path(@event), :class => 'action' %>
        <%- end -%> +

        <%= event.title %>

        +<%- if event.enable_project_creation -%>
        <%= link_to "New project", new_event_project_path(event), :class => 'action' %>
        <%- end -%>
        - diff --git a/app/views/events/_single_project.html.erb b/app/views/events/_single_project.html.erb index f16c14b..e3fc480 100644 --- a/app/views/events/_single_project.html.erb +++ b/app/views/events/_single_project.html.erb @@ -1,14 +1,14 @@ <% awards = project.award_categories if project.has_won_award? %>
      • >
        -

        <%= link_to project.title, event_project_path(@event, project) %>

        +

        <%= link_to project.title, event_project_path(event, project) %>

        by <%= project.team %>
        <% if project.has_won_award? -%>
        <%= awards.map(&:title).join(', ') %>
        @@ -16,4 +16,4 @@
        <%= project.summary %>
        -
      • \ No newline at end of file + diff --git a/app/views/events/index.html.erb b/app/views/events/index.html.erb index 1c98454..ef99a91 100644 --- a/app/views/events/index.html.erb +++ b/app/views/events/index.html.erb @@ -5,7 +5,7 @@

        Event List

          - <% @events.each do |event| %> + <% events.each do |event| %>
        • <%= link_to event.title, event_path(event) %>
        • <% end %> -
            \ No newline at end of file +
              diff --git a/app/views/events/index.json.rabl b/app/views/events/index.json.rabl index d0bdd0f..570b7b6 100644 --- a/app/views/events/index.json.rabl +++ b/app/views/events/index.json.rabl @@ -1,6 +1,6 @@ -collection @events +collection events attributes :title, :hashtag code(:url) {|e| event_url(e)} -code(:projects_count) {|e| e.projects.count } \ No newline at end of file +code(:projects_count) {|e| e.projects.count } diff --git a/app/views/events/show.html.erb b/app/views/events/show.html.erb index a3bce00..a8c257b 100644 --- a/app/views/events/show.html.erb +++ b/app/views/events/show.html.erb @@ -1,17 +1,17 @@ <%= render :partial => 'event_header' %>
              - <%= link_to "See the full event details", ( @event.url.blank? ? "http://rewiredstate.org/events/#{@event.slug}" : @event.url ) %> + <%= link_to "See the full event details", ( event.url.blank? ? "http://rewiredstate.org/events/#{event.slug}" : event.url ) %>
              -<% if @event.winners.any? %> +<% if event.winners.any? %> <%= render :partial => 'display_winners' %> <% end %>
              -

              <%= pluralize @event.projects.size, "projects" %><% if @event.use_centres %> from <%= pluralize @event.centres.size, "centres" %><% end %>

              +

              <%= pluralize event.projects.size, "projects" %><% if event.use_centres %> from <%= pluralize event.centres.size, "centres" %><% end %>

              - <% if @event.use_centres %> + <% if event.use_centres %> <%= render :partial => 'centre_list' %> <% else %> <%= render :partial => 'display_standard' %> diff --git a/app/views/events/show.json.rabl b/app/views/events/show.json.rabl index fda5b5a..0455c18 100644 --- a/app/views/events/show.json.rabl +++ b/app/views/events/show.json.rabl @@ -1,4 +1,4 @@ -object @event +object event attribute :title, :hashtag code(:url) {|e| event_url(e)} @@ -6,11 +6,11 @@ code(:url) {|e| event_url(e)} child :projects do attributes :title, :team, :summary - if @event.use_centres + if event.use_centres code(:centre) {|p| p.centre.slug } end - code(:url) {|p| event_project_url(@event, p)} + code(:url) {|p| event_project_url(event, p)} code(:awarded) {|p| p.has_won_award? } child :award_categories => :awards do @@ -20,6 +20,6 @@ end child :centres do attributes :name - code(:url) {|c| centre_event_url(@event, c.slug) } + code(:url) {|c| centre_event_url(event, c.slug) } code(:count) {|c| c.projects.count } end diff --git a/app/views/events/show_centre.html.erb b/app/views/events/show_centre.html.erb index 0c36fdf..4d7abc8 100644 --- a/app/views/events/show_centre.html.erb +++ b/app/views/events/show_centre.html.erb @@ -1,10 +1,10 @@ <%= render :partial => 'event_header' %>
              - <%= link_to "← See all centres and winners".html_safe, event_path(@event), :class => "back" %> + <%= link_to "← See all centres and winners".html_safe, event_path(event), :class => "back" %>
                - <% @event.centres.each do |c| %> -
              • <%= link_to c.name, centre_event_path(@event, c.slug) %>
              • + <% event.centres.each do |c| %> +
              • <%= link_to c.name, centre_event_path(event, c.slug) %>
              • <% end %>
              @@ -17,7 +17,7 @@ <% end -%>
            <% else %> -

            We don't have any projects yet from <%= @centre.name %>. <%= link_to "Add yours!", new_event_project_path(@event) %>

            +

            We don't have any projects yet from <%= @centre.name %>. <%= link_to "Add yours!", new_event_project_path(event) %>

            <% end %>
            diff --git a/app/views/events/show_centre.json.rabl b/app/views/events/show_centre.json.rabl index 028cab8..f638fe9 100644 --- a/app/views/events/show_centre.json.rabl +++ b/app/views/events/show_centre.json.rabl @@ -1,16 +1,16 @@ object @centre attribute :name -code(:url) {|e| centre_event_url(@event, @centre.slug)} +code(:url) {|e| centre_event_url(event, @centre.slug)} child :projects do attributes :title, :team, :summary - if @event.use_centres + if event.use_centres code(:centre) {|p| p.centre.slug } end - code(:url) {|p| event_project_url(@event, p)} + code(:url) {|p| event_project_url(event, p)} code(:awarded) {|p| p.has_won_award? } child :award_categories => :awards do diff --git a/spec/controllers/events_controller_spec.rb b/spec/controllers/events_controller_spec.rb index 9cc1aaa..264a15b 100644 --- a/spec/controllers/events_controller_spec.rb +++ b/spec/controllers/events_controller_spec.rb @@ -2,53 +2,56 @@ describe EventsController do describe "GET index" do - before do - @events = [ - FactoryGirl.create(:event, :title => "Event One", :start_date => Date.parse("1 January 2013")), - FactoryGirl.create(:event, :title => "Event Two", :start_date => Date.parse("3 January 2013")), - FactoryGirl.create(:event, :title => "Event Three", :start_date => Date.parse("2 January 2013")) + let!(:events) { + [ + create(:event, title: "Event One", start_date: Date.parse('1 January 2013')), + create(:event, title: "Event Two", start_date: Date.parse('3 January 2013')), + create(:event, title: "Event Three", start_date: Date.parse('2 January 2013')), ] - end + } it "should be successful" do get :index - response.should be_success + + expect(response).to be_success end it "assigns a collection of all the events" do get :index - assigns(:events).should =~ @events + + expect(controller.events).to contain_exactly(*events) end it "loads the most recent events first" do get :index - assigns(:events).map(&:title).should == ["Event Two", "Event Three", "Event One"] + expect(controller.events.map(&:title)).to eq(["Event Two", "Event Three", "Event One"]) end end context "given an event exists" do - before do - @event = FactoryGirl.create(:event) - end + let(:event) { create(:event) } describe "GET show" do it "should be successful" do - get :show, :id => @event.slug - response.should be_success + get :show, id: event + + expect(response).to be_success end it "can assign the event details" do - get :show, :id => @event.slug - assigns(:event).should == @event + get :show, id: event + + expect(controller.event).to eq(event) end it "can assign a collection of all the projects" do - @project_one = FactoryGirl.create(:project, :event => @event) - @project_two = FactoryGirl.create(:project, :event => @event) + project_one = create(:project, event: event) + project_two = create(:project, event: event) + + get :show, id: event - get :show, :id => @event.slug - assigns(:event).projects.should =~ [@project_one, @project_two] + expect(assigns(:event).projects).to contain_exactly(project_one, project_two) end end end From acd9d2169db09765f76425e618738177a356a5e4 Mon Sep 17 00:00:00 2001 From: Jordan Hatch Date: Tue, 7 Jul 2015 13:08:08 +0100 Subject: [PATCH 32/34] Add nested params for centres/awards to whitelist --- app/controllers/admin/events_controller.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/controllers/admin/events_controller.rb b/app/controllers/admin/events_controller.rb index fe8101d..32e18ff 100644 --- a/app/controllers/admin/events_controller.rb +++ b/app/controllers/admin/events_controller.rb @@ -43,7 +43,9 @@ def events private def event_params params.fetch(:event, {}).permit(:title, :slug, :hashtag, :use_centres, - :active, :url, :enable_project_creation, :start_date) + :active, :url, :enable_project_creation, :start_date, + centres_attributes: [ :id, :name, :slug ], + award_categories_attributes: [ :id, :title, :description, :format, :level, :featured, :_destroy ]) end end From 31d3012e1cad8640a94f8e630e4436efe59e5091 Mon Sep 17 00:00:00 2001 From: Jordan Hatch Date: Tue, 7 Jul 2015 13:12:09 +0100 Subject: [PATCH 33/34] Update syntax in AwardCategory spec --- spec/models/award_category_spec.rb | 48 ++++++++++++++++-------------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/spec/models/award_category_spec.rb b/spec/models/award_category_spec.rb index 9d3a482..b261d0d 100644 --- a/spec/models/award_category_spec.rb +++ b/spec/models/award_category_spec.rb @@ -1,53 +1,55 @@ require 'rails_helper' -RSpec.describe AwardCategory do +RSpec.describe AwardCategory, type: :model do + + let(:event) { create(:event) } describe "creating an award category" do - before do - @event = FactoryGirl.create(:event) - @valid_attributes = { - :title => 'Best in Show', - :description => 'The best hack', - :level => '1', - :format => 'overall' - } - end + let(:attributes) { attributes_for(:award_category) } context "given valid attributes" do it "can create an award category" do - @event.award_categories.create!(@valid_attributes) + award_category = event.award_categories.create(attributes) + + expect(award_category).to be_persisted end it "features the award category by default" do - @award_category = @event.award_categories.create!(@valid_attributes) - @award_category.featured.should == true + award_category = event.award_categories.create!(attributes) + + expect(award_category).to be_featured end end context "given invalid attributes" do it "can't create an award category without a title" do - @award_category = @event.award_categories.build(@valid_attributes.merge({ :title => nil })) - @award_category.should_not be_valid + award_category = event.award_categories.build(attributes.merge(title: nil)) + + expect(award_category).to_not be_valid end it "can't create an award category without a format" do - @award_category = @event.award_categories.build(@valid_attributes.merge({ :format => nil })) - @award_category.should_not be_valid + award_category = event.award_categories.build(attributes.merge(format: nil)) + + expect(award_category).to_not be_valid end it "can't create an award category with an invalid format" do - @award_category = @event.award_categories.build(@valid_attributes.merge({ :format => 'something else' })) - @award_category.should_not be_valid + award_category = event.award_categories.build(attributes.merge(format: 'something else')) + + expect(award_category).to_not be_valid end it "can't create an award category without a level" do - @award_category = @event.award_categories.build(@valid_attributes.merge({ :level => nil })) - @award_category.should_not be_valid + award_category = event.award_categories.build(attributes.merge(level: nil)) + + expect(award_category).to_not be_valid end it "can't create an award category with an invalid level" do - @award_category = @event.award_categories.build(@valid_attributes.merge({ :level => 'aaaabc' })) - @award_category.should_not be_valid + award_category = event.award_categories.build(attributes.merge(level: 'aaaabc')) + + expect(award_category).to_not be_valid end end end From 72cb358d05b823f56c0c391eda32881b89db4bb5 Mon Sep 17 00:00:00 2001 From: Jordan Hatch Date: Mon, 20 Jul 2015 14:14:20 +0100 Subject: [PATCH 34/34] Separate local database configuration --- config/database.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/config/database.yml b/config/database.yml index d2bcee7..6d43eb9 100644 --- a/config/database.yml +++ b/config/database.yml @@ -2,13 +2,14 @@ development: adapter: postgresql encoding: unicode host: localhost + database: rs_hacks_development test: adapter: postgresql encoding: unicode - database: hacks_test + database: rs_hacks_test production: adapter: postgresql encoding: unicode - database: hacks_production + database: rs_hacks_production