Sha256: 0a4840115c77321a131d97aae8e25295f19fc67d66d2f35939297f441388902e

Contents?: true

Size: 1.53 KB

Versions: 1

Compression:

Stored size: 1.53 KB

Contents

require "acceptance_helper"

RSpec.describe "User manages functions" do
  it "handles simple functions" do
    successfully "rails generate fx:function test"
    write_function_definition "test_v01", <<~EOS
      CREATE OR REPLACE FUNCTION test()
      RETURNS text AS $$
      BEGIN
          RETURN 'test';
      END;
      $$ LANGUAGE plpgsql;
    EOS
    successfully "rake db:migrate"

    result = execute("SELECT * FROM test() AS result")
    expect(result).to eq("result" => "test")

    successfully "rails generate fx:function test"
    verify_identical_definitions(
      "db/functions/test_v01.sql",
      "db/functions/test_v02.sql"
    )
    write_function_definition "test_v02", <<~EOS
      CREATE OR REPLACE FUNCTION test()
      RETURNS text AS $$
      BEGIN
          RETURN 'testest';
      END;
      $$ LANGUAGE plpgsql;
    EOS
    successfully "rake db:migrate"

    result = execute("SELECT * FROM test() AS result")
    expect(result).to eq("result" => "testest")
  end

  it "handles functions with arguments" do
    successfully "rails generate fx:function adder"
    write_function_definition "adder_v01", <<~EOS
      CREATE FUNCTION adder(x int, y int)
      RETURNS int AS $$
      BEGIN
          RETURN $1 + $2;
      END;
      $$ LANGUAGE plpgsql;
    EOS
    successfully "rake db:migrate"

    result = execute("SELECT * FROM adder(1, 2) AS result")
    result["result"] = result["result"].to_i
    expect(result).to eq("result" => 3)

    successfully "rails destroy fx:function adder"
    successfully "rake db:migrate"
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fx-0.9.0 spec/acceptance/user_manages_functions_spec.rb