Permalink
Browse files

Fix specs to only create and drop language plpgsql if on a version le…

…ss than 9.0
  • Loading branch information...
1 parent 0ee3a93 commit 8aa8d58a1a08106d5b921e6f5d39c83e1beff915 @jeremyevans committed Sep 29, 2010
Showing with 9 additions and 10 deletions.
  1. +9 −10 spec/sequel_postgresql_triggers_spec.rb
@@ -7,9 +7,16 @@
$:.unshift(File.join(File.dirname(File.dirname(File.expand_path(__FILE__))), 'lib'))
require 'sequel_postgresql_triggers'
+context "PostgreSQL Triggers" do
+before do
+ DB.create_language(:plpgsql) if DB.server_version < 90000
+end
+after do
+ DB.drop_language(:plpgsql, :cascade=>true) if DB.server_version < 90000
+end
+
context "PostgreSQL Counter Cache Trigger" do
before do
- DB.create_language(:plpgsql)
DB.create_table(:accounts){integer :id; integer :num_entries, :default=>0}
DB.create_table(:entries){integer :id; integer :account_id}
DB.pgt_counter_cache(:accounts, :id, :num_entries, :entries, :account_id)
@@ -19,7 +26,6 @@
after do
DB.drop_table(:entries, :accounts)
- DB.drop_language(:plpgsql, :cascade=>true)
end
specify "Should modify counter cache when adding or removing records" do
@@ -45,14 +51,12 @@
context "PostgreSQL Created At Trigger" do
before do
- DB.create_language(:plpgsql)
DB.create_table(:accounts){integer :id; timestamp :added_on}
DB.pgt_created_at(:accounts, :added_on)
end
after do
DB.drop_table(:accounts)
- DB.drop_language(:plpgsql, :cascade=>true)
end
specify "Should set the column upon insertion and ignore modifications afterward" do
@@ -71,15 +75,13 @@
context "PostgreSQL Immutable Trigger" do
before do
- DB.create_language(:plpgsql)
DB.create_table(:accounts){integer :id; integer :balance, :default=>0}
DB.pgt_immutable(:accounts, :balance)
DB[:accounts] << {:id=>1}
end
after do
DB.drop_table(:accounts)
- DB.drop_language(:plpgsql, :cascade=>true)
end
specify "Should allow updating a record only if the immutable column does not change" do
@@ -92,7 +94,6 @@
context "PostgreSQL Sum Cache Trigger" do
before do
- DB.create_language(:plpgsql)
DB.create_table(:accounts){integer :id; integer :balance, :default=>0}
DB.create_table(:entries){integer :id; integer :account_id; integer :amount}
DB.pgt_sum_cache(:accounts, :id, :balance, :entries, :account_id, :amount)
@@ -102,7 +103,6 @@
after do
DB.drop_table(:entries, :accounts)
- DB.drop_language(:plpgsql, :cascade=>true)
end
specify "Should modify sum cache when adding, updating, or removing records" do
@@ -131,14 +131,12 @@
context "PostgreSQL Updated At Trigger" do
before do
- DB.create_language(:plpgsql)
DB.create_table(:accounts){integer :id; timestamp :changed_on}
DB.pgt_updated_at(:accounts, :changed_on)
end
after do
DB.drop_table(:accounts)
- DB.drop_language(:plpgsql, :cascade=>true)
end
specify "Should set the column always to the current timestamp" do
@@ -152,3 +150,4 @@
DB[:accounts].select((Sequel::SQL::NumericExpression.new(:NOOP, ds.filter(:id=>3)) > ds.filter(:id=>2)).as(:x)).first[:x].should == true
end
end
+end

0 comments on commit 8aa8d58

Please sign in to comment.