Skip to content
This repository was archived by the owner on Dec 3, 2019. It is now read-only.

Https code school url validation #509

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -302,3 +302,5 @@ dump.rdb

# Model Graph image generated
docs/models/model_graph.png
.vscode
OpCodeBackEnd.code-workspace
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,12 @@ db_seed:
.PHONY: test
test: bg
docker-compose run operationcode-psql bash -c "while ! psql --host=operationcode-psql --username=postgres -c 'SELECT 1'; do sleep 5; done;"
docker-compose run ${RAILS_CONTAINER} bash -c 'export RAILS_ENV=test && bundle exec rake db:test:prepare && bundle exec rake test && bundle exec rubocop'
docker-compose run ${RAILS_CONTAINER} bash -xc 'export RAILS_ENV=test && bundle exec rake db:test:prepare && bundle exec rake test && bundle exec rubocop'
# change the appropriate portion of above to enable verbose test output
# bundle exec rake test TESTOPTS='-v'
#
# This one allows you to run one test file at a time by changing the file path to a specific test file
# bundle exec rake test TEST=test/controllers/api/v1/code_schools_controller_test.rb TESTOPTS='-v'

.PHONY: rubocop
rubocop:
Expand Down
3 changes: 2 additions & 1 deletion app/models/code_school.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class CodeSchool < ApplicationRecord
validates :name, :url, :logo, presence: true
validates :name, :logo, :url, presence: true
validates :url, presence: true, format: { with: %r{\Ahttps://(.*)}, message: 'must be HTTPS, if unable please secure your site' }
validates_inclusion_of :full_time, :hardware_included, :has_online, :online_only, :in => [true, false]
has_many :locations, -> { order('state ASC, city ASC') }, dependent: :destroy
end
16 changes: 16 additions & 0 deletions test/controllers/api/v1/code_schools_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,22 @@ class Api::V1::CodeSchoolsControllerTest < ActionDispatch::IntegrationTest
assert errors.include? "Url can't be blank"
end

test ':validates CodeSchool uses HTTPS for URL' do
params = {
code_school: {
name: '1337School',
url: 'http://31337codeschool.com'
}
}
post api_v1_code_schools_url,
params: params,
headers: @headers,
as: :json

errors = JSON.parse(response.body)['errors']
assert errors.include? 'Url must be HTTPS, if unable please secure your site'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you have to have HTTPS for a .dev domain (https://get.dev/#benefits), any coding school worth their salt should have it by default. Would be interested to hear use cases where it's HTTP, but I can't think of a reason to not have it nowadays.

end

test ':index endpoint returns a JSON list of all CodeSchools' do
get api_v1_code_schools_path, as: :json

Expand Down
2 changes: 1 addition & 1 deletion test/factories/code_schools.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FactoryGirl.define do
factory :code_school do
name { Faker::Company.name }
url { Faker::Internet.url }
url { Faker::Internet.url(Faker::Internet.domain_name, '', 'https') }
logo { Faker::Internet.url }
full_time { Faker::Boolean.boolean }
hardware_included { Faker::Boolean.boolean }
Expand Down