Sha256: 3f1a1c47b787c73a2b40d34fe55a3dda3de363d9f0ca994cd6d2857d5f67e6ce

Contents?: true

Size: 1.58 KB

Versions: 7

Compression:

Stored size: 1.58 KB

Contents

require 'rails_helper'
require 'generators/curupira/install/install_generator'

describe Curupira::Generators::InstallGenerator, :generator do
  before do
    provide_existing_routes_file
  end

  describe "role_group_model" do
    context "no existing role group class" do
      it "generates role group" do
        run_generator
        role_group_class = file("app/models/role_group.rb")

        expect(role_group_class).to exist
        expect(role_group_class).to have_correct_syntax
        expect(role_group_class).to contain("belongs_to :role")
        expect(role_group_class).to contain("belongs_to :group")
      end
    end

    context "role group class already exists" do
      it "includes validations" do
        provide_existing_class("role_group")

        run_generator
        role_group_class = file("app/models/role_group.rb")

        expect(role_group_class).to exist
        expect(role_group_class).to have_correct_syntax
        expect(role_group_class).to contain("belongs_to :group")
        expect(role_group_class).to contain("belongs_to :role")
      end
    end
  end

  describe "role group migration" do
    context "role_group table does not exist" do
      it "creates a migration to create the role_groups table" do
        allow(ActiveRecord::Base.connection).to receive(:table_exists?).and_return(false)

        run_generator
        migration = migration_file("db/migrate/create_role_groups.rb")

        expect(migration).to exist
        expect(migration).to have_correct_syntax
        expect(migration).to contain("create_table :role_groups")
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
curupira-0.1.7 spec/generators/curupira/install/role_group_generator_spec.rb
curupira-0.1.6 spec/generators/curupira/install/role_group_generator_spec.rb
curupira-0.1.4 spec/generators/curupira/install/role_group_generator_spec.rb
curupira-0.1.3 spec/generators/curupira/install/role_group_generator_spec.rb
curupira-0.1.2 spec/generators/curupira/install/role_group_generator_spec.rb
curupira-0.1.1 spec/generators/curupira/install/role_group_generator_spec.rb
curupira-0.1.0 spec/generators/curupira/install/role_group_generator_spec.rb