Skip to content

Commit

Permalink
Add test for controller scaffold with namespace
Browse files Browse the repository at this point in the history
Only for Rails::VERSION::MAJOR >= 6 because the method `show_helper`
doesn't handle well the namespaces on previous versions.
  • Loading branch information
ceritium committed Nov 9, 2021
1 parent 1d387e0 commit 56d333b
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions test/scaffold_controller_generator_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,25 @@ class ScaffoldControllerGeneratorTest < Rails::Generators::TestCase
end
end

if Rails::VERSION::MAJOR >= 6
test 'controller with namespace' do
run_generator %w(Admin::Post --model-name=Post)
assert_file 'app/controllers/admin/posts_controller.rb' do |content|
assert_instance_method :create, content do |m|
assert_match %r{format\.html \{ redirect_to admin_post_url\(@post\), notice: "Post was successfully created\." \}}, m
end

assert_instance_method :update, content do |m|
assert_match %r{format\.html \{ redirect_to admin_post_url\(@post\), notice: "Post was successfully updated\." \}}, m
end

assert_instance_method :destroy, content do |m|
assert_match %r{format\.html \{ redirect_to admin_posts_url, notice: "Post was successfully destroyed\." \}}, m
end
end
end
end

test 'dont use require and permit if there are no attributes' do
run_generator %w(Post)

Expand Down

0 comments on commit 56d333b

Please sign in to comment.