diff --git a/Gemfile b/Gemfile index 6d9a825cb7..d030384822 100644 --- a/Gemfile +++ b/Gemfile @@ -181,7 +181,7 @@ group :development, :test do gem 'rubocop-rspec_rails' gem 'webrat' # provides HTML matchers for view tests - gem 'crowdin-cli' # for translations + gem 'crowdin-cli' # for translations gem 'dotenv-rails' # cli utils diff --git a/Gemfile.lock b/Gemfile.lock index 2e44f485d1..0ae96f8156 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -428,7 +428,7 @@ GEM mime-types (3.7.0) logger mime-types-data (~> 3.2025, >= 3.2025.0507) - mime-types-data (3.2025.0805) + mime-types-data (3.2025.0826) mimemagic (0.4.3) nokogiri (~> 1) rake @@ -769,7 +769,6 @@ GEM zeitwerk (2.7.5) PLATFORMS - ruby x86_64-linux DEPENDENCIES diff --git a/app/controllers/plantings_controller.rb b/app/controllers/plantings_controller.rb index 2d7a26d17b..e3f6445639 100644 --- a/app/controllers/plantings_controller.rb +++ b/app/controllers/plantings_controller.rb @@ -89,7 +89,17 @@ def create end def update - @planting.update(planting_params) + if planting_params[:from_other_source] == 'true' + @planting.parent_seed_id = nil + @planting.from_other_source = true + end + + if @planting.update(planting_params) + if planting_params[:finished].present? && @planting.garden.plantings.current.empty? + link = new_activity_path(name: 'Cultivate soil', garden_id: @planting.garden_id) + flash[:notice] = t('plantings.finished_prompt_html', link: link).html_safe + end + end respond_with @planting end @@ -138,7 +148,7 @@ def planting_params params[:planted_at] = parse_date(params[:planted_at]) if params[:planted_at] params.require(:planting).permit( :crop_id, :description, :garden_id, :planted_at, - :parent_seed_id, + :parent_seed_id, :from_other_source, :quantity, :sunniness, :planted_from, :finished, :finished_at, :failed, :overall_rating ) diff --git a/app/models/planting.rb b/app/models/planting.rb index 6b90bc3b8a..bca0d109b0 100644 --- a/app/models/planting.rb +++ b/app/models/planting.rb @@ -12,6 +12,8 @@ class Planting < ApplicationRecord friendly_id :planting_slug, use: %i(slugged finders) + attr_accessor :from_other_source + # Constants SUNNINESS_VALUES = %w(sun semi-shade shade).freeze PLANTED_FROM_VALUES = [ diff --git a/app/views/plantings/show.html.haml b/app/views/plantings/show.html.haml index 4ca71fc71d..9ec3155c18 100644 --- a/app/views/plantings/show.html.haml +++ b/app/views/plantings/show.html.haml @@ -36,6 +36,7 @@ Is this from one of these plantings? - @matching_seeds.each do |seed| = f.radio_button :parent_seed_id, seed.id, label: seed + = f.radio_button :parent_seed_id, 'other', label: 'Other source' = f.submit "save", class: 'btn btn-sm' .planting diff --git a/db/migrate/20250809205309_add_from_other_source_to_plantings.rb b/db/migrate/20250809205309_add_from_other_source_to_plantings.rb new file mode 100644 index 0000000000..5a13907c47 --- /dev/null +++ b/db/migrate/20250809205309_add_from_other_source_to_plantings.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class AddFromOtherSourceToPlantings < ActiveRecord::Migration[7.1] + def change + add_column :plantings, :from_other_source, :boolean + end +end diff --git a/db/schema.rb b/db/schema.rb index 41c702c774..58c1804e5d 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -897,6 +897,7 @@ 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/features/plantings/show_spec.rb b/spec/features/plantings/show_spec.rb index 95e23789d4..abf8807b78 100644 --- a/spec/features/plantings/show_spec.rb +++ b/spec/features/plantings/show_spec.rb @@ -92,6 +92,17 @@ it { expect(page).to have_text 'Parent seed' } it { expect(page).to have_link href: planting_path(planting) } end + + describe 'selecting other source' do + before do + choose 'Other source' + click_button 'save' + end + + it "hides the seed source question" do + expect(page).to have_no_text 'Is this from one of these plantings?' + end + end end end end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index bd64cd3336..64e1a14ae8 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -20,8 +20,6 @@ options = Selenium::WebDriver::Options.chrome options.add_argument("--headless") options.add_argument("--no-sandbox") - options.add_argument("--window-size=1920,1080") - options.add_argument("--disable-dev-shm-usage") # driver = Selenium::WebDriver.for :chrome, options: options