Skip to content

Make generator namespace aware #1283

Merged
merged 1 commit into from Dec 10, 2013

2 participants

@akhilstanislavose

Currently the uploader generator is not namespace aware.

$ rails generate uploader MyModule::Avatar
create  app/uploaders/avatar_uploader.rb

In the above situation the uploader class is MyModule::Avatar and is defined properly in the generated file. But the path of the generated uploader class is wrong, it should have been app/uploaders/my_module/avatar_uploader.rb

@thiagofm
CarrierWave member
thiagofm commented Dec 5, 2013

Can you add a test case for this?

@akhilstanislavose

Wanted to write a test case before sending the pull request, but I could not find any specs for the original generator. Also Rails::Generators::TestCase, which I have used previously to test generators is a part of Unit Test and carrierwave uses RSpec. There are gems which enables us to spec generators in RSpec like ammeter and generator_spec which will have to be added as a dependency. Can you give me your thoughts on it?

@akhilstanislavose

I have added the test cases using the generator_spec gem.

@thiagofm thiagofm commented on an outdated diff Dec 9, 2013
spec/generators/uploaded_generator_spec.rb
+require 'spec_helper'
+require 'generators/uploader_generator'
+
+describe UploaderGenerator, :type => :generator do
+ destination File.expand_path("../../tmp", __FILE__)
+
+ before :each do
+ prepare_destination
+ end
+
+ it "should properly create uploader file" do
+ run_generator %w(Avatar)
+ assert_file 'app/uploaders/avatar_uploader.rb', /class AvatarUploader < CarrierWave::Uploader::Base/
+ end
+
+ it "should properly create namesapced uploader file" do
@thiagofm
CarrierWave member
thiagofm added a note Dec 9, 2013

*namespaced

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@thiagofm
CarrierWave member
thiagofm commented Dec 9, 2013

Looking good! Fix your typo that I mentioned and change the filename of https://github.com/akhilstanislavose/carrierwave/blob/aaf7c7f5e5583def6852f5f10141e31038ff8059/spec/generators/uploaded_generator_spec.rb to uploader_generator_spec.rb

And please squash your commits 👍

@thiagofm
CarrierWave member

👍 thanks for your contribution

@thiagofm thiagofm merged commit ee287f4 into carrierwaveuploader:master Dec 10, 2013

1 check passed

Details default The Travis CI build passed
@akhilstanislavose akhilstanislavose deleted the akhilstanislavose:namespace-fix branch Dec 11, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.