Skip to content

Commit

Permalink
Tests for Candidates#each.
Browse files Browse the repository at this point in the history
  • Loading branch information
ignat-z committed Mar 4, 2015
1 parent 307cf17 commit c9668dd
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions test/candidates_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,30 @@ def slug_candidates
end
end

test "allows to iterate through candidates without passing block" do
klass = Class.new model_class do
def slug_candidates
:name
end
end
with_instances_of klass do |_, city|
candidates = FriendlyId::Candidates.new(city, city.slug_candidates)
assert_equal candidates.each, ['new-york']
end
end

test "iterates through candidates with passed block" do
klass = Class.new model_class do
def slug_candidates
:name
end
end
with_instances_of klass do |_, city|
collected_candidates = []
candidates = FriendlyId::Candidates.new(city, city.slug_candidates)
candidates.each { |candidate| collected_candidates << candidate }
assert_equal collected_candidates, ['new-york']
end
end

end

0 comments on commit c9668dd

Please sign in to comment.