Skip to content

Commit

Permalink
Add a spec to verify the correct behavior is used
Browse files Browse the repository at this point in the history
  • Loading branch information
c-lliope committed Jan 22, 2016
1 parent c78edcb commit 21ad3f7
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 5 deletions.
8 changes: 7 additions & 1 deletion lib/administrate/generator_helpers.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
module Administrate
module GeneratorHelpers
def call_generator(generator, *args)
Rails::Generators.invoke(generator, args, behavior: behavior)
Rails::Generators.invoke(generator, args, generator_options)
end

private

def generator_options
{ behavior: behavior }
end
end
end
1 change: 1 addition & 0 deletions lib/administrate/view_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
module Administrate
class ViewGenerator < Rails::Generators::Base
include Administrate::GeneratorHelpers

private

def self.template_source_path
Expand Down
2 changes: 1 addition & 1 deletion spec/generators/install_generator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class ApplicationController < Administrate::ApplicationController

%w[customer order product line_item].each do |resource|
expect(Rails::Generators).
to invoke_generator("administrate:dashboard", resource)
to invoke_generator("administrate:dashboard", [resource])
end
end
end
Expand Down
12 changes: 11 additions & 1 deletion spec/generators/views_generator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,18 @@

%w[index show new edit].each do |generator|
expect(Rails::Generators).
to invoke_generator("administrate:views:#{generator}", resource)
to invoke_generator("administrate:views:#{generator}", [resource])
end
end

it "revokes sub-generators if run through `rails destroy`" do
allow(Rails::Generators).to receive(:invoke)
resource = "users"

run_generator [resource], behavior: :revoke

expect(Rails::Generators).
to invoke_generator("administrate:views:index", [resource], behavior: :revoke)
end
end
end
4 changes: 2 additions & 2 deletions spec/support/generator_spec_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ def contents_for_application_template(view_name)
)
end

def invoke_generator(generator, *args)
have_received(:invoke).with(generator, args, behavior: :invoke)
def invoke_generator(generator, args = [], options = { behavior: :invoke })
have_received(:invoke).with(generator, args, options)
end

def each_file_in(path)
Expand Down

0 comments on commit 21ad3f7

Please sign in to comment.