Sha256: f9fbb1e6fb33b1e242e2bc4502448212dff269d553739ef542756c806490f10f

Contents?: true

Size: 1.77 KB

Versions: 3

Compression:

Stored size: 1.77 KB

Contents

require 'spec_helper'

# For some reason, trying to load the generator from this spec
# causes problems without an explicit require statement, even
# though the rails executable is able to find the generator
# when you execute it from the command line
require 'generators/g5_authenticatable/install/install_generator'

describe G5Authenticatable::InstallGenerator, type: :generator do
  destination File.expand_path('../../../../tmp', __FILE__)

  before do
    prepare_destination
    setup_routes
    run_generator
  end

  it 'should copy the migration' do
    expect(destination_root).to have_structure {
      directory 'db' do
        directory 'migrate' do
          migration 'create_g5_authenticatable_users' do
            contains 'class CreateG5AuthenticatableUsers < ActiveRecord::Migration'
          end
        end
      end
    }
  end

  it 'should copy the initializer' do
    expect(destination_root).to have_structure {
      directory 'config' do
        directory 'initializers' do
          file 'g5_authenticatable.rb' do
            contains '# G5Authenticatable.strict_token_validation = true'
          end
        end
      end
    }
  end

  it 'should mount the engine' do
    expect(destination_root).to have_structure {
      directory 'config' do
        file 'routes.rb' do
          contains "mount G5Authenticatable::Engine => '/g5_auth'"
        end
      end
    }
  end

  def setup_routes
    routes = <<-END
      Rails.application.routes.draw do
        resource :home, only: [:show, :index]

        match '/some_path', to: 'controller#action', as: :my_alias

        root to: 'home#index'
      end
    END
    config_dir = File.join(destination_root, 'config')

    FileUtils.mkdir_p(config_dir)
    File.write(File.join(config_dir, 'routes.rb'), routes)
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
g5_authenticatable-0.4.2 spec/lib/generators/g5_authenticatable/install_generator_spec.rb
g5_authenticatable-0.4.1 spec/lib/generators/g5_authenticatable/install_generator_spec.rb
g5_authenticatable-0.4.0 spec/lib/generators/g5_authenticatable/install_generator_spec.rb