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
[Generators] ActiveJob #1155
[Generators] ActiveJob #1155
Conversation
@myronmarston Since this generator is only present on 4.2, how can i test it ? |
@cupakromer maintains rspec-rails and is a better person to direct your question towards. |
@seuros are you asking about how to add specs for rspec-rails for your code? Or is it a more general question about how you should test |
@cupakromer , the current PR is working. But as i see that all other generators have specs. |
Maybe i should just skip the tests if rails version < 4.2 ? |
Hmm, yes, I do loath doing version checks, but sometimes it's unavoidable. Let me think on that a little and I'll reply later tonight / tomorrow with my thoughts. I do have some thoughts I want to test out locally. Also, please be aware that right now Rails 4.2. builds are going to fail until we merge #1149. I expect this to be merged very soon (tonight or tomorrow). I'm in the process of seeing if we can get a new patch release for |
Fine. You have to use rails master for tests. I just added few hours ago the hook. |
84725ee
to
10f3204
Compare
@cupakromer I think we are good now. |
|
||
def has_activejob? | ||
Rails::VERSION::STRING >= '4.2' | ||
end |
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'd prefer this was put into a module and referenced as such.
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 changed it few minutes ago to defined?(ActiveJob)
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.
Not pushed though ;)
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.
Done.
Looks good to me, but it'd be nice if it was squashed with a descriptive commit message. |
bc3f8b7
to
9c77e43
Compare
Done! |
|
||
def has_activejob? | ||
defined?(ActiveJob) | ||
end |
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.
It'd still be nice to have this defined in a module and referenced that way... e.g:
module RailsFeatures
def has_activeob?
end
module_function :has_activejob?
end
RSpec.describe ... :skip => !RailsFeatures.has_activejob?
7695ef9
to
3fcf2fc
Compare
def has_activejob? | ||
defined?(::ActiveJob) | ||
end | ||
end |
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'm not a fan of this. In general I'd prefer to see this use module_function
instead. Though I'm not sure this is the right way to go just yet.
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 will have used function_module, but ruby 1.8.7 don't know that.
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.
Yep, please don't extend self
, @cupakromer there's a need to exclude the spec from the build, I'd support either an inline version check or a features module like we do in RSpec itself.
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.
module_function
works fine on 1.8.7, see here
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'm aware of the need, just thinking about alternative ways to do that.
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.
@JonRowe my bad. I had a typo.
We should add this into generator docs in I took a very quick look at the code and I didn't see any obvious additions to |
Done! There is probably also the cucumber specs, but i won't touch that. I'm a carnivore . I'm adding TestCase for AJ, i will update this generator if required. |
I thought about this a bit more. I'm now more sold on the feature toggles. I agree it is helpful for future proofing. My only remaining concern is we won't be as aware when things have changed and require action on our part. This isn't really an issue if a feature is removed, things work as desired in this case. However, if something needs updating, we won't be made aware since the specs simply won't run. I'll leave a few more comments about specific code changes. |
We will notice that, since RSpec show skipped specs. |
def has_activejob? | ||
defined?(::ActiveJob) | ||
end | ||
end |
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.
Can we move this into the lib
directory and place it under the RSpec::Rails
module to avoid potential naming conflicts? Perhaps:
module RSpec
module Rails
module FeatureChecks
# ...
end
end
end
There are some parts of the codebase I'd like to start leveraging this on.
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.
what about
module RSpec
module Rails
module Components
These are not features.
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.
They are features of rails. I plan on expanding this to checks other than just for classes. Such as checks for specific methods on a class or module. Usually these are called "feature flags" or something similar.
unrelated to this PR, why there is no routing generator ? |
That's not as noticeable as a failing spec. No one really looks at all of the output from the Travis CI builds, so unless the build is failing red, it won't get noticed. Regarding local builds, that would really depend on which version(s) the dev was using at the time. It's very likely things ran locally and weren't skipped. It's also possible that the skipped spec wasn't noticed since it didn't fail the spec run. |
AFAIK, there hasn't been a need. Rails doesn't provide a Along these lines, the existing rspec-rails route generator is part of the scaffold generator. This makes sense as it can provide all the helpful route specs by default. Otherwise, routing tends to be fairly non-standard and I'm not sure there's much benefit in creating a generator that doesn't hook into something else. |
I don't think my concern about the generator always being available is a merge blocker. If this goes green I'll merge. Thanks ❤️ for this @seuros! |
Rails just don't drop/add a feature without warning. I can maintain this part if you want. As for the route generator, it should create the file every time a controller is generated. |
To a degree. It does sometimes change APIs without notice. I'm happy to learn better ways to keep up with potential changes. Generally, an angry 😡 test suite has been the most helpful for me personally.
Not all controllers have routes. However, it does seem that if you use the Rails generator to create a controller with some actions, it will automatically add basic routes for it. 😺 Since that is the case, I'm happy to see a PR add this in. It would just need to do two things:
|
Changelog. Any behavior change/bug fix won't be merged without updating the changelog. |
Thanks @seuros! ❤️ |
@seuros I'm adding acceptance specs for this in #1150. However, in generating the sample app and files I've noticed a few things:
|
Beta1 won't work, i added the hook after the release. Try with master. |
Ah thanks @seuros I've confirmed this is true: https://travis-ci.org/rspec/rspec-rails/jobs/33865578#L824 |
Np @cupakromer :). I can add some matchers in the incoming days. |
Sounds good. @seuros if you have any questions about that, or how to try to generalize things for feature specs, etc. let me know. |
Are there any plans on supporting helpers like http://api.rubyonrails.org/classes/ActiveJob/TestHelper.html ? I'd expect to be able to do this for example: |
@Onumis there is now: #1334 ❤️ |
@cupakromer you're the men! 🏆 |
WIP !