Skip to content

fix(events): fixed api to be public and have blank strings be null #552

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 1, 2021
Merged
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
7 changes: 7 additions & 0 deletions app/controllers/events_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class EventsController < ApplicationController
respond_to :json

def show
render json: Event.all
end
end
21 changes: 21 additions & 0 deletions app/models/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,25 @@ def finish_before_start
errors.add(:finish, 'time must be after start time')
end
end

def description=(value)
if value.blank?
value = nil
end
super value
end

def location=(value)
if value.blank?
value = nil
end
super value
end

def category=(value)
if value.blank?
value = nil
end
super value
end
end
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
patch :boarded_bus, on: :collection
end

resource :events, only: :show, constraints: ->(req) { req.format == :json }

namespace :manage do
authenticate :user, ->(u) { u.director? } do
root to: "dashboard#index"
Expand Down
7 changes: 7 additions & 0 deletions test/controllers/events_controller_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'test_helper'

class EventsControllerTest < ActionDispatch::IntegrationTest
# test "the truth" do
# assert true
# end
end