Skip to content

Create events tracking table#869

Open
jamiebenstead wants to merge 3 commits into
mainfrom
create-events-tracking-table
Open

Create events tracking table#869
jamiebenstead wants to merge 3 commits into
mainfrom
create-events-tracking-table

Conversation

@jamiebenstead

Copy link
Copy Markdown
Contributor

Status

What's changed?

  • Created events table
  • Event is created on school creation
  • Created events API route
  • Add tests around new functionality

Copilot AI review requested due to automatic review settings June 12, 2026 15:56
@cla-bot cla-bot Bot added the cla-signed label Jun 12, 2026
@github-actions

Copy link
Copy Markdown

Test coverage

91.6% line coverage reported by SimpleCov.
Run: https://github.com/RaspberryPiFoundation/editor-api/actions/runs/27427075981

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 events table + Event model for storing event name/properties/time/user.
  • Tracks a “School - Created” event on successful school creation.
  • Adds POST /api/events endpoint 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 thread db/schema.rb
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"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants