Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: moertel/sQucumber-postgres
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.0.12
Choose a base ref
...
head repository: moertel/sQucumber-postgres
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
  • 20 commits
  • 9 files changed
  • 3 contributors

Commits on Aug 27, 2019

  1. Update API key for RubyGems

    moertel committed Aug 27, 2019
    Copy the full SHA
    51ba8e4 View commit details

Commits on Oct 15, 2021

  1. Prevent system tables from being truncated

    This would manifest as a permission denied error whenever there are more
    than two scenarios in a feature and the Postgres has only a single
    database object.
    
    From local inspection, only pg_catalog and information_schema show up in
    this query, although it might be wise in the future to exclude all pg_
    prefixed schemas.
    moertel committed Oct 15, 2021
    Copy the full SHA
    78d79d8 View commit details
  2. Merge pull request #20 from moertel/fix-truncating-system-tables

    Prevent system tables from being truncated
    Stefanie Grunwald authored Oct 15, 2021
    Copy the full SHA
    080c1d4 View commit details

Commits on Nov 25, 2021

  1. Fix broken unit test

    moertel committed Nov 25, 2021
    Copy the full SHA
    08cecb2 View commit details
  2. Set Ruby version from 2.3 to 2.5

    Because some gems require it
    moertel committed Nov 25, 2021
    Copy the full SHA
    4dff563 View commit details
  3. Copy the full SHA
    98b3ab7 View commit details
  4. Feature add minutes date placeholders

    Some kinds of tests require higher precision than `today` or `yesterday`. This PR adds support for the following placeholders:
    
    ```
    X minutes ago
    X minutes from now
    X hours ago
    X hours from now
    ```
    
    All timestamps will be added in UTC, so `+00:00` encoded at the end.
    Stefanie Grunwald authored Nov 25, 2021
    Copy the full SHA
    704e0e2 View commit details
  5. Bump version to 0.1.0

    Because now Ruby 2.5 or higher is required (rather than 2.0)
    moertel committed Nov 25, 2021
    Copy the full SHA
    f27b8a6 View commit details

Commits on Oct 18, 2022

  1. Introduce null mapper as step

    moertel committed Oct 18, 2022
    Copy the full SHA
    f4ca89a View commit details
  2. Merge pull request #22 from moertel/allow-null-mapper

    Introduce null mapper as step
    moertel authored Oct 18, 2022
    Copy the full SHA
    fa0f4dd View commit details
  3. Bump version to 0.1.1

    moertel committed Oct 18, 2022
    Copy the full SHA
    6ae867a View commit details
  4. Fix typo, bump to 0.1.2

    moertel committed Oct 18, 2022
    Copy the full SHA
    83659c5 View commit details
  5. Ensure compatibility with data placeholders

    In case of date placeholders being used in addition to NULL mappers,
    we'd run into the issue of Ruby Nil values being tried to match with
    regular expressions. This would cause some ugly exceptions in the code
    and unnecessarily cause tests to fail.
    
    This commit moves null mappings to the end of the mock value
    conversions, so we know that date placeholders are fine.
    moertel committed Oct 18, 2022
    Copy the full SHA
    9bb75b8 View commit details
  6. Bump version to 0.1.3

    moertel committed Oct 18, 2022
    Copy the full SHA
    cd86e44 View commit details
  7. Copy the full SHA
    ae56c3f View commit details
  8. Merge pull request #23 from moertel/fix-matcher

    Fix values being converted to null accidentally
    moertel authored Oct 18, 2022
    Copy the full SHA
    38e2d34 View commit details
  9. Bump to version 0.1.4

    moertel committed Oct 18, 2022
    Copy the full SHA
    3512478 View commit details
  10. Copy the full SHA
    dd05ada View commit details
  11. Merge pull request #24 from moertel/fix-value-matcher-for-nulls

    Fix value matcher if null value does not match
    moertel authored Oct 18, 2022
    Copy the full SHA
    661ec71 View commit details
  12. Bump version to 0.1.5

    moertel committed Oct 18, 2022
    Copy the full SHA
    0e68bd9 View commit details
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ script:
deploy:
provider: rubygems
api_key:
secure: SL1Wqrqa61Es8ogFckEUsq04mrZlWET+t3XfL1YkQNMoMeTu56E21uZViK8/54+QEao2abYVEDNHzSy0Z7Q2OuLap9guCeb69oLXUwDO3sX8kaHIlRUlECXIWNTdyNNmPB+jCOWVwvZgsyI2xI7UR7VTI03vWv4jXFh27KzPZNHwP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/GZd5nwHqr0KXBgFDqL1puHtcjHT5lhRY9K+QLhFBw/A/gJuTA+5aLQnfmd8q0JMT//kHNdzQLl89T+ZE6FIfTKqiFPdhETGaIwnqXISo=
gem: squcumber-postgres
on:
tags: true
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
FROM ruby:2.3.0 as builder
FROM ruby:2.5.0 as builder
COPY ./lib lib
COPY ./spec spec
COPY ./Rakefile .
COPY ./Gemfile .
COPY ./squcumber-postgres.gemspec .
RUN gem build squcumber-postgres.gemspec

