-
Notifications
You must be signed in to change notification settings - Fork 8.6k
DEV: Partially refactor themes controller to services #33141
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
DEV: Partially refactor themes controller to services #33141
Conversation
This commit starts to introduce services to replace actions in the ThemesController. We will start with the low langing fruit: * Create * Destroy * BulkDestroy * GetTranslations Endpoints like `#import` and `#update` will be much harder. Also, the https://github.com/discourse/discourse-theme-creator plugin overrides some of these controller actions directly, so we need to be careful.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added back my comments from the other PR that have not been addressed yet (and added a new one).
…evamp and also review changes
@Flink this is an interesting case, I cannot use this shoulda matcher: it { is_expected.to validate_numericality_of(:id).is_greater_than(0).only_integer } For testing this contract: params do
attribute :id, :integer
# Negative theme IDs are for system themes only, which cannot be destroyed.
validates :id, presence: true, numericality: { only_integer: true, greater_than: 0 }
end ChatGPT says this is a known limitation of shoulda-matchers, since we are casting the
AI recommends to manually test like this, but I was wondering what your thoughts are? We don't use it "is invalid when id is negative" do
contract.id = -5
contract.validate
expect(contract.errors[:id]).to include("must be greater than 0")
end |
@Flink except for the last couple of questions I have I've fixed up everything else, can you please take another look? 🙏 |
@martin-brennan regarding testing numericality when casting to an integer, I had the exact same problem in one of my PRs I’m working on. I solved the problem using |
@Flink but how does that work for an ID? Allowed values are 1 or more up to the ID integer limit, how do you represent this with |
Okay @Flink I think we are pretty much there now except for 1 or 2 last things, wdyt now? Would be good to merge this soon |
Like I did here: https://github.com/discourse/discourse/pull/32884/files#diff-3d10b86f5ff2b7f2b7252f3b7b3666fcd615a70f82d556d25e5cc5732e42874aR6-R8 You need to combine several examples to prove various things. Typically, you need at least two: one to prove which values are authorized (lowest and highest boundaries) and another one to prove that values outside those boundaries will be rejected (like minus one and plus one). Then, depending on if (I’m also adding some comments where we can use those shoulda matchers, with concrete examples) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Almost there, I’m approving anyway 😉
Phew thanks again @Flink , all done now and I will merge next week 🚀 |
Spec failure unrelated |
This commit starts to introduce services to replace actions in the
ThemesController. We will start with the low langing fruit:
Endpoints like
#import
and#update
will be much harder.Also, the https://github.com/discourse/discourse-theme-creator plugin
overrides some of these controller actions directly, so we need
to be careful.