Sha256: 5b5bed20db4fe4f529aede805a03a6204e46675a23a931dcf24843c4f51b2f76

Contents?: true

Size: 1.66 KB

Versions: 4

Compression:

Stored size: 1.66 KB

Contents

require 'spec_helper'

require 'generators/rom/relation_generator'

describe ROM::Generators::RelationGenerator, type: :generator do
  destination File.expand_path('../../../../tmp', __FILE__)

  before(:each) do
    prepare_destination
  end

  specify do
    run_generator ['users']
    default_adapter = ROM.adapters.keys.first

    expect(destination_root).to have_structure {
      directory 'app' do
        directory 'relations' do
          file 'users_relation.rb' do
            contains <<-CONTENT.strip_heredoc
              class UsersRelation < ROM::Relation[:#{default_adapter}]
                # gateway :default

                dataset :users

                register_as :users

                # define your methods here ie:
                #
                # def all
                #   select(:id, :name).order(:id)
                # end
              end
            CONTENT
          end
        end
      end
    }
  end

  specify "with given adapter" do
    run_generator ['users', '--adapter=memory']

    relation = File.read(File.join(destination_root, 'app', 'relations', 'users_relation.rb'))
    expect(relation).to include("class UsersRelation < ROM::Relation[:memory]")
  end

  specify "with given gateway" do
    run_generator ['users', '--gateway=remote']

    relation = File.read(File.join(destination_root, 'app', 'relations', 'users_relation.rb'))
    expect(relation).to include("gateway :remote")
  end

  specify "with given registration" do
    run_generator ['users', '--register=profiles']

    relation = File.read(File.join(destination_root, 'app', 'relations', 'users_relation.rb'))
    expect(relation).to include("register_as :profiles")
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rom-rails-0.9.0 spec/lib/generators/relation_generator_spec.rb
rom-rails-0.9.0.beta1 spec/lib/generators/relation_generator_spec.rb
rom-rails-0.8.0 spec/lib/generators/relation_generator_spec.rb
rom-rails-0.7.0 spec/lib/generators/relation_generator_spec.rb