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

[Generators] ActiveJob #1155

Merged
merged 1 commit into from Aug 27, 2014
Merged

[Generators] ActiveJob #1155

merged 1 commit into from Aug 27, 2014

Conversation

seuros
Copy link
Member

@seuros seuros commented Aug 22, 2014

WIP !

@seuros
Copy link
Member Author

seuros commented Aug 22, 2014

@myronmarston Since this generator is only present on 4.2, how can i test it ?

@myronmarston
Copy link
Member

@cupakromer maintains rspec-rails and is a better person to direct your question towards.

@cupakromer
Copy link
Member

@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 ActiveJob in your projects?

@seuros
Copy link
Member Author

seuros commented Aug 22, 2014

@cupakromer , the current PR is working. But as i see that all other generators have specs.
The issue here is that AJ is not available in other version of rails. So if i add a test, it will fall in all but rails 4.2

@seuros
Copy link
Member Author

seuros commented Aug 22, 2014

Maybe i should just skip the tests if rails version < 4.2 ?

@cupakromer
Copy link
Member

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 ammeter in that time frame. If not, I'll merge it as is pointing at my github branch.

@seuros
Copy link
Member Author

seuros commented Aug 22, 2014

Fine. You have to use rails master for tests. I just added few hours ago the hook.

@seuros seuros force-pushed the master branch 2 times, most recently from 84725ee to 10f3204 Compare August 25, 2014 10:46
@seuros
Copy link
Member Author

seuros commented Aug 25, 2014

@cupakromer I think we are good now.


def has_activejob?
Rails::VERSION::STRING >= '4.2'
end
Copy link
Member

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.

Copy link
Member Author

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)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not pushed though ;)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@JonRowe
Copy link
Member

JonRowe commented Aug 25, 2014

Looks good to me, but it'd be nice if it was squashed with a descriptive commit message.

@seuros seuros force-pushed the master branch 2 times, most recently from bc3f8b7 to 9c77e43 Compare August 25, 2014 14:15
@seuros
Copy link
Member Author

seuros commented Aug 25, 2014

Done!


def has_activejob?
defined?(ActiveJob)
end
Copy link
Member

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?

@seuros seuros force-pushed the master branch 2 times, most recently from 7695ef9 to 3fcf2fc Compare August 25, 2014 14:24
def has_activejob?
defined?(::ActiveJob)
end
end
Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

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.

Copy link
Member

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

Copy link
Member

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.

Copy link
Member Author

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.

@cupakromer
Copy link
Member

We should add this into generator docs in features/Generators.md. Also, it would be good to call this during the smoke tasks. Adding a line (with proper toggle) to templates/generate_stuff.rb (though this will change with #1150): generate('job does_something').

I took a very quick look at the code and I didn't see any obvious additions to ActiveSupport::TestCase to provide custom setup for job tests. So I think we are probably good with this simple generator.

@seuros
Copy link
Member Author

seuros commented Aug 25, 2014

Done! There is probably also the cucumber specs, but i won't touch that. I'm a carnivore :trollface: .

I'm adding TestCase for AJ, i will update this generator if required.

@cupakromer
Copy link
Member

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.

@seuros
Copy link
Member Author

seuros commented Aug 27, 2014

We will notice that, since RSpec show skipped specs.

def has_activejob?
defined?(::ActiveJob)
end
end
Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

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.

@seuros
Copy link
Member Author

seuros commented Aug 27, 2014

unrelated to this PR, why there is no routing generator ?

@cupakromer
Copy link
Member

We will notice that, since RSpec show skipped specs.

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.

@cupakromer
Copy link
Member

unrelated to this PR, why there is no routing generator ?

AFAIK, there hasn't been a need. Rails doesn't provide a routes generator. The majority of the rspec-rails generators are designed to piggy-back off of the out of the box rails generators. They helpfully provide the test parity for the created rails object.

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.

@cupakromer
Copy link
Member

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!

@seuros
Copy link
Member Author

seuros commented Aug 27, 2014

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.

@cupakromer
Copy link
Member

Rails just don't drop/add a feature without warning

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.

it should create the file every time a controller is generated

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:

  1. Automatically add passing specs for the generated routes
  2. If no actions / routes were specified, include our default filler message

@seuros
Copy link
Member Author

seuros commented Aug 27, 2014

I'm happy to learn better ways to keep up with potential changes.

Changelog. Any behavior change/bug fix won't be merged without updating the changelog.

cupakromer added a commit that referenced this pull request Aug 27, 2014
@cupakromer cupakromer merged commit 3921b9d into rspec:master Aug 27, 2014
@cupakromer
Copy link
Member

Thanks @seuros! ❤️

@cupakromer
Copy link
Member

@seuros I'm adding acceptance specs for this in #1150. However, in generating the sample app and files I've noticed a few things:

  • Calling rails:template is not loading ActiveJob by default, I need to manually require it

  • The rails generator isn't calling the RSpec generator for some reason:

    $ bin/rails -v; bin/rails g job something
    Rails 4.2.0.beta1
          create  app/jobs/something_job.rb

@seuros
Copy link
Member Author

seuros commented Aug 29, 2014

Beta1 won't work, i added the hook after the release. Try with master.

@cupakromer
Copy link
Member

Ah thanks @seuros I've confirmed this is true: https://travis-ci.org/rspec/rspec-rails/jobs/33865578#L824

@seuros
Copy link
Member Author

seuros commented Aug 29, 2014

Np @cupakromer :). I can add some matchers in the incoming days.

@cupakromer
Copy link
Member

Sounds good. @seuros if you have any questions about that, or how to try to generalize things for feature specs, etc. let me know.

@nunosilva800
Copy link

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:
expect(enqueued_jobs).to be(0)

@cupakromer
Copy link
Member

@Onumis there is now: #1334 ❤️

@nunosilva800
Copy link

@cupakromer you're the men! 🏆

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

Successfully merging this pull request may close these issues.

None yet

5 participants