Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show the type of field that violated a uniqueness constraint #1205

Merged
merged 2 commits into from
May 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/helpers/unique_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def method_missing(name, *arguments)
return result
end

raise RetryLimitExceeded
raise RetryLimitExceeded, "Retry limit exceeded for #{name}"
Copy link
Member

@vbrazo vbrazo May 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AndrewRayCode thanks for contributing 🥇

Could you write/modify the specs to make sure that this description is working properly?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

end

RetryLimitExceeded = Class.new(StandardError)
Expand Down
15 changes: 15 additions & 0 deletions test/test_faker_unique_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,21 @@ def stubbed_generator.test
end
end

def test_includes_field_name_in_error
stubbed_generator = Object.new
def stubbed_generator.my_field
1
end

generator = Faker::UniqueGenerator.new(stubbed_generator, 3)

generator.my_field

assert_raise_message "Retry limit exceeded for my_field" do
generator.my_field
end
end

def test_clears_unique_values
stubbed_generator = Object.new
def stubbed_generator.test
Expand Down