diff --git a/Gemfile b/Gemfile index bd7ef2466d..69a27b0dad 100644 --- a/Gemfile +++ b/Gemfile @@ -174,7 +174,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 @@ -187,18 +187,16 @@ end group :test do gem 'axe-core-capybara' gem 'axe-core-rspec' + gem "percy-capybara", "~> 5.0.0" gem 'rails-controller-testing' + gem "rspec-rebound" gem 'selenium-webdriver' gem 'timecop' gem 'vcr' - gem "rspec-rebound" - gem "percy-capybara", "~> 5.0.0" end group :travis do gem 'platform-api' end - - gem "i18n_data", "~> 1.1" diff --git a/Gemfile.lock b/Gemfile.lock index 41f0f1878f..f23f8e1518 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -404,13 +404,12 @@ 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 mini_magick (4.12.0) mini_mime (1.1.5) - mini_portile2 (2.8.9) minitest (5.25.5) moneta (1.0.0) msgpack (1.8.0) @@ -430,9 +429,6 @@ GEM net-protocol netrc (0.11.0) nio4r (2.7.4) - nokogiri (1.18.9) - mini_portile2 (~> 2.8.2) - racc (~> 1.4) nokogiri (1.18.9-x86_64-linux-gnu) racc (~> 1.4) oauth (0.5.6) @@ -737,7 +733,6 @@ GEM zeitwerk (2.7.3) PLATFORMS - ruby x86_64-linux DEPENDENCIES diff --git a/app/controllers/plantings_controller.rb b/app/controllers/plantings_controller.rb index 8e62281635..d49cd2768a 100644 --- a/app/controllers/plantings_controller.rb +++ b/app/controllers/plantings_controller.rb @@ -83,6 +83,11 @@ def create end def update + 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) @@ -137,7 +142,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 9f05a7732b..e1083503c2 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 dc5a10f550..72b5fa3b1c 100644 --- a/app/views/plantings/show.html.haml +++ b/app/views/plantings/show.html.haml @@ -29,6 +29,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 982f1e06ac..1ec6e95591 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -582,6 +582,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 e9c69c7867..9299907589 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