Skip to content

Commit 9dd964f

Browse files
lukearndtLuke Arndt
authored andcommitted
Add support_level enum to recommendations
1 parent 98c990a commit 9dd964f

File tree

6 files changed

+36
-2
lines changed

6 files changed

+36
-2
lines changed

app/models/recommendation.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,12 @@ class Recommendation < VersionedRecord
2424

2525
validates :title, presence: true
2626
validates :reference, presence: true, uniqueness: true
27+
28+
SUPPORT_LEVELS = {
29+
noted: 0,
30+
supported_in_part: 1,
31+
supported: 2,
32+
}
33+
enum support_level: SUPPORT_LEVELS
34+
validates :support_level, inclusion: { in: SUPPORT_LEVELS.keys }, unless: -> { support_level.blank? }
2735
end

app/policies/recommendation_policy.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ def permitted_attributes
99
:reference,
1010
:description,
1111
:framework_id,
12+
:support_level,
1213
recommendation_categories_attributes: [:category_id]]
1314
end
1415

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
11
class RecommendationSerializer
22
include FastVersionedSerializer
33

4-
attributes :title, :accepted, :response, :draft, :reference, :description, :framework_id, :relationship_updated_at, :relationship_updated_by_id
4+
attributes(
5+
:title,
6+
:accepted,
7+
:response,
8+
:draft,
9+
:reference,
10+
:description,
11+
:framework_id,
12+
:support_level,
13+
:relationship_updated_at,
14+
:relationship_updated_by_id
15+
)
516

617
set_type :recommendations
718
end
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class AddSupportLevelToRecommendations < ActiveRecord::Migration[6.1]
2+
def change
3+
add_column :recommendations, :support_level, :integer
4+
end
5+
end

db/schema.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#
1111
# It's strongly recommended that you check this file into your version control system.
1212

13-
ActiveRecord::Schema.define(version: 2024_05_05_021300) do
13+
ActiveRecord::Schema.define(version: 2024_07_26_032048) do
1414

1515
# These are extensions that must be enabled in order to support this database
1616
enable_extension "plpgsql"
@@ -235,6 +235,7 @@
235235
t.integer "updated_by_id"
236236
t.integer "framework_id"
237237
t.integer "created_by_id"
238+
t.integer "support_level"
238239
t.bigint "relationship_updated_by_id"
239240
t.datetime "relationship_updated_at", precision: 6
240241
t.index ["draft"], name: "index_recommendations_on_draft"

spec/models/recommendation_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@
1313
expect(FactoryBot.build(:recommendation, reference: "456")).to be_valid
1414
end
1515

16+
it do
17+
is_expected.to(
18+
define_enum_for(:support_level)
19+
.with_values(Recommendation::SUPPORT_LEVELS.keys)
20+
.backed_by_column_of_type(:integer)
21+
)
22+
end
23+
1624
it { is_expected.to have_many :categories }
1725
it { is_expected.to have_many :measures }
1826
it { is_expected.to have_many :indicators }

0 commit comments

Comments
 (0)