Hopefully fix intermittent PG test fail in CI

Test would fail when FFaker::Color.name returned the same exact
string twice in a row. This is not FFaker's fault.

Incidentally, the FFaker color list currently has 19 entries.
(https://github.com/ffaker/ffaker/blob/master/lib/ffaker/data/color/names_list)
The test suite runs this postgres-specific test six times (3 rubies * 2 major
versions of rails). So, I think the chance of the test suite failing was
(1 / 19)^2 * 6, or 0.016, or about 2%.
This commit is contained in:
Jared Beck 2015-12-19 19:58:49 -05:00
parent 7280169f03
commit 811dc0ed47
2 changed files with 15 additions and 11 deletions

View File

@ -56,27 +56,31 @@ if JsonVersion.table_exists?
let(:tropical_fruit_names) { %w(coconut pineapple kiwi mango melon) }
let(:fruit) { Fruit.new }
let(:name) { 'pomegranate' }
let(:color) { FFaker::Color.name }
let(:color) { %w[red green] }
before do
fruit.update_attributes!(:name => name)
fruit.update_attributes!(:name => tropical_fruit_names.sample, :color => color)
fruit.update_attributes!(:name => fruit_names.sample, :color => FFaker::Color.name)
fruit.update_attributes!(:name => tropical_fruit_names.sample, :color => color[0])
fruit.update_attributes!(:name => fruit_names.sample, :color => color[1])
end
it "should be able to locate versions according to their `object_changes` contents" do
expect(fruit.versions.where_object_changes(:name => name)).to eq(fruit.versions[0..1])
expect(fruit.versions.where_object_changes(:color => color)).to eq(fruit.versions[1..2])
it "finds versions according to their `object_changes` contents" do
expect(
fruit.versions.where_object_changes(name: name)
).to match_array(fruit.versions[0..1])
expect(
fruit.versions.where_object_changes(color: color[0])
).to match_array(fruit.versions[1..2])
end
it "should be able to handle queries for multiple attributes" do
expect(fruit.versions.where_object_changes(:color => color, :name => name)).to eq([fruit.versions[1]])
it "finds versions with multiple attributes changed" do
expect(
fruit.versions.where_object_changes(color: color[0], name: name)
).to match_array([fruit.versions[1]])
end
end
end
end
end
end
end

View File

@ -12,4 +12,4 @@ foo:
bar:
<<: *test
database: paper_trail_bar
database: paper_trail_bar