-
Notifications
You must be signed in to change notification settings - Fork 4
Fix/genootschapen dyslexia #612
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
Changes from all commits
c1e2b53
c555dd1
82c8b36
46ef5dd
2e400d5
5d9adb5
a3d0610
8840eac
17bd80a
88c4218
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,110 @@ | ||||||
| # AI Dev Guide - AMBER API | ||||||
|
|
||||||
| ## Env | ||||||
| Container: `development-environment-alpha-1` | ||||||
| Path in container: `~/amber-api` | ||||||
| Shell: Must use `/bin/bash -l` for PATH | ||||||
| CMD: `docker exec -it development-environment-alpha-1 /bin/bash -l -c "cd ~/amber-api && bundle exec <cmd>"` | ||||||
| Direct: Enter container, `cd ~/amber-api`, then run `bundle exec <cmd>` | ||||||
|
Comment on lines
+5
to
+8
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win Use The service-based command can avoid the path change, but Change it to 🤖 Prompt for AI Agents |
||||||
|
|
||||||
| ## Rules | ||||||
| 1. Follow existing patterns | ||||||
| 2. Tests for everything (95%+ coverage) | ||||||
| 3. Follow RuboCop or document exception with reason | ||||||
| 4. Keep it simple: convention over configuration | ||||||
| 5. Don't add gems unless they have real benefit (student-maintained, avoid bloat) | ||||||
|
|
||||||
| ## RuboCop | ||||||
| Config: `.rubocop.yml` | ||||||
| Target: Rails 7.2, Ruby 3.3, NewCops: enable | ||||||
| Disabled: HttpPositionalArguments, HasManyOrHasOneDependent, InverseOf, LexicallyScopedActionFilter, RSpec/LeadingSubject, Documentation, FrozenStringLiteralComment, GuardClause | ||||||
| Modified: RSpec/NestedGroups Max:5, Style/ClassAndModuleChildren excludes v1 resources, Metrics/BlockLength excludes spec/** | ||||||
| Exceptions: Must explain why in .rubocop.yml comments | ||||||
|
|
||||||
| ## Structure | ||||||
| Resources: `app/resources/v1/*.rb` extends `V1::ApplicationResource < JSONAPI::Resource` | ||||||
| Tests: `spec/resources/v1/*_spec.rb` type: :resource | ||||||
| Factories: `spec/factories/*.rb` use FactoryBot + Faker | ||||||
|
|
||||||
| ## Resource Template | ||||||
| ```ruby | ||||||
| # app/resources/v1/model_resource.rb | ||||||
| class V1::ModelResource < V1::ApplicationResource | ||||||
| attributes :attr1, :attr2 | ||||||
| has_one :user | ||||||
| has_many :items | ||||||
| filter :field | ||||||
|
|
||||||
| def self.creatable_fields(context) | ||||||
| %i[attr1 attr2] | ||||||
| end | ||||||
|
Comment on lines
+38
to
+40
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win Align the resource template with the enabled RuboCop rule. When copied into 🤖 Prompt for AI Agents |
||||||
|
|
||||||
| def self.updatable_fields(context) | ||||||
| creatable_fields(context) | ||||||
| end | ||||||
|
|
||||||
| def self.searchable_fields | ||||||
| %i[attr1 attr2] | ||||||
| end | ||||||
| end | ||||||
| ``` | ||||||
|
|
||||||
| ## Test Template | ||||||
| ```ruby | ||||||
| # spec/resources/v1/model_resource_spec.rb | ||||||
| require 'rails_helper' | ||||||
|
|
||||||
| RSpec.describe V1::ModelResource, type: :resource do | ||||||
| let(:user) { create(:user) } | ||||||
| let(:context) { { user: } } | ||||||
|
|
||||||
| describe '#creatable_fields' do | ||||||
| it { expect(described_class.creatable_fields(context)).to match_array(%i[attr1 attr2]) } | ||||||
| end | ||||||
|
|
||||||
| describe '#updatable_fields' do | ||||||
| it { expect(described_class.updatable_fields(context)).to match_array(%i[attr1 attr2]) } | ||||||
| end | ||||||
| end | ||||||
| ``` | ||||||
|
|
||||||
| ## Factory Template | ||||||
| ```ruby | ||||||
| # spec/factories/models.rb | ||||||
| FactoryBot.define do | ||||||
| factory :model do | ||||||
| user | ||||||
| attr1 { Faker::Lorem.word } | ||||||
| attr2 { [true, false].sample } | ||||||
| end | ||||||
| end | ||||||
| ``` | ||||||
|
|
||||||
| ## Test What | ||||||
| Resources: creatable_fields, updatable_fields, fetchable_fields, searchable_fields, filters, relationships, attributes, permissions | ||||||
| Models: validations, associations, scopes, methods, callbacks | ||||||
| Controllers: auth, Pundit policies, response codes, response body, error handling | ||||||
|
|
||||||
| ## Commands | ||||||
| Test all: `bundle exec rspec` | ||||||
| Test file: `bundle exec rspec spec/path/to/file_spec.rb` | ||||||
| Test line: `bundle exec rspec spec/path/to/file_spec.rb:12` | ||||||
| RuboCop: `bundle exec rubocop` | ||||||
| RuboCop fix: `bundle exec rubocop -a` | ||||||
| Guard: `bundle exec guard` | ||||||
| DB: `bundle exec rails db:migrate`, `bundle exec rails g migration Name` | ||||||
|
|
||||||
| ## Docker Commands | ||||||
| Enter: `docker exec -it development-environment-alpha-1 /bin/bash -l` then `cd ~/amber-api` | ||||||
| Start: `cd "C:/Users/jorai/Programeren/1. Alpha/1. Development/amber-api" && docker-compose -f docker-compose.development.yml up -d api` | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win Remove the developer-specific host path. The start command only works for Proposed fix-Start: `cd "C:/Users/jorai/Programeren/1. Alpha/1. Development/amber-api" && docker-compose -f docker-compose.development.yml up -d api`
+Start: From the repository root, run `docker-compose -f docker-compose.development.yml up -d api`📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||
| Stop: `docker-compose -f docker-compose.development.yml down` | ||||||
| Logs: `docker logs development-environment-alpha-1` | ||||||
|
|
||||||
| ## Pitfalls | ||||||
| - Don't use `docker exec ... bundle exec ...` directly (PATH + working dir issues) | ||||||
| - Don't skip tests | ||||||
| - Don't ignore RuboCop | ||||||
| - Don't use hash rockets `{:key => val}` except in excluded dirs | ||||||
| - Don't over-engineer | ||||||
| - Don't use `_context` param if unused (keep it for consistency) | ||||||
| - Do use existing patterns from ApplicationResource for permissions | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| class FixGenootschapenDyslexia < ActiveRecord::Migration[7.2] | ||
| def up | ||
| Activity.where(category: 'genootschapen').find_each do |activity| | ||
| activity.update!(category: 'genootschappen') | ||
| end | ||
| end | ||
|
|
||
| def down | ||
| Activity.where(category: 'genootschappen').find_each do |activity| | ||
| activity.update!(category: 'genootschapen') | ||
| end | ||
| end | ||
|
TimonBoer marked this conversation as resolved.
|
||
| end | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Use Compose service names for container commands.
docker-compose.development.ymldefinesapiwithoutcontainer_name. Compose derives the container name from the project name, service name, and index..env.exampleandREADME.mduse project names such asamber_<env>andamber_development, sodevelopment-environment-alpha-1is not guaranteed. Usedocker-compose -f docker-compose.development.yml exec api ...anddocker-compose -f docker-compose.development.yml logs apiinstead.🤖 Prompt for AI Agents