Sha256: ac0a11a66f2a146941f435ce378fe4fff460a8adc1242294486d798048d6ac5a

Contents?: true

Size: 1.8 KB

Versions: 7

Compression:

Stored size: 1.8 KB

Contents

require "spec_helper"
require "generators/scenic/view/view_generator"

describe Scenic::Generators::ViewGenerator, :generator do
  it "creates view definition and migration files" do
    migration = file("db/migrate/create_searches.rb")
    view_definition = file("db/views/searches_v01.sql")

    run_generator ["search"]

    expect(migration).to be_a_migration
    expect(view_definition).to exist
  end

  it "updates an existing view" do
    with_view_definition("searches", 1, "hello") do
      migration = file("db/migrate/update_searches_to_version_2.rb")
      view_definition = file("db/views/searches_v02.sql")
      allow(Dir).to receive(:entries).and_return(["searches_v01.sql"])

      run_generator ["search"]

      expect(migration).to be_a_migration
      expect(view_definition).to exist
    end
  end

  it "adds 'materialized: true' to the migration if view is materialized" do
    with_view_definition("aired_episodes", 1, "hello") do
      allow(Dir).to receive(:entries).and_return(["aired_episodes_v01.sql"])

      run_generator ["aired_episode", "--materialized"]
      migration = migration_file(
        "db/migrate/update_aired_episodes_to_version_2.rb",
      )
      expect(migration).to contain "materialized: true"
    end
  end

  context "for views created in a schema other than 'public'" do
    it "creates a view definition" do
      view_definition = file("db/views/non_public_searches_v01.sql")

      run_generator ["non_public.search"]

      expect(view_definition).to exist
    end

    it "creates a migration file" do
      run_generator ["non_public.search"]

      migration = migration_file("db/migrate/create_non_public_searches.rb")
      expect(migration).to contain(/class CreateNonPublicSearches/)
      expect(migration).to contain(/create_view "non_public.searches"/)
    end
  end
end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
scenic-1.6.0 spec/generators/scenic/view/view_generator_spec.rb
scenic-1.5.5 spec/generators/scenic/view/view_generator_spec.rb
scenic-jets-1.5.5 spec/generators/scenic/view/view_generator_spec.rb
scenic-jets-1.5.4 spec/generators/scenic/view/view_generator_spec.rb
scenic-1.5.4 spec/generators/scenic/view/view_generator_spec.rb
scenic-1.5.3 spec/generators/scenic/view/view_generator_spec.rb
scenic-1.5.2 spec/generators/scenic/view/view_generator_spec.rb