Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ class ApplicationController < ActionController::Base
before_action :accept_terms, if: :logged_in?

def render_not_found
render template: 'errors/not_found', layout: false, status: :not_found
respond_to do |format|
format.html { render template: 'errors/not_found', layout: false, status: :not_found }
format.all { head :not_found }
end
end

protected
Expand Down
31 changes: 31 additions & 0 deletions spec/controllers/application_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
RSpec.describe ApplicationController do
describe '#render_not_found' do
controller do
def index
raise ActiveRecord::RecordNotFound
end
end

context 'with HTML format' do
before do
get :index, format: :html
end

it 'renders the not_found template' do
expect(response.status).to eq(404)
expect(response).not_to be_redirect
end
end

context 'with JSON format' do
before do
get :index, format: :json
end

it 'returns empty 404 response' do
expect(response.status).to eq(404)
expect(response.body).to be_empty
end
end
end
end
28 changes: 16 additions & 12 deletions spec/models/concerns/listable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
subject(:workshop) { Fabricate(:workshop) }

context 'scopes' do
context '#today_and_upcoming' do
describe '#today_and_upcoming' do
it 'returns a list of all today and upcoming workshops' do
Timecop.travel(Time.now.utc) do
Fabricate.times(2, :past_workshop)
Expand All @@ -26,12 +26,14 @@
end
end

context '#upcoming' do
describe '#upcoming' do
it 'returns a list of all upcoming workshops' do
Fabricate.times(2, :past_workshop)
future_workshops = Fabricate.times(1, :workshop)
Timecop.travel(Time.now.utc) do
Fabricate.times(2, :past_workshop)
future_workshops = Fabricate.times(1, :workshop)

expect(Workshop.upcoming).to match_array(future_workshops)
expect(Workshop.upcoming).to match_array(future_workshops)
end
end

it 'returns workshops ordered by date_and_time ascending (soonest first)' do
Expand All @@ -44,16 +46,18 @@
end
end

context '#past' do
describe '#past' do
it 'returns a list of all upcoming workshops' do
past_workshops = Fabricate.times(2, :past_workshop)
Fabricate.times(1, :workshop)
Timecop.travel(Time.now.utc) do
past_workshops = Fabricate.times(2, :past_workshop)
Fabricate.times(1, :workshop)

expect(Workshop.past).to match_array(past_workshops)
expect(Workshop.past).to match_array(past_workshops)
end
end
end

context '#recent' do
describe '#recent' do
it 'returns a list of the last 10 workshops' do
Fabricate.times(1, :past_workshop)
Fabricate.times(2, :workshop)
Expand All @@ -65,7 +69,7 @@
end
end

context '#completed_since_yesterday' do
describe '#completed_since_yesterday' do
it 'returns a list of yesterday\'s events' do
Fabricate(:workshop, date_and_time: 24.hours.ago)
Fabricate(:workshop, date_and_time: 25.hours.ago)
Expand All @@ -78,7 +82,7 @@
end
end

context '#next' do
describe '#next' do
it 'returns the next workshop to take place' do
next_workshop = Fabricate(:workshop, date_and_time: Time.zone.now + 24.hours)
Fabricate(:workshop, date_and_time: Time.zone.now + 29.hours)
Expand Down