diff --git a/features/filter.feature b/features/filter.feature new file mode 100644 index 0000000..2d9fbcf --- /dev/null +++ b/features/filter.feature @@ -0,0 +1,18 @@ +Feature: Filters + Background: + Given I have a gnap connection + And I have the "delicious" publisher + + Scenario: Getting a named filter + Then I should be able to get the "bazqux" filter + + Scenario: Creating a filter + Then I should be able to create filter "foobar" + + Scenario Outline: Adding rules + Then I should be able to create filter "foobar" + And add an "" rule with a value of "" + Examples: + | type | value | + | actor | steve | + | tag | election | diff --git a/features/step_definitions/filter_steps.rb b/features/step_definitions/filter_steps.rb new file mode 100644 index 0000000..e9faf73 --- /dev/null +++ b/features/step_definitions/filter_steps.rb @@ -0,0 +1,18 @@ +Given /^I have the "([^\"]*)" publisher$/ do |publisher| + @publisher = @gnap.publisher(publisher) +end + +Then /^I should be able to get the "([^\"]*)" filter$/ do |filter| + @publisher.filter(filter).should be_kind_of(Gnap::Filter) +end + +Then /^I should be able to create filter "([^\"]*)"$/ do |name| + @publisher.should_receive(:post).with("/gnip/publishers/#{@publisher}/filters.xml", "bazqux") + @filter = @publisher.create_filter!("foobar", :actor => "bazqux") +end + +Then /^add an "([^\"]*)" rule with a value of "([^\"]*)"$/ do |type, value| + @filter.should_receive(:post).with("/gnip/publishers/delicious/filters/#{@filter}/rules.xml", "#{value}") + @filter.add_rule!(type, value) +end + diff --git a/features/step_definitions/publisher_steps.rb b/features/step_definitions/publisher_steps.rb index e5b5b1e..314b476 100644 --- a/features/step_definitions/publisher_steps.rb +++ b/features/step_definitions/publisher_steps.rb @@ -1,8 +1,3 @@ -Given /^I have a gnap connection$/ do - @gnap = Gnap.new('fakeuser', 'fakepassword') -end - - When /^I get "([^\"]*)" notifications$/ do |publisher| @publisher = @gnap.publisher(publisher) @publisher.should_receive(:get). @@ -16,10 +11,6 @@ @publisher.should be_kind_of(Gnap::Publisher) end -Then /^there should be (\d*) notifications$/ do |n| - @notifications.size.should == n.to_i -end - Then /^the number (\d*) notification (\w*) should be "([^\"]*)"$/ do |n, method, value| @notifications[n.to_i].send(method).should == value end diff --git a/features/step_definitions/shared_steps.rb b/features/step_definitions/shared_steps.rb new file mode 100644 index 0000000..f83b90d --- /dev/null +++ b/features/step_definitions/shared_steps.rb @@ -0,0 +1,8 @@ +Given /^I have a gnap connection$/ do + @gnap = Gnap.new('fakeuser', 'fakepassword') +end + +Then /^there should be (\d*) notifications$/ do |n| + @notifications.size.should == n.to_i +end + diff --git a/lib/gnap/filter.rb b/lib/gnap/filter.rb index 5b56971..c381bc4 100644 --- a/lib/gnap/filter.rb +++ b/lib/gnap/filter.rb @@ -44,6 +44,10 @@ def rules_path "#{path}/rules.xml" end + def to_s + @filter + end + private def rules_to_xml doc, rules diff --git a/lib/gnap/publisher.rb b/lib/gnap/publisher.rb index aedb670..84b783a 100644 --- a/lib/gnap/publisher.rb +++ b/lib/gnap/publisher.rb @@ -21,12 +21,17 @@ def filter name def create_filter! name, rules data = Filter.new(@config, @publisher, name, rules).to_xml post(path + NEW_FILTER_PATH % @publisher, data) + filter(name) end def path PATH % @publisher end + def to_s + @publisher + end + private def build_notification_path time time = time.to_s(:gnap) if Time === time