Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Generator did not include include Noticed::Model in the Notification model #353

Closed
3 tasks done
adamlofting opened this issue Dec 8, 2023 · 2 comments
Closed
3 tasks done

Comments

@adamlofting
Copy link

Bug Report

Describe the Bug:
I've just installed noticed and on initial setup I ran into a stumbling block. I was getting the error:

Invalid single-table inheritance type: MyClassNameNotification is not a subclass of Notification (ActiveRecord::SubclassNotFound)

It turns out that my generated app/models/notification.rb did not include the line include Noticed::Model.

I spotted this line was required via the Screencast, but it might be a bug in the generator, or something worth mentioning in the docs. I can see it's in the generator, but I'm not sure if this is actually being triggered: https://github.com/excid3/noticed/blob/6472cbeb37a5ab6c3a0192dbebc5b718094fa4ad/lib/generators/noticed/model_generator.rb#L22

To Reproduce:
rails generate noticed:model

Expected Behavior:
include include Noticed::Model in the generated Notification model

Environment:

  • Noticed gem version: 1.6.3
  • Ruby version: 3.1.2
  • Rails version: 7.1.0
  • Operating System: macOS 14.1.2 (23B92)

Checklist:

  • I have searched for similar issues and couldn't find any
  • I have checked the documentation for relevant information
  • I have included all the required information
@excid3
Copy link
Owner

excid3 commented Dec 8, 2023

I can confirm this works fine on 1.6.3.

chris at excid3-mbp using 3.2.2 in ~/code/noticed_test on main!
± bundle add noticed
Fetching gem metadata from https://rubygems.org/........
Resolving dependencies...
Fetching gem metadata from https://rubygems.org/........
Resolving dependencies...

chris at excid3-mbp using 3.2.2 in ~/code/noticed_test on main!
± rails generate noticed:model
    generate  model
       rails  generate model Notification recipient:references{polymorphic} type params:json read_at:datetime:index
      invoke  active_record
      create    db/migrate/20231208134411_create_notifications.rb
      create    app/models/notification.rb
      invoke    test_unit
      create      test/models/notification_test.rb
      create      test/fixtures/notifications.yml
      insert  app/models/notification.rb
      insert  db/migrate/20231208134411_create_notifications.rb

🚚 Your notifications database model has been generated!

Next steps:
1. Run "rails db:migrate"
2. Add "has_many :notifications, as: :recipient, dependent: :destroy" to your User model(s).
3. Generate notifications with "rails g noticed:notification"

chris at excid3-mbp using 3.2.2 in ~/code/noticed_test on main!
± cat app/models/notification.rb
class Notification < ApplicationRecord
  include Noticed::Model
  belongs_to :recipient, polymorphic: true
end

If you can provide some steps to reproduce, we can address it, but this is likely going away in v2 anyways.

@excid3 excid3 closed this as not planned Won't fix, can't repro, duplicate, stale Dec 8, 2023
@adamlofting
Copy link
Author

No worries, I guess if anyone else runs into the same issue, they can find this ticket and add it manually.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants