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
1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ group :test do
gem 'shoulda-matchers', '~> 7.0'
gem 'simplecov', require: false
gem 'simplecov-lcov', require: false
gem 'timecop', '~> 0.9.10'
gem 'webmock'
end

Expand Down
2 changes: 0 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,6 @@ GEM
execjs (>= 0.3.0, < 3)
thor (1.5.0)
tilt (2.7.0)
timecop (0.9.10)
timeout (0.6.0)
tsort (0.2.0)
turbo-rails (2.0.23)
Expand Down Expand Up @@ -700,7 +699,6 @@ DEPENDENCIES
stimulus-rails
stripe
terser
timecop (~> 0.9.10)
turbo-rails
tzinfo-data
view_component
Expand Down
12 changes: 4 additions & 8 deletions config/environments/test.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
require "active_support/core_ext/integer/time"
require "timecop"
require 'active_support/core_ext/integer/time'

# The test environment is used exclusively to run your application's
# test suite. You never need to work with it otherwise. Remember that
Expand All @@ -16,10 +15,10 @@
# this is usually not necessary, and can slow down your test suite. However, it's
# recommended that you enable it in continuous integration systems to ensure eager
# loading is working properly before deploying your code.
config.eager_load = ENV["CI"].present?
config.eager_load = ENV['CI'].present?

# Configure public file server for tests with cache-control for performance.
config.public_file_server.headers = { "cache-control" => "public, max-age=#{1.hour.to_i}" }
config.public_file_server.headers = { 'cache-control' => "public, max-age=#{1.hour.to_i}" }

# Show full error reports.
config.consider_all_requests_local = true
Expand All @@ -41,7 +40,7 @@
config.action_mailer.delivery_method = :test

# Set host to be used by links generated in mailer templates.
config.action_mailer.default_url_options = { host: "localhost:3000" }
config.action_mailer.default_url_options = { host: 'localhost:3000' }

# Print deprecation notices to the stderr.
config.active_support.deprecation = :stderr
Expand All @@ -63,7 +62,4 @@
Bullet.bullet_logger = true
Bullet.raise = false # raise an error if n+1 query occurs
end

# https://github.com/travisjeffery/timecop#timecopsafe_mode
Timecop.safe_mode = true
end
22 changes: 12 additions & 10 deletions spec/features/admin/announcements_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
click_on 'announcement[create]'

expect(page).to have_content('Announcement successfully created')
expect(page.current_path).to eq(admin_announcements_path)
expect(page).to have_current_path(admin_announcements_path, ignore_query: true)
end
end

Expand All @@ -37,18 +37,20 @@

expect(page).to have_content('Announcement successfully updated')
expect(page).to have_content('New event coming up soon! Stay tuned.')
expect(page.current_path).to eq(admin_announcements_path)
expect(page).to have_current_path(admin_announcements_path, ignore_query: true)
end
end

scenario 'can view all announcements' do
announcement = Fabricate(:announcement)
old_announcement = Fabricate(:announcement, expires_at: Time.zone.now - 1.week)
travel_to(Time.current) do
announcement = Fabricate(:announcement)
old_announcement = Fabricate(:announcement, expires_at: 1.week.ago)

visit admin_announcements_path
visit admin_announcements_path

expect(page).to have_content(announcement.message)
expect(page).to have_content(old_announcement.message)
expect(page).to have_content(announcement.message)
expect(page).to have_content(old_announcement.message)
end
end

scenario 'can successfully send a new announcement to every group' do
Expand All @@ -60,7 +62,7 @@
expect(page).to have_content('An announcement to every group')
expect(page).to have_content("Coaches #{chapter.name}")
expect(page).to have_content("Students #{chapter.name}")
expect(page.current_path).to eq(admin_announcements_path)
expect(page).to have_current_path(admin_announcements_path, ignore_query: true)
end

scenario 'can successfully send a new announcement to selected groups' do
Expand All @@ -71,8 +73,8 @@

expect(page).to have_content('An announcement to selected groups')
expect(page).to have_content("Coaches #{chapter.name}")
expect(page).to_not have_content("Students #{chapter.name}")
expect(page.current_path).to eq(admin_announcements_path)
expect(page).not_to have_content("Students #{chapter.name}")
expect(page).to have_current_path(admin_announcements_path, ignore_query: true)
end
end
end
86 changes: 48 additions & 38 deletions spec/features/chapter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
end

it 'a visitor to the website can access inactive chapter events' do
past_workshop = Fabricate(:workshop, chapter: inactive_chapter, date_and_time: Time.zone.today - 2.weeks)
travel_to(Time.current) do
past_workshop = Fabricate(:workshop, chapter: inactive_chapter, date_and_time: 2.weeks.ago)

visit workshop_path(past_workshop)
visit workshop_path(past_workshop)

