<%= 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?" %>
<%= 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?" %>
-<%= 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 %>
-<% 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 %>
-<% if @project.new_record? %>
- <% unless @event.has_secret? -%>
+<% if project.new_record? %>
+ <% unless event.has_secret? %>
- <% 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| %>
- <% @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 @@
\ 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 "← 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" %>