rubyforgood / rubyforgood/awbw

Re-enable test for Workshops/new in workshops_categories_and_sectors_spec.rb:9

Open
#742 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

help wanted
Dominant language
Ruby
Stars
15
Forks
26
Avg merge
12h 42m
Merged PRs (30d)
242

Description

Workshop categories & sectors / CREATE workshop / it assigns categories and sectors from checkboxes

This test is failing saying that there was no Workshop created.

It's failing bc going to /workshops/new to create a new Workshop AND clicking the checkboxes for sectors or categories is trying to create associated sectorable_items or categorizable_items but the sectorable_id or categorizable_id of this new workshop is empty bc this new workshop doesn't have an id yet (bc it's a new workshop).

There is a special handshake in the workshops_controller (assign_associations(@workshop)), and a callback on the workshop model (after_save :assign_pending_associations), and those along w the validations on sectorable_id and categorizable_id are making it so this test fails.

This does work correctly in the UI, which is why we've marked this test xit for now.

We'd rather not stub or hack the test too much, as we do want a system test that makes sure we can create a new workshop that has some checkboxes clicked for sector and/or category.

So, this ticket is asking to figure out what about the test is making it be handled differently than the code (otherwise why does it work in the UI, but not in the test?), and to make it so we are testing the feature and that we can validate that the feature is working with the test.

We have some hacks in workshop.rb rn that we prob want to remove as part of this work?

  # Temporary storage for association IDs during creation
  attr_accessor :pending_sector_ids, :pending_category_ids

  # Callbacks
  after_save :assign_pending_associations

 # Override sector_ids= to defer association assignment until after save
  def sector_ids=(ids)
    if new_record?
      @pending_sector_ids = ids
    else
      super
    end
  end

  # Override category_ids= to defer association assignment until after save
  def category_ids=(ids)
    if new_record?
      @pending_category_ids = ids
    else
      super
    end
  end

  private

  def assign_pending_associations
    # Only run this on initial save, not on subsequent updates
    return unless @pending_sector_ids || @pending_category_ids

    if @pending_sector_ids
      self.sectors = Sector.where(id: @pending_sector_ids)
      @pending_sector_ids = nil
    end

    if @pending_category_ids
      self.categories = Category.where(id: @pending_category_ids)
      @pending_category_ids = nil
    end
  end

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with workshops_categories_and_sectors_spec.rb:9 and run the currently skipped CREATE workshop example to reproduce the missing Workshop failure. Read assign_associations(@workshop) in workshops_controller and the pending-association callbacks and validations in workshop.rb to compare the test path with the UI path. Done means the system test is re-enabled, covers selected sectors or categories during workshop creation, passes, and any unnecessary temporary hacks are removed.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
backend, testing
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.