expect(page).to have_content "Workshop at #{past_workshop.host.name}"
expect(page).to have_content "Workshop at #{past_workshop.host.name}"
end
end
end

Expand All @@ -25,59 +27,67 @@
end

it 'renders chapter without organisers' do
chapter = Fabricate(:chapter_without_organisers, name: "Empty Chapter")
chapter = Fabricate(:chapter_without_organisers, name: 'Empty Chapter')
expect(chapter.organisers.size).to eq 0

visit chapter_path(chapter.slug)

expect(page).to have_content "Empty Chapter"
expect(page).not_to have_content "Team"
expect(page).to have_content 'Empty Chapter'
expect(page).not_to have_content 'Team'
end

it 'renders any upcoming workshops for the chapter' do
chapter = Fabricate(:chapter)
workshops = 2.times.map do |n|
Fabricate(:workshop, chapter: chapter, date_and_time: Time.zone.now + 9.days - n.weeks)
end

visit chapter_path(chapter.slug)
workshops.each do |workshop|
expect(page).to have_content "Workshop at #{workshop.host.name}"
travel_to(Time.current) do
chapter = Fabricate(:chapter)
workshops = 2.times.map do |n|
Fabricate(:workshop, chapter: chapter, date_and_time: 9.days.from_now - n.weeks)
end

visit chapter_path(chapter.slug)
workshops.each do |workshop|
expect(page).to have_content "Workshop at #{workshop.host.name}"
end
end
end

it 'renders any upcoming events for the chapter' do
chapter = Fabricate(:chapter)
2.times.map do |n|
Fabricate(:event, name: "Event #{n + 1}",
chapters: [chapter],
date_and_time: Time.zone.now + 2.months - n.months)
travel_to(Time.current) do
chapter = Fabricate(:chapter)
2.times.map do |n|
Fabricate(:event, name: "Event #{n + 1}",
chapters: [chapter],
date_and_time: 2.months.from_now - n.months)
end

visit chapter_path(chapter.slug)
expect(page).to have_content 'Event 1'
expect(page).to have_content 'Event 2'
end

visit chapter_path(chapter.slug)
expect(page).to have_content 'Event 1'
expect(page).to have_content 'Event 2'
end

it 'renders the most recent past workshop for the chapter' do
chapter = Fabricate(:chapter)
past_workshop = Fabricate(:workshop, chapter: chapter, date_and_time: Time.zone.today - 2.weeks)
recent_past_workshop = Fabricate(:workshop, chapter: chapter, date_and_time: Time.zone.today - 1.week)

visit chapter_path(chapter.slug)
expect(page).to have_content "Workshop at #{recent_past_workshop.host.name}"
expect(page).to_not have_content "Workshop at #{past_workshop.host.name}"
travel_to(Time.current) do
chapter = Fabricate(:chapter)
past_workshop = Fabricate(:workshop, chapter: chapter, date_and_time: 2.weeks.ago)
recent_past_workshop = Fabricate(:workshop, chapter: chapter, date_and_time: 1.week.ago)

visit chapter_path(chapter.slug)
expect(page).to have_content "Workshop at #{recent_past_workshop.host.name}"
expect(page).not_to have_content "Workshop at #{past_workshop.host.name}"
end
end

it 'renders the 6 most recent sponsors for the chapter' do
chapter = Fabricate(:chapter)
workshops = 2.times.map do |n|
Fabricate(:workshop, chapter: chapter, date_and_time: Time.zone.now - n.weeks)
end

visit chapter_path(chapter.slug)
workshops.each do |workshop|
expect(page).to have_link(workshop.sponsors.name)
travel_to(Time.current) do
chapter = Fabricate(:chapter)
workshops = 2.times.map do |n|
Fabricate(:workshop, chapter: chapter, date_and_time: n.weeks.ago)
end

visit chapter_path(chapter.slug)
workshops.each do |workshop|
expect(page).to have_link(workshop.sponsors.name)
end
end
end
end
Expand Down
44 changes: 24 additions & 20 deletions spec/features/listing_coaches_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,37 @@
end

scenario 'I can see the top coaches by year' do
latest_workshop = Fabricate(:workshop, date_and_time: Time.zone.now - 1.year)
old_workshop = Fabricate(:workshop, date_and_time: Time.zone.now - 3.years)
invitations = 2.times { Fabricate(:attended_coach, workshop: latest_workshop) }
older_invitations = 4.times { Fabricate(:attended_coach, workshop: old_workshop) }
travel_to(Time.current) do
latest_workshop = Fabricate(:workshop, date_and_time: 1.year.ago)
old_workshop = Fabricate(:workshop, date_and_time: 3.years.ago)
2.times { Fabricate(:attended_coach, workshop: latest_workshop) }
4.times { Fabricate(:attended_coach, workshop: old_workshop) }

