Create events tracking table#869
Open
jamiebenstead wants to merge 3 commits into
Open
Conversation
Test coverage91.6% line coverage reported by SimpleCov. |
Contributor
There was a problem hiding this comment.
Pull request overview
Adds first-party event tracking to the API so actions (starting with school creation) can be recorded and persisted for later analysis, and exposes a new endpoint to create events directly.
Changes:
- Introduces an
eventstable +Eventmodel for storing event name/properties/time/user. - Tracks a “School - Created” event on successful school creation.
- Adds
POST /api/eventsendpoint plus request specs around new behavior.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
spec/features/school/creating_a_school_spec.rb |
Adds a request spec asserting a school creation event is recorded. |
spec/features/event/creating_event_spec.rb |
Adds request specs for POST /api/events. |
db/schema.rb |
Updates schema version and adds new tables (including events, plus ahoy_*). |
db/migrate/20260612144637_create_events_table.rb |
Creates the events table. |
config/routes.rb |
Adds resources :events, only: %i[create] under /api. |
app/models/event.rb |
Defines Event model validations. |
app/controllers/api/schools_controller.rb |
Tracks “School - Created” after successful school creation. |
app/controllers/api/events_controller.rb |
Implements POST /api/events. |
app/controllers/api_controller.rb |
Adds shared track_event helper for API controllers. |
.env.example |
Adds HOSTNAME example value. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
47
to
49
| def render_error_as_json(exception, status) | ||
| render json: { error: "#{exception.class}: #{exception.message}" }, status: | ||
| end |
Comment on lines
+51
to
+53
| def track_event(name, properties = {}) | ||
| Event.create!(user_id: current_user.id, name:, properties:, time: Time.current) | ||
| end |
Comment on lines
+11
to
+13
| else | ||
| render json: { error: event.errors }, status: :bad_request | ||
| end |
Comment on lines
+18
to
+21
| it('creating an event without a name returns bad request') do | ||
| post('/api/events', headers:, params: { event: { properties: { key: 'value' } } }) | ||
| expect(response).to have_http_status(:bad_request) | ||
| end |
| @@ -0,0 +1,10 @@ | |||
| class CreateEventsTable < ActiveRecord::Migration[8.1] | |||
Comment on lines
+3
to
+5
| create_table :events, id: :uuid do |t| | ||
| t.uuid :user_id | ||
| t.string :name, null: false |
Comment on lines
+46
to
+50
| create_table "ahoy_events", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| | ||
| t.string "name" | ||
| t.jsonb "properties" | ||
| t.datetime "time" | ||
| t.uuid "user_id" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Status
What's changed?