FROM ruby:2.3.0
FROM ruby:2.5.0
ENV CUSTOM_STEPS_DIR /custom_step_definitions
VOLUME /custom_step_definitions
VOLUME /features
2 changes: 1 addition & 1 deletion Dockerfile_tests
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ruby:2.3.0
FROM ruby:2.5.0

COPY ./squcumber-postgres.gemspec squcumber-postgres.gemspec
COPY ./Gemfile Gemfile
2 changes: 1 addition & 1 deletion lib/squcumber-postgres/mock/database.rb
Original file line number Diff line number Diff line change
@@ -36,7 +36,7 @@ def setup(schemas)

def truncate_all_tables
@testing_database
.exec("select schemaname || '.' || tablename as schema_and_table from pg_tables where tableowner = '#{ENV['DB_USER']}'")
.exec("select schemaname || '.' || tablename as schema_and_table from pg_tables where tableowner = '#{ENV['DB_USER']}' and schemaname not in ('pg_catalog', 'information_schema')")
.map { |row| row['schema_and_table'] }
.each { |schema_and_table| exec("truncate table #{schema_and_table}") }
end
19 changes: 14 additions & 5 deletions lib/squcumber-postgres/step_definitions/common_steps.rb
Original file line number Diff line number Diff line change
@@ -58,6 +58,10 @@
@defaults[table] = data.hashes[0]
end

Given(/^"([^\s"]+)" as null value$/) do |null_placeholder|
@null ||= null_placeholder
end

Given(/a clean environment/) do
silence_streams(STDERR) do
TESTING_DATABASE.truncate_all_tables()
@@ -74,6 +78,7 @@
end

mock_data = convert_mock_values(mock_data) if placeholder
mock_data = convert_null_values(mock_data, @null) if @null

