aboutsummaryrefslogtreecommitdiffstats
path: root/spec/support/bare_sql.rb
diff options
context:
space:
mode:
authorRobert2017-06-09 17:04:38 +0200
committerRobert2017-06-09 17:25:06 +0200
commit63a893c22feca2c26cd8eecef2e6deb8ff97bd26 (patch)
treea82f97b3732379167760a57012cc3197afd9b846 /spec/support/bare_sql.rb
parent38e5a5329541a54f98d771c3aa252b91b823b94f (diff)
downloadchouette-core-63a893c22feca2c26cd8eecef2e6deb8ff97bd26.tar.bz2
refs 3604 @12h all tests pass
Diffstat (limited to 'spec/support/bare_sql.rb')
-rw-r--r--spec/support/bare_sql.rb58
1 files changed, 58 insertions, 0 deletions
diff --git a/spec/support/bare_sql.rb b/spec/support/bare_sql.rb
new file mode 100644
index 000000000..03a50ef77
--- /dev/null
+++ b/spec/support/bare_sql.rb
@@ -0,0 +1,58 @@
+module Support
+ module BareSQL
+
+ def insert(schema, table, values)
+ execute "INSERT INTO #{schema}.#{table} (#{_keys(values)}) VALUES (#{_values values})"
+ end
+
+ def execute(sql)
+ base_connection.execute(sql)
+ end
+
+ def expect_same_content(table_name)
+ expected_content = get_content(source_schema, table_name)
+ actual_content = get_content(target_schema, table_name)
+ expect( actual_content ).to eq(expected_content)
+ end
+
+ def expect_same_sequence_params(sequence_name)
+ expected_seq = Hash.without(get_sequences(source_schema, sequence_name).first, 'log_cnt')
+ actual_seq = Hash.without(get_sequences(target_schema, sequence_name).first, 'log_cnt')
+ expect( actual_seq ).to eq(expected_seq)
+ end
+
+ def get_content(schema_name, table_name)
+ execute("SELECT * FROM #{schema_name}.#{table_name}").to_a
+ end
+
+ private
+
+ def base_connection
+ ActiveRecord::Base.connection
+ end
+
+ def _keys(values)
+ values.keys.map(&:to_s).join(", ")
+ end
+
+ def _values(values)
+ values
+ .values
+ .map(&method(:_format))
+ .join(', ')
+ end
+
+ def _format(val)
+ case val
+ when String
+ "'#{val}'"
+ when TrueClass
+ "'t'"
+ when FalseClass
+ "'f'"
+ else
+ val.to_s
+ end
+ end
+ end
+end