Skip to content

Instantly share code, notes, and snippets.

@otaviocardoso
Created October 3, 2012 21:50
Show Gist options
  • Save otaviocardoso/3830099 to your computer and use it in GitHub Desktop.
Save otaviocardoso/3830099 to your computer and use it in GitHub Desktop.
Atualização de teste do filtro de sampler
@@ -8,33 +8,21 @@ describe Sampler do
describe "filter" do
shared_examples "a sampler filter" do |hash|
it "should return the correct sampler" do
- attrs = {}
- filter = {}
-
- hash.each do |key, value|
- attrs = attrs.merge({ key => value[:real_value] })
- end
-
- sampler.update_attributes attrs
-
- hash.each do |key, value|
- filter = filter.merge({ key => value[:query_value]})
- end
-
- samplers = Sampler.all
- samplers = samplers.filter(filter)
+ sampler.update_attributes(hash[:real_value])
+ samplers = Sampler.all.filter(hash[:query])
samplers.should include sampler
end
end
- it_behaves_like 'a sampler filter', name: { real_value: 'João', query_value: 'joao' }
- it_behaves_like 'a sampler filter', name: { real_value: 'Ricardo', query_value: 'ric' }
+ it_behaves_like 'a sampler filter', real_value: { name: 'João' }, query: { name: 'joao' }
+ it_behaves_like 'a sampler filter', real_value: { name: 'Ricardo' }, query: { name: 'ric' }
- it_behaves_like 'a sampler filter', email: { real_value: 'exemplo@g.com', query_value: 'exemplo' }
- it_behaves_like 'a sampler filter', email: { real_value: 'exemplo@g.com', query_value: 'g.com' }
+ it_behaves_like 'a sampler filter', real_value: { email: 'exemplo@g.com' }, query: { email: 'exemplo' }
+ it_behaves_like 'a sampler filter', real_value: { email: 'exemplo@g.com' }, query: { email: 'g.com' }
- it_behaves_like 'a sampler filter', email: { real_value: 'exemplo@g.com', query_value: 'exemplo' }, name: { real_value: 'Ricardo', query_value: 'ric' }
+ it_behaves_like 'a sampler filter', real_value: { email: 'exemplo@g.com', name: 'Ricardo' },
+ query: { email: 'exemplo', name: 'ric' }
end
describe '#has_scheduling_on?' do
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment