Skip to content
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

feat(request): temperature en enum et pas en integer #90

Merged
merged 11 commits into from
Dec 18, 2024
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
2 changes: 1 addition & 1 deletion app/controllers/api/v1/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def destroy
user = policy_scope(User).kept.find(params[:id])
authorize user

if current_user.discard
if user.discard
Copy link
Member

Choose a reason for hiding this comment

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

ah, je vois que ma remarque sur la précédente PR a déjà été détecté et corrigé, bien joué :)

head :no_content
else
render_validation_error(user)
Expand Down
8 changes: 7 additions & 1 deletion app/models/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ class Request < ApplicationRecord
in: %i[pending accepted refused in_cancelation canceled completed],
default: :pending

enumerize :temperature,
in: %i[Chaud Froid Extérieur Autre],
Copy link
Member

Choose a reason for hiding this comment

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

en général, on va préférer que les enums soient en anglais et en minuscule dans le code, et avoir les clés de traductions dans côté front et éventuellement côté back (cf le fichier enumerize.fr.yml)

Suggested change
in: %i[Chaud Froid Extérieur Autre],
in: %i[hot cold outside other],

predicates: true,
scope: true

# Validations
validates :name,
:status,
Expand Down Expand Up @@ -85,7 +90,7 @@ class Request < ApplicationRecord
# comment :text
# due_date :date
# quantity :integer
# temperature :integer
# temperature :string
# photoperiod :integer
# created_at :datetime not null
# updated_at :datetime not null
Expand All @@ -99,3 +104,4 @@ class Request < ApplicationRecord
# index_requests_on_handler_id (handler_id)
# index_requests_on_plant_stage_id (plant_stage_id)
#
#
5 changes: 0 additions & 5 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@

resource :passwords, only: :update

resources :account_requests, only: %i[index show create destroy] do
get :pending_account_requests_count, on: :collection
post :accept, on: :member
end

resources :users, only: %i[index show create destroy]

resources :pots, only: %i[index show create update destroy]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

class ChangeTemperatureToEnumInRequests < ActiveRecord::Migration[7.2]
def up
change_column :requests, :temperature, :string
end

def down
change_column :requests, :temperature, :integer
end
end
4 changes: 2 additions & 2 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.2].define(version: 2024_12_17_133422) do
ActiveRecord::Schema[7.2].define(version: 2024_12_17_142757) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"

Expand Down Expand Up @@ -135,7 +135,7 @@
t.text "comment"
t.date "due_date"
t.integer "quantity"
t.integer "temperature"
t.string "temperature"
t.integer "photoperiod"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
Expand Down
2 changes: 1 addition & 1 deletion db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@
comment: Faker::Movies::LordOfTheRings.quote,
due_date: Date.current + 3.months,
quantity: 50,
temperature: 20,
temperature: 'Chaud',
photoperiod: 8
)

Expand Down
Binary file modified erd.pdf
Binary file not shown.
2 changes: 1 addition & 1 deletion spec/acceptance/api/v1/requests_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
let(:due_date) { Date.current + 6.months }
let(:quantity) { 150 }
let(:comment) { 'The specimens have to be in perfect condition, please be careful!' }
let(:temperature) { 35 }
let(:temperature) { 'Froid' }
let(:photoperiod) { 12 }
let(:requester_first_name) { 'John' }
let(:requester_last_name) { 'Doe' }
Expand Down
16 changes: 8 additions & 8 deletions spec/requests/api/v1/requests_spec.rb
Lelievre-david marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
quantity: 150,
due_date: Date.current + 6.months,
comment: 'My comment',
temperature: 10,
temperature: 'Chaud',
photoperiod: 4,
requester_first_name: 'John',
requester_last_name: 'Doe',
Expand All @@ -144,7 +144,7 @@
expect(request.quantity).to eq(150)
expect(request.due_date).to eq(Date.current + 6.months)
expect(request.comment).to eq('My comment')
expect(request.temperature).to eq(10)
expect(request.temperature).to eq('Chaud')
expect(request.photoperiod).to eq(4)
expect(request.requester_first_name).to eq('John')
expect(request.requester_last_name).to eq('Doe')
Expand All @@ -162,7 +162,7 @@
quantity: 150,
due_date: Date.current + 6.months,
comment: 'My comment',
temperature: 10,
temperature: 'Chaud',
photoperiod: 4,
requester_first_name: 'John',
requester_last_name: 'Doe',
Expand All @@ -183,7 +183,7 @@
expect(request.quantity).to eq(150)
expect(request.due_date).to eq(Date.current + 6.months)
expect(request.comment).to eq('My comment')
expect(request.temperature).to eq(10)
expect(request.temperature).to eq('Chaud')
expect(request.photoperiod).to eq(4)
expect(request.requester_first_name).to eq('John')
expect(request.requester_last_name).to eq('Doe')
Expand All @@ -205,7 +205,7 @@
quantity: 150,
due_date: Date.current + 6.months,
comment: 'My comment',
temperature: 10,
temperature: 'Chaud',
photoperiod: 4,
requester_first_name: 'John',
requester_last_name: 'Doe',
Expand All @@ -227,7 +227,7 @@
expect(request.quantity).to eq(150)
expect(request.due_date).to eq(Date.current + 6.months)
expect(request.comment).to eq('My comment')
expect(request.temperature).to eq(10)
expect(request.temperature).to eq('Chaud')
expect(request.photoperiod).to eq(4)
expect(request.requester_first_name).to eq('John')
expect(request.requester_last_name).to eq('Doe')
Expand All @@ -245,7 +245,7 @@
quantity: 150,
due_date: Date.current + 6.months,
comment: 'My comment',
temperature: 10,
temperature: 'Chaud',
photoperiod: 4,
requester_first_name: 'John',
requester_last_name: 'Doe',
Expand All @@ -267,7 +267,7 @@
expect(request.quantity).to eq(150)
expect(request.due_date).to eq(Date.current + 6.months)
expect(request.comment).to eq('My comment')
expect(request.temperature).to eq(10)
expect(request.temperature).to eq('Chaud')
expect(request.photoperiod).to eq(4)
expect(request.requester_first_name).to eq('John')
expect(request.requester_last_name).to eq('Doe')
Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/requests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ request1:
comment: I didn't think it would end this way.
due_date: 2020-05-13
quantity: 100
temperature: 20
temperature: "Chaud"
photoperiod: 8
created_at: !ruby/object:ActiveSupport::TimeWithZone
utc: &1 2020-02-13 00:04:08.434029000 Z
Expand Down Expand Up @@ -67,7 +67,7 @@ request2:
# comment :text
# due_date :date
# quantity :integer
# temperature :integer
# temperature :string
# photoperiod :integer
# created_at :datetime not null
# updated_at :datetime not null
Expand Down
8 changes: 7 additions & 1 deletion test/models/request_test.rb
Lelievre-david marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ def setup
assert_not_empty @request.errors[:status]
end

test 'invalid with incorrect temperature value' do
@request.temperature = 'foo'
assert_not @request.valid?
assert_not_empty @request.errors[:temperature]
end

# State Machine
test 'can\'t be accepted without at least one request distribution' do
@request.request_distributions = []
Expand Down Expand Up @@ -133,7 +139,7 @@ def setup
# comment :text
# due_date :date
# quantity :integer
# temperature :integer
# temperature :string
# photoperiod :integer
# created_at :datetime not null
# updated_at :datetime not null
Expand Down
Loading