Skip to content

Commit

Permalink
Merge pull request #416 from impactoss/nz-justice-development
Browse files Browse the repository at this point in the history
bringing in changes from nz-justice-development
  • Loading branch information
tmfrnz authored Sep 12, 2024
2 parents 20f1188 + 756e5db commit 39aee81
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 20 deletions.
2 changes: 1 addition & 1 deletion app/models/indicator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class Indicator < VersionedRecord
validates :title, presence: true
validates :end_date, presence: true, if: :repeat?
validates :frequency_months, presence: true, if: :repeat?
validates :reference, uniqueness: true
validates :reference, presence: true, uniqueness: true
validate :end_date_after_start_date, if: :end_date?

after_create :build_due_dates
Expand Down
2 changes: 1 addition & 1 deletion app/models/measure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Measure < VersionedRecord
accepts_nested_attributes_for :measure_categories

validates :title, presence: true
validates :reference, uniqueness: true
validates :reference, presence: true, uniqueness: true

def is_current
recommendations.empty? || recommendations.any?(&:is_current)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class MakeReferenceAndTitleFieldsMandatory < ActiveRecord::Migration[6.1]
def change
change_column_null :measures, :reference, false, ""
change_column_null :indicators, :reference, false, ""
change_column_null :pages, :title, false, ""
change_column_null :categories, :title, false, ""
change_column_null :progress_reports, :title, false, ""
end
end
12 changes: 6 additions & 6 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.define(version: 2024_07_26_032048) do
ActiveRecord::Schema.define(version: 2024_09_10_012254) do

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

create_table "categories", id: :serial, force: :cascade do |t|
t.text "title"
t.text "title", null: false
t.string "short_title"
t.text "description"
t.string "url"
Expand Down Expand Up @@ -101,7 +101,7 @@
t.date "start_date"
t.boolean "repeat", default: false
t.date "end_date"
t.string "reference"
t.string "reference", null: false
t.integer "updated_by_id"
t.integer "created_by_id"
t.datetime "relationship_updated_at", precision: 6
Expand Down Expand Up @@ -147,14 +147,14 @@
t.integer "created_by_id"
t.datetime "relationship_updated_at", precision: 6
t.bigint "relationship_updated_by_id"
t.string "reference"
t.string "reference", null: false
t.boolean "is_archive", default: false, null: false
t.index ["draft"], name: "index_measures_on_draft"
t.index ["reference"], name: "index_measures_on_reference", unique: true
end

create_table "pages", id: :serial, force: :cascade do |t|
t.string "title"
t.string "title", null: false
t.text "content"
t.string "menu_title"
t.boolean "draft", default: false
Expand All @@ -170,7 +170,7 @@
create_table "progress_reports", id: :serial, force: :cascade do |t|
t.integer "indicator_id"
t.integer "due_date_id"
t.text "title"
t.text "title", null: false
t.text "description"
t.string "document_url"
t.boolean "document_public"
Expand Down
21 changes: 15 additions & 6 deletions spec/controllers/indicators_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,10 @@ def show(subject_indicator)
let(:params) {
{
indicator: {
title: "test",
description: "test",
target_date: "today"
reference: "test reference",
target_date: "today",
title: "test"
}
}
}
Expand All @@ -201,10 +202,11 @@ def show(subject_indicator)
let(:params) {
{
indicator: {
title: "test",
description: "test",
is_archive: true,
reference: "test reference",
target_date: "today",
is_archive: true
title: "test"
}
}
}
Expand Down Expand Up @@ -242,8 +244,15 @@ def show(subject_indicator)
subject do
put :update,
format: :json,
params: {id: indicator,
indicator: {title: "test update", description: "test update", target_date: "today update"}}
params: {
id: indicator,
indicator: {
description: "test update",
reference: "test refrerence update",
target_date: "today update",
title: "test update"
}
}
end

context "when not signed in" do
Expand Down
21 changes: 15 additions & 6 deletions spec/controllers/measures_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,10 @@ def show(subject_measure)
let(:params) {
{
measure: {
title: "test",
description: "test",
target_date: "today"
reference: "test reference",
target_date: "today",
title: "test"
}
}
}
Expand Down Expand Up @@ -197,10 +198,11 @@ def show(subject_measure)
let(:params) {
{
measure: {
title: "test",
description: "test",
is_archive: true,
reference: "test reference",
target_date: "today",
is_archive: true
title: "test"
}
}
}
Expand Down Expand Up @@ -240,8 +242,15 @@ def show(subject_measure)
subject do
put :update,
format: :json,
params: {id: measure,
measure: {title: "test update", description: "test update", target_date: "today update"}}
params: {
id: measure,
measure: {
title: "test update",
description: "test update",
reference: "test reference update",
target_date: "today update"
}
}
end

context "when not signed in" do
Expand Down
1 change: 1 addition & 0 deletions spec/models/indicator_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require "rails_helper"

RSpec.describe Indicator, type: :model do
it { is_expected.to validate_presence_of :reference }
it { is_expected.to validate_presence_of :title }

it "validates uniqueness of reference" do
Expand Down
1 change: 1 addition & 0 deletions spec/models/measure_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require "rails_helper"

RSpec.describe Measure, type: :model do
it { is_expected.to validate_presence_of :reference }
it { is_expected.to validate_presence_of :title }

it "validates uniqueness of reference" do
Expand Down

0 comments on commit 39aee81

Please sign in to comment.