Sha256: c452717872a20e09f7d73404ec8aabc6cc38ca5ca34ea1ffcca370f51af4ad8b

Contents?: true

Size: 1.41 KB

Versions: 2

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

2 entries across 2 versions & 1 rubygems

Version Path
scenic-1.5.1 spec/scenic/definition_spec.rb
scenic-1.5.0 spec/scenic/definition_spec.rb