From 474f09e110bd7aa91e4372c0616bf360fbbe5886 Mon Sep 17 00:00:00 2001 From: Daniel O'Connor Date: Sat, 29 Nov 2025 15:32:08 +1030 Subject: [PATCH] Merge pull request #4332 from Growstuff/crops-controller Add coverage for crops --- .devcontainer/docker-compose.yml | 2 +- app/views/crops/show.html.haml | 1 + db/schema.rb | 5 +++-- spec/controllers/crops_controller_spec.rb | 10 +++++++--- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml index dca028a51..297d7a8d8 100644 --- a/.devcontainer/docker-compose.yml +++ b/.devcontainer/docker-compose.yml @@ -27,7 +27,7 @@ services: command: sleep infinity db: - image: postgres:latest + image: postgres:17 restart: unless-stopped volumes: - postgres-data:/var/lib/postgresql/data diff --git a/app/views/crops/show.html.haml b/app/views/crops/show.html.haml index a2f0fe88a..fa1c98c67 100644 --- a/app/views/crops/show.html.haml +++ b/app/views/crops/show.html.haml @@ -32,6 +32,7 @@ - if @crop.en_youtube_url.present? %section.youtube + %h2 Video .embed-responsive.embed-responsive-16by9 %iframe.embed-responsive-item{ src: "https://www.youtube.com/embed/#{youtube_video_id(@crop.en_youtube_url)}", allowfullscreen: true } diff --git a/db/schema.rb b/db/schema.rb index b7722905e..85f94d755 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.2].define(version: 2025_09_01_144900) do +ActiveRecord::Schema[7.2].define(version: 2025_11_28_200506) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -259,6 +259,8 @@ ActiveRecord::Schema[7.2].define(version: 2025_09_01_144900) do t.string "sowing_method" t.string "sun_requirements" t.integer "growing_degree_days" + t.string "en_youtube_url" + t.text "description" t.index ["creator_id"], name: "index_crops_on_creator_id" t.index ["name"], name: "index_crops_on_name" t.index ["parent_id"], name: "index_crops_on_parent_id" @@ -583,7 +585,6 @@ ActiveRecord::Schema[7.2].define(version: 2025_09_01_144900) do t.integer "harvests_count", default: 0 t.integer "likes_count", default: 0 t.boolean "failed", default: false, null: false - t.boolean "from_other_source" t.integer "overall_rating" t.index ["crop_id"], name: "index_plantings_on_crop_id" t.index ["garden_id"], name: "index_plantings_on_garden_id" diff --git a/spec/controllers/crops_controller_spec.rb b/spec/controllers/crops_controller_spec.rb index 3b3b4ab10..cfd5c3491 100644 --- a/spec/controllers/crops_controller_spec.rb +++ b/spec/controllers/crops_controller_spec.rb @@ -101,7 +101,7 @@ describe CropsController do it { expect { subject }.to change(AlternateName, :count).by(2) } it { expect { subject }.to change(ScientificName, :count).by(1) } - context 'with openfarm data' do + context 'with data' do let(:crop_params) do { crop: { @@ -110,16 +110,18 @@ describe CropsController do row_spacing: 10, spread: 20, height: 30, + description: 'hello', sowing_method: 'direct', sun_requirements: 'full sun', - growing_degree_days: 100 + growing_degree_days: 100, + en_youtube_url: 'https://www.youtube.com/watch?v=INZybkX8tLI' }, alt_name: { '1': "egg plant", '2': "purple apple" }, sci_name: { '1': "fancy sci name", '2': "" } } end - it 'saves openfarm data' do + it 'saves data' do subject crop = Crop.last expect(crop.row_spacing).to eq(10) @@ -128,6 +130,8 @@ describe CropsController do expect(crop.sowing_method).to eq('direct') expect(crop.sun_requirements).to eq('full sun') expect(crop.growing_degree_days).to eq(100) + expect(crop.description).to eq 'hello' + expect(crop.en_youtube_url).to eq 'https://www.youtube.com/watch?v=INZybkX8tLI' end end end