Skip to content
Snippets Groups Projects
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
query_generator_spec.rb 1.53 KiB
require "generator_spec"
require_relative '../../../lib/generators/nexus_cqrs/query_generator'

describe NexusCqrs::QueryGenerator, type: :generator do
  destination File.expand_path("../../tmp", __FILE__)

  before(:all) do
    prepare_destination
    run_generator ["TestQuery"]
  end

  it "creates the registration config file for handlers" do
    assert_file "config/initializers/register_cqrs_handlers.rb"
    assert_file "app/domain/queries/test_query.rb"
    assert_file "app/domain/queries/test_query_handler.rb"
  end

  it "creates the registration config file for handlers" do
    line = "$QUERY_EXECUTOR.register_command(TestQuery, TestQueryHandler.new)"
    base_path = File.expand_path("../../tmp", __FILE__)
    expect(File.read(base_path + "/config/initializers/register_cqrs_handlers.rb")).to(include(line))
  end

  context 'namespacing class names' do
    before(:all) do
      prepare_destination
      run_generator ["Test::TestQuery"]
    end

    it "creates the registration config file for handlers" do
      assert_file "config/initializers/register_cqrs_handlers.rb"
      assert_file "app/domain/queries/test/test_query.rb"
      assert_file "app/domain/queries/test/test_query_handler.rb"
    end

    it "creates the registration config file for handlers" do
      line = "$QUERY_EXECUTOR.register_command(Test::TestQuery, Test::TestQueryHandler.new)"
      base_path = File.expand_path("../../tmp", __FILE__)
      expect(File.read(base_path + "/config/initializers/register_cqrs_handlers.rb")).to(include(line))
    end
  end
end