Skip to content

Commit 39aee81

Browse files
authored
Merge pull request #416 from impactoss/nz-justice-development
bringing in changes from nz-justice-development
2 parents 20f1188 + 756e5db commit 39aee81

File tree

8 files changed

+49
-20
lines changed

8 files changed

+49
-20
lines changed

app/models/indicator.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ class Indicator < VersionedRecord
22
validates :title, presence: true
33
validates :end_date, presence: true, if: :repeat?
44
validates :frequency_months, presence: true, if: :repeat?
5-
validates :reference, uniqueness: true
5+
validates :reference, presence: true, uniqueness: true
66
validate :end_date_after_start_date, if: :end_date?
77

88
after_create :build_due_dates

app/models/measure.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class Measure < VersionedRecord
2020
accepts_nested_attributes_for :measure_categories
2121

2222
validates :title, presence: true
23-
validates :reference, uniqueness: true
23+
validates :reference, presence: true, uniqueness: true
2424

2525
def is_current
2626
recommendations.empty? || recommendations.any?(&:is_current)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class MakeReferenceAndTitleFieldsMandatory < ActiveRecord::Migration[6.1]
2+
def change
3+
change_column_null :measures, :reference, false, ""
4+
change_column_null :indicators, :reference, false, ""
5+
change_column_null :pages, :title, false, ""
6+
change_column_null :categories, :title, false, ""
7+
change_column_null :progress_reports, :title, false, ""
8+
end
9+
end

db/schema.rb

Lines changed: 6 additions & 6 deletions
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_07_26_032048) do
13+
ActiveRecord::Schema.define(version: 2024_09_10_012254) do
1414

1515
# These are extensions that must be enabled in order to support this database
1616
enable_extension "plpgsql"
@@ -27,7 +27,7 @@
2727
end
2828

2929
create_table "categories", id: :serial, force: :cascade do |t|
30-
t.text "title"
30+
t.text "title", null: false
3131
t.string "short_title"
3232
t.text "description"
3333
t.string "url"
@@ -101,7 +101,7 @@
101101
t.date "start_date"
102102
t.boolean "repeat", default: false
103103
t.date "end_date"
104-
t.string "reference"
104+
t.string "reference", null: false
105105
t.integer "updated_by_id"
106106
t.integer "created_by_id"
107107
t.datetime "relationship_updated_at", precision: 6
@@ -147,14 +147,14 @@
147147
t.integer "created_by_id"
148148
t.datetime "relationship_updated_at", precision: 6
149149
t.bigint "relationship_updated_by_id"
150-
t.string "reference"
150+
t.string "reference", null: false
151151
t.boolean "is_archive", default: false, null: false
152152
t.index ["draft"], name: "index_measures_on_draft"
153153
t.index ["reference"], name: "index_measures_on_reference", unique: true
154154
end
155155

156156
create_table "pages", id: :serial, force: :cascade do |t|
157-
t.string "title"
157+
t.string "title", null: false
158158
t.text "content"
159159
t.string "menu_title"
160160
t.boolean "draft", default: false
@@ -170,7 +170,7 @@
170170
create_table "progress_reports", id: :serial, force: :cascade do |t|
171171
t.integer "indicator_id"
172172
t.integer "due_date_id"
173-
t.text "title"
173+
t.text "title", null: false
174174
t.text "description"
175175
t.string "document_url"
176176
t.boolean "document_public"

spec/controllers/indicators_controller_spec.rb

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,10 @@ def show(subject_indicator)
174174
let(:params) {
175175
{
176176
indicator: {
177-
title: "test",
178177
description: "test",
179-
target_date: "today"
178+
reference: "test reference",
179+
target_date: "today",
180+
title: "test"
180181
}
181182
}
182183
}
@@ -201,10 +202,11 @@ def show(subject_indicator)
201202
let(:params) {
202203
{
203204
indicator: {
204-
title: "test",
205205
description: "test",
206+
is_archive: true,
207+
reference: "test reference",
206208
target_date: "today",
207-
is_archive: true
209+
title: "test"
208210
}
209211
}
210212
}
@@ -242,8 +244,15 @@ def show(subject_indicator)
242244
subject do
243245
put :update,
244246
format: :json,
245-
params: {id: indicator,
246-
indicator: {title: "test update", description: "test update", target_date: "today update"}}
247+
params: {
248+
id: indicator,
249+
indicator: {
250+
description: "test update",
251+
reference: "test refrerence update",
252+
target_date: "today update",
253+
title: "test update"
254+
}
255+
}
247256
end
248257

249258
context "when not signed in" do

spec/controllers/measures_controller_spec.rb

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,10 @@ def show(subject_measure)
156156
let(:params) {
157157
{
158158
measure: {
159-
title: "test",
160159
description: "test",
161-
target_date: "today"
160+
reference: "test reference",
161+
target_date: "today",
162+
title: "test"
162163
}
163164
}
164165
}
@@ -197,10 +198,11 @@ def show(subject_measure)
197198
let(:params) {
198199
{
199200
measure: {
200-
title: "test",
201201
description: "test",
202+
is_archive: true,
203+
reference: "test reference",
202204
target_date: "today",
203-
is_archive: true
205+
title: "test"
204206
}
205207
}
206208
}
@@ -240,8 +242,15 @@ def show(subject_measure)
240242
subject do
241243
put :update,
242244
format: :json,
243-
params: {id: measure,
244-
measure: {title: "test update", description: "test update", target_date: "today update"}}
245+
params: {
246+
id: measure,
247+
measure: {
248+
title: "test update",
249+
description: "test update",
250+
reference: "test reference update",
251+
target_date: "today update"
252+
}
253+
}
245254
end
246255

247256
context "when not signed in" do

spec/models/indicator_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
require "rails_helper"
22

33
RSpec.describe Indicator, type: :model do
4+
it { is_expected.to validate_presence_of :reference }
45
it { is_expected.to validate_presence_of :title }
56

67
it "validates uniqueness of reference" do

spec/models/measure_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
require "rails_helper"
22

33
RSpec.describe Measure, type: :model do
4+
it { is_expected.to validate_presence_of :reference }
45
it { is_expected.to validate_presence_of :title }
56

67
it "validates uniqueness of reference" do

0 commit comments

Comments
 (0)