test/segment_test.rb in createsend-2.5.1 vs test/segment_test.rb in createsend-3.0.0

- old
+ new

@@ -1,38 +1,36 @@ require File.dirname(__FILE__) + '/helper' class SegmentTest < Test::Unit::TestCase - context "when an api caller is authenticated" do + multiple_contexts "authenticated_using_oauth_context", "authenticated_using_api_key_context" do setup do - @api_key = '123123123123123123123' - CreateSend.api_key @api_key - @segment = CreateSend::Segment.new('98y2e98y289dh89h938389') + @segment = CreateSend::Segment.new @auth, '98y2e98y289dh89h938389' end should "create a new segment" do list_id = "2983492834987394879837498" rules = [ { :Subject => "EmailAddress", :Clauses => [ "CONTAINS example.com" ] } ] - stub_post(@api_key, "segments/#{list_id}.json", "create_segment.json") - res = CreateSend::Segment.create list_id, "new segment title", rules + stub_post(@auth, "segments/#{list_id}.json", "create_segment.json") + res = CreateSend::Segment.create @auth, list_id, "new segment title", rules res.should == "0246c2aea610a3545d9780bf6ab89006" end should "update a segment" do rules = [ { :Subject => "Name", :Clauses => [ "EQUALS subscriber" ] } ] - stub_put(@api_key, "segments/#{@segment.segment_id}.json", nil) + stub_put(@auth, "segments/#{@segment.segment_id}.json", nil) @segment.update "new title for segment", rules end - + should "add a rule to a segment" do clauses = [ "CONTAINS example.com" ] - stub_post(@api_key, "segments/#{@segment.segment_id}/rules.json", nil) + stub_post(@auth, "segments/#{@segment.segment_id}/rules.json", nil) @segment.add_rule "EmailAddress", clauses end should "get the active subscribers for a particular segment in the list" do min_date = "2010-01-01" - stub_get(@api_key, "segments/#{@segment.segment_id}/active.json?pagesize=1000&orderfield=email&page=1&orderdirection=asc&date=#{CGI.escape(min_date)}", + stub_get(@auth, "segments/#{@segment.segment_id}/active.json?pagesize=1000&orderfield=email&page=1&orderdirection=asc&date=#{CGI.escape(min_date)}", "segment_subscribers.json") res = @segment.subscribers min_date res.ResultsOrderedBy.should == "email" res.OrderDirection.should == "asc" res.PageNumber.should == 1 @@ -45,18 +43,18 @@ res.Results.first.Name.should == "Person One" res.Results.first.Date.should == "2010-10-27 13:13:00" res.Results.first.State.should == "Active" res.Results.first.CustomFields.should == [] end - + should "delete a segment" do - stub_delete(@api_key, "segments/#{@segment.segment_id}.json", nil) + stub_delete(@auth, "segments/#{@segment.segment_id}.json", nil) @segment.delete end should "get the details of a segment" do - stub_get(@api_key, "segments/#{@segment.segment_id}.json", "segment_details.json") + stub_get(@auth, "segments/#{@segment.segment_id}.json", "segment_details.json") res = @segment.details res.ActiveSubscribers.should == 0 res.Rules.size.should == 2 res.Rules.first.Subject.should == "EmailAddress" res.Rules.first.Clauses.size.should == 1 @@ -65,10 +63,10 @@ res.SegmentID.should == "dba84a225d5ce3d19105d7257baac46f" res.Title.should == "My Segment" end should "clear a segment's rules" do - stub_delete(@api_key, "segments/#{@segment.segment_id}/rules.json", nil) + stub_delete(@auth, "segments/#{@segment.segment_id}/rules.json", nil) @segment.clear_rules end end end