Files
growstuff/spec/factories/posts.rb
google-labs-jules[bot] f2421bf4c7 Here's the plan to add polymorphic comments and update related functionality:
This change introduces polymorphic comments, allowing you to comment on Photos, Plantings, Harvests, and Activities, in addition to Posts.

Key changes include:

-   **Comment Model:**
    -   Made `Comment.commentable` a polymorphic association.
    -   Added a data migration to move existing post comments to the new structure.
    -   Updated notification creation logic for polymorphic commentables.
-   **CommentsController:**
    -   Refactored to handle various commentable types using a `find_commentable` method.
-   **Ability Model:**
    -   Updated permissions for comment creation, editing (author/admin), and deletion (author/commentable owner/admin).
-   **Routes:**
    -   Added nested comment routes for Photos, Plantings, Harvests, Activities, and Posts using a `commentable` concern with shallow routes.
-   **Views:**
    -   Created generic partials for comment forms (`_form.html.haml`) and display (`_comment.html.haml`, `_comments.html.haml`).
    -   Integrated these partials into the show pages of all commentable types.
    -   Updated `comments/new` and `comments/edit` views to be generic.
    -   Relevant parent controller `show` actions now eager-load comments.
-   **Testing:**
    -   Added extensive model, controller (using shared examples), and feature tests to cover the new polymorphic comment functionality, including permissions and UI interactions for all commentable types.
    -   Updated and created factories as needed.

This fulfills the issue requirements for adding comments to multiple resource types with appropriate permissions.
2025-05-25 02:03:17 +00:00

38 lines
1.1 KiB
Ruby

# frozen_string_literal: true
FactoryBot.define do
factory :post do
association :author, factory: :member
association :forum # Assuming posts belong to a forum
sequence(:subject) { |n| "Test Post Subject #{n}" }
sequence(:body) { |n| "This is the body of test post #{n}." }
# Add traits if needed, e.g., for posts with photos, crops, etc.
trait :with_photos do
transient do
photos_count { 1 }
end
after(:create) do |post, evaluator|
create_list(:photo, evaluator.photos_count, owner: post.author, post_id: post.id) # Assuming Photo has post_id or similar
end
end
trait :with_crops do
transient do
crops_count { 1 }
end
after(:create) do |post, evaluator|
create_list(:crop, evaluator.crops_count, posts: [post]) # Assuming a has_and_belongs_to_many or has_many :through
end
end
end
end
# Assuming a Forum model exists and has a factory
FactoryBot.define do
factory :forum do
sequence(:name) { |n| "Test Forum #{n}" }
# Add other attributes for Forum as needed
end
end