Sha256: 8126291ada97d6b111cae93d6452d0ce3e1a1cbc3fe8839294b3a5d010a5ead0

Contents?: true

Size: 1.41 KB

Versions: 10

Compression:

Stored size: 1.41 KB

Contents

require "spec_helper"

module Scenic
  describe Definition do
    describe "to_sql" do
      it "returns the content of a view definition" do
        sql_definition = "SELECT text 'Hi' as greeting"
        allow(File).to receive(:read).and_return(sql_definition)

        definition = Definition.new("searches", 1)

        expect(definition.to_sql).to eq sql_definition
      end

      it "raises an error if the file is empty" do
        allow(File).to receive(:read).and_return("")

        expect do
          Definition.new("searches", 1).to_sql
        end.to raise_error RuntimeError
      end
    end

    describe "path" do
      it "returns a sql file in db/views with padded version and view name"  do
        expected = "db/views/searches_v01.sql"

        definition = Definition.new("searches", 1)

        expect(definition.path).to eq expected
      end
    end

    describe "full_path" do
      it "joins the path with Rails.root" do
        definition = Definition.new("searches", 15)

        expect(definition.full_path).to eq Rails.root.join(definition.path)
      end
    end

    describe "version" do
      it "pads the version number with 0" do
        definition = Definition.new(:_, 1)

        expect(definition.version).to eq "01"
      end

      it "doesn't pad more than 2 characters" do
        definition = Definition.new(:_, 15)

        expect(definition.version).to eq "15"
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
scenic-1.4.1 spec/scenic/definition_spec.rb
scenic-1.4.0 spec/scenic/definition_spec.rb
scenic-1.3.0 spec/scenic/definition_spec.rb
scenic-1.2.0 spec/scenic/definition_spec.rb
scenic-1.1.1 spec/scenic/definition_spec.rb
scenic-1.1.0 spec/scenic/definition_spec.rb
scenic-1.0.0 spec/scenic/definition_spec.rb
scenic-0.3.0 spec/scenic/definition_spec.rb
scenic-0.2.1 spec/scenic/definition_spec.rb
scenic-0.2.0 spec/scenic/definition_spec.rb