From cbd5aa53f4e2f924e2d7fc39e8e90eea2e4dae21 Mon Sep 17 00:00:00 2001 From: "Howard M. Miller" Date: Sat, 1 Jul 2017 11:41:47 -0400 Subject: [PATCH 1/2] fix admin page error when site has no property This fixes issue #84. The page was erroring out because the requirement that a site has a property existed in the database, but did not exist in the Rails model. ActiveAdmin does not handle this situation well, but it is easy enough to fix. --- app/models/site.rb | 1 + spec/models/site_spec.rb | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/app/models/site.rb b/app/models/site.rb index 47d90ba..580c1ec 100644 --- a/app/models/site.rb +++ b/app/models/site.rb @@ -3,4 +3,5 @@ class Site < ActiveRecord::Base has_many :subsites validates :name, presence: true + validates :property, presence: true end diff --git a/spec/models/site_spec.rb b/spec/models/site_spec.rb index c13f555..553b185 100644 --- a/spec/models/site_spec.rb +++ b/spec/models/site_spec.rb @@ -1,4 +1,10 @@ require 'rails_helper' RSpec.describe Site, type: :model do + it "model should fail validation if the property is missing" do + subject = Site.new + subject.name = "The Farm" + expect(subject.valid?).to equal false + expect(subject.errors.messages).to match({:property=>["can't be blank"]}) + end end From f7937dd7a752cf9e8ae67d41205265e6e1a4f566 Mon Sep 17 00:00:00 2001 From: "Howard M. Miller" Date: Sat, 1 Jul 2017 11:52:48 -0400 Subject: [PATCH 2/2] fix failing tests now that properties are validated for sites --- spec/features/entry_submission_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/features/entry_submission_spec.rb b/spec/features/entry_submission_spec.rb index 1c9a193..c77abe4 100644 --- a/spec/features/entry_submission_spec.rb +++ b/spec/features/entry_submission_spec.rb @@ -1,8 +1,8 @@ require 'rails_helper' RSpec.describe "submitting an individual entry", type: :feature do - - let(:site) { Site.create! name: "test site", property_id: 22} + let(:property) { Property.create! } + let(:site) { Site.create! name: "test site", property_id: property.id} let(:sample) { observation.samples.create subsite_id: 33 } let(:observation ) { Observation.create site_id: site.id, protocol: protocol }