Sha256: d96dcb00ce245c7cbda918a1f512e8ccef437ea8bb42a902e1ad44c36c7409bb

Contents?: true

Size: 1.64 KB

Versions: 13

Compression:

Stored size: 1.64 KB

Contents

# Generators are not automatically loaded by Rails
require 'rails_helper'
require 'generators/graphql_devise/install_generator'

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

  before do
    prepare_destination
  end

  let(:routes_path)    { "#{destination_root}/config/routes.rb" }
  let(:routes_content) { File.read(routes_path) }
  let(:dta_route)      { "mount_devise_token_auth_for 'User', at: 'auth'" }

  xcontext 'when the file exists' do
    before do
      create_file_with_content(
        routes_path,
        "Rails.application.routes.draw do\n#{dta_route}\nend"
      )
    end

    context 'when passing no params to the generator' do
      before { run_generator }

      it 'replaces dta route using the default values for class and path' do
        generator_added_route = /  mount_graphql_devise_for 'User', at: 'auth'/
        expect(routes_content).to match(generator_added_route)
        expect(routes_content).not_to match(dta_route)
      end
    end

    context 'when passing custom params to the generator' do
      before { run_generator %w[Admin api] }

      it 'add the routes using the provided values for class and path and keeps dta route' do
        generator_added_route = /  mount_graphql_devise_for 'Admin', at: 'api'/
        expect(routes_content).to match(generator_added_route)
        expect(routes_content).to match(dta_route)
      end
    end
  end

  xcontext 'when file does *NOT* exist' do
    before { run_generator }

    it 'does *NOT* create the file and throw no exception' do
      expect(File.exist?(routes_path)).to be_falsey
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
graphql_devise-0.11.2 spec/generators/graphql_devise/install_generator_spec.rb
graphql_devise-0.11.1 spec/generators/graphql_devise/install_generator_spec.rb
graphql_devise-0.11.0 spec/generators/graphql_devise/install_generator_spec.rb
graphql_devise-0.10.1 spec/generators/graphql_devise/install_generator_spec.rb
graphql_devise-0.10.0 spec/generators/graphql_devise/install_generator_spec.rb
graphql_devise-0.9.2 spec/generators/graphql_devise/install_generator_spec.rb
graphql_devise-0.9.1 spec/generators/graphql_devise/install_generator_spec.rb
graphql_devise-0.9.0 spec/generators/graphql_devise/install_generator_spec.rb
graphql_devise-0.8.1 spec/generators/graphql_devise/install_generator_spec.rb
graphql_devise-0.8.0 spec/generators/graphql_devise/install_generator_spec.rb
graphql_devise-0.7.0 spec/generators/graphql_devise/install_generator_spec.rb
graphql_devise-0.6.0 spec/generators/graphql_devise/install_generator_spec.rb
graphql_devise-0.5.0 spec/generators/graphql_devise/install_generator_spec.rb