Sha256: 1cbed061db1d09c1a81a3fdffbc69600aa32ac189339427cd0d483d28df300ce

Contents?: true

Size: 1.79 KB

Versions: 5

Compression:

Stored size: 1.79 KB

Contents

require 'test_helper'
require 'generators/controller/controller_scaffolding_generator'

class ExtControllerScaffoldingGeneratorTest < Rails::Generators::TestCase
	tests Rails::Generators::ControllerScaffoldingGenerator
	#destination "#{::Rails.root.to_s}/" #File.expand_path("../ctrlr_tmp", File.dirname(__FILE__))
  destination File.expand_path("../tmp", File.dirname(__FILE__))
  
  def setup
    @contr_name = "people"
    @actions = %w(index new create edit update destroy custom_action)
    @opts = %w(--force --quiet) # --template-engine=haml #thought it would need that option
    @args = [@contr_name] | @actions | @opts
    prepare_destination
    copy_dummy_files
  end

  def teardown
    run_generator @args , {:behavior => :revoke}
  end

  test "Controller was created properly with appropriate actions" do
  	assert_no_file "app/controllers/#{@contr_name}_controller.rb"
    #Note: This is the controller file that will be generated after the generator runs
    assert_no_file "app/controllers/#{@contr_name}_controller.rb"
      
  	run_generator @args
  	
  	assert_file "app/controllers/#{@contr_name}_controller.rb" do |p_ctrl|
  		@actions.each do |a|
	  		assert_instance_method a, p_ctrl do |action|
	  			assert_match(/\.paginate\(per_page: @per_page, page: @page\)/, action) if a == "index"
			  end
			end
  	end 
   #strong params method definition
    assert_file "app/controllers/#{@contr_name}_controller.rb" do |p_ctrl|
      assert_match %r(def #{@contr_name.singularize}_params), p_ctrl
    end
  end

  test "Routes were added properly" do
    assert_file "config/routes.rb" do |routes|
      assert_no_match %r(resources :#{@contr_name}), routes
    end

    run_generator @args

    assert_file "config/routes.rb" do |routes|
      assert_match %r(resources :#{@contr_name}), routes
    end
  end


end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
controller_scaffolding-1.0.4 test/lib/generators/ext_controller_scaffolding_generator_test.rb
controller_scaffolding-1.0.3 test/lib/generators/ext_controller_scaffolding_generator_test.rb
controller_scaffolding-1.0.2 test/lib/generators/ext_controller_scaffolding_generator_test.rb
controller_scaffolding-1.0.1 test/lib/generators/ext_controller_scaffolding_generator_test.rb
controller_scaffolding-1.0.0 test/lib/generators/ext_controller_scaffolding_generator_test.rb