Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This change adds an acceptance test suite. These tests don't have great failure messages currently and could likely stand to be broken into smaller pieces. Changes: - Split up `spec` task to run all unittests before the acceptance tests.
- Loading branch information
1 parent
a229cdc
commit 156a171
Showing
3 changed files
with
94 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
require "acceptance_helper" | ||
|
||
describe "User manages functions" do | ||
it "handles simple functions" do | ||
successfully "rails generate fx:function test" | ||
write_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" | ||
write_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 | ||
|
||
def successfully(command) | ||
`RAILS_ENV=test #{command}` | ||
expect($?.exitstatus).to eq(0), "'#{command}' was unsuccessful" | ||
end | ||
|
||
def write_definition(file, contents) | ||
File.open("db/functions/#{file}.sql", File::WRONLY) do |definition| | ||
definition.truncate(0) | ||
definition.write(contents) | ||
end | ||
end | ||
|
||
def execute(command) | ||
ActiveRecord::Base.connection.execute(command).first | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
require "bundler" | ||
|
||
ENV["RAILS_ENV"] = "test" | ||
|
||
RSpec.configure do |config| | ||
config.around(:each) do |example| | ||
Dir.chdir("spec/dummy") do | ||
example.run | ||
end | ||
end | ||
|
||
config.before(:suite) do | ||
Dir.chdir("spec/dummy") do | ||
system <<-CMD | ||
git init 1>/dev/null && | ||
git add -A && | ||
git commit --no-gpg-sign --message 'initial' 1>/dev/null | ||
CMD | ||
end | ||
end | ||
|
||
config.after(:suite) do | ||
Dir.chdir("spec/dummy") do | ||
ActiveRecord::Base.connection.disconnect! | ||
system <<-CMD | ||
rake db:drop db:create && | ||
git add -A && | ||
git reset --hard HEAD 1>/dev/null && | ||
rm -rf .git/ 1>/dev/null | ||
CMD | ||
end | ||
end | ||
end |