Permalink
Browse files

Merge pull request #1283 from akhilstanislavose/namespace-fix

Make generator namespace aware
  • Loading branch information...
2 parents 0fa6a88 + da941d4 commit ee287f49660a9448c9d2749c3936b1c8d7caf8ea @thiagofm thiagofm committed Dec 10, 2013
Showing with 24 additions and 1 deletion.
  1. +1 −0 .gitignore
  2. +1 −0 carrierwave.gemspec
  3. +1 −1 lib/generators/uploader_generator.rb
  4. +20 −0 spec/generators/uploader_generator_spec.rb
  5. +1 −0 spec/spec_helper.rb
View
@@ -9,6 +9,7 @@ more/activerecord/spec/public
more/datamapper/spec/public
*.project
spec/test.log
+spec/tmp
*.swp
.rvmrc
.bundle
View
@@ -39,4 +39,5 @@ Gem::Specification.new do |s|
s.add_development_dependency "rmagick"
s.add_development_dependency "nokogiri", "~> 1.5.10" # 1.6 requires ruby > 1.8.7
s.add_development_dependency "timecop", "0.6.1" # 0.6.2 requires ruby > 1.8.7
+ s.add_development_dependency "generator_spec"
end
@@ -2,6 +2,6 @@ class UploaderGenerator < Rails::Generators::NamedBase
source_root File.expand_path("../templates", __FILE__)
def create_uploader_file
- template "uploader.rb", "app/uploaders/#{file_name}_uploader.rb"
+ template "uploader.rb", File.join('app/uploaders', class_path, "#{file_name}_uploader.rb")
end
end
@@ -0,0 +1,20 @@
+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 namespaced uploader file" do
+ run_generator %w(MyModule::Avatar)
+ assert_file 'app/uploaders/my_module/avatar_uploader.rb', /class MyModule::AvatarUploader < CarrierWave::Uploader::Base/
+ end
+end
View
@@ -12,6 +12,7 @@
require 'open-uri'
require 'sham_rack'
require 'mini_magick'
+require 'generator_spec'
require 'mysql2'

0 comments on commit ee287f4

Please sign in to comment.