visit coaches_path(year: latest_workshop.date_and_time.year)
expect(page).to have_css(".coach", count: 2)
visit coaches_path(year: latest_workshop.date_and_time.year)
expect(page).to have_css('.coach', count: 2)

visit coaches_path(year: old_workshop.date_and_time.year)
expect(page).to have_css(".coach", count: 4)
visit coaches_path(year: old_workshop.date_and_time.year)
expect(page).to have_css('.coach', count: 4)
end
end

scenario 'I can navigate the top coaches by year' do
current_workshop = Fabricate(:workshop, date_and_time: Time.zone.now)
latest_workshop = Fabricate(:workshop, date_and_time: Time.zone.now - 1.year)
old_workshop = Fabricate(:workshop, date_and_time: Time.zone.now - 3.years)
current_invitations = 1.times { Fabricate(:attended_coach, workshop: current_workshop) }
invitations = 3.times { Fabricate(:attended_coach, workshop: latest_workshop) }
older_invitations = 2.times { Fabricate(:attended_coach, workshop: old_workshop) }
travel_to(Time.current) do
current_workshop = Fabricate(:workshop, date_and_time: Time.current)
latest_workshop = Fabricate(:workshop, date_and_time: 1.year.ago)
old_workshop = Fabricate(:workshop, date_and_time: 3.years.ago)
1.times { Fabricate(:attended_coach, workshop: current_workshop) }
3.times { Fabricate(:attended_coach, workshop: latest_workshop) }
2.times { Fabricate(:attended_coach, workshop: old_workshop) }

visit coaches_path
expect(page).to have_css(".coach", count: 1)
visit coaches_path
expect(page).to have_css('.coach', count: 1)

click_on latest_workshop.date_and_time.year.to_s
expect(page).to have_css(".coach", count: 3)
click_on latest_workshop.date_and_time.year.to_s
expect(page).to have_css('.coach', count: 3)

click_on old_workshop.date_and_time.year.to_s
expect(page).to have_css(".coach", count: 2)
click_on old_workshop.date_and_time.year.to_s
expect(page).to have_css('.coach', count: 2)
end
end
end
48 changes: 29 additions & 19 deletions spec/features/listing_events_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,25 @@
let!(:event) { Fabricate(:event) }

scenario 'displays upcoming events page' do
visit upcoming_events_path
expect(page).to have_content 'Upcoming Events'
expect(page).to have_content event.name
travel_to(Time.current) do
visit upcoming_events_path
expect(page).to have_content 'Upcoming Events'
expect(page).to have_content event.name
end
end
end

describe 'I can see past events' do
let!(:chapter) { Fabricate(:chapter, active: true) }
let!(:past_event) { Fabricate(:event, date_and_time: Time.zone.now - 2.weeks) }
let!(:past_workshop) { Fabricate(:workshop, date_and_time: Time.zone.now - 1.week, chapter: chapter) }
let!(:past_event) { Fabricate(:event, date_and_time: 2.weeks.ago) }
let!(:past_workshop) { Fabricate(:workshop, date_and_time: 1.week.ago, chapter: chapter) }

scenario 'displays past events page' do
visit past_events_path
expect(page).to have_content 'Past Events'
expect(page).to have_content past_event.name
travel_to(Time.current) do
visit past_events_path
expect(page).to have_content 'Past Events'
expect(page).to have_content past_event.name
end
end
end

Expand All @@ -33,26 +37,32 @@

context 'pagination' do
scenario 'past events paginates at 20 per page' do
chapter = Fabricate(:chapter, active: true)
Fabricate.times(22, :event, date_and_time: 2.weeks.ago)
Fabricate(:workshop, date_and_time: 3.weeks.ago, chapter: chapter)
travel_to(Time.current) do
chapter = Fabricate(:chapter, active: true)
Fabricate.times(22, :event, date_and_time: 2.weeks.ago)
Fabricate(:workshop, date_and_time: 3.weeks.ago, chapter: chapter)

visit past_events_path
expect(page).to have_selector('.card', count: 20)
visit past_events_path
expect(page).to have_selector('.card', count: 20)
end
end

scenario 'past meetings paginate at 20 per page' do
Fabricate.times(22, :meeting, date_and_time: 2.weeks.ago)
travel_to(Time.current) do
Fabricate.times(22, :meeting, date_and_time: 2.weeks.ago)

visit past_events_path
expect(page).to have_selector('.card', count: 20)
visit past_events_path
expect(page).to have_selector('.card', count: 20)
end
end

scenario 'upcoming meetings paginate at 20 per page' do
Fabricate.times(22, :meeting, date_and_time: 2.weeks.from_now)
travel_to(Time.current) do
Fabricate.times(22, :meeting, date_and_time: 2.weeks.from_now)

visit upcoming_events_path
expect(page).to have_selector('.card', count: 20)
visit upcoming_events_path
expect(page).to have_selector('.card', count: 20)
end
end
end
end
Loading