Skip to content

Commit f4f622b

Browse files
Reduce default Hackathon validations (#75)
Co-authored-by: Gary Tou <gary@garytou.com>
1 parent 7dfdfe9 commit f4f622b

File tree

10 files changed

+45
-35
lines changed

10 files changed

+45
-35
lines changed

app/models/hackathon.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@ class Hackathon < ApplicationRecord
22
include Eventable
33
include Taggable
44

5-
include Status
6-
include Named
7-
include Regional
8-
include Scheduled
95
include Applicant
106
include Brand
7+
include FinanciallyAssisting # depends on Taggable
118
include Gathering
9+
include Named
10+
include Regional
11+
include Scheduled
12+
include Status
1213
include Swag
1314
end

app/models/hackathon/brand.rb

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module Hackathon::Brand
22
extend ActiveSupport::Concern
33

44
included do
5-
validates :website, presence: true, format: URI::DEFAULT_PARSER.make_regexp(%w[http https])
5+
validates :website, format: URI::DEFAULT_PARSER.make_regexp(%w[http https]), on: :submit
66

77
has_one_attached :logo do |logo|
88
logo.variant :small, resize_to_limit: [128, 128]
@@ -13,10 +13,9 @@ module Hackathon::Brand
1313

1414
validates :logo, :banner,
1515
attached: true, content_type: {in: /\Aimage\/.*\z/, message: "is not an image"},
16-
size: {less_than: 25.megabytes, message: "is too powerful (max 25 MB)"}
16+
size: {less_than: 25.megabytes, message: "is too powerful (max 25 MB)"},
17+
on: :submit
1718

1819
validates :banner, aspect_ratio: :landscape
19-
20-
validates :high_school_led, :financial_assistance, inclusion: [true, false]
2120
end
2221
end
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module Hackathon::FinanciallyAssisting
2+
def offers_financial_assistance?
3+
tagged_with? "Offers Financial Assistance"
4+
end
5+
end

app/models/hackathon/gathering.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ module Hackathon::Gathering
44
included do
55
enum modality: {in_person: 0, online: 1, hybrid: 2}
66

7-
validates :expected_attendees, presence: true, numericality: {greater_than: 0}
7+
validates :expected_attendees, numericality: {greater_than: 0}, on: :submit
88
end
99
end
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class DropFinancialAssistanceOnHackathons < ActiveRecord::Migration[7.0]
2+
def change
3+
remove_column :hackathons, :financial_assistance
4+
end
5+
end
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class AllowNullOnHackathonExpectedAttendees < ActiveRecord::Migration[7.0]
2+
def change
3+
change_column_null :hackathons, :expected_attendees, true
4+
end
5+
end

db/schema.rb

Lines changed: 2 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/fixtures/hackathons.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ assemble:
77
high_school_led: true
88
expected_attendees: 150
99
modality: <%= Hackathon.modalities[:in_person] %>
10-
financial_assistance: true
1110
applicant: gary
1211
zephyr:
1312
name: The Hacker Zephyr
@@ -18,7 +17,6 @@ zephyr:
1817
high_school_led: true
1918
expected_attendees: 50
2019
modality: <%= Hackathon.modalities[:in_person] %>
21-
financial_assistance: true
2220
applicant: gary
2321
seattle_hacks:
2422
name: SeattleHacks
@@ -29,7 +27,6 @@ seattle_hacks:
2927
high_school_led: true
3028
expected_attendees: 50
3129
modality: <%= Hackathon.modalities[:in_person] %>
32-
financial_assistance: true
3330
applicant: gary
3431
city: Seattle
3532
province: Washington
@@ -43,7 +40,6 @@ bellevue_hacks:
4340
high_school_led: true
4441
expected_attendees: 50
4542
modality: <%= Hackathon.modalities[:in_person] %>
46-
financial_assistance: true
4743
applicant: gary
4844
city: Bellevue
4945
province: Washington

test/models/hackathon/regional_test.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ class Hackathon::RegionalTest < ActiveSupport::TestCase
1010
high_school_led: true,
1111
expected_attendees: 20,
1212
modality: "in_person",
13-
financial_assistance: true,
1413
logo: active_storage_blobs(:assemble_logo),
1514
banner: active_storage_blobs(:assemble),
1615
applicant: users(:gary)

test/models/hackathon_test.rb

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,21 @@
22

33
class HackathonTest < ActiveSupport::TestCase
44
setup do
5-
# This contains the bare basics of an instantiable Hackathon object
5+
Current.user = users(:gary)
6+
67
@hackathon = Hackathon.new(
78
name: "TestHacks",
89
starts_at: Time.now,
910
ends_at: 2.days.from_now,
1011
website: "https://hackclub.com",
11-
high_school_led: true,
1212
expected_attendees: 100,
13-
modality: "in_person",
14-
financial_assistance: true,
15-
logo: active_storage_blobs(:assemble_logo),
16-
banner: active_storage_blobs(:assemble),
17-
applicant: users(:gary)
13+
modality: :in_person
1814
)
1915
end
2016

2117
test "creating a hackathon" do
2218
assert @hackathon.save
19+
assert_equal users(:gary), @hackathon.applicant
2320
end
2421

2522
test "creating a hackathon with invalid dates" do
@@ -28,29 +25,37 @@ class HackathonTest < ActiveSupport::TestCase
2825
starts_at: Time.now,
2926
ends_at: 2.days.ago,
3027
website: "https://hackclub.com",
31-
high_school_led: true,
3228
expected_attendees: 100,
33-
modality: "in_person",
34-
financial_assistance: true,
35-
logo: active_storage_blobs(:assemble_logo),
36-
banner: active_storage_blobs(:assemble),
37-
applicant: users(:gary)
29+
modality: :in_person
3830
)
3931

4032
assert_not hackathon.save
33+
34+
hackathon.ends_at = 2.days.from_now
35+
36+
assert hackathon.save
4137
end
4238

4339
test "creating a hackathon without an applicant" do
40+
Current.user = nil
41+
4442
hackathon = Hackathon.new(
4543
name: "TestHacks",
44+
website: "https://hackclub.com",
4645
starts_at: Time.now,
4746
ends_at: 2.days.from_now
4847
)
4948

5049
assert_not hackathon.save
50+
51+
Current.user = users(:gary)
52+
53+
assert hackathon.save
5154
end
5255

53-
test "create a hackathon with swag mailing address" do
56+
test "creating a hackathon wanting swag mailed" do
57+
assert_not @hackathon.requested_swag?
58+
5459
@hackathon.swag_mailing_address_attributes = {
5560
line1: "123 Test St",
5661
city: "Test City",
@@ -61,8 +66,4 @@ class HackathonTest < ActiveSupport::TestCase
6166
assert @hackathon.save
6267
assert @hackathon.requested_swag?
6368
end
64-
65-
test "#requested_swag? without swag mailing address" do
66-
assert_not @hackathon.requested_swag?
67-
end
6869
end

0 commit comments

Comments
 (0)