TESTING_DATABASE.mock(
Hash["#{schema}.#{table}", mock_data]
@@ -112,12 +117,13 @@
actual = @result[0..(data.hashes.length - 1)] || []
expected = data.hashes || []
expected = convert_mock_values(expected) if placeholder
expected = convert_null_values(expected, @null) if @null

sanity_check_result(actual, expected)

expected.each_with_index do |hash, i|
raise("Does not start with expected result, got:\n#{format_error(data, actual)}") unless actual[i].all? do |key, value|
values_match(value, hash[key]) # actual,expected
values_match(value, hash[key], null=@null) # actual,expected
end
end
end
@@ -126,13 +132,14 @@
actual = @result || []
expected = data.hashes || []
expected = convert_mock_values(expected) if placeholder
expected = convert_null_values(expected, @null) if @null

sanity_check_result(actual, expected)

expected.each do |hash|
raise("Result is not included, got:\n#{format_error(data, actual)}") unless actual.any? do |row|
row.all? do |key, value|
values_match(value, hash[key]) # actual, expected
values_match(value, hash[key], null=@null) # actual, expected
end
end
end
@@ -142,13 +149,14 @@
actual = @result || []
expected = data.hashes || []
expected = convert_mock_values(expected) if placeholder
expected = convert_null_values(expected, @null) if @null

sanity_check_result(actual, expected)

expected.each do |hash|
raise("Result is included, got:\n#{format_error(data, actual)}") if actual.any? do |row|
row.all? do |key, value|
values_match(value, hash[key]) # actual,expected
values_match(value, hash[key], null=@null) # actual,expected
end
end
end
@@ -158,20 +166,21 @@
actual = @result || []
expected = data.hashes || []
expected = convert_mock_values(expected) if placeholder
expected = convert_null_values(expected, @null) if @null

sanity_check_result(actual, expected)

raise("Does not match exactly, got:\n#{format_error(data, actual)}") if actual.length != expected.length

actual.each_with_index do |row, i|
raise("Does not match exactly, got:\n#{format_error(data, actual)}") unless (expected[i] || {}).all? do |key, value|
values_match(row[key], value) # actual,expected
values_match(row[key], value, null=@null) # actual,expected
end
end

expected.each_with_index do |hash, i|
raise("Does not match exactly, got:\n#{format_error(data, actual)}") unless (actual[i] || {}).all? do |key, value|
values_match(value, hash[key]) # actual,expected
values_match(value, hash[key], null=@null) # actual,expected
end
end
end
34 changes: 33 additions & 1 deletion lib/squcumber-postgres/support/matchers.rb
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@ def sanity_check_result(actual, expected)
end
end

def values_match(actual, expected)
def values_match(actual, expected, null=nil)
if expected.eql?('today')
actual.match(/#{Regexp.quote(Date.today.to_s)}/)
elsif expected.eql?('yesterday')
@@ -21,6 +21,8 @@ def values_match(actual, expected)
actual.match(/^#{Regexp.quote(Date.today.to_s)} \d{2}:\d{2}:\d{2}$/)
elsif expected.eql?('sometime yesterday')
actual.match(/^#{Regexp.quote((Date.today - 1).to_s)} \d{2}:\d{2}:\d{2}$/)
elsif !null.nil? and !expected.nil? and expected.eql?(null)
actual.nil?
elsif expected.eql?('any_string')
true if actual.is_a?(String) or actual.nil?
elsif expected.eql?('false') or expected.eql?('true')
@@ -33,6 +35,24 @@ def values_match(actual, expected)
end
end

def convert_null_values(mock_data, null)
mock_data.map do |entry|
entry.each do |key, value|
entry[key] = convert_null_value(value, null)
end
end
end

def convert_null_value(value, null)
if null.nil?
value
elsif value.eql?(null)
nil
else
value
end
end

def convert_mock_values(mock_data)
mock_data.map do |entry|
entry.each do |key, value|
@@ -85,6 +105,12 @@ def convert_mock_value(value)
Date.today.prev_year
when /next year/
Date.today.next_year
when /\s*\d+\s+minute(s)?\s+ago\s*?/
number_of_minutes = value.match(/\d+/)[0].to_i
DateTime.now - (number_of_minutes/24.0/60.0)
when /\s*\d+\s+hours(s)?\s+ago\s*?/
number_of_hours = value.match(/\d+/)[0].to_i
DateTime.now - (number_of_hours/24.0)
when /\s*\d+\s+month(s)?\s+ago\s*?/
number_of_months = value.match(/\d+/)[0].to_i
Date.today.prev_month(number_of_months)
@@ -94,6 +120,12 @@ def convert_mock_value(value)
when /\s*\d+\s+year(s)?\s+ago\s*/
number_of_years = value.match(/\d+/)[0].to_i
Date.today.prev_year(number_of_years)
when /\s*\d+\s+minute(s)?\s+from now\s*?/
number_of_minutes = value.match(/\d+/)[0].to_i
DateTime.now + (number_of_minutes/24.0/60.0)
when /\s*\d+\s+hours(s)?\s+from now\s*?/
number_of_hours = value.match(/\d+/)[0].to_i
DateTime.now + (number_of_hours/24.0)
when /\s*\d+\s+month(s)?\s+from now\s*?/
number_of_months = value.match(/\d+/)[0].to_i
Date.today.next_month(number_of_months)
2 changes: 1 addition & 1 deletion spec/squcumber-postgres/mock/database_spec.rb
Original file line number Diff line number Diff line change
@@ -182,7 +182,7 @@ module Squcumber::Postgres::Mock
end

it 'asks the testing database for currently existing tables in production schemas' do
expect(testing_database).to have_received(:exec).with(/^\s*select\s+schemaname\s+\|\|\s+'\.'\s+\|\|\s+tablename\s+as schema\_and\_table\s+from\s+pg_tables\s+where\s+tableowner\s*=\s*'some_user'\s*;?\s*$/)
expect(testing_database).to have_received(:exec).with(/^\s*select\s+schemaname\s+\|\|\s+'\.'\s+\|\|\s+tablename\s+as schema\_and\_table\s+from\s+pg_tables\s+where\s+tableowner\s*=\s*'some_user'\s+and\s+schemaname\s+not\s+in\s+\('pg_catalog',\s+'information_schema'\s*\)\s*;?\s*$/)
end

it 'truncates the returned tables in the testing database' do
78 changes: 78 additions & 0 deletions spec/squcumber-postgres/support/matchers_spec.rb
Original file line number Diff line number Diff line change
@@ -7,6 +7,84 @@ module Squcumber

before(:each) do
allow(Date).to receive(:today).and_return Date.new(2017, 7, 15)
allow(DateTime).to receive(:now).and_return DateTime.new(2017, 7, 15, 10, 20, 30)
end

describe '#convert_null_values' do
context 'when no mapping is defined' do
it 'leaves the original value as it is' do
expect(dummy_class.new.convert_null_value('some_value', nil)).to eql('some_value')
end
end
context 'when a mapping is defined' do
context 'and the value matches the mapper' do
it 'maps the value to nil' do
expect(dummy_class.new.convert_null_value('some_value', 'some_value')).to eql(nil)
end
end
context 'and the value does not match the mapper' do
it 'maps the value to itself' do
expect(dummy_class.new.convert_null_value('some_value', 'some_other_value')).to eql('some_value')
end
end
end
end

describe '#values_match' do
context 'when no null mapping is defined' do
it 'always matches if there was no expectation' do
actual = 'some_value'
expected = nil
expect(dummy_class.new.values_match(actual, expected)).to eql(true)
end
it 'never matches if the actual value is null' do
actual = nil
expected = 'some_value'
expect(dummy_class.new.values_match(actual, expected)).to eql(false)
end
end
context 'when some null mapping is defined' do
it 'always matches if there was no expectation' do
actual = 'some_value'
expected = nil
expect(dummy_class.new.values_match(actual, expected, null='whatever')).to eql(true)
end
it 'matches the set null placeholder' do
actual = nil
expected = 'some_value'
null = 'some_value'
expect(dummy_class.new.values_match(actual, expected, null=null)).to eql(true)
end
it 'does not match if the null placeholder does not match' do
actual = nil
expected = 'some_value'
null = 'some_other_value'
expect(dummy_class.new.values_match(actual, expected, null)).to eql(false)
end
it 'matches if the null placeholder does not match but the values do' do
actual = 'some_value'
expected = 'some_value'
null = 'some_other_value'
expect(dummy_class.new.values_match(actual, expected, null)).to eql(true)
end
end
end

describe '#convert_mock_values' do
context 'with minute placeholders' do
it 'sets minutes in the future' do
expect(dummy_class.new.convert_mock_value('10 minutes from now')).to eql('2017-07-15T10:30:30+00:00')
end
it 'sets minutes in the past' do
expect(dummy_class.new.convert_mock_value('10 minutes ago')).to eql('2017-07-15T10:10:30+00:00')
end
it 'sets hours in the future' do
expect(dummy_class.new.convert_mock_value('9 hours from now')).to eql('2017-07-15T19:20:30+00:00')
end
it 'sets hours in the past' do
expect(dummy_class.new.convert_mock_value('9 hours ago')).to eql('2017-07-15T01:20:30+00:00')
end
end
end

describe '#convert_mock_values' do
8 changes: 4 additions & 4 deletions squcumber-postgres.gemspec
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
Gem::Specification.new do |s|
s.name = 'squcumber-postgres'
s.version = '0.0.12'
s.version = '0.1.5'
s.default_executable = 'squcumber-postgres'

s.licenses = ['MIT']
s.required_ruby_version = '>= 2.0'
s.required_ruby_version = '>= 2.5'
s.required_rubygems_version = Gem::Requirement.new('>= 0') if s.respond_to? :required_rubygems_version=
s.authors = ['Stefanie Grunwald']
s.date = %q{2019-08-27}
s.email = %q{steffi@physics.org}
s.date = %q{2022-10-18}
s.email = %q{hi@moer.tel}
s.files = [
'Rakefile',
'lib/squcumber-postgres.rb',