test/subscriber_test.rb in createsend-1.0.1 vs test/subscriber_test.rb in createsend-1.0.2

- old
+ new

@@ -50,10 +50,19 @@ stub_put(@api_key, "subscribers/#{@list_id}.json?email=#{CGI.escape(email)}", nil) custom_fields = [ { :Key => 'website', :Value => 'http://example.com/' } ] @subscriber.update new_email, "Subscriber", custom_fields, true @subscriber.email_address.should == new_email end + + should "update a subscriber with custom fields including the clear option" do + email = "subscriber@example.com" + new_email = "new_email_address@example.com" + stub_put(@api_key, "subscribers/#{@list_id}.json?email=#{CGI.escape(email)}", nil) + custom_fields = [ { :Key => 'website', :Value => '', :Clear => true } ] + @subscriber.update new_email, "Subscriber", custom_fields, true + @subscriber.email_address.should == new_email + end should "import many subscribers at once" do stub_post(@api_key, "subscribers/#{@list_id}/import.json", "import_subscribers.json") subscribers = [ { :EmailAddress => "example+1@example.com", :Name => "Example One" }, @@ -66,10 +75,40 @@ import_result.TotalExistingSubscribers.should == 0 import_result.TotalNewSubscribers.should == 3 import_result.DuplicateEmailsInSubmission.size.should == 0 end + should "import many subscribers at once, and start subscription-based autoresponders" do + stub_post(@api_key, "subscribers/#{@list_id}/import.json", "import_subscribers.json") + subscribers = [ + { :EmailAddress => "example+1@example.com", :Name => "Example One" }, + { :EmailAddress => "example+2@example.com", :Name => "Example Two" }, + { :EmailAddress => "example+3@example.com", :Name => "Example Three" }, + ] + import_result = CreateSend::Subscriber.import @list_id, subscribers, true, true + import_result.FailureDetails.size.should == 0 + import_result.TotalUniqueEmailsSubmitted.should == 3 + import_result.TotalExistingSubscribers.should == 0 + import_result.TotalNewSubscribers.should == 3 + import_result.DuplicateEmailsInSubmission.size.should == 0 + end + + should "import many subscribers at once with custom fields, including the clear option" do + stub_post(@api_key, "subscribers/#{@list_id}/import.json", "import_subscribers.json") + subscribers = [ + { :EmailAddress => "example+1@example.com", :Name => "Example One", :CustomFields => [ { :Key => 'website', :Value => '', :Clear => true } ] }, + { :EmailAddress => "example+2@example.com", :Name => "Example Two", :CustomFields => [ { :Key => 'website', :Value => '', :Clear => false } ] }, + { :EmailAddress => "example+3@example.com", :Name => "Example Three", :CustomFields => [ { :Key => 'website', :Value => '', :Clear => false } ] }, + ] + import_result = CreateSend::Subscriber.import @list_id, subscribers, true + import_result.FailureDetails.size.should == 0 + import_result.TotalUniqueEmailsSubmitted.should == 3 + import_result.TotalExistingSubscribers.should == 0 + import_result.TotalNewSubscribers.should == 3 + import_result.DuplicateEmailsInSubmission.size.should == 0 + end + should "import many subscribers at once with partial success" do # Stub request with 400 Bad Request as the expected response status stub_post(@api_key, "subscribers/#{@list_id}/import.json", "import_subscribers_partial_success.json", 400) subscribers = [ { :EmailAddress => "example+1@example", :Name => "Example One" }, @@ -104,7 +143,11 @@ history.first.Actions.first.Date.should == "2010-10-12 13:18:00" history.first.Actions.first.IPAddress.should == "192.168.126.87" history.first.Actions.first.Detail.should == "" end + should "delete a subscriber" do + stub_delete(@api_key, "subscribers/#{@subscriber.list_id}.json?email=#{CGI.escape(@subscriber.email_address)}", nil) + @subscriber.delete + end end end \ No newline at end of file